public void DragCopyRtf() { var stylesheet = new MockStylesheet(); var styleFirst = stylesheet.AddStyle("first", false); var styleSecond = stylesheet.AddStyle("second", false); var propsTrue = new MockStyleProp <bool>() { Value = true, ValueIsSet = true }; var charInfo = new MockCharStyleInfo(); styleFirst.DefaultCharacterStyleInfo = charInfo; charInfo.Bold = propsTrue; // Todo: make styleSecond have pretty much everything else. var charInfo2 = new MockCharStyleInfo(); styleSecond.DefaultCharacterStyleInfo = charInfo2; charInfo2.FontColor = MakeColorProp(Color.Red); charInfo2.BackColor = MakeColorProp(Color.Yellow); charInfo2.UnderlineColor = MakeColorProp(Color.Green); charInfo2.Italic = propsTrue; charInfo2.FontName = new MockStyleProp <string>() { Value = "Arial", ValueIsSet = true }; var styles = new AssembledStyles(stylesheet); var root = new RootBoxFdo(styles); var mock1 = new MockData1(23, 23); mock1.SimpleThree = "This is"; var mock2 = new MockData1(23, 23); mock2.SimpleThree = " the day"; var mock3 = new MockData1(23, 23); mock3.SimpleThree = " that the"; var engine = new FakeRenderEngine() { Ws = 23, SegmentHeight = 13 }; var factory = new FakeRendererFactory(); var wsf = new MockWsf(); engine.WritingSystemFactory = wsf; var wsEngine = wsf.MakeMockEngine(23, "en", engine); factory.SetRenderer(23, engine); root.Builder.Show( Paragraph.Containing( Display.Of(() => mock1.SimpleThree, 23).Style("first"), Display.Of(() => mock2.SimpleThree, 23).Style("second"), Display.Of(() => mock3.SimpleThree, 23).Style("first") )); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory); root.Layout(layoutArgs); PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96); MockSite site = new MockSite(); site.m_transform = ptrans; site.m_vwGraphics = m_gm.VwGraphics; root.Site = site; SelectionBuilder.In(root).Offset("This ".Length).To.Offset("This is the day that".Length).Install(); int indent = FakeRenderEngine.SimulatedWidth("This "); root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 4, 0), Keys.None, m_gm.VwGraphics, ptrans); root.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 4, 0), Keys.None, m_gm.VwGraphics, ptrans); Assert.That(GetStringDropData(site), Is.EqualTo("is the day that")); // The order of the font and colors in the color table is arbitrary. This happens to be what the code does now. For some reason // Color.Green has green only 128. // The order of items in the definition of a style is arbitrary. // We're not doing anything yet for background color. \highlightN can specify background color for a character run, // but it can't be part of a style definition. Assert.That(GetRtfDropData(site), Is.EqualTo( RangeSelection.RtfPrefix + @"{\fonttbl{\f0 MockFont;}{\f1 Arial;}}" + @"{\colortbl ;\red0\green0\blue0;\red255\green255\blue255;\red255\green0\blue0;\red255\green255\blue0;\red0\green128\blue0;}" + @"{\stylesheet{\*\cs1\b\additive first;\*\cs2\i\f1\cf3\ulc5\additive second;}}" + RangeSelection.RtfDataPrefix + @"{\*\cs1\b is}{\*\cs2\i\f1\cf3\ulc5\highlight4 the day}{\*\cs1\b that\par}" + @"}")); // Todo: handle styles that depend on WS // Todo: handle more than two runs // Todo: handle runs where actual formatting differs from style-specified formatting // Todo: handle multiple paragraphs // Todo: handle paragraph styles }
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. }