1 51 package org.apache.fop.pdf; 52 53 import java.io.UnsupportedEncodingException ; 55 import java.util.List ; 56 57 import org.apache.fop.datatypes.ColorSpace; 59 60 70 public class PDFShading extends PDFObject { 71 73 76 protected String shadingName = null; 77 78 81 protected int shadingType = 3; 83 86 protected ColorSpace colorSpace = null; 88 89 93 protected List background = null; 94 95 98 protected List bBox = null; 99 100 104 protected boolean antiAlias = false; 105 106 111 112 protected List domain = null; 113 114 117 protected List matrix = null; 118 119 124 protected PDFFunction function = null; 125 126 131 protected List coords = null; 132 133 138 protected List extend = null; 139 140 144 protected int bitsPerCoordinate = 0; 145 146 150 protected int bitsPerFlag = 0; 151 152 157 protected List decode = null; 158 159 163 protected int bitsPerComponent = 0; 164 165 168 protected int verticesPerRow = 0; 169 170 194 public PDFShading(int theNumber, String theShadingName, 195 int theShadingType, ColorSpace theColorSpace, 196 List theBackground, List theBBox, 197 boolean theAntiAlias, List theDomain, 198 List theMatrix, PDFFunction theFunction) { 199 super(theNumber); 200 this.shadingName = theShadingName; 201 this.shadingType = theShadingType; this.colorSpace = theColorSpace; 203 this.background = theBackground; 204 this.bBox = theBBox; 205 this.antiAlias = theAntiAlias; 206 207 this.domain = theDomain; 208 this.matrix = theMatrix; 209 this.function = theFunction; 210 211 } 212 213 235 public PDFShading(int theNumber, String theShadingName, 236 int theShadingType, ColorSpace theColorSpace, 237 List theBackground, List theBBox, 238 boolean theAntiAlias, List theCoords, 239 List theDomain, PDFFunction theFunction, 240 List theExtend) { 241 super(theNumber); 242 this.shadingName = theShadingName; 243 this.shadingType = theShadingType; this.colorSpace = theColorSpace; 245 this.background = theBackground; 246 this.bBox = theBBox; 247 this.antiAlias = theAntiAlias; 248 249 this.coords = theCoords; 250 this.domain = theDomain; 251 this.function = theFunction; 252 this.extend = theExtend; 253 254 } 255 256 280 public PDFShading(int theNumber, String theShadingName, 281 int theShadingType, ColorSpace theColorSpace, 282 List theBackground, List theBBox, 283 boolean theAntiAlias, int theBitsPerCoordinate, 284 int theBitsPerComponent, int theBitsPerFlag, 285 List theDecode, PDFFunction theFunction) { 286 super(theNumber); 287 288 this.shadingType = theShadingType; this.colorSpace = theColorSpace; 290 this.background = theBackground; 291 this.bBox = theBBox; 292 this.antiAlias = theAntiAlias; 293 294 this.bitsPerCoordinate = theBitsPerCoordinate; 295 this.bitsPerComponent = theBitsPerComponent; 296 this.bitsPerFlag = theBitsPerFlag; 297 this.decode = theDecode; 298 this.function = theFunction; 299 } 300 301 323 public PDFShading(int theNumber, String theShadingName, 324 int theShadingType, ColorSpace theColorSpace, 325 List theBackground, List theBBox, 326 boolean theAntiAlias, int theBitsPerCoordinate, 327 int theBitsPerComponent, List theDecode, 328 int theVerticesPerRow, PDFFunction theFunction) { 329 super(theNumber); 330 this.shadingName = theShadingName; 331 this.shadingType = theShadingType; this.colorSpace = theColorSpace; 333 this.background = theBackground; 334 this.bBox = theBBox; 335 this.antiAlias = theAntiAlias; 336 337 this.bitsPerCoordinate = theBitsPerCoordinate; 338 this.bitsPerComponent = theBitsPerComponent; 339 this.decode = theDecode; 340 this.verticesPerRow = theVerticesPerRow; 341 this.function = theFunction; 342 343 } 344 345 public String getName() { 346 return (this.shadingName); 347 } 348 349 360 public byte[] toPDF() { 361 int vectorSize; 362 int tempInt; 363 StringBuffer p = new StringBuffer (); 364 p.append(this.number + " " + this.generation 365 + " obj\n<< \n/ShadingType " + this.shadingType + " \n"); 366 if (this.colorSpace != null) { 367 p.append("/ColorSpace /" 368 + this.colorSpace.getColorSpacePDFString() + " \n"); 369 } 370 371 if (this.background != null) { 372 p.append("/Background [ "); 373 vectorSize = this.background.size(); 374 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 375 p.append(PDFNumber.doubleOut((Double )this.background.get(tempInt)) 376 + " "); 377 } 378 p.append("] \n"); 379 } 380 381 if (this.bBox 382 != null) { p.append("/BBox [ "); 384 vectorSize = this.bBox.size(); 385 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 386 p.append(PDFNumber.doubleOut((Double )this.bBox.get(tempInt)) 387 + " "); 388 } 389 p.append("] \n"); 390 } 391 392 if (this.antiAlias) { 393 p.append("/AntiAlias " + this.antiAlias + " \n"); 394 } 395 396 if (this.shadingType == 1) { if (this.domain != null) { 399 p.append("/Domain [ "); 400 vectorSize = this.domain.size(); 401 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 402 p.append(PDFNumber.doubleOut((Double )this.domain.get(tempInt)) 403 + " "); 404 } 405 p.append("] \n"); 406 } else { 407 p.append("/Domain [ 0 1 ] \n"); 408 } 409 410 if (this.matrix != null) { 411 p.append("/Matrix [ "); 412 vectorSize = this.matrix.size(); 413 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 414 p.append(PDFNumber.doubleOut((Double )this.matrix.get(tempInt)) 415 + " "); 416 } 417 p.append("] \n"); 418 } 419 420 if (this.function != null) { 421 p.append("/Function "); 422 p.append(this.function.referencePDF() + " \n"); 423 } 424 } else if ((this.shadingType == 2) 425 || (this.shadingType 426 == 3)) { if (this.coords != null) { 429 p.append("/Coords [ "); 430 vectorSize = this.coords.size(); 431 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 432 p.append(PDFNumber.doubleOut((Double )this.coords.get(tempInt)) 433 + " "); 434 } 435 p.append("] \n"); 436 } 437 438 if (this.domain != null) { 440 p.append("/Domain [ "); 441 vectorSize = this.domain.size(); 442 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 443 p.append(PDFNumber.doubleOut((Double )this.domain.get(tempInt)) 444 + " "); 445 } 446 p.append("] \n"); 447 } else { 448 p.append("/Domain [ 0 1 ] \n"); 449 } 450 451 if (this.extend != null) { 452 p.append("/Extend [ "); 453 vectorSize = this.extend.size(); 454 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 455 p.append(((Boolean )this.extend.get(tempInt)) + " "); 456 } 457 458 p.append("] \n"); 459 } else { 460 p.append("/Extend [ true true ] \n"); 461 } 462 463 464 if (this.function != null) { 465 p.append("/Function "); 466 p.append(this.function.referencePDF() + " \n"); 467 } 468 469 470 } else if ((this.shadingType == 4) || (this.shadingType == 6) 471 || (this.shadingType 472 == 7)) { if (this.bitsPerCoordinate > 0) { 476 p.append("/BitsPerCoordinate " + this.bitsPerCoordinate 477 + " \n"); 478 } else { 479 p.append("/BitsPerCoordinate 1 \n"); 480 } 481 482 if (this.bitsPerComponent > 0) { 483 p.append("/BitsPerComponent " + this.bitsPerComponent 484 + " \n"); 485 } else { 486 p.append("/BitsPerComponent 1 \n"); 487 } 488 489 if (this.bitsPerFlag > 0) { 490 p.append("/BitsPerFlag " + this.bitsPerFlag + " \n"); 491 } else { 492 p.append("/BitsPerFlag 2 \n"); 493 } 494 495 if (this.decode != null) { 496 p.append("/Decode [ "); 497 vectorSize = this.decode.size(); 498 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 499 p.append(((Boolean )this.decode.get(tempInt)) + " "); 500 } 501 502 p.append("] \n"); 503 } 504 505 if (this.function != null) { 506 p.append("/Function "); 507 p.append(this.function.referencePDF() + " \n"); 508 } 509 510 } else if (this.shadingType 511 == 5) { 513 if (this.bitsPerCoordinate > 0) { 514 p.append("/BitsPerCoordinate " + this.bitsPerCoordinate 515 + " \n"); 516 } else { 517 p.append("/BitsPerCoordinate 1 \n"); 518 } 519 520 if (this.bitsPerComponent > 0) { 521 p.append("/BitsPerComponent " + this.bitsPerComponent 522 + " \n"); 523 } else { 524 p.append("/BitsPerComponent 1 \n"); 525 } 526 527 if (this.decode != null) { 528 p.append("/Decode [ "); 529 vectorSize = this.decode.size(); 530 for (tempInt = 0; tempInt < vectorSize; tempInt++) { 531 p.append(((Boolean )this.decode.get(tempInt)) + " "); 532 } 533 534 p.append("] \n"); 535 } 536 537 if (this.function != null) { 538 p.append("/Function "); 539 p.append(this.function.referencePDF() + " \n"); 540 } 541 542 if (this.verticesPerRow > 0) { 543 p.append("/VerticesPerRow " + this.verticesPerRow + " \n"); 544 } else { 545 p.append("/VerticesPerRow 2 \n"); 546 } 547 548 } 549 550 p.append(">> \nendobj\n"); 551 552 try { 553 return p.toString().getBytes(PDFDocument.ENCODING); 554 } catch (UnsupportedEncodingException ue) { 555 return p.toString().getBytes(); 556 } 557 } 558 559 } 560 | Popular Tags |