3 using System.Drawing.Imaging;
4 using System.Drawing.Text;
5 using System.Windows.Forms;
7 using System.Threading;
8 using System.Windows.Forms.RTF;
11 namespace TextTestClass {
16 private string rtf_string = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs17 testing 123testiong\\par\r\n}";
17 private string rtf_string2 = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}{\\f1\\fmodern\\fprq1\\fcharset0 Courier;}{\\f2\\fswiss\\fprq2\\fcharset0 Arial;}}\r\n" +
18 "{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green0\\blue0;}\r\n" +
19 "{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard\\f0\\fs20 I am in Arial 10pt\\par\r\n" +
20 "\\fs24 I am in Arial 12pt\\par\r\n" +
21 "\\f1 I am in Courier 12pt\\par\r\n" +
22 "\\cf1 I am in Courier 12pt Red\\par\r\n" +
23 "\\cf2\\f2\\fs20 I am in Arial 10pt\\par\r\n" +
24 "\\b I am in Arial 10pt Italic\\cf0\\b0\\f0\\par\r\n" +
26 private string rtf_string3 = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}{" +
27 "\\f1\\fmodern\\fprq1\\fcharset0 Courier;}{\\f2\\fswiss\\fprq2\\fcharset0 Arial;}{\\f3\\fni" +
28 "l\\fcharset0 Impact;}{\\f4\\fnil\\fcharset0 Arial Unicode MS;}{\\f5\\fnil\\fcharset136 Arial Unicode MS;}{\\f6\\fnil\\fcharset0 MS" +
30 "{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green0\\blue0;}" +
31 "{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard\\f0\\fs20 I am in Arial 1" +
33 "\\fs24 I am in Arial 12pt\\par" +
34 "\\f1 I am in Courier 12pt\\par" +
35 "\\cf1 I am in Courier 12pt Red\\par" +
36 "\\cf2\\f2\\fs20 I am in Arial 10pt\\par" +
37 "\\b I am in Arial 10pt Bold\\par" +
38 "\\i I am in Arial 10pt Bold Italic\\par" +
39 "\\ul I am in Arial 10pt Bold Italic Underline\\par" +
40 "\\ulnone\\b0\\i0\\strike I am in Arial 10pt Strikethrough\\par" +
41 "\\cf0\\strike0\\f3\\fs23 Some cyrilic character: \\u1034?\\par" +
42 "And 5 CJK characters: \\f4\\fs21\\u23854?\\u23854?\\u23854?\\u23854?\\u23854?\\f5\\fs17\\par" +
43 "Some special chars:\\par" +
44 "\\tab Tilde: ~\\par" +
45 "\\tab Questionmark:?\\par" +
46 "\\tab Yen: \\f5\\u165?\\f6\\fs17\\par" +
47 "\\tab Umlaut: \\'e4\\par" +
59 TextMap.SetupStandardTable(text.Table);
61 buffer = new byte[rtf_string.Length];
62 for (int i = 0; i < buffer.Length; i++) {
63 buffer[i] = (byte)rtf_string[i];
65 stream = new MemoryStream(buffer);
66 rtf = new RTF(stream);
71 rtf.ClassCallback[TokenClass.Text] = new ClassDelegate(HandleText);
72 rtf.ClassCallback[TokenClass.Control] = new ClassDelegate(HandleControl);
79 void HandleControl(RTF rtf) {
83 case Minor.UnicodeCharBytes: {
84 skip_width = rtf.Param;
88 case Minor.UnicodeChar: {
89 Console.Write("[Unicode {0:X4}]", rtf.Param);
90 skip_count += skip_width;
97 case Major.Destination: {
98 Console.Write("[Got Destination control {0}]", rtf.Minor);
103 case Major.CharAttr: {
105 case Minor.ForeColor: {
106 System.Windows.Forms.RTF.Color color;
109 color = System.Windows.Forms.RTF.Color.GetColor(rtf, rtf.Param);
111 if (color.Red == -1 && color.Green == -1 && color.Blue == -1) {
112 Console.Write("[Default Color]");
114 Console.Write("[Color {0} [{1:X2}{2:X2}{3:X}]]", rtf.Param, color.Red, color.Green, color.Blue);
120 case Minor.FontSize: {
121 Console.Write("[Fontsize {0}]", rtf.Param);
125 case Minor.FontNum: {
126 System.Windows.Forms.RTF.Font font;
128 font = System.Windows.Forms.RTF.Font.GetFont(rtf, rtf.Param);
130 Console.Write("[Font {0} [{1}]]", rtf.Param, font.Name);
136 Console.Write("[Normal]");
141 if (rtf.Param == RTF.NoParam) {
142 Console.Write("[Bold]");
144 Console.Write("[NoBold]");
150 if (rtf.Param == RTF.NoParam) {
151 Console.Write("[Italic]");
153 Console.Write("[NoItalic]");
158 case Minor.StrikeThru: {
159 if (rtf.Param == RTF.NoParam) {
160 Console.Write("[StrikeThru]");
162 Console.Write("[NoStrikeThru]");
167 case Minor.Underline: {
168 if (rtf.Param == RTF.NoParam) {
169 Console.Write("[Underline]");
171 Console.Write("[NoUnderline]");
176 case Minor.NoUnderline: {
177 Console.Write("[NoUnderline]");
184 case Major.SpecialChar: {
185 Console.Write("[Got SpecialChar control {0}]", rtf.Minor);
192 void SpecialChar(RTF rtf) {
208 case Minor.NoBrkSpace: {
218 case Minor.NoBrkHyphen: {
229 Console.Write("
\97");
234 Console.Write("
\96");
239 Console.Write("
\91");
244 Console.Write("
\92");
248 case Minor.LDblQuote: {
249 Console.Write("
\93");
253 case Minor.RDblQuote: {
254 Console.Write("
\94");
266 void HandleText(RTF rtf) {
267 if (skip_count > 0) {
271 if ((StandardCharCode)rtf.Minor != StandardCharCode.nothing) {
272 Console.Write("{0}", text[(StandardCharCode)rtf.Minor]);
274 if ((int)rtf.Major > 31 && (int)rtf.Major < 128) {
275 Console.Write("{0}", (char)rtf.Major);
277 Console.Write("[Literal:0x{0:X2}]", (int)rtf.Major);
282 public static void Main() {