Package de.rototor.pdfbox.graphics2d
Class PdfBoxGraphics2DPaintApplier
- java.lang.Object
-
- de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DPaintApplier
-
- All Implemented Interfaces:
IPdfBoxGraphics2DPaintApplier
public class PdfBoxGraphics2DPaintApplier extends java.lang.Object implements IPdfBoxGraphics2DPaintApplier
Default paint mapper.NOTE: Objects of this class are stateful and *not* thread safe!
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PdfBoxGraphics2DPaintApplier.COSResourceCacheBase<TObject extends org.apache.pdfbox.pdmodel.common.COSObjectable>
private class
PdfBoxGraphics2DPaintApplier.CreateAlphaShadingMask
private static class
PdfBoxGraphics2DPaintApplier.ExtGStateCache
(package private) static class
PdfBoxGraphics2DPaintApplier.IdentityShadingMaskModifier
static class
PdfBoxGraphics2DPaintApplier.PaintApplierState
Internal State of the PaintApplyer.private static class
PdfBoxGraphics2DPaintApplier.PDShadingCache
(package private) static interface
PdfBoxGraphics2DPaintApplier.ShadingMaskModifier
-
Nested classes/interfaces inherited from interface de.rototor.pdfbox.graphics2d.IPdfBoxGraphics2DPaintApplier
IPdfBoxGraphics2DPaintApplier.IPaintEnv
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
BATIK_COLORSPACE_LINEAR_RGB
private java.lang.Object
BATIK_COLORSPACE_SRGB
private java.lang.Object
BATIK_GRADIENT_NO_CYCLE
private java.lang.Object
BATIK_GRADIENT_REFLECT
private java.lang.Object
BATIK_GRADIENT_REPEAT
private static double
EPSILON
Very small number, everything smaller than this is zero for us.private PdfBoxGraphics2DPaintApplier.ExtGStateCache
extGStateCache
private PdfBoxGraphics2DPaintApplier.PDShadingCache
shadingCache
-
Constructor Summary
Constructors Constructor Description PdfBoxGraphics2DPaintApplier()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyAsStrokingColor(java.awt.Color color, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private void
applyComposite(PdfBoxGraphics2DPaintApplier.PaintApplierState state)
protected org.apache.pdfbox.pdmodel.graphics.shading.PDShading
applyPaint(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
Apply paint and graphic stateorg.apache.pdfbox.pdmodel.graphics.shading.PDShading
applyPaint(java.awt.Paint paint, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, java.awt.geom.AffineTransform tf, IPdfBoxGraphics2DPaintApplier.IPaintEnv env)
Apply the paint on the ContentStreamprivate void
applyPatternPaint(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private void
applyPdfBoxTilingPaint(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private void
applyTexturePaint(java.awt.TexturePaint texturePaint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
buildGradientShading(java.awt.GradientPaint gradientPaint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
buildLinearGradientShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
buildRadialGradientShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private org.apache.pdfbox.cos.COSArray
buildType2Functions(java.util.List<java.awt.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(java.awt.Color[] colors, float[] fractions, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
Encode a color gradient as a type3 functionprivate java.awt.geom.Point2D
clonePoint(java.awt.geom.Point2D point2D)
private java.awt.MultipleGradientPaint.ColorSpaceType
getColorSpaceType(java.awt.Paint paint)
private java.awt.MultipleGradientPaint.CycleMethod
getCycleMethod(java.awt.Paint paint)
Map the cycleMethod of the GradientPaint to the java.awt.MultipleGradientPaint.CycleMethod enum.protected static <T> T
getPropertyValue(java.lang.Object obj, java.lang.String propertyGetter)
Get a property value from an object using reflection(package private) static boolean
haveColorsTransparency(java.awt.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(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading
linearGradientUserSpaceOnUseShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
This is the default gradient mode for both SVG and java.awt gradients.(package private) static PdfBoxGraphics2DColor
mapAlphaToGrayscale(java.awt.Color c)
(package private) static PdfBoxGraphics2DColor[]
mapAlphaToGrayscale(java.awt.Color[] colors)
private org.apache.pdfbox.pdmodel.graphics.color.PDColor
mapFirstColorOfGradient(PdfBoxGraphics2DPaintApplier.PaintApplierState state, java.awt.Color[] colors)
private boolean
needBoundsKeyFrameEntry(float[] fractions)
private org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType3
setupBasicLinearShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
private void
setupBatikReflectionAccess(java.awt.Paint paint)
private org.apache.pdfbox.cos.COSArray
setupExtends()
private void
setupShadingCoords(org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType3 shading, java.awt.geom.Point2D startPoint, java.awt.geom.Point2D endPoint)
-
-
-
Field Detail
-
extGStateCache
private final PdfBoxGraphics2DPaintApplier.ExtGStateCache extGStateCache
-
shadingCache
private final PdfBoxGraphics2DPaintApplier.PDShadingCache shadingCache
-
EPSILON
private static final double EPSILON
Very small number, everything smaller than this is zero for us.- See Also:
- Constant Field Values
-
BATIK_GRADIENT_NO_CYCLE
private java.lang.Object BATIK_GRADIENT_NO_CYCLE
-
BATIK_GRADIENT_REFLECT
private java.lang.Object BATIK_GRADIENT_REFLECT
-
BATIK_GRADIENT_REPEAT
private java.lang.Object BATIK_GRADIENT_REPEAT
-
BATIK_COLORSPACE_SRGB
private java.lang.Object BATIK_COLORSPACE_SRGB
-
BATIK_COLORSPACE_LINEAR_RGB
private java.lang.Object BATIK_COLORSPACE_LINEAR_RGB
-
-
Method Detail
-
applyPaint
public org.apache.pdfbox.pdmodel.graphics.shading.PDShading applyPaint(java.awt.Paint paint, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, java.awt.geom.AffineTransform tf, IPdfBoxGraphics2DPaintApplier.IPaintEnv env) throws java.io.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:
java.io.IOException
- if its not possible to write the paint into the contentStream
-
applyAsStrokingColor
protected void applyAsStrokingColor(java.awt.Color color, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
applyPaint
protected org.apache.pdfbox.pdmodel.graphics.shading.PDShading applyPaint(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
Apply paint and graphic state- Throws:
java.io.IOException
-
importPDFBoxShadingPaint
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading importPDFBoxShadingPaint(org.apache.pdfbox.pdmodel.graphics.shading.ShadingPaint<?> paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
applyPatternPaint
private void applyPatternPaint(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
applyPdfBoxTilingPaint
private void applyPdfBoxTilingPaint(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state)
-
applyComposite
private void applyComposite(PdfBoxGraphics2DPaintApplier.PaintApplierState state)
-
clonePoint
private java.awt.geom.Point2D clonePoint(java.awt.geom.Point2D point2D)
-
haveColorsTransparency
static boolean haveColorsTransparency(java.awt.Color[] colors)
-
buildLinearGradientShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading buildLinearGradientShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
linearGradientObjectBoundingBoxShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading linearGradientObjectBoundingBoxShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
setupShadingCoords
private void setupShadingCoords(org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType3 shading, java.awt.geom.Point2D startPoint, java.awt.geom.Point2D endPoint)
-
linearGradientUserSpaceOnUseShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading linearGradientUserSpaceOnUseShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
This is the default gradient mode for both SVG and java.awt gradients.- Throws:
java.io.IOException
-
setupBasicLinearShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType3 setupBasicLinearShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
mapFirstColorOfGradient
private org.apache.pdfbox.pdmodel.graphics.color.PDColor mapFirstColorOfGradient(PdfBoxGraphics2DPaintApplier.PaintApplierState state, java.awt.Color[] colors) throws java.io.IOException
- Throws:
java.io.IOException
-
setupExtends
private org.apache.pdfbox.cos.COSArray setupExtends()
-
getCycleMethod
private java.awt.MultipleGradientPaint.CycleMethod getCycleMethod(java.awt.Paint paint)
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
private java.awt.MultipleGradientPaint.ColorSpaceType getColorSpaceType(java.awt.Paint paint)
-
setupBatikReflectionAccess
private void setupBatikReflectionAccess(java.awt.Paint paint)
-
buildRadialGradientShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading buildRadialGradientShading(java.awt.Paint paint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
mapAlphaToGrayscale
static PdfBoxGraphics2DColor mapAlphaToGrayscale(java.awt.Color c)
-
mapAlphaToGrayscale
static PdfBoxGraphics2DColor[] mapAlphaToGrayscale(java.awt.Color[] colors)
-
buildGradientShading
private org.apache.pdfbox.pdmodel.graphics.shading.PDShading buildGradientShading(java.awt.GradientPaint gradientPaint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
applyTexturePaint
private void applyTexturePaint(java.awt.TexturePaint texturePaint, PdfBoxGraphics2DPaintApplier.PaintApplierState state) throws java.io.IOException
- Throws:
java.io.IOException
-
buildType3Function
private org.apache.pdfbox.pdmodel.common.function.PDFunctionType3 buildType3Function(java.awt.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(java.util.List<java.awt.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
protected static <T> T getPropertyValue(java.lang.Object obj, java.lang.String propertyGetter)
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
-
-