Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.pdfjet.Image Maven / Gradle / Ivy
/* */ package com.pdfjet;
/* */
/* */ import java.io.InputStream;
/* */ import java.util.List;
/* */
/* */ public class Image
/* */ implements Drawable
/* */ {
/* */ protected int objNumber;
/* */ protected float x;
/* */ protected float y;
/* */ protected float w;
/* */ protected float h;
/* */ protected long size;
/* */ protected String uri;
/* */ protected String key;
/* */ private float box_x;
/* */ private float box_y;
/* 58 */ private int degrees = 0;
/* */
/* 60 */ private String language = null;
/* 61 */ private String altDescription = " ";
/* 62 */ private String actualText = " ";
/* */
/* */ public Image(PDF paramPDF, InputStream paramInputStream, int paramInt)
/* */ throws Exception
/* */ {
/* */ Object localObject;
/* */ byte[] arrayOfByte;
/* 76 */ if (paramInt == 0) {
/* 77 */ localObject = new JPGImage(paramInputStream);
/* 78 */ arrayOfByte = ((JPGImage)localObject).getData();
/* 79 */ this.w = ((JPGImage)localObject).getWidth();
/* 80 */ this.h = ((JPGImage)localObject).getHeight();
/* 81 */ if (((JPGImage)localObject).getColorComponents() == 1) {
/* 82 */ addImage(paramPDF, arrayOfByte, null, paramInt, "DeviceGray", 8);
/* */ }
/* 84 */ else if (((JPGImage)localObject).getColorComponents() == 3) {
/* 85 */ addImage(paramPDF, arrayOfByte, null, paramInt, "DeviceRGB", 8);
/* */ }
/* 87 */ else if (((JPGImage)localObject).getColorComponents() == 4) {
/* 88 */ addImage(paramPDF, arrayOfByte, null, paramInt, "DeviceCMYK", 8);
/* */ }
/* */ }
/* 91 */ else if (paramInt == 1) {
/* 92 */ localObject = new PNGImage(paramInputStream);
/* 93 */ arrayOfByte = ((PNGImage)localObject).getData();
/* 94 */ this.w = ((PNGImage)localObject).getWidth();
/* 95 */ this.h = ((PNGImage)localObject).getHeight();
/* 96 */ if (((PNGImage)localObject).getColorType() == 0) {
/* 97 */ addImage(paramPDF, arrayOfByte, null, paramInt, "DeviceGray", ((PNGImage)localObject).getBitDepth());
/* */ }
/* 100 */ else if (((PNGImage)localObject).getBitDepth() == 16) {
/* 101 */ addImage(paramPDF, arrayOfByte, null, paramInt, "DeviceRGB", 16);
/* */ }
/* */ else {
/* 104 */ addImage(paramPDF, arrayOfByte, ((PNGImage)localObject).getAlpha(), paramInt, "DeviceRGB", 8);
/* */ }
/* */
/* */ }
/* 108 */ else if (paramInt == 2) {
/* 109 */ localObject = new BMPImage(paramInputStream);
/* 110 */ arrayOfByte = ((BMPImage)localObject).getData();
/* 111 */ this.w = ((BMPImage)localObject).getWidth();
/* 112 */ this.h = ((BMPImage)localObject).getHeight();
/* 113 */ addImage(paramPDF, arrayOfByte, null, paramInt, "DeviceRGB", 8);
/* */ }
/* 115 */ else if (paramInt == 3) {
/* 116 */ addImage(paramPDF, paramInputStream);
/* */ }
/* */
/* 119 */ paramInputStream.close();
/* */ }
/* */
/* */ public void setPosition(double paramDouble1, double paramDouble2)
/* */ {
/* 130 */ setPosition((float)paramDouble1, (float)paramDouble2);
/* */ }
/* */
/* */ public void setPosition(float paramFloat1, float paramFloat2)
/* */ {
/* 141 */ setLocation(paramFloat1, paramFloat2);
/* */ }
/* */
/* */ public void setLocation(float paramFloat1, float paramFloat2)
/* */ {
/* 152 */ this.x = paramFloat1;
/* 153 */ this.y = paramFloat2;
/* */ }
/* */
/* */ public void scaleBy(double paramDouble)
/* */ {
/* 163 */ scaleBy((float)paramDouble, (float)paramDouble);
/* */ }
/* */
/* */ public void scaleBy(float paramFloat)
/* */ {
/* 173 */ scaleBy(paramFloat, paramFloat);
/* */ }
/* */
/* */ public void scaleBy(float paramFloat1, float paramFloat2)
/* */ {
/* 185 */ this.w *= paramFloat1;
/* 186 */ this.h *= paramFloat2;
/* */ }
/* */
/* */ public void placeIn(Box paramBox)
/* */ throws Exception
/* */ {
/* 196 */ this.box_x = paramBox.x;
/* 197 */ this.box_y = paramBox.y;
/* */ }
/* */
/* */ public void setURIAction(String paramString)
/* */ {
/* 207 */ this.uri = paramString;
/* */ }
/* */
/* */ public void setGoToAction(String paramString)
/* */ {
/* 217 */ this.key = paramString;
/* */ }
/* */
/* */ public void setRotateCW90(boolean paramBoolean)
/* */ {
/* 228 */ if (paramBoolean) {
/* 229 */ this.degrees = 90;
/* */ }
/* */ else
/* 232 */ this.degrees = 0;
/* */ }
/* */
/* */ public void setRotate(int paramInt)
/* */ {
/* 243 */ this.degrees = paramInt;
/* */ }
/* */
/* */ public Image setAltDescription(String paramString)
/* */ {
/* 254 */ this.altDescription = paramString;
/* 255 */ return this;
/* */ }
/* */
/* */ public Image setActualText(String paramString)
/* */ {
/* 266 */ this.actualText = paramString;
/* 267 */ return this;
/* */ }
/* */
/* */ public float[] drawOn(Page paramPage)
/* */ throws Exception
/* */ {
/* 279 */ paramPage.addBMC("Span", this.language, this.altDescription, this.actualText);
/* */
/* 281 */ this.x += this.box_x;
/* 282 */ this.y += this.box_y;
/* 283 */ paramPage.append("q\n");
/* */
/* 285 */ if (this.degrees == 0) {
/* 286 */ paramPage.append(this.w);
/* 287 */ paramPage.append(' ');
/* 288 */ paramPage.append(0.0F);
/* 289 */ paramPage.append(' ');
/* 290 */ paramPage.append(0.0F);
/* 291 */ paramPage.append(' ');
/* 292 */ paramPage.append(this.h);
/* 293 */ paramPage.append(' ');
/* 294 */ paramPage.append(this.x);
/* 295 */ paramPage.append(' ');
/* 296 */ paramPage.append(paramPage.height - (this.y + this.h));
/* 297 */ paramPage.append(" cm\n");
/* */ }
/* 299 */ else if (this.degrees == 90) {
/* 300 */ paramPage.append(this.h);
/* 301 */ paramPage.append(' ');
/* 302 */ paramPage.append(0.0F);
/* 303 */ paramPage.append(' ');
/* 304 */ paramPage.append(0.0F);
/* 305 */ paramPage.append(' ');
/* 306 */ paramPage.append(this.w);
/* 307 */ paramPage.append(' ');
/* 308 */ paramPage.append(this.x);
/* 309 */ paramPage.append(' ');
/* 310 */ paramPage.append(paramPage.height - this.y);
/* 311 */ paramPage.append(" cm\n");
/* 312 */ paramPage.append("0 -1 1 0 0 0 cm\n");
/* */ }
/* 314 */ else if (this.degrees == 180) {
/* 315 */ paramPage.append(this.w);
/* 316 */ paramPage.append(' ');
/* 317 */ paramPage.append(0.0F);
/* 318 */ paramPage.append(' ');
/* 319 */ paramPage.append(0.0F);
/* 320 */ paramPage.append(' ');
/* 321 */ paramPage.append(this.h);
/* 322 */ paramPage.append(' ');
/* 323 */ paramPage.append(this.x + this.w);
/* 324 */ paramPage.append(' ');
/* 325 */ paramPage.append(paramPage.height - this.y);
/* 326 */ paramPage.append(" cm\n");
/* 327 */ paramPage.append("-1 0 0 -1 0 0 cm\n");
/* */ }
/* 329 */ else if (this.degrees == 270) {
/* 330 */ paramPage.append(this.h);
/* 331 */ paramPage.append(' ');
/* 332 */ paramPage.append(0.0F);
/* 333 */ paramPage.append(' ');
/* 334 */ paramPage.append(0.0F);
/* 335 */ paramPage.append(' ');
/* 336 */ paramPage.append(this.w);
/* 337 */ paramPage.append(' ');
/* 338 */ paramPage.append(this.x + this.h);
/* 339 */ paramPage.append(' ');
/* 340 */ paramPage.append(paramPage.height - (this.y + this.w));
/* 341 */ paramPage.append(" cm\n");
/* 342 */ paramPage.append("0 1 -1 0 0 0 cm\n");
/* */ }
/* */
/* 345 */ paramPage.append("/Im");
/* 346 */ paramPage.append(this.objNumber);
/* 347 */ paramPage.append(" Do\n");
/* 348 */ paramPage.append("Q\n");
/* */
/* 350 */ paramPage.addEMC();
/* */
/* 352 */ if ((this.uri != null) || (this.key != null)) {
/* 353 */ paramPage.addAnnotation(new Annotation(this.uri, this.key, this.x, paramPage.height - this.y, this.x + this.w, paramPage.height - (this.y + this.h), this.language, this.altDescription, this.actualText));
/* */ }
/* */
/* 365 */ return new float[] { this.x + this.w, this.y + this.h };
/* */ }
/* */
/* */ public float getWidth()
/* */ {
/* 376 */ return this.w;
/* */ }
/* */
/* */ public float getHeight()
/* */ {
/* 387 */ return this.h;
/* */ }
/* */
/* */ private void addSoftMask(PDF paramPDF, byte[] paramArrayOfByte, String paramString, int paramInt)
/* */ throws Exception
/* */ {
/* 396 */ paramPDF.newobj();
/* 397 */ paramPDF.append("<<\n");
/* 398 */ paramPDF.append("/Type /XObject\n");
/* 399 */ paramPDF.append("/Subtype /Image\n");
/* 400 */ paramPDF.append("/Filter /FlateDecode\n");
/* 401 */ paramPDF.append("/Width ");
/* 402 */ paramPDF.append((int)this.w);
/* 403 */ paramPDF.append('\n');
/* 404 */ paramPDF.append("/Height ");
/* 405 */ paramPDF.append((int)this.h);
/* 406 */ paramPDF.append('\n');
/* 407 */ paramPDF.append("/ColorSpace /");
/* 408 */ paramPDF.append(paramString);
/* 409 */ paramPDF.append('\n');
/* 410 */ paramPDF.append("/BitsPerComponent ");
/* 411 */ paramPDF.append(paramInt);
/* 412 */ paramPDF.append('\n');
/* 413 */ paramPDF.append("/Length ");
/* 414 */ paramPDF.append(paramArrayOfByte.length);
/* 415 */ paramPDF.append('\n');
/* 416 */ paramPDF.append(">>\n");
/* 417 */ paramPDF.append("stream\n");
/* 418 */ paramPDF.append(paramArrayOfByte, 0, paramArrayOfByte.length);
/* 419 */ paramPDF.append("\nendstream\n");
/* 420 */ paramPDF.endobj();
/* 421 */ this.objNumber = paramPDF.objNumber;
/* */ }
/* */
/* */ private void addImage(PDF paramPDF, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, int paramInt1, String paramString, int paramInt2)
/* */ throws Exception
/* */ {
/* 432 */ if (paramArrayOfByte2 != null) {
/* 433 */ addSoftMask(paramPDF, paramArrayOfByte2, "DeviceGray", 8);
/* */ }
/* 435 */ paramPDF.newobj();
/* 436 */ paramPDF.append("<<\n");
/* 437 */ paramPDF.append("/Type /XObject\n");
/* 438 */ paramPDF.append("/Subtype /Image\n");
/* 439 */ if (paramInt1 == 0) {
/* 440 */ paramPDF.append("/Filter /DCTDecode\n");
/* */ }
/* 442 */ else if ((paramInt1 == 1) || (paramInt1 == 2)) {
/* 443 */ paramPDF.append("/Filter /FlateDecode\n");
/* 444 */ if (paramArrayOfByte2 != null) {
/* 445 */ paramPDF.append("/SMask ");
/* 446 */ paramPDF.append(this.objNumber);
/* 447 */ paramPDF.append(" 0 R\n");
/* */ }
/* */ }
/* 450 */ paramPDF.append("/Width ");
/* 451 */ paramPDF.append((int)this.w);
/* 452 */ paramPDF.append('\n');
/* 453 */ paramPDF.append("/Height ");
/* 454 */ paramPDF.append((int)this.h);
/* 455 */ paramPDF.append('\n');
/* 456 */ paramPDF.append("/ColorSpace /");
/* 457 */ paramPDF.append(paramString);
/* 458 */ paramPDF.append('\n');
/* 459 */ paramPDF.append("/BitsPerComponent ");
/* 460 */ paramPDF.append(paramInt2);
/* 461 */ paramPDF.append('\n');
/* 462 */ if (paramString.equals("DeviceCMYK"))
/* */ {
/* 464 */ paramPDF.append("/Decode [1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0]\n");
/* */ }
/* 466 */ paramPDF.append("/Length ");
/* 467 */ paramPDF.append(paramArrayOfByte1.length);
/* 468 */ paramPDF.append('\n');
/* 469 */ paramPDF.append(">>\n");
/* 470 */ paramPDF.append("stream\n");
/* 471 */ paramPDF.append(paramArrayOfByte1, 0, paramArrayOfByte1.length);
/* 472 */ paramPDF.append("\nendstream\n");
/* 473 */ paramPDF.endobj();
/* 474 */ paramPDF.images.add(this);
/* 475 */ this.objNumber = paramPDF.objNumber;
/* */ }
/* */
/* */ private void addImage(PDF paramPDF, InputStream paramInputStream)
/* */ throws Exception
/* */ {
/* 481 */ this.w = getInt(paramInputStream);
/* 482 */ this.h = getInt(paramInputStream);
/* 483 */ int i = (byte)paramInputStream.read();
/* 484 */ int j = (byte)paramInputStream.read();
/* */
/* 486 */ if (j != 0) {
/* 487 */ paramPDF.newobj();
/* 488 */ paramPDF.append("<<\n");
/* 489 */ paramPDF.append("/Type /XObject\n");
/* 490 */ paramPDF.append("/Subtype /Image\n");
/* 491 */ paramPDF.append("/Filter /FlateDecode\n");
/* 492 */ paramPDF.append("/Width ");
/* 493 */ paramPDF.append(this.w);
/* 494 */ paramPDF.append('\n');
/* 495 */ paramPDF.append("/Height ");
/* 496 */ paramPDF.append(this.h);
/* 497 */ paramPDF.append('\n');
/* 498 */ paramPDF.append("/ColorSpace /DeviceGray\n");
/* 499 */ paramPDF.append("/BitsPerComponent 8\n");
/* 500 */ int k = getInt(paramInputStream);
/* 501 */ paramPDF.append("/Length ");
/* 502 */ paramPDF.append(k);
/* 503 */ paramPDF.append('\n');
/* 504 */ paramPDF.append(">>\n");
/* 505 */ paramPDF.append("stream\n");
/* 506 */ byte[] arrayOfByte2 = new byte[k];
/* 507 */ paramInputStream.read(arrayOfByte2, 0, k);
/* 508 */ paramPDF.append(arrayOfByte2, 0, k);
/* 509 */ paramPDF.append("\nendstream\n");
/* 510 */ paramPDF.endobj();
/* 511 */ this.objNumber = paramPDF.objNumber;
/* */ }
/* */
/* 514 */ paramPDF.newobj();
/* 515 */ paramPDF.append("<<\n");
/* 516 */ paramPDF.append("/Type /XObject\n");
/* 517 */ paramPDF.append("/Subtype /Image\n");
/* 518 */ paramPDF.append("/Filter /FlateDecode\n");
/* 519 */ if (j != 0) {
/* 520 */ paramPDF.append("/SMask ");
/* 521 */ paramPDF.append(this.objNumber);
/* 522 */ paramPDF.append(" 0 R\n");
/* */ }
/* 524 */ paramPDF.append("/Width ");
/* 525 */ paramPDF.append(this.w);
/* 526 */ paramPDF.append('\n');
/* 527 */ paramPDF.append("/Height ");
/* 528 */ paramPDF.append(this.h);
/* 529 */ paramPDF.append('\n');
/* 530 */ paramPDF.append("/ColorSpace /");
/* 531 */ if (i == 1) {
/* 532 */ paramPDF.append("DeviceGray");
/* */ }
/* 534 */ else if ((i == 3) || (i == 6)) {
/* 535 */ paramPDF.append("DeviceRGB");
/* */ }
/* 537 */ paramPDF.append('\n');
/* 538 */ paramPDF.append("/BitsPerComponent 8\n");
/* 539 */ paramPDF.append("/Length ");
/* 540 */ paramPDF.append(getInt(paramInputStream));
/* 541 */ paramPDF.append('\n');
/* 542 */ paramPDF.append(">>\n");
/* 543 */ paramPDF.append("stream\n");
/* 544 */ byte[] arrayOfByte1 = new byte[2048];
/* */ int m;
/* 546 */ while ((m = paramInputStream.read(arrayOfByte1, 0, arrayOfByte1.length)) > 0) {
/* 547 */ paramPDF.append(arrayOfByte1, 0, m);
/* */ }
/* 549 */ paramPDF.append("\nendstream\n");
/* 550 */ paramPDF.endobj();
/* 551 */ paramPDF.images.add(this);
/* 552 */ this.objNumber = paramPDF.objNumber;
/* */ }
/* */
/* */ private int getInt(InputStream paramInputStream) throws Exception
/* */ {
/* 557 */ byte[] arrayOfByte = new byte[4];
/* 558 */ paramInputStream.read(arrayOfByte, 0, 4);
/* 559 */ int i = 0;
/* 560 */ i |= arrayOfByte[0] & 0xFF;
/* 561 */ i <<= 8;
/* 562 */ i |= arrayOfByte[1] & 0xFF;
/* 563 */ i <<= 8;
/* 564 */ i |= arrayOfByte[2] & 0xFF;
/* 565 */ i <<= 8;
/* 566 */ i |= arrayOfByte[3] & 0xFF;
/* 567 */ return i;
/* */ }
/* */ }
/* Location: E:\EGGWIFI\Customer\trunk\src\Workspace\Customer\Customer Maven Webapp\src\main\webapp\WEB-INF\lib\PDFjet.jar
* Qualified Name: com.pdfjet.Image
* JD-Core Version: 0.6.2
*/