1 50 package com.lowagie.text.rtf.direct; 51 52 import java.awt.Color ; 53 54 62 public class RtfColorTableParser { 63 66 private RtfImportHeader importHeader = null; 67 70 private int colorNr = 0; 71 74 private int red = -1; 75 78 private int green = -1; 79 82 private int blue = -1; 83 84 89 public RtfColorTableParser(RtfImportHeader importHeader) { 90 this.importHeader = importHeader; 91 this.colorNr = 0; 92 this.red = -1; 93 this.green = -1; 94 this.blue = -1; 95 } 96 97 public static boolean stringMatches(String text, String start) { 98 if (!text.startsWith(start)) 99 return false; 100 int first = start.length(); 101 int last = text.length(); 102 if (first == last) 103 return false; 104 for (int k = first; k < last; ++k) { 105 char c = text.charAt(k); 106 if (c < '0' || c > '9') 107 return false; 108 } 109 return true; 110 } 111 112 120 public void handleCtrlWord(String ctrlWord, int groupLevel) { 121 if (stringMatches(ctrlWord, "\\red")) 122 this.red = Integer.parseInt(ctrlWord.substring(4)); 123 else if (stringMatches(ctrlWord, "\\green")) 124 this.green = Integer.parseInt(ctrlWord.substring(6)); 125 else if (stringMatches(ctrlWord, "\\blue")) 126 this.blue = Integer.parseInt(ctrlWord.substring(5)); 127 } 128 129 136 public void handleText(String text, int groupLevel) { 137 if(text.indexOf(';') != -1) { 138 if(red != -1 && green != -1 && blue != -1) { 139 this.importHeader.importColor(Integer.toString(this.colorNr), new Color (this.red, this.green, this.blue)); 140 } 141 this.colorNr++; 142 } 143 } 144 } 145 | Popular Tags |