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