public void RtfStyle_LineSpacingAsString() { CheckDisposed(); DummyRtfStyle style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 10000, false, null, null); Assert.AreEqual(@"\sl200", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, -10000, false, null, null); Assert.AreEqual(@"\sl-200\slmult0", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 10000, true, null, null); Assert.AreEqual(string.Empty, style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 15000, false, null, null); Assert.AreEqual(@"\sl300", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, -15000, false, null, null); Assert.AreEqual(@"\sl-300\slmult0", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 15000, true, null, null); Assert.AreEqual(@"\sl360\slmult1", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 20000, false, null, null); Assert.AreEqual(@"\sl400", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, -20000, false, null, null); Assert.AreEqual(@"\sl-400\slmult0", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 20000, true, null, null); Assert.AreEqual(@"\sl480\slmult1", style.GetLineSpacingAsString); }
public void RtfStyle_ToString_LeftToRight() { CheckDisposed(); // Build up a style table for testing RtfStyleInfoTable styleTable = new RtfStyleInfoTable(null, false); BuildStyleTable(styleTable); // Create a "Paragraph" style that is based on Normal (#2) DummyRtfStyle paragraph = new DummyRtfStyle("\\MyFavoriteStyle", StyleType.kstParagraph, 72000, // space before 36000, // space after 18000, // first line indent 9000, // leading indent 4500, // trailing indent "Normal", // based-on style name null); // next style name styleTable.Add("\\MyFavoriteStyle", paragraph); styleTable.ConnectStyles(); RtfStyle style = (RtfStyle)styleTable["Normal"]; string rtfString = style.ToString("Normal", true); Assert.AreEqual(@"\s1\f1\fs20\snext1 Normal", rtfString); style = (RtfStyle)styleTable["Paragraph"]; rtfString = style.ToString("Paragraph", true); Assert.AreEqual(@"\s2\fi360\lin180\rin90\sb1440\sa720\f1\fs20\sbasedon1\snext2 Paragraph", rtfString); style = (RtfStyle)styleTable["Heading"]; rtfString = style.ToString("Heading", true); Assert.AreEqual(@"\s3\f1\fs20\sbasedon1\snext2 Heading", rtfString); style = (RtfStyle)styleTable["Emphasis"]; rtfString = style.ToString("Emphasis", true); Assert.AreEqual(@"\*\cs4\b\f1\fs40\additive Emphasis", rtfString); style = (RtfStyle)styleTable["ExactSpacing"]; rtfString = style.ToString("ExactSpacing", true); Assert.AreEqual(@"\s5\sl-360\slmult0\f1\fs20\sbasedon1\snext2 ExactSpacing", rtfString); style = (RtfStyle)styleTable["AtLeastSpacing"]; rtfString = style.ToString("AtLeastSpacing", true); Assert.AreEqual(@"\s6\sl360\f1\fs20\sbasedon1\snext2 AtLeastSpacing", rtfString); style = (RtfStyle)styleTable["Border"]; rtfString = style.ToString("Border", true); Assert.AreEqual(@"\s7\qj\f2\fs40" + @"\brdrt\brdrs\brdrw10\brsp20\brdrcf1" + @"\brdrb\brdrs\brdrw20\brsp20\brdrcf1" + @"\brdrl\brdrs\brdrw30\brsp80\brdrcf1" + @"\brdrr\brdrs\brdrw40\brsp80\brdrcf1\nosupersub\snext7" + " Border", rtfString); style = (RtfStyle)styleTable["\\MyFavoriteStyle"]; rtfString = style.ToString("\\MyFavoriteStyle", true); Assert.AreEqual(@"\s8\fi360\lin180\rin90\sb1440\sa720\f1\fs20\sbasedon1\snext8 \\MyFavoriteStyle", rtfString); }
///-------------------------------------------------------------------------------------- /// <summary> /// Build a table of styles for testing /// </summary> ///-------------------------------------------------------------------------------------- private void BuildStyleTable(RtfStyleInfoTable styleTable) { // Create a Normal style for everything to be based on (#1) DummyRtfStyle normal = new DummyRtfStyle("Normal", StyleType.kstParagraph); normal.FontInfoForWs(-1).m_fontName.ExplicitValue = "Times New Roman"; styleTable.Add("Normal", normal); // Create a "Paragraph" style that is based on Normal (#2) DummyRtfStyle paragraph = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 72000, // space before 36000, // space after 18000, // first line indent 9000, // leading indent 4500, // trailing indent "Normal", // based-on style name null); // next style name styleTable.Add("Paragraph", paragraph); // Create a Heading style that is based on "Normal" and has "Paragraph" // as a following style (#3) DummyRtfStyle heading = new DummyRtfStyle("Heading", StyleType.kstParagraph, "Normal", // based-on style name "Paragraph"); // next style name styleTable.Add("Heading", heading); // Create a character style "Emphasis" (#4) DummyRtfStyle emphasis = new DummyRtfStyle("Emphasis", StyleType.kstCharacter, true, 20000); emphasis.FontInfoForWs(-1).m_fontName.ExplicitValue = "Times New Roman"; styleTable.Add("Emphasis", emphasis); // Create a paragraph style that has exact spacing (#5) DummyRtfStyle exactSpacing = new DummyRtfStyle("ExactSpacing", StyleType.kstParagraph, -18000, // line spacing false, // line spacing relativity "Normal", // based-on style name "Paragraph"); // next style name styleTable.Add("ExactSpacing", exactSpacing); // Create a paragraph style that has "at least n" spacing (#6) DummyRtfStyle atLeastSpacing = new DummyRtfStyle("AtLeastSpacing", StyleType.kstParagraph, 18000, // line spacing false, // line spacing relativity "Normal", // based-on style name "Paragraph"); // next style name styleTable.Add("AtLeastSpacing", atLeastSpacing); // Create a Border style (#7) DummyRtfStyle border = new DummyRtfStyle("Border", StyleType.kstParagraph, false, // bold false, // italic FwSuperscriptVal.kssvOff, FwTextAlign.ktalJustify, 0, // line spacing false, // line spacing relativity 0, // space before 0, // space after 0, // first line indent 0, // leading indent 0, // trailing indent "Arial", // font name 20000, // font size Color.Empty, // font color 500, // border top 1000, // border bottom 1500, // border leading 2000, // border trailing Color.Black, // border color null, // based-on style name null); // next style name styleTable.Add("Border", border); styleTable.ConnectStyles(); }
///-------------------------------------------------------------------------------------- /// <summary> /// Build a table of styles for testing /// </summary> ///-------------------------------------------------------------------------------------- private void BuildStyleTable(RtfStyleInfoTable styleTable) { // Create a Normal style for everything to be based on (#1) DummyRtfStyle normal = new DummyRtfStyle("Normal", StyleType.kstParagraph); normal.FontInfoForWs(-1).m_fontName.ExplicitValue = "Times New Roman"; styleTable.Add("Normal", normal); // Create a "Paragraph" style that is based on Normal (#2) DummyRtfStyle paragraph = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 72000, // space before 36000, // space after 18000, // first line indent 9000, // leading indent 4500, // trailing indent "Normal", // based-on style name null); // next style name styleTable.Add("Paragraph", paragraph); // Create a Heading style that is based on "Normal" and has "Paragraph" // as a following style (#3) DummyRtfStyle heading = new DummyRtfStyle("Heading", StyleType.kstParagraph, "Normal", // based-on style name "Paragraph"); // next style name styleTable.Add("Heading", heading); // Create a character style "Emphasis" (#4) DummyRtfStyle emphasis = new DummyRtfStyle("Emphasis", StyleType.kstCharacter, true, 20000); emphasis.FontInfoForWs(-1).m_fontName.ExplicitValue = "Times New Roman"; styleTable.Add("Emphasis", emphasis); // Create a paragraph style that has exact spacing (#5) DummyRtfStyle exactSpacing = new DummyRtfStyle("ExactSpacing", StyleType.kstParagraph, -18000, // line spacing false, // line spacing relativity "Normal", // based-on style name "Paragraph"); // next style name styleTable.Add("ExactSpacing", exactSpacing); // Create a paragraph style that has "at least n" spacing (#6) DummyRtfStyle atLeastSpacing = new DummyRtfStyle("AtLeastSpacing", StyleType.kstParagraph, 18000, // line spacing false, // line spacing relativity "Normal", // based-on style name "Paragraph"); // next style name styleTable.Add("AtLeastSpacing", atLeastSpacing); // Create a Border style (#7) DummyRtfStyle border = new DummyRtfStyle("Border", StyleType.kstParagraph, false, // bold false, // italic FwSuperscriptVal.kssvOff, FwTextAlign.ktalJustify, 0, // line spacing false, // line spacing relativity 0, // space before 0, // space after 0, // first line indent 0, // leading indent 0, // trailing indent "Arial", // font name 20000, // font size Color.Empty, // font color 500, // border top 1000, // border bottom 1500, // border leading 2000, // border trailing Color.Black, // border color null, // based-on style name null); // next style name styleTable.Add("Border", border); styleTable.ConnectStyles(); }
public void RtfStyle_LineSpacingAsString() { CheckDisposed(); DummyRtfStyle style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 10000, false, null, null); Assert.AreEqual(@"\sl200", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, -10000, false, null, null); Assert.AreEqual(@"\sl-200\slmult0", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 10000, true, null, null); Assert.AreEqual(string.Empty, style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 15000, false, null, null); Assert.AreEqual(@"\sl300", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, -15000, false, null, null); Assert.AreEqual(@"\sl-300\slmult0", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 15000, true, null, null); Assert.AreEqual(@"\sl360\slmult1", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 20000, false, null, null); Assert.AreEqual(@"\sl400", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, -20000, false, null, null); Assert.AreEqual(@"\sl-400\slmult0", style.GetLineSpacingAsString); style = new DummyRtfStyle("Paragraph", StyleType.kstParagraph, 20000, true, null, null); Assert.AreEqual(@"\sl480\slmult1", style.GetLineSpacingAsString); }
public void RtfStyle_ToString_LeftToRight() { CheckDisposed(); // Build up a style table for testing RtfStyleInfoTable styleTable = new RtfStyleInfoTable(null, false); BuildStyleTable(styleTable); // Create a "Paragraph" style that is based on Normal (#2) DummyRtfStyle paragraph = new DummyRtfStyle("\\MyFavoriteStyle", StyleType.kstParagraph, 72000, // space before 36000, // space after 18000, // first line indent 9000, // leading indent 4500, // trailing indent "Normal", // based-on style name null); // next style name styleTable.Add("\\MyFavoriteStyle", paragraph); styleTable.ConnectStyles(); RtfStyle style = (RtfStyle)styleTable["Normal"]; string rtfString = style.ToString("Normal", true); Assert.AreEqual(@"\s1\f1\fs20\snext1 Normal", rtfString); style = (RtfStyle)styleTable["Paragraph"]; rtfString = style.ToString("Paragraph", true); Assert.AreEqual(@"\s2\fi360\lin180\rin90\sb1440\sa720\f1\fs20\sbasedon1\snext2 Paragraph", rtfString); style = (RtfStyle)styleTable["Heading"]; rtfString = style.ToString("Heading", true); Assert.AreEqual(@"\s3\f1\fs20\sbasedon1\snext2 Heading", rtfString); style = (RtfStyle)styleTable["Emphasis"]; rtfString = style.ToString("Emphasis", true); Assert.AreEqual(@"\*\cs4\b\f1\fs40\additive Emphasis", rtfString); style = (RtfStyle)styleTable["ExactSpacing"]; rtfString = style.ToString("ExactSpacing", true); Assert.AreEqual(@"\s5\sl-360\slmult0\f1\fs20\sbasedon1\snext2 ExactSpacing", rtfString); style = (RtfStyle)styleTable["AtLeastSpacing"]; rtfString = style.ToString("AtLeastSpacing", true); Assert.AreEqual(@"\s6\sl360\f1\fs20\sbasedon1\snext2 AtLeastSpacing", rtfString); style = (RtfStyle)styleTable["Border"]; rtfString = style.ToString("Border", true); Assert.AreEqual(@"\s7\qj\f2\fs40" + @"\brdrt\brdrs\brdrw10\brsp20\brdrcf1" + @"\brdrb\brdrs\brdrw20\brsp20\brdrcf1" + @"\brdrl\brdrs\brdrw30\brsp80\brdrcf1" + @"\brdrr\brdrs\brdrw40\brsp80\brdrcf1\nosupersub\snext7" + " Border", rtfString); style = (RtfStyle)styleTable["\\MyFavoriteStyle"]; rtfString = style.ToString("\\MyFavoriteStyle", true); Assert.AreEqual(@"\s8\fi360\lin180\rin90\sb1440\sa720\f1\fs20\sbasedon1\snext8 \\MyFavoriteStyle", rtfString); }