|
|
|
@ -49,15 +49,6 @@
|
|
|
|
|
|
|
|
|
|
package com.fr.third.com.lowagie.text; |
|
|
|
|
|
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
import java.awt.color.ICC_Profile; |
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.lang.reflect.Constructor; |
|
|
|
|
import java.net.MalformedURLException; |
|
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
|
|
import com.fr.third.com.lowagie.text.pdf.PRIndirectReference; |
|
|
|
|
import com.fr.third.com.lowagie.text.pdf.PdfArray; |
|
|
|
|
import com.fr.third.com.lowagie.text.pdf.PdfContentByte; |
|
|
|
@ -79,6 +70,15 @@ import com.fr.third.com.lowagie.text.pdf.codec.JBIG2Image;
|
|
|
|
|
import com.fr.third.com.lowagie.text.pdf.codec.PngImage; |
|
|
|
|
import com.fr.third.com.lowagie.text.pdf.codec.TiffImage; |
|
|
|
|
|
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
import java.awt.color.ICC_Profile; |
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.lang.reflect.Constructor; |
|
|
|
|
import java.net.MalformedURLException; |
|
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* An <CODE>Image</CODE> is the representation of a graphic element (JPEG, PNG |
|
|
|
|
* or GIF) that has to be inserted into the document |
|
|
|
@ -155,7 +155,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
public static final int ORIGINAL_WMF = 6; |
|
|
|
|
|
|
|
|
|
/** type of image */ |
|
|
|
|
public static final int ORIGINAL_PS = 7; |
|
|
|
|
public static final int ORIGINAL_PS = 7; |
|
|
|
|
|
|
|
|
|
/** type of image */ |
|
|
|
|
public static final int ORIGINAL_JPEG2000 = 8; |
|
|
|
@ -166,7 +166,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
*/ |
|
|
|
|
public static final int ORIGINAL_JBIG2 = 9; |
|
|
|
|
|
|
|
|
|
// member variables
|
|
|
|
|
// member variables
|
|
|
|
|
|
|
|
|
|
/** The image type. */ |
|
|
|
|
protected int type; |
|
|
|
@ -207,17 +207,27 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
/** This is the original height of the image taking rotation into account. */ |
|
|
|
|
protected float scaledHeight; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The compression level of the content streams. |
|
|
|
|
* @since 2.1.3 |
|
|
|
|
*/ |
|
|
|
|
protected int compressionLevel = PdfStream.DEFAULT_COMPRESSION; |
|
|
|
|
/** |
|
|
|
|
* The compression level of the content streams. |
|
|
|
|
* @since 2.1.3 |
|
|
|
|
*/ |
|
|
|
|
protected int compressionLevel = PdfStream.DEFAULT_COMPRESSION; |
|
|
|
|
|
|
|
|
|
/** an iText attributed unique id for this image. */ |
|
|
|
|
protected Long mySerialId = getSerialId(); |
|
|
|
|
|
|
|
|
|
// image from file or URL
|
|
|
|
|
|
|
|
|
|
private String srcString = ""; |
|
|
|
|
|
|
|
|
|
public String getSrcString() { |
|
|
|
|
return srcString; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setSrcString(String srcString) { |
|
|
|
|
this.srcString = srcString; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructs an <CODE>Image</CODE> -object, using an <VAR>url </VAR>. |
|
|
|
|
* |
|
|
|
@ -288,7 +298,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
try { |
|
|
|
|
if (url.getProtocol().equals("file")) { |
|
|
|
|
String file = url.getFile(); |
|
|
|
|
file = Utilities.unEscapeURL(file); |
|
|
|
|
file = Utilities.unEscapeURL(file); |
|
|
|
|
ra = new RandomAccessFileOrArray(file); |
|
|
|
|
} else |
|
|
|
|
ra = new RandomAccessFileOrArray(url); |
|
|
|
@ -308,20 +318,22 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
if (url.getProtocol().equals("file")) { |
|
|
|
|
String file = url.getFile(); |
|
|
|
|
file = Utilities.unEscapeURL(file); |
|
|
|
|
ra = new RandomAccessFileOrArray(file); |
|
|
|
|
ra = new RandomAccessFileOrArray(file); |
|
|
|
|
} else |
|
|
|
|
ra = new RandomAccessFileOrArray(url); |
|
|
|
|
Image img = JBIG2Image.getJbig2Image(ra, 1); |
|
|
|
|
img.url = url; |
|
|
|
|
return img; |
|
|
|
|
} finally { |
|
|
|
|
if (ra != null) |
|
|
|
|
ra.close(); |
|
|
|
|
if (ra != null) |
|
|
|
|
ra.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
throw new IOException(url.toString() |
|
|
|
|
+ " is not a recognized imageformat."); |
|
|
|
|
} finally { |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
return null; |
|
|
|
|
}finally { |
|
|
|
|
if (is != null) { |
|
|
|
|
is.close(); |
|
|
|
|
} |
|
|
|
@ -395,8 +407,8 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
try { |
|
|
|
|
ra = new RandomAccessFileOrArray(imgb); |
|
|
|
|
Image img = TiffImage.getTiffImage(ra, 1); |
|
|
|
|
if (img.getOriginalData() == null) |
|
|
|
|
img.setOriginalData(imgb); |
|
|
|
|
if (img.getOriginalData() == null) |
|
|
|
|
img.setOriginalData(imgb); |
|
|
|
|
return img; |
|
|
|
|
} finally { |
|
|
|
|
if (ra != null) |
|
|
|
@ -461,7 +473,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
* on error |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(int width, int height, int components, |
|
|
|
|
int bpc, byte data[]) throws BadElementException { |
|
|
|
|
int bpc, byte data[]) throws BadElementException { |
|
|
|
|
return Image.getInstance(width, height, components, bpc, data, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -503,7 +515,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
* on error |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(int width, int height, boolean reverseBits, |
|
|
|
|
int typeCCITT, int parameters, byte[] data) |
|
|
|
|
int typeCCITT, int parameters, byte[] data) |
|
|
|
|
throws BadElementException { |
|
|
|
|
return Image.getInstance(width, height, reverseBits, typeCCITT, |
|
|
|
|
parameters, data, null); |
|
|
|
@ -537,7 +549,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
* on error |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(int width, int height, boolean reverseBits, |
|
|
|
|
int typeCCITT, int parameters, byte[] data, int transparency[]) |
|
|
|
|
int typeCCITT, int parameters, byte[] data, int transparency[]) |
|
|
|
|
throws BadElementException { |
|
|
|
|
if (transparency != null && transparency.length != 2) |
|
|
|
|
throw new BadElementException( |
|
|
|
@ -569,7 +581,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
* on error |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(int width, int height, int components, |
|
|
|
|
int bpc, byte data[], int transparency[]) |
|
|
|
|
int bpc, byte data[], int transparency[]) |
|
|
|
|
throws BadElementException { |
|
|
|
|
if (transparency != null && transparency.length != components * 2) |
|
|
|
|
throw new BadElementException( |
|
|
|
@ -599,7 +611,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
return new ImgTemplate(template); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// images from a java.awt.Image
|
|
|
|
|
// images from a java.awt.Image
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets an instance of an Image from a java.awt.Image. |
|
|
|
@ -618,7 +630,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
* on error |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(java.awt.Image image, java.awt.Color color, |
|
|
|
|
boolean forceBW) throws BadElementException, IOException { |
|
|
|
|
boolean forceBW) throws BadElementException, IOException { |
|
|
|
|
|
|
|
|
|
if(image instanceof BufferedImage){ |
|
|
|
|
BufferedImage bi = (BufferedImage) image; |
|
|
|
@ -811,97 +823,97 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
return getInstance(new PdfContentByte(writer), awtImage, quality); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets an instance of a Image from a java.awt.Image. |
|
|
|
|
* The image is added as a JPEG with a user defined quality. |
|
|
|
|
* |
|
|
|
|
* @param cb |
|
|
|
|
* the <CODE>PdfContentByte</CODE> object to which the image will be added |
|
|
|
|
* @param awtImage |
|
|
|
|
* the <CODE>java.awt.Image</CODE> to convert |
|
|
|
|
* @param quality |
|
|
|
|
* a float value between 0 and 1 |
|
|
|
|
* @return an object of type <CODE>PdfTemplate</CODE> |
|
|
|
|
* @throws BadElementException |
|
|
|
|
* on error |
|
|
|
|
* @throws IOException |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, IOException { |
|
|
|
|
java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage, |
|
|
|
|
0, 0, -1, -1, true); |
|
|
|
|
try { |
|
|
|
|
pg.grabPixels(); |
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
throw new IOException( |
|
|
|
|
"java.awt.Image Interrupted waiting for pixels!"); |
|
|
|
|
} |
|
|
|
|
if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) { |
|
|
|
|
throw new IOException("java.awt.Image fetch aborted or errored"); |
|
|
|
|
} |
|
|
|
|
int w = pg.getWidth(); |
|
|
|
|
int h = pg.getHeight(); |
|
|
|
|
PdfTemplate tp = cb.createTemplate(w, h); |
|
|
|
|
Graphics2D g2d = tp.createGraphics(w, h, true, quality); |
|
|
|
|
g2d.drawImage(awtImage, 0, 0, null); |
|
|
|
|
g2d.dispose(); |
|
|
|
|
return getInstance(tp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// image from indirect reference
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Holds value of property directReference. |
|
|
|
|
* An image is embedded into a PDF as an Image XObject. |
|
|
|
|
* This object is referenced by a PdfIndirectReference object. |
|
|
|
|
*/ |
|
|
|
|
private PdfIndirectReference directReference; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Getter for property directReference. |
|
|
|
|
* @return Value of property directReference. |
|
|
|
|
*/ |
|
|
|
|
public PdfIndirectReference getDirectReference() { |
|
|
|
|
return this.directReference; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Setter for property directReference. |
|
|
|
|
* @param directReference New value of property directReference. |
|
|
|
|
*/ |
|
|
|
|
public void setDirectReference(PdfIndirectReference directReference) { |
|
|
|
|
this.directReference = directReference; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Reuses an existing image. |
|
|
|
|
* @param ref the reference to the image dictionary |
|
|
|
|
* @throws BadElementException on error |
|
|
|
|
* @return the image |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(PRIndirectReference ref) throws BadElementException { |
|
|
|
|
PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref); |
|
|
|
|
int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue(); |
|
|
|
|
int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue(); |
|
|
|
|
Image imask = null; |
|
|
|
|
PdfObject obj = dic.get(PdfName.SMASK); |
|
|
|
|
if (obj != null && obj.isIndirect()) { |
|
|
|
|
imask = getInstance((PRIndirectReference)obj); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
obj = dic.get(PdfName.MASK); |
|
|
|
|
if (obj != null && obj.isIndirect()) { |
|
|
|
|
PdfObject obj2 = PdfReader.getPdfObjectRelease(obj); |
|
|
|
|
if (obj2 instanceof PdfDictionary) |
|
|
|
|
imask = getInstance((PRIndirectReference)obj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Image img = new ImgRaw(width, height, 1, 1, null); |
|
|
|
|
img.imageMask = imask; |
|
|
|
|
img.directReference = ref; |
|
|
|
|
return img; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// copy constructor
|
|
|
|
|
/** |
|
|
|
|
* Gets an instance of a Image from a java.awt.Image. |
|
|
|
|
* The image is added as a JPEG with a user defined quality. |
|
|
|
|
* |
|
|
|
|
* @param cb |
|
|
|
|
* the <CODE>PdfContentByte</CODE> object to which the image will be added |
|
|
|
|
* @param awtImage |
|
|
|
|
* the <CODE>java.awt.Image</CODE> to convert |
|
|
|
|
* @param quality |
|
|
|
|
* a float value between 0 and 1 |
|
|
|
|
* @return an object of type <CODE>PdfTemplate</CODE> |
|
|
|
|
* @throws BadElementException |
|
|
|
|
* on error |
|
|
|
|
* @throws IOException |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, IOException { |
|
|
|
|
java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage, |
|
|
|
|
0, 0, -1, -1, true); |
|
|
|
|
try { |
|
|
|
|
pg.grabPixels(); |
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
throw new IOException( |
|
|
|
|
"java.awt.Image Interrupted waiting for pixels!"); |
|
|
|
|
} |
|
|
|
|
if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) { |
|
|
|
|
throw new IOException("java.awt.Image fetch aborted or errored"); |
|
|
|
|
} |
|
|
|
|
int w = pg.getWidth(); |
|
|
|
|
int h = pg.getHeight(); |
|
|
|
|
PdfTemplate tp = cb.createTemplate(w, h); |
|
|
|
|
Graphics2D g2d = tp.createGraphics(w, h, true, quality); |
|
|
|
|
g2d.drawImage(awtImage, 0, 0, null); |
|
|
|
|
g2d.dispose(); |
|
|
|
|
return getInstance(tp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// image from indirect reference
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Holds value of property directReference. |
|
|
|
|
* An image is embedded into a PDF as an Image XObject. |
|
|
|
|
* This object is referenced by a PdfIndirectReference object. |
|
|
|
|
*/ |
|
|
|
|
private PdfIndirectReference directReference; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Getter for property directReference. |
|
|
|
|
* @return Value of property directReference. |
|
|
|
|
*/ |
|
|
|
|
public PdfIndirectReference getDirectReference() { |
|
|
|
|
return this.directReference; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Setter for property directReference. |
|
|
|
|
* @param directReference New value of property directReference. |
|
|
|
|
*/ |
|
|
|
|
public void setDirectReference(PdfIndirectReference directReference) { |
|
|
|
|
this.directReference = directReference; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Reuses an existing image. |
|
|
|
|
* @param ref the reference to the image dictionary |
|
|
|
|
* @throws BadElementException on error |
|
|
|
|
* @return the image |
|
|
|
|
*/ |
|
|
|
|
public static Image getInstance(PRIndirectReference ref) throws BadElementException { |
|
|
|
|
PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref); |
|
|
|
|
int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue(); |
|
|
|
|
int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue(); |
|
|
|
|
Image imask = null; |
|
|
|
|
PdfObject obj = dic.get(PdfName.SMASK); |
|
|
|
|
if (obj != null && obj.isIndirect()) { |
|
|
|
|
imask = getInstance((PRIndirectReference)obj); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
obj = dic.get(PdfName.MASK); |
|
|
|
|
if (obj != null && obj.isIndirect()) { |
|
|
|
|
PdfObject obj2 = PdfReader.getPdfObjectRelease(obj); |
|
|
|
|
if (obj2 instanceof PdfDictionary) |
|
|
|
|
imask = getInstance((PRIndirectReference)obj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Image img = new ImgRaw(width, height, 1, 1, null); |
|
|
|
|
img.imageMask = imask; |
|
|
|
|
img.directReference = ref; |
|
|
|
|
return img; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// copy constructor
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructs an <CODE>Image</CODE> -object, using an <VAR>url </VAR>. |
|
|
|
@ -913,6 +925,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
super(image); |
|
|
|
|
this.type = image.type; |
|
|
|
|
this.url = image.url; |
|
|
|
|
this.srcString = image.srcString; |
|
|
|
|
this.rawData = image.rawData; |
|
|
|
|
this.bpc = image.bpc; |
|
|
|
|
this.template = image.template; |
|
|
|
@ -926,12 +939,12 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
this.scaledHeight = image.scaledHeight; |
|
|
|
|
this.mySerialId = image.mySerialId; |
|
|
|
|
|
|
|
|
|
this.directReference = image.directReference; |
|
|
|
|
this.directReference = image.directReference; |
|
|
|
|
|
|
|
|
|
this.rotationRadians = image.rotationRadians; |
|
|
|
|
this.initialRotation = image.initialRotation; |
|
|
|
|
this.indentationLeft = image.indentationLeft; |
|
|
|
|
this.indentationRight = image.indentationRight; |
|
|
|
|
this.initialRotation = image.initialRotation; |
|
|
|
|
this.indentationLeft = image.indentationLeft; |
|
|
|
|
this.indentationRight = image.indentationRight; |
|
|
|
|
this.spacingBefore = image.spacingBefore; |
|
|
|
|
this.spacingAfter = image.spacingAfter; |
|
|
|
|
|
|
|
|
@ -989,7 +1002,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @see com.fr.third.com.lowagie.text.Element#isNestable() |
|
|
|
|
* @see Element#isNestable() |
|
|
|
|
* @since iText 2.0.8 |
|
|
|
|
*/ |
|
|
|
|
public boolean isNestable() { |
|
|
|
@ -1310,7 +1323,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
* the height to fit |
|
|
|
|
*/ |
|
|
|
|
public void scaleToFit(float fitWidth, float fitHeight) { |
|
|
|
|
scalePercent(100); |
|
|
|
|
scalePercent(100); |
|
|
|
|
float percentX = (fitWidth * 100) / getScaledWidth(); |
|
|
|
|
float percentY = (fitHeight * 100) / getScaledHeight(); |
|
|
|
|
scalePercent(percentX < percentY ? percentX : percentY); |
|
|
|
@ -1374,26 +1387,26 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
return mySerialId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// rotation, note that the superclass also has a rotation value.
|
|
|
|
|
// rotation, note that the superclass also has a rotation value.
|
|
|
|
|
|
|
|
|
|
/** This is the rotation of the image in radians. */ |
|
|
|
|
protected float rotationRadians; |
|
|
|
|
|
|
|
|
|
/** Holds value of property initialRotation. */ |
|
|
|
|
private float initialRotation; |
|
|
|
|
/** Holds value of property initialRotation. */ |
|
|
|
|
private float initialRotation; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets the current image rotation in radians. |
|
|
|
|
* @return the current image rotation in radians |
|
|
|
|
*/ |
|
|
|
|
public float getImageRotation() { |
|
|
|
|
/** |
|
|
|
|
* Gets the current image rotation in radians. |
|
|
|
|
* @return the current image rotation in radians |
|
|
|
|
*/ |
|
|
|
|
public float getImageRotation() { |
|
|
|
|
double d = 2.0 * Math.PI; |
|
|
|
|
float rot = (float) ((rotationRadians - initialRotation) % d); |
|
|
|
|
if (rot < 0) { |
|
|
|
|
rot += d; |
|
|
|
|
} |
|
|
|
|
return rot; |
|
|
|
|
} |
|
|
|
|
return rot; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets the rotation of the image in radians. |
|
|
|
@ -1423,26 +1436,26 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
setRotation(deg / 180 * (float) d); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Getter for property initialRotation. |
|
|
|
|
* @return Value of property initialRotation. |
|
|
|
|
*/ |
|
|
|
|
public float getInitialRotation() { |
|
|
|
|
return this.initialRotation; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Getter for property initialRotation. |
|
|
|
|
* @return Value of property initialRotation. |
|
|
|
|
*/ |
|
|
|
|
public float getInitialRotation() { |
|
|
|
|
return this.initialRotation; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Some image formats, like TIFF may present the images rotated that have |
|
|
|
|
* to be compensated. |
|
|
|
|
* @param initialRotation New value of property initialRotation. |
|
|
|
|
*/ |
|
|
|
|
public void setInitialRotation(float initialRotation) { |
|
|
|
|
float old_rot = rotationRadians - this.initialRotation; |
|
|
|
|
this.initialRotation = initialRotation; |
|
|
|
|
setRotation(old_rot); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Some image formats, like TIFF may present the images rotated that have |
|
|
|
|
* to be compensated. |
|
|
|
|
* @param initialRotation New value of property initialRotation. |
|
|
|
|
*/ |
|
|
|
|
public void setInitialRotation(float initialRotation) { |
|
|
|
|
float old_rot = rotationRadians - this.initialRotation; |
|
|
|
|
this.initialRotation = initialRotation; |
|
|
|
|
setRotation(old_rot); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// indentations
|
|
|
|
|
// indentations
|
|
|
|
|
|
|
|
|
|
/** the indentation to the left. */ |
|
|
|
|
protected float indentationLeft = 0; |
|
|
|
@ -1532,7 +1545,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
this.spacingAfter = spacing; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// widthpercentage (for the moment only used in ColumnText)
|
|
|
|
|
// widthpercentage (for the moment only used in ColumnText)
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Holds value of property widthPercentage. |
|
|
|
@ -1558,7 +1571,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
this.widthPercentage = widthPercentage; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// annotation
|
|
|
|
|
// annotation
|
|
|
|
|
|
|
|
|
|
/** if the annotation is not null the image will be clickable. */ |
|
|
|
|
protected Annotation annotation = null; |
|
|
|
@ -1582,9 +1595,9 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
return annotation; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Optional Content
|
|
|
|
|
// Optional Content
|
|
|
|
|
|
|
|
|
|
/** Optional Content layer to which we want this Image to belong. */ |
|
|
|
|
/** Optional Content layer to which we want this Image to belong. */ |
|
|
|
|
protected PdfOCG layer; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1861,48 +1874,48 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
this.additional = additional; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. |
|
|
|
|
*/ |
|
|
|
|
public void simplifyColorspace() { |
|
|
|
|
if (additional == null) |
|
|
|
|
return; |
|
|
|
|
PdfArray value = additional.getAsArray(PdfName.COLORSPACE); |
|
|
|
|
if (value == null) |
|
|
|
|
return; |
|
|
|
|
PdfObject cs = simplifyColorspace(value); |
|
|
|
|
PdfObject newValue; |
|
|
|
|
if (cs.isName()) |
|
|
|
|
newValue = cs; |
|
|
|
|
else { |
|
|
|
|
newValue = value; |
|
|
|
|
PdfName first = value.getAsName(0); |
|
|
|
|
if (PdfName.INDEXED.equals(first)) { |
|
|
|
|
if (value.size() >= 2) { |
|
|
|
|
PdfArray second = value.getAsArray(1); |
|
|
|
|
if (second != null) { |
|
|
|
|
value.set(1, simplifyColorspace(second)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
additional.put(PdfName.COLORSPACE, newValue); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. |
|
|
|
|
*/ |
|
|
|
|
public void simplifyColorspace() { |
|
|
|
|
if (additional == null) |
|
|
|
|
return; |
|
|
|
|
PdfArray value = additional.getAsArray(PdfName.COLORSPACE); |
|
|
|
|
if (value == null) |
|
|
|
|
return; |
|
|
|
|
PdfObject cs = simplifyColorspace(value); |
|
|
|
|
PdfObject newValue; |
|
|
|
|
if (cs.isName()) |
|
|
|
|
newValue = cs; |
|
|
|
|
else { |
|
|
|
|
newValue = value; |
|
|
|
|
PdfName first = value.getAsName(0); |
|
|
|
|
if (PdfName.INDEXED.equals(first)) { |
|
|
|
|
if (value.size() >= 2) { |
|
|
|
|
PdfArray second = value.getAsArray(1); |
|
|
|
|
if (second != null) { |
|
|
|
|
value.set(1, simplifyColorspace(second)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
additional.put(PdfName.COLORSPACE, newValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets a PDF Name from an array or returns the object that was passed. |
|
|
|
|
*/ |
|
|
|
|
private PdfObject simplifyColorspace(PdfArray obj) { |
|
|
|
|
if (obj == null) |
|
|
|
|
return obj; |
|
|
|
|
PdfName first = obj.getAsName(0); |
|
|
|
|
if (PdfName.CALGRAY.equals(first)) |
|
|
|
|
return PdfName.DEVICEGRAY; |
|
|
|
|
else if (PdfName.CALRGB.equals(first)) |
|
|
|
|
return PdfName.DEVICERGB; |
|
|
|
|
else |
|
|
|
|
return obj; |
|
|
|
|
} |
|
|
|
|
private PdfObject simplifyColorspace(PdfArray obj) { |
|
|
|
|
if (obj == null) |
|
|
|
|
return obj; |
|
|
|
|
PdfName first = obj.getAsName(0); |
|
|
|
|
if (PdfName.CALGRAY.equals(first)) |
|
|
|
|
return PdfName.DEVICEGRAY; |
|
|
|
|
else if (PdfName.CALRGB.equals(first)) |
|
|
|
|
return PdfName.DEVICERGB; |
|
|
|
|
else |
|
|
|
|
return obj; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Is this image a mask? */ |
|
|
|
|
protected boolean mask = false; |
|
|
|
@ -2023,7 +2036,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
/** |
|
|
|
|
* Returns the compression level used for images written as a compressed stream. |
|
|
|
|
* @return the compression level (0 = best speed, 9 = best compression, -1 is default) |
|
|
|
|
* @since 2.1.3 |
|
|
|
|
* @since 2.1.3 |
|
|
|
|
*/ |
|
|
|
|
public int getCompressionLevel() { |
|
|
|
|
return compressionLevel; |
|
|
|
@ -2032,7 +2045,7 @@ public abstract class Image extends Rectangle {
|
|
|
|
|
/** |
|
|
|
|
* Sets the compression level to be used if the image is written as a compressed stream. |
|
|
|
|
* @param compressionLevel a value between 0 (best speed) and 9 (best compression) |
|
|
|
|
* @since 2.1.3 |
|
|
|
|
* @since 2.1.3 |
|
|
|
|
*/ |
|
|
|
|
public void setCompressionLevel(int compressionLevel) { |
|
|
|
|
if (compressionLevel < PdfStream.NO_COMPRESSION || compressionLevel > PdfStream.BEST_COMPRESSION) |
|
|
|
|