Package de.rototor.pdfbox.graphics2d
Class PdfBoxGraphics2DPaintApplier
java.lang.Object
de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DPaintApplier
- All Implemented Interfaces:
IPdfBoxGraphics2DPaintApplier
Default paint mapper.
NOTE: Objects of this class are stateful and *not* thread safe!
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
PdfBoxGraphics2DPaintApplier.COSResourceCacheBase<TObject extends org.apache.pdfbox.pdmodel.common.COSObjectable>
private final class
private static class
(package private) static class
static class
Internal State of the PaintApplyer.private static class
(package private) static interface
Nested classes/interfaces inherited from interface de.rototor.pdfbox.graphics2d.IPdfBoxGraphics2DPaintApplier
IPdfBoxGraphics2DPaintApplier.IPaintEnv
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Object
private Object
private Object
private Object
private Object
private static final double
Very small number, everything smaller than this is zero for us.private final PdfBoxGraphics2DPaintApplier.ExtGStateCache
private final PdfBoxGraphics2DPaintApplier.PDShadingCache
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
private void
protected org.apache.pdfbox.pdmodel.graphics.shading.PDShading
applyPaint
(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) Apply paint and graphic stateorg.apache.pdfbox.pdmodel.graphics.shading.PDShading
applyPaint
(Paint paint, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, AffineTransform tf, IPdfBoxGraphics2DPaintApplier.IPaintEnv env) Apply the paint on the ContentStreamprivate void
private void
private void
applyTexturePaint
(TexturePaint texturePaint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
buildGradientShading
(GradientPaint gradientPaint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
private org.apache.pdfbox.cos.COSArray
buildType2Functions
(List<Color> colors, org.apache.pdfbox.cos.COSArray domain, org.apache.pdfbox.cos.COSArray encode, PdfBoxGraphics2DPaintApplier.PaintApplierState state) Build a type2 function to interpolate between the given colors.private org.apache.pdfbox.pdmodel.common.function.PDFunctionType3
buildType3Function
(Color[] colors, float[] fractions, PdfBoxGraphics2DPaintApplier.PaintApplierState state) Encode a color gradient as a type3 functionprivate Point2D
clonePoint
(Point2D point2D) getColorSpaceType
(Paint paint) getCycleMethod
(Paint paint) Map the cycleMethod of the GradientPaint to the java.awt.MultipleGradientPaint.CycleMethod enum.protected static <T> T
getPropertyValue
(Object obj, String propertyGetter) Get a property value from an object using reflection(package private) static boolean
haveColorsTransparency
(Color[] colors) private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
importPDFBoxShadingPaint
(org.apache.pdfbox.pdmodel.graphics.shading.ShadingPaint<?> paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
linearGradientObjectBoundingBoxShading
(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
linearGradientUserSpaceOnUseShading
(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) This is the default gradient mode for both SVG and java.awt gradients.(package private) static PdfBoxGraphics2DColor
(package private) static PdfBoxGraphics2DColor[]
mapAlphaToGrayscale
(Color[] colors) private org.apache.pdfbox.pdmodel.graphics.color.PDColor
mapFirstColorOfGradient
(PdfBoxGraphics2DPaintApplier.PaintApplierState state, Color[] colors) private boolean
needBoundsKeyFrameEntry
(float[] fractions) private org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType3
private void
setupBatikReflectionAccess
(Paint paint) private org.apache.pdfbox.cos.COSArray
private void
setupShadingCoords
(org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType3 shading, Point2D startPoint, Point2D endPoint)
-
Field Details
-
extGStateCache
-
shadingCache
-
EPSILON
private static final double EPSILONVery small number, everything smaller than this is zero for us.- See Also:
-
BATIK_GRADIENT_NO_CYCLE
-
BATIK_GRADIENT_REFLECT
-
BATIK_GRADIENT_REPEAT
-
BATIK_COLORSPACE_SRGB
-
BATIK_COLORSPACE_LINEAR_RGB
-
-
Constructor Details
-
PdfBoxGraphics2DPaintApplier
public PdfBoxGraphics2DPaintApplier()
-
-
Method Details
-
applyPaint
public org.apache.pdfbox.pdmodel.graphics.shading.PDShading applyPaint(Paint paint, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, AffineTransform tf, IPdfBoxGraphics2DPaintApplier.IPaintEnv env) throws IOException Description copied from interface:IPdfBoxGraphics2DPaintApplier
Apply the paint on the ContentStream- Specified by:
applyPaint
in interfaceIPdfBoxGraphics2DPaintApplier
- Parameters:
paint
- the paint which should be appliedcontentStream
- the content stream to apply the paint ontf
- the current transform of the Graphics2D relative to the contentStream default coordinate space. This is always a copy of the current transform, so we can modify it.env
- Environment for mapping the paint.- Returns:
- null or a PDShading which should be used to fill a shape.
- Throws:
IOException
- if its not possible to write the paint into the contentStream
-
applyAsStrokingColor
protected void applyAsStrokingColor(Color color, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
applyPaint
protected org.apache.pdfbox.pdmodel.graphics.shading.PDShading applyPaint(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException Apply paint and graphic state- Throws:
IOException
-
importPDFBoxShadingPaint
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading importPDFBoxShadingPaint(org.apache.pdfbox.pdmodel.graphics.shading.ShadingPaint<?> paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
applyPatternPaint
private void applyPatternPaint(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
applyPdfBoxTilingPaint
private void applyPdfBoxTilingPaint(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) -
applyComposite
-
clonePoint
-
haveColorsTransparency
-
buildLinearGradientShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading buildLinearGradientShading(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
linearGradientObjectBoundingBoxShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading linearGradientObjectBoundingBoxShading(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
setupShadingCoords
-
linearGradientUserSpaceOnUseShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading linearGradientUserSpaceOnUseShading(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException This is the default gradient mode for both SVG and java.awt gradients.- Throws:
IOException
-
setupBasicLinearShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType3 setupBasicLinearShading(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
mapFirstColorOfGradient
private org.apache.pdfbox.pdmodel.graphics.color.PDColor mapFirstColorOfGradient(PdfBoxGraphics2DPaintApplier.PaintApplierState state, Color[] colors) throws IOException - Throws:
IOException
-
setupExtends
private org.apache.pdfbox.cos.COSArray setupExtends() -
getCycleMethod
Map the cycleMethod of the GradientPaint to the java.awt.MultipleGradientPaint.CycleMethod enum.- Parameters:
paint
- the paint to get the cycleMethod from (if not in any other way possible using reflection)- Returns:
- the CycleMethod
-
getColorSpaceType
-
setupBatikReflectionAccess
-
buildRadialGradientShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading buildRadialGradientShading(Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
mapAlphaToGrayscale
-
mapAlphaToGrayscale
-
buildGradientShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading buildGradientShading(GradientPaint gradientPaint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
applyTexturePaint
private void applyTexturePaint(TexturePaint texturePaint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws IOException - Throws:
IOException
-
buildType3Function
private org.apache.pdfbox.pdmodel.common.function.PDFunctionType3 buildType3Function(Color[] colors, float[] fractions, PdfBoxGraphics2DPaintApplier.PaintApplierState state) Encode a color gradient as a type3 function- Parameters:
colors
- The colors to encodefractions
- the fractions for encodingstate
- our state, this is needed for color mapping- Returns:
- the type3 function
-
needBoundsKeyFrameEntry
private boolean needBoundsKeyFrameEntry(float[] fractions) -
buildType2Functions
private org.apache.pdfbox.cos.COSArray buildType2Functions(List<Color> colors, org.apache.pdfbox.cos.COSArray domain, org.apache.pdfbox.cos.COSArray encode, PdfBoxGraphics2DPaintApplier.PaintApplierState state) Build a type2 function to interpolate between the given colors.- Parameters:
colors
- the color to encodedomain
- the domain which should already been setuped. It will be used for the Type2 functionencode
- will get the domain information per color channel, i.e. colors.length x [0, 1]state
- our internal state, this is needed for color mapping- Returns:
- the Type2 function COSArray
-
getPropertyValue
Get a property value from an object using reflection- Type Parameters:
T
- the type of the property you want to get.- Parameters:
obj
- The object to get a property from.propertyGetter
- method name of the getter, i.e. "getXY".- Returns:
- the value read from the object
-