public void ApplyingTtp() { AssembledStyles astyles = new AssembledStyles(); Assert.That(astyles.Chrp.ttvBold, Is.EqualTo((int)FwTextToggleVal.kttvOff)); ITsPropsBldr bldr = TsPropsBldrClass.Create(); bldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 47); bldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); ITsTextProps props = bldr.GetTextProps(); AssembledStyles result = astyles.ApplyTextProps(props); Assert.AreEqual(47, result.Ws); Assert.AreEqual(700, result.FontWeight); Assert.That(result.Chrp.ttvBold, Is.EqualTo((int)FwTextToggleVal.kttvForceOn)); }
public void StylesheetTests() { var stylesheet = new MockStylesheet(); var styles = new AssembledStyles(stylesheet); var styleBold = stylesheet.AddStyle("bold", false); var boldFontInfo = new MockCharStyleInfo(); styleBold.DefaultCharacterStyleInfo = boldFontInfo; boldFontInfo.Bold = new MockStyleProp <bool>() { Value = true, ValueIsSet = true }; ITsPropsBldr bldr = TsPropsBldrClass.Create(); bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "bold"); var props = bldr.GetTextProps(); var styles2 = styles.ApplyTextProps(props); Assert.That(styles2.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwBold)); // Another style with the same properties but different name does NOT produce the same AssembledStyles var styleBold2 = stylesheet.AddStyle("bold2", false); styleBold2.DefaultCharacterStyleInfo = boldFontInfo; bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "bold2"); props = bldr.GetTextProps(); var styles2b = styles.ApplyTextProps(props); Assert.That(styles2b.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwBold)); Assert.That(styles2b.StyleName, Is.EqualTo("bold2")); Assert.That(styles2b, Is.Not.EqualTo(styles2)); var styleSize14 = stylesheet.AddStyle("size14", false); var size14FontInfo = new MockCharStyleInfo(); styleSize14.DefaultCharacterStyleInfo = size14FontInfo; size14FontInfo.FontSize = new MockStyleProp <int>() { Value = 14000, ValueIsSet = true }; size14FontInfo.Bold = new MockStyleProp <bool>(); // no value set, should ignore bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "size14"); props = bldr.GetTextProps(); var styles3 = styles.ApplyTextProps(props); Assert.That(styles3.StyleName, Is.EqualTo("size14")); Assert.That(styles3.FontSize, Is.EqualTo(14000)); Assert.That(styles3.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwNormal)); // Since styleSize14 does NOT affect bold, applying it to styles2 should yield 14-pt bold var styles4 = styles2.ApplyTextProps(props); Assert.That(styles4.FontSize, Is.EqualTo(14000)); Assert.That(styles4.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwBold)); // Check that we can explicitly turn bold off. var styleNotBold = stylesheet.AddStyle("notBold", false); var notBoldInfo = new MockCharStyleInfo(); styleNotBold.DefaultCharacterStyleInfo = notBoldInfo; notBoldInfo.Bold = new MockStyleProp <bool>() { Value = false, ValueIsSet = true }; bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "notBold"); props = bldr.GetTextProps(); var styles5 = styles4.ApplyTextProps(props); Assert.That(styles3.FontSize, Is.EqualTo(14000)); Assert.That(styles3.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwNormal)); // now try an override font size. size14_16bold is 14 point for most writing systems, 16 point for 37. // It is also bold for all WSs. var styleSize14_16bold = stylesheet.AddStyle("size14_16bold", false); var size14boldFontInfo = new MockCharStyleInfo(); styleSize14_16bold.DefaultCharacterStyleInfo = size14boldFontInfo; size14boldFontInfo.FontSize = new MockStyleProp <int>() { Value = 14000, ValueIsSet = true }; size14boldFontInfo.Bold = new MockStyleProp <bool>() { Value = true, ValueIsSet = true }; var size16FontInfo = new MockCharStyleInfo(); styleSize14_16bold.Overrides[37] = size16FontInfo; // ws 37 should be 16 point size16FontInfo.FontSize = new MockStyleProp <int>() { Value = 16000, ValueIsSet = true }; bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "size14_16bold"); props = bldr.GetTextProps(); var styles6 = styles.ApplyTextProps(props); Assert.That(styles6.FontSize, Is.EqualTo(14000)); Assert.That(styles6.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwBold)); bldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 33); props = bldr.GetTextProps(); var styles7 = styles.ApplyTextProps(props); Assert.That(styles7.FontSize, Is.EqualTo(14000)); // other wss not affected Assert.That(styles7.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwBold)); bldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 37); props = bldr.GetTextProps(); var styles8 = styles.ApplyTextProps(props); Assert.That(styles8.FontSize, Is.EqualTo(16000)); // ws 37 overridden Assert.That(styles8.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwBold)); // bold inherited // Test for other font-info properties. var stylesFonts = stylesheet.AddStyle("allFontProps", false); var allFontPropsFontInfo = new MockCharStyleInfo(); stylesFonts.DefaultCharacterStyleInfo = allFontPropsFontInfo; allFontPropsFontInfo.BackColor = new MockStyleProp <Color>() { Value = Color.Red, ValueIsSet = true }; allFontPropsFontInfo.FontSize = new MockStyleProp <int>() { Value = 14000, ValueIsSet = true }; allFontPropsFontInfo.FontColor = new MockStyleProp <Color>() { Value = Color.Blue, ValueIsSet = true }; allFontPropsFontInfo.Italic = new MockStyleProp <bool>() { Value = true, ValueIsSet = true }; allFontPropsFontInfo.Offset = new MockStyleProp <int>() { Value = 2000, ValueIsSet = true }; allFontPropsFontInfo.UnderlineColor = new MockStyleProp <Color>() { Value = Color.Green, ValueIsSet = true }; allFontPropsFontInfo.FontName = new MockStyleProp <string>() { Value = "MyFont", ValueIsSet = true }; allFontPropsFontInfo.Underline = new MockStyleProp <FwUnderlineType>() { Value = FwUnderlineType.kuntDashed, ValueIsSet = true }; //allFontPropsFontInfo.SuperSub = new MockStyleProp<FwSuperscriptVal>() { Value = FwSuperscriptVal.kssvSuper, ValueIsSet = true }; bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "allFontProps"); props = bldr.GetTextProps(); var styles9 = styles.ApplyTextProps(props); Assert.That(styles9.BackColor.ToArgb(), Is.EqualTo(Color.Red.ToArgb())); Assert.That(styles9.FontWeight, Is.EqualTo((int)VwFontWeight.kvfwNormal)); // did not set this one, make sure not affected Assert.That(styles9.FontSize, Is.EqualTo(14000)); Assert.That(styles9.ForeColor.ToArgb(), Is.EqualTo(Color.Blue.ToArgb())); Assert.That(styles9.FontItalic, Is.EqualTo(true)); Assert.That(styles9.BaselineOffset, Is.EqualTo(2000)); Assert.That(styles9.UnderlineColor.ToArgb(), Is.EqualTo(Color.Green.ToArgb())); Assert.That(styles9.FaceName, Is.EqualTo("MyFont")); Assert.That(styles9.Underline, Is.EqualTo(FwUnderlineType.kuntDashed)); // Todo: make some use of SuperSub and FontFeatures, when we have the applicable capabilities in AssembledStyles // Todo: test for non-font-related properties (in paragraph styles). // Todo: test special case of paragraph style that sets ws-dependent properties (and // possible ws-dependent (or not) character style that overrides them). // Todo: test that style is ignored cleanly if no stylesheet. }