You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/02/20 07:31:05 UTC
svn commit: r1570086 [6/7] - in /pdfbox/trunk:
examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
examples/src/main/java/org/apache/pdfbox/examples/util/
pdfbox/src/main/java/org/apache/pdfbox/cos/
pdfbox/src/main/java/org/apache/pdfbox/filter/...
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingPaint.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingPaint.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingPaint.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingPaint.java Thu Feb 20 06:31:01 2014
@@ -27,15 +27,17 @@ import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.util.Matrix;
/**
- * This represents the Paint of an type5 shading.
- *
- *
+ * This represents the Paint of a Type 5 shading.
*/
public class Type5ShadingPaint implements Paint
{
+ private static final Log LOG = LogFactory.getLog(Type5ShadingPaint.class);
+
private PDShadingType5 shading;
private Matrix currentTransformationMatrix;
private int pageHeight;
@@ -76,7 +78,7 @@ public class Type5ShadingPaint implement
}
catch (IOException ex)
{
- Logger.getLogger(Type5ShadingPaint.class.getName()).log(Level.SEVERE, null, ex);
+ LOG.error(ex);
return null;
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java Thu Feb 20 06:31:01 2014
@@ -22,8 +22,9 @@ import org.apache.pdfbox.cos.COSDictiona
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.pdmodel.common.COSObjectable;
+import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.pdmodel.graphics.color.PDGamma;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
/**
* This class represents an appearance characteristics dictionary.
@@ -200,12 +201,12 @@ public class PDAppearanceCharacteristics
*
* @return the normal icon.
*/
- public PDXObjectForm getNormalIcon()
+ public PDFormXObject getNormalIcon()
{
COSBase i = this.getDictionary().getDictionaryObject("I");
if (i instanceof COSStream)
{
- return new PDXObjectForm((COSStream) i);
+ return new PDFormXObject(new PDStream((COSStream) i), "I");
}
return null;
}
@@ -215,12 +216,12 @@ public class PDAppearanceCharacteristics
*
* @return the rollover icon
*/
- public PDXObjectForm getRolloverIcon()
+ public PDFormXObject getRolloverIcon()
{
COSBase i = this.getDictionary().getDictionaryObject("RI");
if (i instanceof COSStream)
{
- return new PDXObjectForm((COSStream) i);
+ return new PDFormXObject(new PDStream((COSStream) i), "RI");
}
return null;
}
@@ -230,12 +231,12 @@ public class PDAppearanceCharacteristics
*
* @return the alternate icon.
*/
- public PDXObjectForm getAlternateIcon()
+ public PDFormXObject getAlternateIcon()
{
COSBase i = this.getDictionary().getDictionaryObject("IX");
if (i instanceof COSStream)
{
- return new PDXObjectForm((COSStream) i);
+ return new PDFormXObject(new PDStream((COSStream) i), "IX");
}
return null;
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateBuilder.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateBuilder.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateBuilder.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateBuilder.java Thu Feb 20 06:31:01 2014
@@ -17,8 +17,8 @@
package org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible;
import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
import java.io.IOException;
-import java.io.InputStream;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.pdmodel.PDDocument;
@@ -26,8 +26,8 @@ import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
@@ -104,10 +104,10 @@ public interface PDFTemplateBuilder {
/**
* Creates signature image
* @param template
- * @param InputStream
+ * @param image
* @throws IOException
*/
- public void createSignatureImage(PDDocument template, InputStream InputStream) throws IOException;
+ public void createSignatureImage(PDDocument template, BufferedImage image) throws IOException;
/**
*
@@ -140,7 +140,7 @@ public interface PDFTemplateBuilder {
* @param signatureField
* @throws IOException
*/
- public void createAppearanceDictionary(PDXObjectForm holderForml, PDSignatureField signatureField) throws IOException;
+ public void createAppearanceDictionary(PDFormXObject holderForml, PDSignatureField signatureField) throws IOException;
/**
*
@@ -168,7 +168,7 @@ public interface PDFTemplateBuilder {
* @param innerForm
* @param holderFormResources
*/
- public void insertInnerFormToHolerResources(PDXObjectForm innerForm, PDResources holderFormResources);
+ public void insertInnerFormToHolerResources(PDFormXObject innerForm, PDResources holderFormResources);
/**
*
@@ -192,7 +192,7 @@ public interface PDFTemplateBuilder {
* @throws IOException
*/
public void createImageForm(PDResources imageFormResources, PDResources innerFormResource, PDStream imageFormStream, PDRectangle formrect,
- AffineTransform affineTransform, PDJpeg img) throws IOException;
+ AffineTransform affineTransform, PDImageXObject img) throws IOException;
/**
* Inject procSetArray
@@ -203,7 +203,7 @@ public interface PDFTemplateBuilder {
* @param holderFormResources
* @param procSet
*/
- public void injectProcSetArray(PDXObjectForm innerForm, PDPage page, PDResources innerFormResources, PDResources imageFormResources,
+ public void injectProcSetArray(PDFormXObject innerForm, PDPage page, PDResources innerFormResources, PDResources imageFormResources,
PDResources holderFormResources, COSArray procSet);
/**
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java Thu Feb 20 06:31:01 2014
@@ -29,7 +29,7 @@ import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
@@ -109,7 +109,7 @@ public class PDFTemplateCreator
this.pdfBuilder.createSignatureRectangle(pdSignatureField, properties);
this.pdfBuilder.createFormaterRectangle(properties.getFormaterRectangleParams());
PDRectangle formater = pdfStructure.getFormaterRectangle();
- this.pdfBuilder.createSignatureImage(template, properties.getImageStream());
+ this.pdfBuilder.createSignatureImage(template, properties.getImage());
// create form stream, form and resource.
this.pdfBuilder.createHolderFormStream(template);
@@ -126,7 +126,7 @@ public class PDFTemplateCreator
this.pdfBuilder.createInnerFormResource();
PDResources innerFormResource = pdfStructure.getInnerFormResources();
this.pdfBuilder.createInnerForm(innerFormResource, pdfStructure.getInnterFormStream(), formater);
- PDXObjectForm innerForm = pdfStructure.getInnerForm();
+ PDFormXObject innerForm = pdfStructure.getInnerForm();
// inner form must be in the holder form as we wrote
this.pdfBuilder.insertInnerFormToHolerResources(innerForm, holderFormResources);
@@ -137,7 +137,7 @@ public class PDFTemplateCreator
this.pdfBuilder.createImageFormResources();
PDResources imageFormResources = pdfStructure.getImageFormResources();
this.pdfBuilder.createImageForm(imageFormResources, innerFormResource, imageFormStream, formater, transform,
- pdfStructure.getJpedImage());
+ pdfStructure.getImage());
// now inject procSetArray
this.pdfBuilder.injectProcSetArray(innerForm, page, innerFormResource, imageFormResources, holderFormResources,
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java Thu Feb 20 06:31:01 2014
@@ -32,8 +32,8 @@ import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
@@ -48,7 +48,6 @@ import org.apache.pdfbox.pdmodel.interac
*/
public class PDFTemplateStructure
{
-
private PDPage page;
private PDDocument template;
private PDAcroForm acroForm;
@@ -58,15 +57,15 @@ public class PDFTemplateStructure
private PDRectangle singatureRectangle;
private AffineTransform affineTransform;
private COSArray procSet;
- private PDJpeg jpedImage;
+ private PDImageXObject image;
private PDRectangle formaterRectangle;
private PDStream holderFormStream;
private PDResources holderFormResources;
- private PDXObjectForm holderForm;
+ private PDFormXObject holderForm;
private PDAppearanceDictionary appearanceDictionary;
private PDStream innterFormStream;
private PDResources innerFormResources;
- private PDXObjectForm innerForm;
+ private PDFormXObject innerForm;
private PDStream imageFormStream;
private PDResources imageFormResources;
private List<PDField> acroFormFields;
@@ -74,12 +73,12 @@ public class PDFTemplateStructure
private String imageFormName;
private String imageName;
private COSDocument visualSignature;
- private PDXObjectForm imageForm;
+ private PDFormXObject imageForm;
private COSDictionary widgetDictionary;
/**
* Returns document page.
- * @return the document page.
+ * @return
*/
public PDPage getPage()
{
@@ -99,7 +98,7 @@ public class PDFTemplateStructure
* Gets PDDocument template.
* This represents a digital signature
* that can be attached to a document
- * @return the template to be used.
+ * @return
*/
public PDDocument getTemplate()
{
@@ -119,7 +118,7 @@ public class PDFTemplateStructure
/**
* Gets Acroform
- * @return the documents AcroForm.
+ * @return
*/
public PDAcroForm getAcroForm()
{
@@ -137,7 +136,7 @@ public class PDFTemplateStructure
/**
* Gets Signature field
- * @return the signature filed to be used.
+ * @return
*/
public PDSignatureField getSignatureField()
{
@@ -155,7 +154,7 @@ public class PDFTemplateStructure
/**
* Gets PDSignature
- * @return the signature object.
+ * @return
*/
public PDSignature getPdSignature()
{
@@ -174,7 +173,7 @@ public class PDFTemplateStructure
/**
* Gets Dictionary of AcroForm. Thats <b> /DR </b>
* entry in the AcroForm
- * @return the AcroForms dictionary object.
+ * @return
*/
public COSDictionary getAcroFormDictionary()
{
@@ -194,7 +193,7 @@ public class PDFTemplateStructure
/**
* Gets SignatureRectangle
- * @return the signatures rectangle.
+ * @return
*/
public PDRectangle getSingatureRectangle()
{
@@ -212,7 +211,7 @@ public class PDFTemplateStructure
/**
* Gets AffineTransform
- * @return the affine transform.
+ * @return
*/
public AffineTransform getAffineTransform()
{
@@ -230,7 +229,7 @@ public class PDFTemplateStructure
/**
* Gets ProcSet Array
- * @return the proc set array.
+ * @return
*/
public COSArray getProcSet()
{
@@ -248,25 +247,25 @@ public class PDFTemplateStructure
/**
* Gets the image of visible signature
- * @return the image used for a visioble signature.
+ * @return
*/
- public PDJpeg getJpedImage()
+ public PDImageXObject getImage()
{
- return jpedImage;
+ return image;
}
/**
* Sets the image of visible signature
- * @param jpedImage
+ * @param image Image XObject
*/
- public void setJpedImage(PDJpeg jpedImage)
+ public void setImage(PDImageXObject image)
{
- this.jpedImage = jpedImage;
+ this.image = image;
}
/**
* Gets formatter rectangle
- * @return the rectangle used by the formatter.
+ * @return
*/
public PDRectangle getFormaterRectangle()
{
@@ -284,7 +283,7 @@ public class PDFTemplateStructure
/**
* Sets HolderFormStream
- * @return the form stream of the holder.
+ * @return
*/
public PDStream getHolderFormStream()
{
@@ -305,9 +304,9 @@ public class PDFTemplateStructure
* That form is here <b> AcroForm/DR/XObject/{holder form name} </b>
* By default, name stars with FRM. We also add number of form
* to the name.
- * @return the holder form.
+ * @return
*/
- public PDXObjectForm getHolderForm()
+ public PDFormXObject getHolderForm()
{
return holderForm;
}
@@ -316,14 +315,14 @@ public class PDFTemplateStructure
* In the structure, form will be contained by XObject in the <b>AcroForm/DR/ </b>
* @param holderForm
*/
- public void setHolderForm(PDXObjectForm holderForm)
+ public void setHolderForm(PDFormXObject holderForm)
{
this.holderForm = holderForm;
}
/**
* Gets Holder form resources
- * @return the holder forms ressources.
+ * @return
*/
public PDResources getHolderFormResources()
{
@@ -342,7 +341,7 @@ public class PDFTemplateStructure
/**
* Gets AppearanceDictionary
* That is <b>/AP</b> entry the appearance dictionary.
- * @return the appearance dictionary.
+ * @return
*/
public PDAppearanceDictionary getAppearanceDictionary()
{
@@ -361,7 +360,7 @@ public class PDFTemplateStructure
/**
* Gets Inner form Stream.
- * @return the inner form's stream.
+ * @return
*/
public PDStream getInnterFormStream()
{
@@ -379,7 +378,7 @@ public class PDFTemplateStructure
/**
* Gets inner form Resource
- * @return the inner form's resources.
+ * @return
*/
public PDResources getInnerFormResources()
{
@@ -400,9 +399,9 @@ public class PDFTemplateStructure
* <b> AcroForm/DR/XObject/{holder form name}/Resources/XObject/{inner name} </b>
* By default inner form name starts with "n". Then we add number of form
* to the name.
- * @return the inner form.
+ * @return
*/
- public PDXObjectForm getInnerForm()
+ public PDFormXObject getInnerForm()
{
return innerForm;
}
@@ -412,14 +411,14 @@ public class PDFTemplateStructure
* <b> AcroForm/DR/XObject/{holder form name}/Resources/XObject/{destination} </b>
* @param innerForm
*/
- public void setInnerForm(PDXObjectForm innerForm)
+ public void setInnerForm(PDFormXObject innerForm)
{
this.innerForm = innerForm;
}
/**
* Gets name of inner form
- * @return the inner form's name.
+ * @return
*/
public String getInnerFormName()
{
@@ -437,7 +436,7 @@ public class PDFTemplateStructure
/**
* Gets Image form stream
- * @return the image form's stream.
+ * @return
*/
public PDStream getImageFormStream()
{
@@ -455,7 +454,7 @@ public class PDFTemplateStructure
/**
* Gets image form resources
- * @return the image form's resources.
+ * @return
*/
public PDResources getImageFormResources()
{
@@ -475,9 +474,9 @@ public class PDFTemplateStructure
* Gets Image form. Image form is in this structure:
* <b>/AcroForm/DR/{holder form}/Resources/XObject /{inner form} </b>
* /Resources/XObject/{image form name}.
- * @return the image form.
+ * @return
*/
- public PDXObjectForm getImageForm()
+ public PDFormXObject getImageForm()
{
return imageForm;
}
@@ -491,14 +490,14 @@ public class PDFTemplateStructure
* Sets image form
* @param imageForm
*/
- public void setImageForm(PDXObjectForm imageForm)
+ public void setImageForm(PDFormXObject imageForm)
{
this.imageForm = imageForm;
}
/**
* Gets image form name
- * @return the image form's name.
+ * @return
*/
public String getImageFormName()
{
@@ -516,7 +515,7 @@ public class PDFTemplateStructure
/**
* Gets visible signature image name
- * @return the visible signature image's name
+ * @return
*/
public String getImageName()
{
@@ -535,7 +534,7 @@ public class PDFTemplateStructure
/**
* Gets COSDocument of visible Signature.
* @see org.apache.pdfbox.cos.COSDocument
- * @return the document representing the visual signature.
+ * @return
*/
public COSDocument getVisualSignature()
{
@@ -555,7 +554,7 @@ public class PDFTemplateStructure
/**
* Gets acroFormFields
- * @return the fields within the AcroForm.
+ * @return
*/
public List<PDField> getAcroFormFields()
{
@@ -573,7 +572,7 @@ public class PDFTemplateStructure
/**
* Gets AP of the created template
- * @return the appearance stream of the created template.
+ * @return
* @throws IOException
* @throws COSVisitorException
*/
@@ -594,8 +593,8 @@ public class PDFTemplateStructure
/**
* Gets Widget Dictionary.
* {@link org.apache.pdfbox.pdmodel.interactive.form.PDField}
- * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#getWidget()
- * @return the dictionary representing the widget.
+ * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#getWidget()
+ * @return
*/
public COSDictionary getWidgetDictionary()
{
@@ -605,7 +604,7 @@ public class PDFTemplateStructure
/**
* Sets Widget Dictionary.
* {@link org.apache.pdfbox.pdmodel.interactive.form.PDField}
- * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#getWidget()
+ * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#getWidget()
* @param widgetDictionary
*/
public void setWidgetDictionary(COSDictionary widgetDictionary)
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java Thu Feb 20 06:31:01 2014
@@ -17,8 +17,8 @@
package org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible;
import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
@@ -32,8 +32,9 @@ import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
@@ -49,7 +50,6 @@ import org.apache.pdfbox.pdmodel.interac
*/
public class PDVisibleSigBuilder implements PDFTemplateBuilder
{
-
private PDFTemplateStructure pdfStructure;
private static final Log logger = LogFactory.getLog(PDVisibleSigBuilder.class);
@@ -169,20 +169,17 @@ public class PDVisibleSigBuilder impleme
}
@Override
- public void createSignatureImage(PDDocument template, InputStream inputStream) throws IOException
+ public void createSignatureImage(PDDocument template, BufferedImage image) throws IOException
{
- PDJpeg img = new PDJpeg(template, inputStream);
- pdfStructure.setJpedImage(img);
- logger.info("Visible Signature Image has been created");
- // pdfStructure.setTemplate(template);
- inputStream.close();
+ pdfStructure.setImage(JPEGFactory.createFromImage(template, image));
+ logger.info("Visible Signature Image has been created");
+ // pdfStructure.setTemplate(template);'
}
@Override
public void createFormaterRectangle(byte[] params)
{
-
PDRectangle formrect = new PDRectangle();
formrect.setUpperRightX(params[0]);
formrect.setUpperRightY(params[1]);
@@ -191,7 +188,6 @@ public class PDVisibleSigBuilder impleme
pdfStructure.setFormaterRectangle(formrect);
logger.info("Formater rectangle has been created");
-
}
@Override
@@ -215,7 +211,7 @@ public class PDVisibleSigBuilder impleme
public void createHolderForm(PDResources holderFormResources, PDStream holderFormStream, PDRectangle formrect)
{
- PDXObjectForm holderForm = new PDXObjectForm(holderFormStream);
+ PDFormXObject holderForm = new PDFormXObject(holderFormStream);
holderForm.setResources(holderFormResources);
holderForm.setBBox(formrect);
holderForm.setFormType(1);
@@ -225,7 +221,7 @@ public class PDVisibleSigBuilder impleme
}
@Override
- public void createAppearanceDictionary(PDXObjectForm holderForml, PDSignatureField signatureField)
+ public void createAppearanceDictionary(PDFormXObject holderForml, PDSignatureField signatureField)
throws IOException
{
@@ -261,7 +257,7 @@ public class PDVisibleSigBuilder impleme
@Override
public void createInnerForm(PDResources innerFormResources, PDStream innerFormStream, PDRectangle formrect)
{
- PDXObjectForm innerForm = new PDXObjectForm(innerFormStream);
+ PDFormXObject innerForm = new PDFormXObject(innerFormStream);
innerForm.setResources(innerFormResources);
innerForm.setBBox(formrect);
innerForm.setFormType(1);
@@ -271,7 +267,7 @@ public class PDVisibleSigBuilder impleme
}
@Override
- public void insertInnerFormToHolerResources(PDXObjectForm innerForm, PDResources holderFormResources)
+ public void insertInnerFormToHolerResources(PDFormXObject innerForm, PDResources holderFormResources)
{
String name = holderFormResources.addXObject(innerForm, "FRM");
pdfStructure.setInnerFormName(name);
@@ -297,10 +293,9 @@ public class PDVisibleSigBuilder impleme
@Override
public void createImageForm(PDResources imageFormResources, PDResources innerFormResource,
- PDStream imageFormStream, PDRectangle formrect, AffineTransform affineTransform, PDJpeg img)
+ PDStream imageFormStream, PDRectangle formrect, AffineTransform at, PDImageXObject img)
throws IOException
{
-
/*
* if you need text on the visible signature
*
@@ -309,9 +304,9 @@ public class PDVisibleSigBuilder impleme
*
* Map<String, PDFont> fonts = new HashMap<String, PDFont>(); fonts.put("arial", font);
*/
- PDXObjectForm imageForm = new PDXObjectForm(imageFormStream);
+ PDFormXObject imageForm = new PDFormXObject(imageFormStream);
imageForm.setBBox(formrect);
- imageForm.setMatrix(affineTransform);
+ imageForm.setMatrix(at);
imageForm.setResources(imageFormResources);
imageForm.setFormType(1);
/*
@@ -329,7 +324,7 @@ public class PDVisibleSigBuilder impleme
}
@Override
- public void injectProcSetArray(PDXObjectForm innerForm, PDPage page, PDResources innerFormResources,
+ public void injectProcSetArray(PDFormXObject innerForm, PDPage page, PDResources innerFormResources,
PDResources imageFormResources, PDResources holderFormResources, COSArray procSet)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java Thu Feb 20 06:31:01 2014
@@ -18,7 +18,6 @@ package org.apache.pdfbox.pdmodel.intera
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -26,66 +25,63 @@ import java.util.List;
import javax.imageio.ImageIO;
+import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.bouncycastle.util.Arrays;
/**
- *
- * That class is in order to build your
- * visible signature design. Because of
- * this is builder, instead of setParam()
- * we use param() methods.
- * @author <a href="mailto:vakhtang.koroghlishvili@gmail.com"> vakhtang koroghlishvili (gogebashvili) </a>
+ * Builder for visible signature design.
+ *
+ * Uses use param() instead of setParam()
+ *
+ * @author Vakhtang Koroghlishvili
*/
public class PDVisibleSignDesigner
{
-
- private Float sigImgWidth;
- private Float sigImgHeight;
+ private Float imageWidth;
+ private Float imageHeight;
private float xAxis;
private float yAxis;
private float pageHeight;
private float pageWidth;
- private InputStream imgageStream;
+ private BufferedImage image;
private String signatureFieldName = "sig"; // default
private byte[] formaterRectangleParams = { 0, 0, 100, 50 }; // default
private byte[] AffineTransformParams = { 1, 0, 0, 1, 0, 0 }; // default
private float imageSizeInPercents;
- private PDDocument document = null;
-
-
/**
- *
- * @param originalDocumenStream
- * @param imageStream
- * @param page the page the visible signature is added to.
+ * Constructor.
+ *
+ * @param filename Path of the PDF file
+ * @param jpegStream JPEG image as a stream
+ * @param page The page are you going to add visible signature
* @throws IOException
*/
- public PDVisibleSignDesigner(InputStream originalDocumenStream, InputStream imageStream, int page) throws IOException
+ public PDVisibleSignDesigner(String filename, InputStream jpegStream, int page)
+ throws IOException
{
- signatureImageStream(imageStream);
- document = PDDocument.load(originalDocumenStream);
- calculatePageSize(document, page);
+ this(new FileInputStream(filename), jpegStream, page);
}
/**
- *
- * @param documentPath - path of your pdf document
- * @param imageStream - stream of image
- * @param page the page the visible signature is added to.
+ * Constructor.
+ *
+ * @param documentStream Original PDF document as stream
+ * @param jpegStream JPEG image as a stream
+ * @param page The page are you going to add visible signature
* @throws IOException
*/
- public PDVisibleSignDesigner(String documentPath, InputStream imageStream, int page) throws IOException
+ public PDVisibleSignDesigner(InputStream documentStream, InputStream jpegStream, int page)
+ throws IOException
{
-
// set visible singature image Input stream
- signatureImageStream(imageStream);
+ signatureImageStream(jpegStream);
// create PD document
- document = PDDocument.load(documentPath);
+ PDDocument document = PDDocument.load(documentStream);
// calculate height an width of document
calculatePageSize(document, page);
@@ -94,15 +90,16 @@ public class PDVisibleSignDesigner
}
/**
- *
+ * Constructor.
+ *
* @param doc - Already created PDDocument of your PDF document
- * @param imageStream
+ * @param jpegStream
* @param page
* @throws IOException - If we can't read, flush, or can't close stream
*/
- public PDVisibleSignDesigner(PDDocument doc, InputStream imageStream, int page) throws IOException
+ public PDVisibleSignDesigner(PDDocument doc, InputStream jpegStream, int page) throws IOException
{
- signatureImageStream(imageStream);
+ signatureImageStream(jpegStream);
calculatePageSize(doc, page);
}
@@ -149,21 +146,21 @@ public class PDVisibleSignDesigner
/**
* zoom signature image with some percent.
*
- * @param percent the percentage for zooming the image.
+ * @param percent- x % increase image with x percent.
* @return Visible Signature Configuration Object
*/
public PDVisibleSignDesigner zoom(float percent)
{
- sigImgHeight = sigImgHeight + (sigImgHeight * percent) / 100;
- sigImgWidth = sigImgWidth + (sigImgWidth * percent) / 100;
+ imageHeight = imageHeight + (imageHeight * percent) / 100;
+ imageWidth = imageWidth + (imageWidth * percent) / 100;
return this;
}
/**
*
- * @param x the x coordinate.
- * @param y the y coordinate.
- * @return Visible Signature Configuration Object.
+ * @param x - x coordinate
+ * @param y - y coordinate
+ * @return Visible Signature Configuration Object
*/
public PDVisibleSignDesigner coordinates(float x, float y)
{
@@ -218,17 +215,17 @@ public class PDVisibleSignDesigner
*/
public float getWidth()
{
- return sigImgWidth;
+ return imageWidth;
}
/**
*
- * @param signatureImgWidth the signature image width.
- * @return Visible Signature Configuration Object.
+ * @param width signature image width
+ * @return Visible Signature Configuration Object
*/
- public PDVisibleSignDesigner width(float signatureImgWidth)
+ public PDVisibleSignDesigner width(float width)
{
- this.sigImgWidth = signatureImgWidth;
+ this.imageWidth = width;
return this;
}
@@ -238,17 +235,17 @@ public class PDVisibleSignDesigner
*/
public float getHeight()
{
- return sigImgHeight;
+ return imageHeight;
}
/**
*
- * @param signatureImgHeight the signature image height
+ * @param height signature image Height
* @return Visible Signature Configuration Object
*/
- public PDVisibleSignDesigner height(float signatureImgHeight)
+ public PDVisibleSignDesigner height(float height)
{
- this.sigImgHeight = signatureImgHeight;
+ this.imageHeight = height;
return this;
}
@@ -294,67 +291,29 @@ public class PDVisibleSignDesigner
/**
*
- * @return image Stream
+ * @return image Image
*/
- public InputStream getImageStream()
+ public BufferedImage getImage()
{
- return imgageStream;
+ return image;
}
/**
*
- * @param imgageStream- stream of your visible signature image
+ * @param stream stream of your visible signature image
* @return Visible Signature Configuration Object
- * @throws IOException - If we can't read, flush, or close stream of image
+ * @throws IOException If we can't read, flush, or close stream of image
*/
- private PDVisibleSignDesigner signatureImageStream(InputStream imageStream) throws IOException
+ private PDVisibleSignDesigner signatureImageStream(InputStream stream) throws IOException
{
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int len;
- while ((len = imageStream.read(buffer)) > -1)
- {
- baos.write(buffer, 0, len);
- }
- baos.flush();
- baos.close();
-
- byte[] byteArray = baos.toByteArray();
- byte[] byteArraySecond = Arrays.clone(byteArray);
-
- InputStream inputForBufferedImage = new ByteArrayInputStream(byteArray);
- InputStream revertInputStream = new ByteArrayInputStream(byteArraySecond);
-
- if (sigImgHeight == null || sigImgWidth == null)
- {
- calcualteImageSize(inputForBufferedImage);
- }
-
- this.imgageStream = revertInputStream;
-
+ ImageIO.setUseCache(false);
+ image = ImageIO.read(stream);
+ imageHeight = (float)image.getHeight();
+ imageWidth = (float)image.getWidth();
return this;
}
/**
- * calculates image width and height. sported formats: all
- *
- * @param fis - input stream of image
- * @throws IOException - if can't read input stream
- */
- private void calcualteImageSize(InputStream fis) throws IOException
- {
-
- BufferedImage bimg = ImageIO.read(fis);
- int width = bimg.getWidth();
- int height = bimg.getHeight();
-
- sigImgHeight = (float) height;
- sigImgWidth = (float) width;
-
- }
-
- /**
*
* @return Affine Transform parameters of for PDF Matrix
*/
@@ -406,8 +365,8 @@ public class PDVisibleSignDesigner
/**
*
- * @param pageWidth the pageWidth.
- * @return Visible Signature Configuration Object.
+ * @param pageWidth pageWidth
+ * @return Visible Signature Configuration Object
*/
public PDVisibleSignDesigner pageWidth(float pageWidth)
{
@@ -426,7 +385,7 @@ public class PDVisibleSignDesigner
/**
* get image size in percents
- * @return image size in percents.
+ * @return
*/
public float getImageSizeInPercents()
{
@@ -444,7 +403,7 @@ public class PDVisibleSignDesigner
/**
* returns visible signature text
- * @return visible signature text.
+ * @return
*/
public String getSignatureText()
{
@@ -454,11 +413,10 @@ public class PDVisibleSignDesigner
/**
*
* @param signatureText - adds the text on visible signature
- * @return the signature design representing the text.
+ * @return
*/
public PDVisibleSignDesigner signatureText(String signatureText)
{
throw new UnsupportedOperationException("That method is not yet implemented");
}
-
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java Thu Feb 20 06:31:01 2014
@@ -30,8 +30,7 @@ import org.apache.pdfbox.pdmodel.PDDocum
import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorState;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.interactive.action.PDActionFactory;
import org.apache.pdfbox.pdmodel.interactive.action.type.PDAction;
import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionGoTo;
@@ -331,14 +330,14 @@ public class PDOutlineItem extends PDOut
}
/**
- * Get the text color of this node. Default is black and this method
+ * Get the RGB text color of this node. Default is black and this method
* will never return null.
*
* @return The structure element of this node.
*/
- public PDColorState getTextColor()
+ public PDColor getTextColor()
{
- PDColorState retval = null;
+ PDColor retval = null;
COSArray csValues = (COSArray)node.getDictionaryObject( COSName.C );
if( csValues == null )
{
@@ -346,23 +345,22 @@ public class PDOutlineItem extends PDOut
csValues.growToSize( 3, new COSFloat( 0 ) );
node.setItem( COSName.C, csValues );
}
- retval = new PDColorState(csValues);
- retval.setColorSpace( PDDeviceRGB.INSTANCE );
+ retval = new PDColor(csValues.toFloatArray());
return retval;
}
/**
- * Set the text color for this node. The colorspace must be a PDDeviceRGB.
+ * Set the RGB text color for this node.
*
* @param textColor The text color for this node.
*/
- public void setTextColor( PDColorState textColor )
+ public void setTextColor( PDColor textColor )
{
- node.setItem( COSName.C, textColor.getCOSColorSpaceValue() );
+ node.setItem( COSName.C, textColor.toCOSArray() );
}
/**
- * Set the text color for this node. The colorspace must be a PDDeviceRGB.
+ * Set the RGB text color for this node.
*
* @param textColor The text color for this node.
*/
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java Thu Feb 20 06:31:01 2014
@@ -36,9 +36,9 @@ import org.apache.pdfbox.pdmodel.PDResou
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup;
import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentProperties;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
import org.apache.pdfbox.pdmodel.markedcontent.PDPropertyList;
/**
@@ -129,7 +129,7 @@ public class LayerUtility
* @return a Form XObject containing the original page's content
* @throws IOException if an I/O error occurs
*/
- public PDXObjectForm importPageAsForm(PDDocument sourceDoc, int pageNumber) throws IOException
+ public PDFormXObject importPageAsForm(PDDocument sourceDoc, int pageNumber) throws IOException
{
PDPage page = (PDPage)sourceDoc.getDocumentCatalog().getAllPages().get(pageNumber);
return importPageAsForm(sourceDoc, page);
@@ -146,12 +146,12 @@ public class LayerUtility
* @return a Form XObject containing the original page's content
* @throws IOException if an I/O error occurs
*/
- public PDXObjectForm importPageAsForm(PDDocument sourceDoc, PDPage page) throws IOException
+ public PDFormXObject importPageAsForm(PDDocument sourceDoc, PDPage page) throws IOException
{
COSStream pageStream = (COSStream)page.getContents().getCOSObject();
PDStream newStream = new PDStream(targetDoc,
pageStream.getUnfilteredStream(), false);
- PDXObjectForm form = new PDXObjectForm(newStream);
+ PDFormXObject form = new PDFormXObject(newStream);
//Copy resources
PDResources pageRes = page.findResources();
@@ -223,7 +223,7 @@ public class LayerUtility
* @throws IOException if an I/O error occurs
*/
public PDOptionalContentGroup appendFormAsLayer(PDPage targetPage,
- PDXObjectForm form, AffineTransform transform,
+ PDFormXObject form, AffineTransform transform,
String layerName) throws IOException
{
PDDocumentCatalog catalog = targetDoc.getDocumentCatalog();
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMarkedContentExtractor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMarkedContentExtractor.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMarkedContentExtractor.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMarkedContentExtractor.java Thu Feb 20 06:31:01 2014
@@ -27,7 +27,7 @@ import java.util.Stack;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDMarkedContent;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
/**
* This is an stream engine to extract the marked content of a pdf.
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java Thu Feb 20 06:31:01 2014
@@ -16,6 +16,8 @@
*/
package org.apache.pdfbox.util;
+import org.apache.pdfbox.cos.COSDictionary;
+
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -28,7 +30,7 @@ public class PDFOperator
{
private String theOperator;
private byte[] imageData;
- private ImageParameters imageParameters;
+ private COSDictionary imageParameters;
/** map for singleton operator objects; use {@link ConcurrentHashMap} for better scalability with multiple threads */
private final static ConcurrentHashMap<String,PDFOperator> operators = new ConcurrentHashMap<String, PDFOperator>();
@@ -126,7 +128,7 @@ public class PDFOperator
*
* @return The image parameters.
*/
- public ImageParameters getImageParameters()
+ public COSDictionary getImageParameters()
{
return imageParameters;
}
@@ -136,7 +138,7 @@ public class PDFOperator
*
* @param params The image parameters.
*/
- public void setImageParameters( ImageParameters params)
+ public void setImageParameters( COSDictionary params)
{
imageParameters = params;
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Thu Feb 20 06:31:01 2014
@@ -44,7 +44,7 @@ import org.apache.pdfbox.pdmodel.font.PD
import org.apache.pdfbox.pdmodel.graphics.PDExtendedGraphicsState;
import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
import org.apache.pdfbox.util.operator.OperatorProcessor;
/**
@@ -547,12 +547,32 @@ public class PDFStreamEngine
}
/**
- * @return Returns the colorSpaces.
- */
- public Map<String, PDColorSpace> getColorSpaces()
- {
- return streamResourcesStack.peek().getColorSpaces();
- }
+ * Transforms the given point using the current transformation matrix
+ *
+ * @param x x-coordinate of the point to be transformed
+ * @param y y-coordinate of the point to be transformed
+ * @return the transformed point
+ */
+ /* public Point2D.Double transformPoint(double x, double y)
+ {
+ double[] position = { x, y };
+ Matrix ctm = graphicsState.getCurrentTransformationMatrix();
+ ctm.createAffineTransform().transform(position, 0, position, 0, 1);
+ return new Point2D.Double(position[0], position[1]);
+ }*/
+
+ /**
+ * Transforms the given width using the current transformation matrix
+ *
+ * @param width the width to be transformed
+ * @return the transformed width
+ */
+ /*public double transformWidth(double width) {
+ Matrix ctm = graphicsState.getCurrentTransformationMatrix();
+ double x = ctm.getValue(0, 0) + ctm.getValue(1, 0);
+ double y = ctm.getValue(0, 1) + ctm.getValue(1, 1);
+ return width * Math.sqrt(0.5 * (x * x + y * y));
+ }*/
/**
* @return Returns the colorSpaces.
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/RenderUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/RenderUtil.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/RenderUtil.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/RenderUtil.java Thu Feb 20 06:31:01 2014
@@ -153,8 +153,8 @@ public class RenderUtil
float scale = resolution / (float) PDPage.DEFAULT_USER_SPACE_UNIT_DPI;
int widthPx = Math.round(widthPt * scale);
int heightPx = Math.round(heightPt * scale);
- BufferedImage retval = null;
int rotationAngle = page.findRotation();
+
// normalize the rotation angle
if (rotationAngle < 0)
{
@@ -164,25 +164,38 @@ public class RenderUtil
{
rotationAngle -= 360;
}
+
// swap width and height
+ BufferedImage image;
if (rotationAngle == 90 || rotationAngle == 270)
{
- retval = new BufferedImage(heightPx, widthPx, imageType);
+ image = new BufferedImage(heightPx, widthPx, imageType);
+ }
+ else
+ {
+ image = new BufferedImage(widthPx, heightPx, imageType);
+ }
+
+ // use a transparent background if the imageType supports alpha
+ Graphics2D g = image.createGraphics();
+ if (image.getColorModel().hasAlpha())
+ {
+ g.setBackground(TRANSPARENT_WHITE);
}
else
{
- retval = new BufferedImage(widthPx, heightPx, imageType);
+ g.setBackground(Color.WHITE);
}
- Graphics2D graphics2D = (Graphics2D) retval.getGraphics();
- renderPage(page, graphics2D, retval.getWidth(), retval.getHeight(), scale, scale);
- graphics2D.dispose();
- return retval;
+
+ renderPage(page, g, image.getWidth(), image.getHeight(), scale, scale);
+ g.dispose();
+
+ return image;
}
private static void renderPage(PDPage page, Graphics2D graphics, int width, int height, float scaleX, float scaleY)
throws IOException
{
- graphics.setBackground(TRANSPARENT_WHITE);
graphics.clearRect(0, 0, width, height);
int rotationAngle = page.findRotation();
if (rotationAngle != 0)
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java Thu Feb 20 06:31:01 2014
@@ -20,8 +20,8 @@ import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.pdmodel.PDResources;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.util.Matrix;
import org.apache.pdfbox.util.PDFMarkedContentExtractor;
import org.apache.pdfbox.util.PDFOperator;
@@ -41,38 +41,39 @@ import java.util.Map;
public class Invoke extends OperatorProcessor
{
/**
- * process : Do - Invoke a named xobject.
+ * Do: Invoke the named XObject.
*
* @param operator The operator that is being executed.
* @param arguments List
- *
* @throws IOException If there is an error processing this operator.
*/
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
{
- COSName name = (COSName) arguments.get( 0 );
+ COSName name = (COSName) arguments.get(0);
Map<String,PDXObject> xobjects = context.getXObjects();
- PDXObject xobject = (PDXObject) xobjects.get(name.getName());
+ PDXObject xobject = xobjects.get(name.getName());
if (context instanceof PDFMarkedContentExtractor)
{
((PDFMarkedContentExtractor) context).xobject(xobject);
}
- if(xobject instanceof PDXObjectForm)
+ if(xobject instanceof PDFormXObject)
{
- PDXObjectForm form = (PDXObjectForm)xobject;
+ PDFormXObject form = (PDFormXObject)xobject;
COSStream formContentstream = form.getCOSStream();
+
// if there is an optional form matrix, we have to map the form space to the user space
Matrix matrix = form.getMatrix();
if (matrix != null)
{
- Matrix xobjectCTM = matrix.multiply( context.getGraphicsState().getCurrentTransformationMatrix());
+ Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix());
context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
}
+
// find some optional resources, instead of using the current resources
PDResources pdResources = form.getResources();
- context.processSubStream( pdResources, formContentstream );
+ context.processSubStream(pdResources, formContentstream);
}
}
}
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetColor.java?rev=1570086&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetColor.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetColor.java Thu Feb 20 06:31:01 2014
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.util.operator;
+
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
+import org.apache.pdfbox.util.PDFOperator;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Sets the color to use for stroking or non-stroking operations.
+ *
+ * @author John Hewson
+ */
+public abstract class SetColor extends OperatorProcessor
+{
+ /**
+ * sc,scn,SC,SCN Sets the colour to use for stroking or non-stroking operations.
+ * @param operator the operator that is being executed.
+ * @param arguments list of operands
+ * @throws IOException if the color space cannot be read
+ */
+ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ {
+ COSArray array = new COSArray();
+ array.addAll(arguments);
+ setColor(new PDColor(array));
+ }
+
+ /**
+ * Returns either the stroking or non-stroking color value.
+ * @return The stroking or non-stroking color value.
+ */
+ protected abstract PDColor getColor();
+
+ /**
+ * Sets either the stroking or non-stroking color value.
+ * @param color The stroking or non-stroking color value.
+ */
+ protected abstract void setColor(PDColor color);
+
+ /**
+ * Returns either the stroking or non-stroking color space.
+ * @return The stroking or non-stroking color space.
+ */
+ protected abstract PDColorSpace getColorSpace();
+}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java Thu Feb 20 06:31:01 2014
@@ -16,105 +16,40 @@
*/
package org.apache.pdfbox.util.operator;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
-import org.apache.pdfbox.pdmodel.graphics.color.PDICCBased;
-import org.apache.pdfbox.pdmodel.graphics.color.PDCalRGB;
-import org.apache.pdfbox.pdmodel.graphics.color.PDIndexed;
-import org.apache.pdfbox.pdmodel.graphics.color.PDLab;
-import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
-import org.apache.pdfbox.pdmodel.graphics.color.PDSeparation;
-import org.apache.pdfbox.util.PDFOperator;
-import java.io.IOException;
/**
- * <p>Set the non stroking color space.</p>
- *
- * @version $Revision: 1.0 $
+ * sc,scn Sets the colour to use for stroking non-stroking operations.
+ *
+ * @author John Hewson
*/
-public class SetNonStrokingColor extends OperatorProcessor
+public class SetNonStrokingColor extends SetColor
{
-
/**
- * Log instance.
+ * Returns the non-stroking color.
+ * @return The non-stroking color.
*/
- private static final Log LOG = LogFactory.getLog(SetNonStrokingColor.class);
+ protected PDColor getColor()
+ {
+ return context.getGraphicsState().getNonStrokingColor();
+ }
/**
- * sc,scn Set color space for non stroking operations.
- * @param operator The operator that is being executed.
- * @param arguments List
- * @throws IOException If an error occurs while processing the font.
+ * Sets the non-stroking color.
+ * @param color The new non-stroking color.
*/
- public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ protected void setColor(PDColor color)
{
- PDColorSpace colorSpace = context.getGraphicsState().getNonStrokingColor().getColorSpace();
- if (colorSpace != null)
- {
- OperatorProcessor newOperator = null;
- if (colorSpace instanceof PDDeviceGray)
- {
- newOperator = new SetNonStrokingGrayColor();
- }
- else if (colorSpace instanceof PDDeviceRGB)
- {
- newOperator = new SetNonStrokingRGBColor();
- }
- else if (colorSpace instanceof PDDeviceCMYK)
- {
- newOperator = new SetNonStrokingCMYKColor();
- }
- else if (colorSpace instanceof PDICCBased)
- {
- newOperator = new SetNonStrokingICCBasedColor();
- }
- else if (colorSpace instanceof PDCalRGB)
- {
- newOperator = new SetNonStrokingCalRGBColor();
- }
- else if (colorSpace instanceof PDSeparation)
- {
- newOperator = new SetNonStrokingSeparation();
- }
- else if (colorSpace instanceof PDDeviceN)
- {
- newOperator = new SetNonStrokingDeviceN();
- }
- else if (colorSpace instanceof PDPattern)
- {
- newOperator = new SetNonStrokingPattern();
- }
- else if (colorSpace instanceof PDIndexed)
- {
- newOperator = new SetNonStrokingIndexed();
- }
- else if (colorSpace instanceof PDLab)
- {
- newOperator = new SetNonStrokingLabColor();
- }
+ context.getGraphicsState().setNonStrokingColor(color);
+ }
- if (newOperator != null)
- {
- newOperator.setContext(getContext());
- newOperator.process(operator, arguments);
- }
- else
- {
- LOG.warn("Not supported colorspace "+colorSpace.getName()
- + " within operator "+operator.getOperation());
- }
- }
- else
- {
- LOG.warn("Colorspace not found in "+getClass().getName()+".process!!");
- }
+ /**
+ * Returns the non-stroking color space.
+ * @return The non-stroking color space.
+ */
+ protected PDColorSpace getColorSpace()
+ {
+ return context.getGraphicsState().getNonStrokingColorSpace();
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColorSpace.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColorSpace.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColorSpace.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColorSpace.java Thu Feb 20 06:31:01 2014
@@ -21,50 +21,35 @@ import java.util.List;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorState;
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
+import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
import org.apache.pdfbox.util.PDFOperator;
/**
- * <p>Set the non stroking color space.</p>
+ * Sets the non-stroking color space.
*
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.4 $
+ * @author Ben Litchfield
+ * @author John Hewson
*/
public class SetNonStrokingColorSpace extends OperatorProcessor
{
- private static final float[] EMPTY_FLOAT_ARRAY = new float[0];
-
/**
- * cs Set color space for non stroking operations.
+ * cs Set color space for non-stroking operations.
* @param operator The operator that is being executed.
* @param arguments List
* @throws IOException If an error occurs while processing the font.
*/
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
{
- // (PDF 1.1) Set color space for stroking operations
- COSName name = (COSName)arguments.get( 0 );
- PDColorSpace cs = PDColorSpaceFactory.createColorSpace( name, context.getColorSpaces(),
- context.getResources().getPatterns() );
- PDColorState colorInstance = context.getGraphicsState().getNonStrokingColor();
- colorInstance.setColorSpace( cs );
- int numComponents = cs.getNumberOfComponents();
- float[] values = EMPTY_FLOAT_ARRAY;
- if( numComponents >= 0 )
- {
- values = new float[numComponents];
- for( int i=0; i<numComponents; i++ )
- {
- values[i] = 0f;
- }
- if( cs instanceof PDDeviceCMYK )
- {
- values[3] = 1f;
- }
- }
- colorInstance.setColorSpaceValue( values );
+ COSName name = (COSName)arguments.get(0);
+
+ PDColorSpace cs = PDColorSpace.create(name,
+ context.getResources().getColorSpaces(),
+ context.getResources().getPatterns());
+
+ context.getGraphicsState().setNonStrokingColorSpace(cs);
+ context.getGraphicsState().setNonStrokingColor(cs.getInitialColor());
}
}
\ No newline at end of file
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceCMYKColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceCMYKColor.java?rev=1570086&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceCMYKColor.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceCMYKColor.java Thu Feb 20 06:31:01 2014
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.util.operator;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
+import org.apache.pdfbox.util.PDFOperator;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * k Set the non-stroking colour space to DeviceCMYK and set the colour to
+ * use for non-stroking operations.
+ *
+ * @author John Hewson
+ */
+public class SetNonStrokingDeviceCMYKColor extends SetNonStrokingColor
+{
+ /**
+ * k Set the non-stroking colour space to DeviceCMYK and set the colour to
+ * use for non-stroking operations.
+ *
+ * @param operator The operator that is being executed.
+ * @param arguments List
+ * @throws IOException If the color space cannot be read.
+ */
+ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ {
+ context.getGraphicsState().setNonStrokingColorSpace(PDDeviceCMYK.INSTANCE);
+ super.process(operator, arguments);
+ }
+}
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceGrayColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceGrayColor.java?rev=1570086&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceGrayColor.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceGrayColor.java Thu Feb 20 06:31:01 2014
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.util.operator;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
+import org.apache.pdfbox.util.PDFOperator;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * g Set the non-stroking colour space to DeviceGray and set the gray
+ * level to use for non-stroking operations.
+ *
+ * @author John Hewson
+ */
+public class SetNonStrokingDeviceGrayColor extends SetNonStrokingColor
+{
+ /**
+ * g Set the non-stroking colour space to DeviceGray and set the gray
+ * level to use for non-stroking operations.
+ *
+ * @param operator The operator that is being executed.
+ * @param arguments List
+ * @throws IOException If the color space cannot be read.
+ */
+ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ {
+ context.getGraphicsState().setNonStrokingColorSpace(PDDeviceGray.INSTANCE);
+ super.process(operator, arguments);
+ }
+}
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceRGBColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceRGBColor.java?rev=1570086&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceRGBColor.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingDeviceRGBColor.java Thu Feb 20 06:31:01 2014
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.util.operator;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
+import org.apache.pdfbox.util.PDFOperator;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * rg Set the non-stroking colour space to DeviceRGB and set the colour to
+ * use for non-stroking operations.
+ *
+ * @author John Hewson
+ */
+public class SetNonStrokingDeviceRGBColor extends SetNonStrokingColor
+{
+ /**
+ * k Set the non-stroking colour space to DeviceRGB and set the colour to
+ * use for non-stroking operations.
+ *
+ * @param operator The operator that is being executed.
+ * @param arguments List
+ * @throws IOException If the color space cannot be read.
+ */
+ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ {
+ context.getGraphicsState().setNonStrokingColorSpace(PDDeviceRGB.INSTANCE);
+ super.process(operator, arguments);
+ }
+}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java Thu Feb 20 06:31:01 2014
@@ -16,105 +16,40 @@
*/
package org.apache.pdfbox.util.operator;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
-import org.apache.pdfbox.pdmodel.graphics.color.PDICCBased;
-import org.apache.pdfbox.pdmodel.graphics.color.PDCalRGB;
-import org.apache.pdfbox.pdmodel.graphics.color.PDIndexed;
-import org.apache.pdfbox.pdmodel.graphics.color.PDLab;
-import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
-import org.apache.pdfbox.pdmodel.graphics.color.PDSeparation;
-import org.apache.pdfbox.util.PDFOperator;
-import java.io.IOException;
/**
- * <p>Set the stroking color space.</p>
- *
- * @version $Revision: 1.0 $
+ * SC,SCN Sets the colour to use for stroking stroking operations.
+ *
+ * @author John Hewson
*/
-public class SetStrokingColor extends OperatorProcessor
+public class SetStrokingColor extends SetColor
{
-
/**
- * Log instance.
+ * Returns the stroking color.
+ * @return The stroking color.
*/
- private static final Log LOG = LogFactory.getLog(SetStrokingColor.class);
+ protected PDColor getColor()
+ {
+ return context.getGraphicsState().getStrokingColor();
+ }
/**
- * SC,SCN Set color space for stroking operations.
- * @param operator The operator that is being executed.
- * @param arguments List
- * @throws IOException If an error occurs while processing the font.
+ * Sets the stroking color.
+ * @param color The new stroking color.
*/
- public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ protected void setColor(PDColor color)
{
- PDColorSpace colorSpace = context.getGraphicsState().getStrokingColor().getColorSpace();
- if (colorSpace != null)
- {
- OperatorProcessor newOperator = null;
- if (colorSpace instanceof PDDeviceGray)
- {
- newOperator = new SetStrokingGrayColor();
- }
- else if (colorSpace instanceof PDDeviceRGB)
- {
- newOperator = new SetStrokingRGBColor();
- }
- else if (colorSpace instanceof PDDeviceCMYK)
- {
- newOperator = new SetStrokingCMYKColor();
- }
- else if (colorSpace instanceof PDICCBased)
- {
- newOperator = new SetStrokingICCBasedColor();
- }
- else if (colorSpace instanceof PDCalRGB)
- {
- newOperator = new SetStrokingCalRGBColor();
- }
- else if (colorSpace instanceof PDSeparation)
- {
- newOperator = new SetStrokingSeparation();
- }
- else if (colorSpace instanceof PDDeviceN)
- {
- newOperator = new SetStrokingDeviceN();
- }
- else if (colorSpace instanceof PDPattern)
- {
- newOperator = new SetStrokingPattern();
- }
- else if (colorSpace instanceof PDIndexed)
- {
- newOperator = new SetStrokingIndexed();
- }
- else if (colorSpace instanceof PDLab)
- {
- newOperator = new SetStrokingLabColor();
- }
+ context.getGraphicsState().setStrokingColor(color);
+ }
- if (newOperator != null)
- {
- newOperator.setContext(getContext());
- newOperator.process(operator, arguments);
- }
- else
- {
- LOG.info("Not supported colorspace "+colorSpace.getName()
- + " within operator "+operator.getOperation());
- }
- }
- else
- {
- LOG.warn("Colorspace not found in "+getClass().getName()+".process!!");
- }
+ /**
+ * Returns the stroking color space.
+ * @return The stroking color space.
+ */
+ protected PDColorSpace getColorSpace()
+ {
+ return context.getGraphicsState().getStrokingColorSpace();
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColorSpace.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColorSpace.java?rev=1570086&r1=1570085&r2=1570086&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColorSpace.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColorSpace.java Thu Feb 20 06:31:01 2014
@@ -21,25 +21,20 @@ import java.util.List;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorState;
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
+import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
import org.apache.pdfbox.util.PDFOperator;
/**
- * <p>Structal modification of the PDFEngine class :
- * the long sequence of conditions in processOperator is remplaced by
- * this strategy pattern.</p>
+ * Sets the stroking color space.
*
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.5 $
+ * @author Ben Litchfield
+ * @author John Hewson
*/
-
public class SetStrokingColorSpace extends OperatorProcessor
{
- private static final float[] EMPTY_FLOAT_ARRAY = new float[0];
-
/**
* CS Set color space for stroking operations.
* @param operator The operator that is being executed.
@@ -48,26 +43,13 @@ public class SetStrokingColorSpace exten
*/
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
{
- //(PDF 1.1) Set color space for stroking operations
- COSName name = (COSName)arguments.get( 0 );
- PDColorSpace cs = PDColorSpaceFactory.createColorSpace( name, context.getColorSpaces(),
- context.getResources().getPatterns() );
- PDColorState color = context.getGraphicsState().getStrokingColor();
- color.setColorSpace( cs );
- int numComponents = cs.getNumberOfComponents();
- float[] values = EMPTY_FLOAT_ARRAY;
- if( numComponents >= 0 )
- {
- values = new float[numComponents];
- for( int i=0; i<numComponents; i++ )
- {
- values[i] = 0f;
- }
- if( cs instanceof PDDeviceCMYK )
- {
- values[3] = 1f;
- }
- }
- color.setColorSpaceValue( values );
+ COSName name = (COSName)arguments.get(0);
+
+ PDColorSpace cs = PDColorSpace.create(name,
+ context.getResources().getColorSpaces(),
+ context.getResources().getPatterns());
+
+ context.getGraphicsState().setStrokingColorSpace(cs);
+ context.getGraphicsState().setStrokingColor(cs.getInitialColor());
}
}
\ No newline at end of file
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceCMYKColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceCMYKColor.java?rev=1570086&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceCMYKColor.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceCMYKColor.java Thu Feb 20 06:31:01 2014
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.util.operator;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
+import org.apache.pdfbox.util.PDFOperator;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * K Set the stroking colour space to DeviceCMYK and set the colour to
+ * use for stroking operations.
+ *
+ * @author John Hewson
+ */
+public class SetStrokingDeviceCMYKColor extends SetStrokingColor
+{
+ /**
+ * K Set the stroking colour space to DeviceCMYK and set the colour to
+ * use for stroking operations.
+ *
+ * @param operator The operator that is being executed.
+ * @param arguments List
+ * @throws IOException If the color space cannot be read.
+ */
+ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ {
+ context.getGraphicsState().setStrokingColorSpace(PDDeviceCMYK.INSTANCE);
+ super.process(operator, arguments);
+ }
+}
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceGrayColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceGrayColor.java?rev=1570086&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceGrayColor.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceGrayColor.java Thu Feb 20 06:31:01 2014
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.util.operator;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
+import org.apache.pdfbox.util.PDFOperator;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * G Set the stroking colour space to DeviceGray and set the gray
+ * level to use for stroking operations.
+ *
+ * @author John Hewson
+ */
+public class SetStrokingDeviceGrayColor extends SetStrokingColor
+{
+ /**
+ * G Set the stroking colour space to DeviceGray and set the gray
+ * level to use for stroking operations.
+ *
+ * @param operator The operator that is being executed.
+ * @param arguments List
+ * @throws IOException If the color space cannot be read.
+ */
+ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ {
+ context.getGraphicsState().setStrokingColorSpace(PDDeviceGray.INSTANCE);
+ super.process(operator, arguments);
+ }
+}
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceRGBColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceRGBColor.java?rev=1570086&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceRGBColor.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingDeviceRGBColor.java Thu Feb 20 06:31:01 2014
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.util.operator;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
+import org.apache.pdfbox.util.PDFOperator;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * RG Set the stroking colour space to DeviceRGB and set the colour to
+ * use for stroking operations.
+ *
+ * @author John Hewson
+ */
+public class SetStrokingDeviceRGBColor extends SetStrokingColor
+{
+ /**
+ * RG Set the stroking colour space to DeviceRGB and set the colour to
+ * use for stroking operations.
+ *
+ * @param operator The operator that is being executed.
+ * @param arguments List
+ * @throws IOException If the color space cannot be read.
+ */
+ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
+ {
+ context.getGraphicsState().setStrokingColorSpace(PDDeviceRGB.INSTANCE);
+ super.process(operator, arguments);
+ }
+}