1 45 package com.lowagie.text.pdf; 46 47 import java.awt.Color ; 48 49 import com.lowagie.text.DocumentException; 50 import com.lowagie.text.Image; 51 import com.lowagie.text.Rectangle; 52 53 56 57 public class PdfPatternPainter extends PdfTemplate { 58 59 protected float xstep, ystep; 60 protected boolean stencil = false; 61 protected Color defaultColor; 62 63 66 67 private PdfPatternPainter() { 68 super(); 69 type = TYPE_PATTERN; 70 } 71 72 77 78 PdfPatternPainter(PdfWriter wr) { 79 super(wr); 80 type = TYPE_PATTERN; 81 } 82 83 PdfPatternPainter(PdfWriter wr, Color defaultColor) { 84 this(wr); 85 stencil = true; 86 if (defaultColor == null) 87 this.defaultColor = Color.gray; 88 else 89 this.defaultColor = defaultColor; 90 } 91 92 97 98 public void setXStep(float xstep) { 99 this.xstep = xstep; 100 } 101 102 107 108 public void setYStep(float ystep) { 109 this.ystep = ystep; 110 } 111 112 116 public float getXStep() { 117 return this.xstep; 118 } 119 120 124 public float getYStep() { 125 return this.ystep; 126 } 127 128 132 public boolean isStencil() { 133 return stencil; 134 } 135 136 145 public void setPatternMatrix(float a, float b, float c, float d, float e, float f) { 146 setMatrix(a, b, c, d, e, f); 147 } 148 153 154 PdfPattern getPattern() { 155 return new PdfPattern(this); 156 } 157 158 163 164 public PdfContentByte getDuplicate() { 165 PdfPatternPainter tpl = new PdfPatternPainter(); 166 tpl.writer = writer; 167 tpl.pdf = pdf; 168 tpl.thisReference = thisReference; 169 tpl.pageResources = pageResources; 170 tpl.bBox = new Rectangle(bBox); 171 tpl.xstep = xstep; 172 tpl.ystep = ystep; 173 tpl.matrix = matrix; 174 tpl.stencil = stencil; 175 tpl.defaultColor = defaultColor; 176 return tpl; 177 } 178 179 183 public Color getDefaultColor() { 184 return defaultColor; 185 } 186 187 190 public void setGrayFill(float gray) { 191 checkNoColor(); 192 super.setGrayFill(gray); 193 } 194 195 198 public void resetGrayFill() { 199 checkNoColor(); 200 super.resetGrayFill(); 201 } 202 203 206 public void setGrayStroke(float gray) { 207 checkNoColor(); 208 super.setGrayStroke(gray); 209 } 210 211 214 public void resetGrayStroke() { 215 checkNoColor(); 216 super.resetGrayStroke(); 217 } 218 219 222 public void setRGBColorFillF(float red, float green, float blue) { 223 checkNoColor(); 224 super.setRGBColorFillF(red, green, blue); 225 } 226 227 230 public void resetRGBColorFill() { 231 checkNoColor(); 232 super.resetRGBColorFill(); 233 } 234 235 238 public void setRGBColorStrokeF(float red, float green, float blue) { 239 checkNoColor(); 240 super.setRGBColorStrokeF(red, green, blue); 241 } 242 243 246 public void resetRGBColorStroke() { 247 checkNoColor(); 248 super.resetRGBColorStroke(); 249 } 250 251 254 public void setCMYKColorFillF(float cyan, float magenta, float yellow, float black) { 255 checkNoColor(); 256 super.setCMYKColorFillF(cyan, magenta, yellow, black); 257 } 258 259 262 public void resetCMYKColorFill() { 263 checkNoColor(); 264 super.resetCMYKColorFill(); 265 } 266 267 270 public void setCMYKColorStrokeF(float cyan, float magenta, float yellow, float black) { 271 checkNoColor(); 272 super.setCMYKColorStrokeF(cyan, magenta, yellow, black); 273 } 274 275 278 public void resetCMYKColorStroke() { 279 checkNoColor(); 280 super.resetCMYKColorStroke(); 281 } 282 283 286 public void addImage(Image image, float a, float b, float c, float d, float e, float f) throws DocumentException { 287 if (stencil && !image.isMask()) 288 checkNoColor(); 289 super.addImage(image, a, b, c, d, e, f); 290 } 291 292 295 public void setCMYKColorFill(int cyan, int magenta, int yellow, int black) { 296 checkNoColor(); 297 super.setCMYKColorFill(cyan, magenta, yellow, black); 298 } 299 300 303 public void setCMYKColorStroke(int cyan, int magenta, int yellow, int black) { 304 checkNoColor(); 305 super.setCMYKColorStroke(cyan, magenta, yellow, black); 306 } 307 308 311 public void setRGBColorFill(int red, int green, int blue) { 312 checkNoColor(); 313 super.setRGBColorFill(red, green, blue); 314 } 315 316 319 public void setRGBColorStroke(int red, int green, int blue) { 320 checkNoColor(); 321 super.setRGBColorStroke(red, green, blue); 322 } 323 324 327 public void setColorStroke(Color color) { 328 checkNoColor(); 329 super.setColorStroke(color); 330 } 331 332 335 public void setColorFill(Color color) { 336 checkNoColor(); 337 super.setColorFill(color); 338 } 339 340 343 public void setColorFill(PdfSpotColor sp, float tint) { 344 checkNoColor(); 345 super.setColorFill(sp, tint); 346 } 347 348 351 public void setColorStroke(PdfSpotColor sp, float tint) { 352 checkNoColor(); 353 super.setColorStroke(sp, tint); 354 } 355 356 359 public void setPatternFill(PdfPatternPainter p) { 360 checkNoColor(); 361 super.setPatternFill(p); 362 } 363 364 367 public void setPatternFill(PdfPatternPainter p, Color color, float tint) { 368 checkNoColor(); 369 super.setPatternFill(p, color, tint); 370 } 371 372 375 public void setPatternStroke(PdfPatternPainter p, Color color, float tint) { 376 checkNoColor(); 377 super.setPatternStroke(p, color, tint); 378 } 379 380 383 public void setPatternStroke(PdfPatternPainter p) { 384 checkNoColor(); 385 super.setPatternStroke(p); 386 } 387 388 void checkNoColor() { 389 if (stencil) 390 throw new RuntimeException ("Colors are not allowed in uncolored tile patterns."); 391 } 392 } 393 | Popular Tags |