@@ -19,94 +19,9 @@ namespace RtfDomParser
1919 /// </summary>
2020 public class RTFWriter : System . IDisposable
2121 {
22-
23- #region test ******************************************************
24-
25- /// <summary>
26- /// Test generate rtf file
27- /// after execute this function you can open c:\a.rtf
28- /// </summary>
29- internal static void TestWriteFile ( )
30- {
31- RTFWriter w = new RTFWriter ( "c:\\ a.rtf" ) ;
32- TestBuildRTF ( w ) ;
33- w . Close ( ) ;
34- System . Windows . Forms . MessageBox . Show ( "OK , you can open file c:\\ a.rtf 了." ) ;
35- }
36-
37- /// <summary>
38- /// Test generate rtf text and copy to windows clipboard
39- /// after execute this function , you can paste rtf text in MS Word
40- /// </summary>
41- internal static void TestClipboard ( )
42- {
43- System . IO . StringWriter myStr = new System . IO . StringWriter ( ) ;
44- RTFWriter w = new RTFWriter ( myStr ) ;
45- TestBuildRTF ( w ) ;
46- w . Close ( ) ;
47- System . Windows . Forms . DataObject data = new System . Windows . Forms . DataObject ( ) ;
48- data . SetData ( System . Windows . Forms . DataFormats . Rtf , myStr . ToString ( ) ) ;
49- System . Windows . Forms . Clipboard . SetDataObject ( data , true ) ;
50- System . Windows . Forms . MessageBox . Show ( "OK, you can paste words in MS Word." ) ;
51- }
5222 static RTFWriter ( ) => Defaults . LoadEncodings ( ) ;
5323
54- /// <summary>
55- /// Test to generate a little rtf document
56- /// </summary>
57- /// <param name="w">RTF text writer</param>
58- private static void TestBuildRTF ( RTFWriter w )
59- {
60- w . Encoding = System . Text . Encoding . GetEncoding ( 936 ) ;
61- // write header
62- w . WriteStartGroup ( ) ;
63- w . WriteKeyword ( "rtf1" ) ;
64- w . WriteKeyword ( "ansi" ) ;
65- w . WriteKeyword ( "ansicpg" + w . Encoding . CodePage ) ;
66- // wirte font table
67- w . WriteStartGroup ( ) ;
68- w . WriteKeyword ( "fonttbl" ) ;
69- w . WriteStartGroup ( ) ;
70- w . WriteKeyword ( "f0" ) ;
71- w . WriteText ( "Arial;" ) ;
72- w . WriteEndGroup ( ) ;
73- w . WriteStartGroup ( ) ;
74- w . WriteKeyword ( "f1" ) ;
75- w . WriteText ( "Times New Roman;" ) ;
76- w . WriteEndGroup ( ) ;
77- w . WriteEndGroup ( ) ;
78- // write color table
79- w . WriteStartGroup ( ) ;
80- w . WriteKeyword ( "colortbl" ) ;
81- w . WriteText ( ";" ) ;
82- w . WriteKeyword ( "red0" ) ;
83- w . WriteKeyword ( "green0" ) ;
84- w . WriteKeyword ( "blue255" ) ;
85- w . WriteText ( ";" ) ;
86- w . WriteEndGroup ( ) ;
87- // write content
88- w . WriteKeyword ( "qc" ) ; // set alignment center
89- w . WriteKeyword ( "f0" ) ; // set font
90- w . WriteKeyword ( "fs30" ) ; // set font size
91- w . WriteText ( "This is the first paragraph text " ) ;
92- w . WriteKeyword ( "cf1" ) ; // set text color
93- w . WriteText ( "Arial " ) ;
94- w . WriteKeyword ( "cf0" ) ; // set default color
95- w . WriteKeyword ( "f1" ) ; // set font
96- w . WriteText ( "Align center ABC12345" ) ;
97- w . WriteKeyword ( "par" ) ; // new paragraph
98- w . WriteKeyword ( "pard" ) ; // clear format
99- w . WriteKeyword ( "f1" ) ; // set font
100- w . WriteKeyword ( "fs20" ) ; // set font size
101- w . WriteKeyword ( "cf1" ) ;
102- w . WriteText ( "This is the secend paragraph Arial left alignment ABC12345" ) ;
103- // finish
104- w . WriteEndGroup ( ) ;
105- }
106-
107- #endregion
108-
109- /// <summary>
24+ /// <summary>
11025 /// Initialize instance
11126 /// </summary>
11227 /// <param name="w">text writer</param>
0 commit comments