|
8 | 8 | using System.Linq; |
9 | 9 | using System.Text.RegularExpressions; |
10 | 10 | using System.Xml; |
| 11 | +using DocumentFormat.OpenXml; |
| 12 | +using DocumentFormat.OpenXml.Wordprocessing; |
11 | 13 | using NUnit.Framework; |
12 | 14 | using SIL.FieldWorks.Common.Framework; |
13 | 15 | using SIL.FieldWorks.Common.FwUtils; |
|
19 | 21 | using SIL.TestUtilities; |
20 | 22 | using XCore; |
21 | 23 | using static SIL.FieldWorks.XWorks.LcmWordGenerator; |
| 24 | +using W14 = DocumentFormat.OpenXml.Office2010.Word; |
22 | 25 | // ReSharper disable StringLiteralTypo |
23 | 26 |
|
24 | 27 | namespace SIL.FieldWorks.XWorks |
@@ -59,6 +62,7 @@ static LcmWordGeneratorTests() |
59 | 62 | WordNamespaceManager.AddNamespace("w", openXmlSchema); |
60 | 63 | WordNamespaceManager.AddNamespace("r", openXmlSchema); |
61 | 64 | WordNamespaceManager.AddNamespace("wp", openXmlSchema); |
| 65 | + WordNamespaceManager.AddNamespace("w14", "http://schemas.microsoft.com/office/word/2010/wordml"); |
62 | 66 | } |
63 | 67 |
|
64 | 68 | [OneTimeSetUp] |
@@ -210,6 +214,62 @@ public void Setup() |
210 | 214 | DefaultSettings.StylesGenerator.AddGlobalStyles(null, new ReadOnlyPropertyTable(m_propertyTable)); |
211 | 215 | } |
212 | 216 |
|
| 217 | + [Test] |
| 218 | + public void GenerateCharacterStyleFromLcmStyleSheet_OpenTypeFontFeatures_AddsWordTypographyProperties() |
| 219 | + { |
| 220 | + var styleName = "WordFeatureStyle" + Guid.NewGuid().ToString("N"); |
| 221 | + var fontInfo = new FontInfo { m_features = { ExplicitValue = "liga=0,lnum=1,pnum=1,calt=0,ss02=0,cv01=2" } }; |
| 222 | + var projectStyle = new TestStyle(fontInfo, Cache) { Name = styleName, IsParagraphStyle = false }; |
| 223 | + FontHeightAdjuster.StyleSheetFromPropertyTable(m_propertyTable).Styles.Add(projectStyle); |
| 224 | + |
| 225 | + var style = WordStylesGenerator.GenerateCharacterStyleFromLcmStyleSheet(styleName, Cache.DefaultVernWs, |
| 226 | + new ReadOnlyPropertyTable(m_propertyTable)); |
| 227 | + |
| 228 | + var runProps = style.GetFirstChild<StyleRunProperties>(); |
| 229 | + AssertWordTypographyProperties(runProps, W14.LigaturesValues.None, W14.NumberFormValues.Lining, |
| 230 | + W14.NumberSpacingValues.Proportional, false, 2U, false); |
| 231 | + } |
| 232 | + |
| 233 | + [Test] |
| 234 | + public void GetExplicitFontProperties_OpenTypeFontFeatures_AddsWordTypographyProperties() |
| 235 | + { |
| 236 | + var fontInfo = new FontInfo { m_features = { ExplicitValue = "liga=1,clig=1,onum=1,tnum=1,calt=1,ss03=1,cv01=2" } }; |
| 237 | + |
| 238 | + var runProps = WordStylesGenerator.GetExplicitFontProperties(fontInfo); |
| 239 | + |
| 240 | + AssertWordTypographyProperties(runProps, W14.LigaturesValues.StandardContextual, W14.NumberFormValues.OldStyle, |
| 241 | + W14.NumberSpacingValues.Tabular, true, 3U, true); |
| 242 | + } |
| 243 | + |
| 244 | + private static void AssertWordTypographyProperties(OpenXmlCompositeElement runProps, |
| 245 | + W14.LigaturesValues ligaturesValue, W14.NumberFormValues numberFormValue, |
| 246 | + W14.NumberSpacingValues numberSpacingValue, bool contextualAlternativesValue, |
| 247 | + uint stylisticSetId, bool stylisticSetValue) |
| 248 | + { |
| 249 | + Assert.That(runProps, Is.Not.Null); |
| 250 | + var ligatures = runProps.GetFirstChild<W14.Ligatures>(); |
| 251 | + Assert.That(ligatures, Is.Not.Null); |
| 252 | + Assert.That(ligatures.Val.Value, Is.EqualTo(ligaturesValue)); |
| 253 | + |
| 254 | + var numberForm = runProps.GetFirstChild<W14.NumberingFormat>(); |
| 255 | + Assert.That(numberForm, Is.Not.Null); |
| 256 | + Assert.That(numberForm.Val.Value, Is.EqualTo(numberFormValue)); |
| 257 | + |
| 258 | + var numberSpacing = runProps.GetFirstChild<W14.NumberSpacing>(); |
| 259 | + Assert.That(numberSpacing, Is.Not.Null); |
| 260 | + Assert.That(numberSpacing.Val.Value, Is.EqualTo(numberSpacingValue)); |
| 261 | + |
| 262 | + var contextualAlternatives = runProps.GetFirstChild<W14.ContextualAlternatives>(); |
| 263 | + Assert.That(contextualAlternatives, Is.Not.Null); |
| 264 | + Assert.That(contextualAlternatives.Val.Value, Is.EqualTo(contextualAlternativesValue)); |
| 265 | + |
| 266 | + var stylisticSets = runProps.GetFirstChild<W14.StylisticSets>(); |
| 267 | + Assert.That(stylisticSets, Is.Not.Null); |
| 268 | + var styleSet = stylisticSets.Elements<W14.StyleSet>().Single(); |
| 269 | + Assert.That(styleSet.Id.Value, Is.EqualTo(stylisticSetId)); |
| 270 | + Assert.That(styleSet.Val.Value, Is.EqualTo(stylisticSetValue)); |
| 271 | + } |
| 272 | + |
213 | 273 |
|
214 | 274 | [Test] |
215 | 275 | public void GenerateWordDocForEntry_OneSenseWithGlossGeneratesCorrectResult() |
|
0 commit comments