/// <summary>Set the default font for documents without font table</summary> public void DefaultFont(string name) { Font font; font = new Font(this); font.Num = 0; font.Name = name; }
private void ReadFontTbl(RTF rtf) { int old; Font font; old = -1; font = null; while (true) { rtf.GetToken(); if (rtf.CheckCM(TokenClass.Group, Major.EndGroup)) { break; } if (old < 0) { if (rtf.CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum)) { old = 1; } else if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup)) { old = 0; } else { throw new RTFException(rtf, "Cannot determine format"); } } if (old == 0) { if (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup)) { throw new RTFException(rtf, "missing \"{\""); } rtf.GetToken(); } font = new Font(rtf); while ((rtf.rtf_class != TokenClass.EOF) && (!rtf.CheckCM(TokenClass.Text, (Major)';')) && (!rtf.CheckCM(TokenClass.Group, Major.EndGroup))) { if (rtf.rtf_class == TokenClass.Control) { switch(rtf.major) { case Major.FontFamily: { font.Family = (int)rtf.minor; break; } case Major.CharAttr: { switch(rtf.minor) { case Minor.FontNum: { font.Num = rtf.param; break; } default: { #if RTF_DEBUG Console.WriteLine("Got unhandled Control.CharAttr.Minor: " + rtf.minor); #endif break; } } break; } case Major.FontAttr: { switch (rtf.minor) { case Minor.FontCharSet: { font.Charset = (CharsetType)rtf.param; break; } case Minor.FontPitch: { font.Pitch = rtf.param; break; } case Minor.FontCodePage: { font.Codepage = rtf.param; break; } case Minor.FTypeNil: case Minor.FTypeTrueType: { font.Type = rtf.param; break; } default: { #if RTF_DEBUG Console.WriteLine("Got unhandled Control.FontAttr.Minor: " + rtf.minor); #endif break; } } break; } default: { #if RTF_DEBUG Console.WriteLine("ReadFontTbl: Unknown Control token " + rtf.major); #endif break; } } } else if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup)) { rtf.SkipGroup(); } else if (rtf.rtf_class == TokenClass.Text) { StringBuilder sb; sb = new StringBuilder(); while ((rtf.rtf_class != TokenClass.EOF) && (!rtf.CheckCM(TokenClass.Text, (Major)';')) && (!rtf.CheckCM(TokenClass.Group, Major.EndGroup)) && (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup))) { sb.Append((char)rtf.major); rtf.GetToken(); } if (rtf.CheckCM(TokenClass.Group, Major.EndGroup)) { rtf.UngetToken(); } font.Name = sb.ToString(); continue; #if RTF_DEBUG } else { Console.WriteLine("ReadFontTbl: Unknown token " + rtf.text_buffer); #endif } rtf.GetToken(); } if (old == 0) { rtf.GetToken(); if (!rtf.CheckCM(TokenClass.Group, Major.EndGroup)) { throw new RTFException(rtf, "Missing \"}\""); } } } if (font == null) { throw new RTFException(rtf, "No font created"); } if (font.Num == -1) { throw new RTFException(rtf, "Missing font number"); } rtf.RouteToken(); }
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; font_list = null; charset_stack = null; 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); }