You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/02/02 18:01:27 UTC
svn commit: r1728159 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state:
PDExtendedGraphicsState.java PDGraphicsState.java
Author: tilman
Date: Tue Feb 2 17:01:27 2016
New Revision: 1728159
URL: http://svn.apache.org/viewvc?rev=1728159&view=rev
Log:
PDFBOX-3221: add getter and setter for transfer function
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java?rev=1728159&r1=1728158&r2=1728159&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java Tue Feb 2 17:01:27 2016
@@ -141,6 +141,20 @@ public class PDExtendedGraphicsState imp
{
gs.setBlendMode( getBlendMode() );
}
+ else if (key.equals(COSName.TR))
+ {
+ if (dict.containsKey(COSName.TR2))
+ {
+ // "If both TR and TR2 are present in the same graphics state parameter dictionary,
+ // TR2 shall take precedence."
+ continue;
+ }
+ gs.setTransfer(getTransfer());
+ }
+ else if (key.equals(COSName.TR2))
+ {
+ gs.setTransfer(getTransfer2());
+ }
}
}
@@ -580,4 +594,68 @@ public class PDExtendedGraphicsState imp
dict.setItem(key, new COSFloat(value));
}
}
-}
+
+ /**
+ * This will get the transfer function of the /TR dictionary.
+ *
+ * @return The transfer function. According to the PDF specification, this is either a single
+ * function (which applies to all process colorants) or an array of four functions (which apply
+ * to the process colorants individually). The name Identity may be used to represent the
+ * identity function.
+ */
+ public COSBase getTransfer()
+ {
+ COSBase base = dict.getDictionaryObject(COSName.TR);
+ if (base instanceof COSArray && ((COSArray) base).size() != 4)
+ {
+ return null;
+ }
+ return base;
+ }
+
+ /**
+ * This will set the transfer function of the /TR dictionary.
+ *
+ * @param transfer The transfer function. According to the PDF specification, this is either a
+ * single function (which applies to all process colorants) or an array of four functions (which
+ * apply to the process colorants individually). The name Identity may be used to represent the
+ * identity function.
+ */
+ public void setTransfer(COSBase transfer)
+ {
+ dict.setItem(COSName.TR, transfer);
+ }
+
+ /**
+ * This will get the transfer function of the /TR2 dictionary.
+ *
+ * @return The transfer function. According to the PDF specification, this is either a single
+ * function (which applies to all process colorants) or an array of four functions (which apply
+ * to the process colorants individually). The name Identity may be used to represent the
+ * identity function, and the name Default denotes the transfer function that was in effect at
+ * the start of the page.
+ */
+ public COSBase getTransfer2()
+ {
+ COSBase base = dict.getDictionaryObject(COSName.TR2);
+ if (base instanceof COSArray && ((COSArray) base).size() != 4)
+ {
+ return null;
+ }
+ return base;
+ }
+
+ /**
+ * This will set the transfer function of the /TR2 dictionary.
+ *
+ * @param transfer2 The transfer function. According to the PDF specification, this is either a
+ * single function (which applies to all process colorants) or an array of four functions (which
+ * apply to the process colorants individually). The name Identity may be used to represent the
+ * identity function, and the name Default denotes the transfer function that was in effect at
+ * the start of the page.
+ */
+ public void setTransfer2(COSBase transfer2)
+ {
+ dict.setItem(COSName.TR2, transfer2);
+ }
+}
\ No newline at end of file
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java?rev=1728159&r1=1728158&r2=1728159&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java Tue Feb 2 17:01:27 2016
@@ -20,6 +20,7 @@ import java.awt.BasicStroke;
import java.awt.Composite;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
+import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern;
@@ -63,7 +64,7 @@ public class PDGraphicsState implements
private double overprintMode = 0;
//black generation
//undercolor removal
- //transfer
+ private COSBase transfer = null;
//halftone
private double flatness = 1.0;
private double smoothness = 0;
@@ -593,4 +594,32 @@ public class PDGraphicsState implements
{
return BlendComposite.getInstance(blendMode, (float) nonStrokingAlphaConstant);
}
+
+ /**
+ * This will get the transfer function.
+ *
+ * @return The transfer function. According to the PDF specification, this is either a single
+ * function (which applies to all process colorants) or an array of four functions (which apply
+ * to the process colorants individually). The name Identity may be used to represent the
+ * identity function, and the name Default denotes the transfer function that was in effect at
+ * the start of the page.
+ */
+ public COSBase getTransfer()
+ {
+ return transfer;
+ }
+
+ /**
+ * This will set the transfer function.
+ *
+ * @param transfer The transfer function. According to the PDF specification, this is either a
+ * single function (which applies to all process colorants) or an array of four functions (which
+ * apply to the process colorants individually). The name Identity may be used to represent the
+ * identity function, and the name Default denotes the transfer function that was in effect at
+ * the start of the page.
+ */
+ public void setTransfer(COSBase transfer)
+ {
+ this.transfer = transfer;
+ }
}