1 51 package org.apache.fop.pdf; 52 53 import java.io.UnsupportedEncodingException ; 55 import java.util.List ; 56 57 67 public class PDFPattern extends PDFPathPaint { 68 69 72 74 protected PDFResources resources = null; 75 76 79 protected int patternType = 2; 81 84 protected String patternName = null; 85 86 89 protected int paintType = 2; 90 91 94 protected int tilingType = 1; 95 96 99 protected List bBox = null; 100 101 104 protected double xStep = -1; 105 106 109 protected double yStep = -1; 110 111 114 protected PDFShading shading = null; 115 116 119 protected List xUID = null; 120 121 125 protected StringBuffer extGState = 126 null; 128 131 protected List matrix = null; 132 133 136 protected StringBuffer patternDataStream = null; 137 138 139 155 public PDFPattern(int theNumber, String thePatternName, 156 PDFResources theResources, int thePatternType, int thePaintType, int theTilingType, List theBBox, 158 double theXStep, double theYStep, 159 List theMatrix, List theXUID, 160 StringBuffer thePatternDataStream) { 161 super(theNumber); 162 this.patternName = thePatternName; 163 164 this.resources = theResources; 165 168 this.patternType = 1; this.paintType = thePaintType; 170 this.tilingType = theTilingType; 171 this.bBox = theBBox; 172 this.xStep = theXStep; 173 this.yStep = theYStep; 174 this.matrix = theMatrix; 175 this.xUID = theXUID; 176 this.patternDataStream = thePatternDataStream; 177 } 178 179 190 public PDFPattern(int theNumber, String thePatternName, 191 int thePatternType, PDFShading theShading, 192 List theXUID, StringBuffer theExtGState, 193 List theMatrix) { 194 super(theNumber); 195 196 this.patternName = thePatternName; 197 198 this.patternType = 2; this.shading = theShading; 200 this.xUID = theXUID; 201 this.extGState = theExtGState; this.matrix = theMatrix; 205 } 206 207 212 public String getName() { 213 return (this.patternName); 214 } 215 216 public String getColorSpaceOut(boolean fillNotStroke) { 217 if (fillNotStroke) { return ("/Pattern cs /" + this.getName() + " scn \n"); 219 } else { return ("/Pattern CS /" + this.getName() + " SCN \n"); 221 } 222 } 223 224 225 236 public byte[] toPDF() { 237 238 239 int vectorSize = 0; 240 int tempInt = 0; 241 StringBuffer p = new StringBuffer (); 242 p.append(this.number + " " + this.generation 243 + " obj\n<< \n/Type /Pattern \n"); 244 245 if (this.resources != null) { 246 p.append("/Resources " + this.resources.referencePDF() + " \n"); 247 } 248 249 p.append("/PatternType " + this.patternType + " \n"); 250 251 if (this.patternType == 1) { 252 p.append("/PaintType " + this.paintType + " \n"); 253 p.append("/TilingType " + this.tilingType + " \n"); 254 255 if (this.bBox != null) { 256 vectorSize = this.bBox.size(); 257 p.append("/BBox [ "); 258 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 259 p.append(PDFNumber.doubleOut((Double )this.bBox.get(tempInt))); 260 p.append(" "); 261 } 262 p.append("] \n"); 263 } 264 p.append("/XStep " + PDFNumber.doubleOut(new Double (this.xStep)) 265 + " \n"); 266 p.append("/YStep " + PDFNumber.doubleOut(new Double (this.yStep)) 267 + " \n"); 268 269 if (this.matrix != null) { 270 vectorSize = this.matrix.size(); 271 p.append("/Matrix [ "); 272 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 273 p.append(PDFNumber.doubleOut((Double )this.matrix.get(tempInt))); 274 p.append(" "); 275 } 276 p.append("] \n"); 277 } 278 279 if (this.xUID != null) { 280 vectorSize = this.xUID.size(); 281 p.append("/XUID [ "); 282 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 283 p.append(((Integer )this.xUID.get(tempInt)) + " "); 284 } 285 p.append("] \n"); 286 } 287 if (this.patternDataStream != null) { 289 p.append("/Length " + (this.patternDataStream.length() + 1) 290 + " \n"); 291 } 292 293 } else { if (this.shading != null) { 296 p.append("/Shading " + this.shading.referencePDF() + " \n"); 297 } 298 299 if (this.xUID != null) { 300 vectorSize = this.xUID.size(); 301 p.append("/XUID [ "); 302 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 303 p.append(((Integer )this.xUID.get(tempInt)) + " "); 304 } 305 p.append("] \n"); 306 } 307 308 if (this.extGState 309 != null) { p.append("/ExtGState " + this.extGState + " \n"); 311 } 312 313 if (this.matrix != null) { 314 vectorSize = this.matrix.size(); 315 p.append("/Matrix [ "); 316 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 317 p.append(PDFNumber.doubleOut((Double )this.matrix.get(tempInt))); 318 p.append(" "); 319 } 320 p.append("] \n"); 321 } 322 } 324 p.append(">> \n"); 325 326 if (this.patternDataStream != null) { 328 p.append("stream\n" + this.patternDataStream + "\nendstream\n"); 329 } 330 331 p.append("endobj\n"); 332 333 try { 334 return p.toString().getBytes(PDFDocument.ENCODING); 335 } catch (UnsupportedEncodingException ue) { 336 return p.toString().getBytes(); 337 } 338 } 339 340 } 341 | Popular Tags |