1 50 51 package com.lowagie.text.rtf.style; 52 53 import java.awt.Color ; 54 import java.io.ByteArrayOutputStream ; 55 import java.io.IOException ; 56 import java.io.OutputStream ; 57 58 import com.lowagie.text.rtf.RtfElement; 59 import com.lowagie.text.rtf.RtfExtendedElement; 60 import com.lowagie.text.rtf.document.RtfDocument; 61 62 63 70 public class RtfColor extends RtfElement implements RtfExtendedElement { 71 72 75 private static final byte[] COLOR_RED = "\\red".getBytes(); 76 79 private static final byte[] COLOR_GREEN = "\\green".getBytes(); 80 83 private static final byte[] COLOR_BLUE = "\\blue".getBytes(); 84 87 private static final byte COLON = (byte) ';'; 88 91 private static final byte[] COLOR_NUMBER = "\\cf".getBytes(); 92 93 96 private int colorNumber = 0; 97 100 private int red = 0; 101 104 private int green = 0; 105 108 private int blue = 0; 109 110 119 protected RtfColor(RtfDocument doc, int red, int green, int blue, int colorNumber) { 120 super(doc); 121 this.red = red; 122 this.blue = blue; 123 this.green = green; 124 this.colorNumber = colorNumber; 125 } 126 127 133 public RtfColor(RtfDocument doc, RtfColor col) { 134 super(doc); 135 if(col != null) { 136 this.red = col.getRed(); 137 this.green = col.getGreen(); 138 this.blue = col.getBlue(); 139 } 140 if(this.document != null) { 141 this.colorNumber = this.document.getDocumentHeader().getColorNumber(this); 142 } 143 } 144 145 151 public RtfColor(RtfDocument doc, Color col) { 152 super(doc); 153 if(col != null) { 154 this.red = col.getRed(); 155 this.blue = col.getBlue(); 156 this.green = col.getGreen(); 157 } 158 if(this.document != null) { 159 this.colorNumber = this.document.getDocumentHeader().getColorNumber(this); 160 } 161 } 162 163 171 public RtfColor(RtfDocument doc, int red, int green, int blue) { 172 super(doc); 173 this.red = red; 174 this.blue = blue; 175 this.green = green; 176 if(this.document != null) { 177 this.colorNumber = this.document.getDocumentHeader().getColorNumber(this); 178 } 179 } 180 181 185 public byte[] write() 186 { 187 return(new byte[0]); 188 } 189 192 public void writeContent(final OutputStream out) throws IOException 193 { 194 } 195 196 202 public byte[] writeDefinition() { 203 ByteArrayOutputStream result = new ByteArrayOutputStream (); 204 try { 205 writeDefinition(result); 206 } catch(IOException ioe) { 207 ioe.printStackTrace(); 208 } 209 return result.toByteArray(); 210 } 211 212 215 public void writeDefinition(final OutputStream result) throws IOException 216 { 217 result.write(COLOR_RED); 218 result.write(intToByteArray(red)); 219 result.write(COLOR_GREEN); 220 result.write(intToByteArray(green)); 221 result.write(COLOR_BLUE); 222 result.write(intToByteArray(blue)); 223 result.write(COLON); 224 } 225 226 231 public byte[] writeBegin() { 232 ByteArrayOutputStream result = new ByteArrayOutputStream (); 233 try { 234 result.write(COLOR_NUMBER); 235 result.write(intToByteArray(colorNumber)); 236 } catch(IOException ioe) { 237 ioe.printStackTrace(); 238 } 239 return result.toByteArray(); 240 } 241 242 247 public byte[] writeEnd() { 248 return new byte[0]; 249 } 250 251 258 public boolean equals(Object obj) { 259 if(!(obj instanceof RtfColor)) { 260 return false; 261 } 262 RtfColor color = (RtfColor) obj; 263 return (this.red == color.getRed() && this.green == color.getGreen() && this.blue == color.getBlue()); 264 } 265 266 273 public int hashCode() { 274 return (this.red << 16) | (this.green << 8) | this.blue; 275 } 276 277 282 public int getBlue() { 283 return blue; 284 } 285 286 291 public int getGreen() { 292 return green; 293 } 294 295 300 public int getRed() { 301 return red; 302 } 303 304 309 public int getColorNumber() { 310 return colorNumber; 311 } 312 313 318 public void setRtfDocument(RtfDocument doc) { 319 super.setRtfDocument(doc); 320 if(document != null) { 321 this.colorNumber = document.getDocumentHeader().getColorNumber(this); 322 } 323 } 324 } 325 | Popular Tags |