/// <summary>Return the next token in the stream</summary> public TokenClass GetToken() { if (pushed_class != TokenClass.None) { this.rtf_class = this.pushed_class; this.major = this.pushed_major; this.minor = this.pushed_minor; this.param = this.pushed_param; this.pushed_class = TokenClass.None; return this.rtf_class; } GetToken2(); if (this.rtf_class == TokenClass.Text) { this.minor = (Minor)this.cur_charset[(int)this.major]; } if (this.cur_charset.Flags == CharsetFlags.None) { return this.rtf_class; } if (((this.cur_charset.Flags & CharsetFlags.Read) != 0) && CheckCM(TokenClass.Control, Major.CharSet)) { this.cur_charset.ReadMap(); } else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum)) { Font fp; fp = Font.GetFont(this.font_list, this.param); if (fp != null) { if (fp.Name.StartsWith("Symbol")) { this.cur_charset.ID = CharsetType.Symbol; } else { this.cur_charset.ID = CharsetType.General; } } else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && (this.rtf_class == TokenClass.Group)) { switch(this.major) { case Major.BeginGroup: { this.charset_stack.Push(this.cur_charset); break; } case Major.EndGroup: { this.cur_charset = (Charset)this.charset_stack.Pop(); break; } } } } return this.rtf_class; }
public RTF(Stream stream) { source = new StreamReader(stream); text_buffer = new StringBuilder(1024); //pushed_text_buffer = new StringBuilder(1024); rtf_class = TokenClass.None; pushed_class = TokenClass.None; pushed_char = unchecked((char)-1); line_num = 0; line_pos = 0; prev_char = unchecked((char)-1); bump_line = false; cur_charset = new Charset(); destination_callbacks = new DestinationCallback(); class_callbacks = new ClassCallback(); destination_callbacks [Minor.OptDest] = new DestinationDelegate (HandleOptDest); destination_callbacks[Minor.FontTbl] = new DestinationDelegate(ReadFontTbl); destination_callbacks[Minor.ColorTbl] = new DestinationDelegate(ReadColorTbl); destination_callbacks[Minor.StyleSheet] = new DestinationDelegate(ReadStyleSheet); destination_callbacks[Minor.Info] = new DestinationDelegate(ReadInfoGroup); destination_callbacks[Minor.Pict] = new DestinationDelegate(ReadPictGroup); destination_callbacks[Minor.Object] = new DestinationDelegate(ReadObjGroup); }
/// <summary>Return the next token in the stream</summary> public TokenClass GetToken() { if (pushed_class != TokenClass.None) { this.rtf_class = this.pushed_class; this.major = this.pushed_major; this.minor = this.pushed_minor; this.param = this.pushed_param; this.pushed_class = TokenClass.None; return this.rtf_class; } GetToken2(); if (this.rtf_class == TokenClass.Text) { this.minor = (Minor)this.cur_charset[(int)this.major]; if (encoding == null) { encoding = Encoding.GetEncoding (encoding_code_page); } encoded_text = new String (encoding.GetChars (new byte [] { (byte) this.major })); } if (this.cur_charset.Flags == CharsetFlags.None) { return this.rtf_class; } if (CheckCMM (TokenClass.Control, Major.Unicode, Minor.UnicodeAnsiCodepage)) { encoding_code_page = param; // fallback to the default one in case we have an invalid value if (encoding_code_page < 0 || encoding_code_page > 65535) encoding_code_page = DefaultEncodingCodePage; } if (((this.cur_charset.Flags & CharsetFlags.Read) != 0) && CheckCM(TokenClass.Control, Major.CharSet)) { this.cur_charset.ReadMap(); } else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum)) { Font fp; fp = Font.GetFont(this.font_list, this.param); if (fp != null) { if (fp.Name.StartsWith("Symbol")) { this.cur_charset.ID = CharsetType.Symbol; } else { this.cur_charset.ID = CharsetType.General; } } else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && (this.rtf_class == TokenClass.Group)) { switch(this.major) { case Major.BeginGroup: { this.charset_stack.Push(this.cur_charset); break; } case Major.EndGroup: { this.cur_charset = (Charset)this.charset_stack.Pop(); break; } } } } return this.rtf_class; }