Example #1
0
 /**
  * Handles the font number control word. Only relevant if the
  * group nesting level is 3.
  *
  * @param ctrlWord The control word to handle.
  * @param groupLevel The current group nesting level.
  */
 public void HandleCtrlWord(String ctrlWord, int groupLevel)
 {
     if (RtfColorTableParser.StringMatches(ctrlWord, "\\f") && groupLevel == 3)
     {
         this.fontNr = ctrlWord.Substring(2);
     }
 }
Example #2
0
 /**
  * Imports a complete RTF document.
  *
  * @param reader The Reader to read the RTF document from.
  * @param rtfDoc The RtfDocument to add the imported document to.
  * @throws IOException On I/O errors.
  * @throws DocumentException On document writing errors.
  */
 public void ImportRtfDocument(TextReader reader, RtfDocument rtfDoc)
 {
     this.rtfDoc           = rtfDoc;
     this.state            = PARSER_IN_HEADER;
     this.importHeader     = new RtfImportHeader(this.rtfDoc);
     this.fontTableParser  = new RtfFontTableParser(this.importHeader);
     this.colorTableParser = new RtfColorTableParser(this.importHeader);
     this.tokeniser        = new RtfTokeniser(this, 0);
     this.tokeniser.Tokenise(reader);
 }
Example #3
0
 /**
  * Imports an RTF fragment.
  *
  * @param reader The Reader to read the RTF fragment from.
  * @param rtfDoc The RTF document to add the RTF fragment to.
  * @param importMappings The RtfImportMappings defining font and color mappings for the fragment.
  * @throws IOException On I/O errors.
  * @throws DocumentException On document writing errors.
  */
 public void ImportRtfFragment(TextReader reader, RtfDocument rtfDoc, RtfImportMappings importMappings)
 {
     this.rtfDoc           = rtfDoc;
     this.state            = PARSER_IN_DOCUMENT;
     this.importHeader     = new RtfImportHeader(this.rtfDoc);
     this.fontTableParser  = new RtfFontTableParser(this.importHeader);
     this.colorTableParser = new RtfColorTableParser(this.importHeader);
     HandleImportMappings(importMappings);
     this.tokeniser = new RtfTokeniser(this, 1);
     this.tokeniser.Tokenise(reader);
 }
Example #4
0
 /**
  * Handles control word tokens. Depending on the current
  * state a control word can lead to a state change. When
  * parsing the actual document contents, The font number,
  * color number and background color number are remapped.
  *
  * @param ctrlWord The control word to handle.
  * @param groupLevel The current group nesting level.
  * @throws DocumentException On document writing errors.
  */
 public void HandleCtrlWord(String ctrlWord, int groupLevel)
 {
     if (this.state == PARSER_IN_DOCUMENT)
     {
         if (RtfColorTableParser.StringMatches(ctrlWord, "\\f"))
         {
             ctrlWord = "\\f" + this.importHeader.MapFontNr(ctrlWord.Substring(2));
         }
         else if (RtfColorTableParser.StringMatches(ctrlWord, "\\cf"))
         {
             ctrlWord = "\\cf" + this.importHeader.MapColorNr(ctrlWord.Substring(3));
         }
         else if (RtfColorTableParser.StringMatches(ctrlWord, "\\cb"))
         {
             ctrlWord = "\\cb" + this.importHeader.MapColorNr(ctrlWord.Substring(3));
         }
         this.rtfDoc.Add(new RtfDirectContent(ctrlWord));
     }
     else if (this.state == PARSER_IN_FONT_TABLE)
     {
         this.fontTableParser.HandleCtrlWord(ctrlWord, groupLevel);
     }
     else if (this.state == PARSER_IN_COLOR_TABLE)
     {
         this.colorTableParser.HandleCtrlWord(ctrlWord, groupLevel);
     }
     else if (this.state == PARSER_IN_HEADER)
     {
         if (ctrlWord.Equals("\\info"))
         {
             this.state = PARSER_IN_INFO_GROUP;
         }
         else if (ctrlWord.Equals("\\fonttbl"))
         {
             this.state = PARSER_IN_FONT_TABLE;
         }
         else if (ctrlWord.Equals("\\colortbl"))
         {
             this.state = PARSER_IN_COLOR_TABLE;
         }
     }
 }
Example #5
0
 /**
 * Imports an RTF fragment.
 *
 * @param reader The Reader to read the RTF fragment from.
 * @param rtfDoc The RTF document to add the RTF fragment to.
 * @param importMappings The RtfImportMappings defining font and color mappings for the fragment.
 * @throws IOException On I/O errors.
 * @throws DocumentException On document writing errors.
 */
 public void ImportRtfFragment(TextReader reader, RtfDocument rtfDoc, RtfImportMappings importMappings)
 {
     this.rtfDoc = rtfDoc;
     this.state = PARSER_IN_DOCUMENT;
     this.importHeader = new RtfImportHeader(this.rtfDoc);
     this.fontTableParser = new RtfFontTableParser(this.importHeader);
     this.colorTableParser = new RtfColorTableParser(this.importHeader);
     HandleImportMappings(importMappings);
     this.tokeniser = new RtfTokeniser(this, 1);
     this.tokeniser.Tokenise(reader);
 }
Example #6
0
 /**
 * Imports a complete RTF document.
 *
 * @param reader The Reader to read the RTF document from.
 * @param rtfDoc The RtfDocument to add the imported document to.
 * @throws IOException On I/O errors.
 * @throws DocumentException On document writing errors.
 */
 public void ImportRtfDocument(TextReader reader, RtfDocument rtfDoc)
 {
     this.rtfDoc = rtfDoc;
     this.state = PARSER_IN_HEADER;
     this.importHeader = new RtfImportHeader(this.rtfDoc);
     this.fontTableParser = new RtfFontTableParser(this.importHeader);
     this.colorTableParser = new RtfColorTableParser(this.importHeader);
     this.tokeniser = new RtfTokeniser(this, 0);
     this.tokeniser.Tokenise(reader);
 }