Class PdfBoxGraphics2D
- java.lang.Object
-
- java.awt.Graphics
-
- java.awt.Graphics2D
-
- de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D
-
public class PdfBoxGraphics2D extends java.awt.Graphics2D
Graphics 2D Adapter for PDFBox.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PdfBoxGraphics2D.CopyInfo
private static class
PdfBoxGraphics2D.PaintApplyResult
private class
PdfBoxGraphics2D.PaintEnvImpl
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Color
backgroundColor
private java.awt.geom.AffineTransform
baseTransform
(package private) org.apache.pdfbox.pdmodel.common.PDRectangle
bbox
private java.awt.Graphics2D
calcGfx
private java.awt.image.BufferedImage
calcImage
private java.awt.Shape
clipShape
private IPdfBoxGraphics2DColorMapper
colorMapper
(package private) IPdfBoxGraphics2DColorMapper.IColorMapperEnv
colorMapperEnv
private java.awt.Composite
composite
private org.apache.pdfbox.pdmodel.PDPageContentStream
contentStream
private PdfBoxGraphics2D.CopyInfo
copyInfo
private java.util.List<PdfBoxGraphics2D.CopyInfo>
copyList
private org.apache.pdfbox.pdmodel.PDDocument
document
private IPdfBoxGraphics2DDrawControl
drawControl
private IPdfBoxGraphics2DDrawControl.IDrawControlEnv
drawControlEnv
static boolean
ENABLE_CHILD_CREATING_DEBUG
Global Flag: If set to true the Callstack when creating a context is recorded.private static boolean
ENABLE_DEBUG_INTERNAL_CLIP
Internal Debug flag.private static boolean
ENABLE_DEBUG_UNKOWN_STROKE
Interal debugflag to see if an unkown stroke is mappedprivate java.awt.Font
font
private IPdfBoxGraphics2DFontTextDrawer.IFontTextDrawerEnv
fontDrawerEnv
private IPdfBoxGraphics2DFontTextDrawer
fontTextDrawer
private boolean
hasPathOnStream
Do we currently have an active path on the content stream, which has not been closed?private IPdfBoxGraphics2DImageEncoder
imageEncoder
(package private) IPdfBoxGraphics2DImageEncoder.IPdfBoxGraphics2DImageEncoderEnv
imageEncoderEnv
private java.awt.Paint
paint
private IPdfBoxGraphics2DPaintApplier
paintApplier
private PdfBoxGraphics2D.PaintApplyResult
paintApplyResult
private PdfBoxGraphics2D.PaintEnvImpl
paintEnv
private java.util.Map<java.awt.RenderingHints.Key,java.lang.Object>
renderingHints
private int
saveCounter
private java.awt.Stroke
stroke
private java.awt.geom.AffineTransform
transform
private org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject
xFormObject
private java.awt.Color
xorColor
-
Constructor Summary
Constructors Modifier Constructor Description private
PdfBoxGraphics2D(PdfBoxGraphics2D gfx)
PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, float pixelWidth, float pixelHeight)
Create a PDfBox Graphics2D.PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, int pixelWidth, int pixelHeight)
Create a PDfBox Graphics2D.PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.common.PDRectangle bbox)
(package private)
PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.common.PDRectangle bbox, PdfBoxGraphics2D parentGfx)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRenderingHints(java.util.Map<?,?> hints)
private PdfBoxGraphics2D.PaintApplyResult
applyPaint(java.awt.Paint paintToApply, java.awt.Shape shapeToDraw)
private PdfBoxGraphics2D.PaintApplyResult
applyPaint(java.awt.Shape shapeToDraw)
private void
applyShadingAsColor(org.apache.pdfbox.pdmodel.graphics.shading.PDShading shading)
private void
applyStroke(java.awt.Stroke strokeToApply)
Internal usage only!private float
calculateTransformedLength(float length, java.awt.geom.AffineTransform tf)
private void
checkNoCopyActive()
void
clearRect(int x, int y, int width, int height)
void
clip(java.awt.Shape shape)
void
clipRect(int x, int y, int width, int height)
private void
contentStreamRestoreState()
private void
contentStreamSaveState()
void
copyArea(int x, int y, int width, int height, int dx, int dy)
PdfBoxGraphics2D
create()
Creates a copy of this graphics object.PdfBoxGraphics2D
create(int x, int y, int width, int height)
void
dispose()
private static void
disposeCopies(java.util.List<PdfBoxGraphics2D.CopyInfo> cl)
void
disposeDanglingChildGraphics()
void
draw(java.awt.Shape s)
void
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
void
drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)
void
drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)
boolean
drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
boolean
drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
boolean
drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
boolean
drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
boolean
drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
boolean
drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
boolean
drawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)
void
drawInMarkedContentSequence(org.apache.pdfbox.cos.COSName tagName, IPdfBoxGraphics2DMarkedContentDrawer drawer)
Draw on the Graphics2D and enclose the drawing command with a BMC/EMC content marking pair.void
drawInMarkedContentSequence(org.apache.pdfbox.cos.COSName tagName, org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList properties, IPdfBoxGraphics2DMarkedContentDrawer drawer)
Draw on the Graphics2D and enclose the drawing command with a BDC/EMC content marking pair.void
drawLine(int x1, int y1, int x2, int y2)
void
drawOval(int x, int y, int width, int height)
void
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
void
drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
void
drawRect(int x, int y, int width, int height)
void
drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
void
drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
void
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
void
drawString(java.lang.String str, float x, float y)
void
drawString(java.lang.String str, int x, int y)
void
drawString(java.text.AttributedCharacterIterator iterator, float x, float y)
void
drawString(java.text.AttributedCharacterIterator iterator, int x, int y)
private void
drawStringUsingShapes(java.text.AttributedCharacterIterator iterator, float x, float y)
private void
drawStringUsingText(java.text.AttributedCharacterIterator iterator, float x, float y)
private void
fill(boolean useEvenOdd)
void
fill(java.awt.Shape s)
void
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
void
fillOval(int x, int y, int width, int height)
void
fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
void
fillRect(int x, int y, int width, int height)
void
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
private java.lang.String
gatherContext()
private static java.lang.String
gatherDebugCopyInfo(PdfBoxGraphics2D gfx)
java.awt.Color
getBackground()
java.awt.Shape
getClip()
java.awt.Rectangle
getClipBounds()
java.awt.Color
getColor()
java.awt.Composite
getComposite()
private java.awt.geom.AffineTransform
getCurrentEffectiveTransform()
java.awt.GraphicsConfiguration
getDeviceConfiguration()
java.awt.Font
getFont()
java.awt.FontMetrics
getFontMetrics(java.awt.Font f)
java.awt.font.FontRenderContext
getFontRenderContext()
java.awt.Paint
getPaint()
java.lang.Object
getRenderingHint(java.awt.RenderingHints.Key hintKey)
java.awt.RenderingHints
getRenderingHints()
org.apache.pdfbox.pdmodel.PDResources
getResources()
Sometimes you need to access the PDResources and add special resources to it for some stuff (e.g.java.awt.Stroke
getStroke()
java.awt.geom.AffineTransform
getTransform()
org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject
getXFormObject()
*AFTER* you have disposed() this Graphics2D you can access the XFormboolean
hit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)
(package private) void
internalClip(boolean useEvenOdd)
Perform a clip, but only if we really have an active clipping pathprivate static boolean
isFinite(float f)
Float#isFinite() is JDK 8+.private static boolean
isFinite(float[] coords, int count)
(package private) void
markPathIsOnStream()
Set an internal flag that some path - which may be added from the paint applyer to the content stream or by walkShape() - is on the content stream.void
rotate(double theta)
void
rotate(double theta, double x, double y)
void
scale(double sx, double sy)
void
setBackground(java.awt.Color color)
void
setClip(int x, int y, int width, int height)
void
setClip(java.awt.Shape clip)
void
setColor(java.awt.Color color)
void
setColorMapper(IPdfBoxGraphics2DColorMapper colorMapper)
Set a new color mapper.void
setComposite(java.awt.Composite comp)
void
setDrawControl(IPdfBoxGraphics2DDrawControl drawControl)
Set a new draw control.void
setFont(java.awt.Font font)
void
setFontTextDrawer(IPdfBoxGraphics2DFontTextDrawer fontTextDrawer)
Set an optional text drawer.void
setImageEncoder(IPdfBoxGraphics2DImageEncoder imageEncoder)
Set a new image encodervoid
setPaint(java.awt.Paint paint)
void
setPaintApplier(IPdfBoxGraphics2DPaintApplier paintApplier)
Set a new paint applier.void
setPaintMode()
void
setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)
void
setRenderingHints(java.util.Map<?,?> hints)
void
setStroke(java.awt.Stroke stroke)
void
setTransform(java.awt.geom.AffineTransform Tx)
void
setXORMode(java.awt.Color c1)
XOR Mode is currently not implemented as it's not possible in PDF.void
shear(double shx, double shy)
(package private) static <T> T
throwException(java.lang.Exception e)
Internal helper functionvoid
transform(java.awt.geom.AffineTransform Tx)
void
translate(double tx, double ty)
void
translate(int x, int y)
private void
walkAndFillFromApplyPaintResult(java.awt.Shape shapeToFill, PdfBoxGraphics2D.PaintApplyResult result)
private void
walkAndFillShape(java.awt.Shape shapeToFill)
private boolean
walkShape(java.awt.Shape clip)
Walk the path and return true if we need to use the even odd winding rule.
-
-
-
Field Detail
-
xFormObject
private final org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject xFormObject
-
calcGfx
private final java.awt.Graphics2D calcGfx
-
contentStream
private final org.apache.pdfbox.pdmodel.PDPageContentStream contentStream
-
calcImage
private java.awt.image.BufferedImage calcImage
-
document
private org.apache.pdfbox.pdmodel.PDDocument document
-
baseTransform
private final java.awt.geom.AffineTransform baseTransform
-
transform
private java.awt.geom.AffineTransform transform
-
imageEncoder
private IPdfBoxGraphics2DImageEncoder imageEncoder
-
colorMapper
private IPdfBoxGraphics2DColorMapper colorMapper
-
paintApplier
private IPdfBoxGraphics2DPaintApplier paintApplier
-
fontTextDrawer
private IPdfBoxGraphics2DFontTextDrawer fontTextDrawer
-
drawControl
private IPdfBoxGraphics2DDrawControl drawControl
-
paint
private java.awt.Paint paint
-
stroke
private java.awt.Stroke stroke
-
xorColor
private java.awt.Color xorColor
-
font
private java.awt.Font font
-
composite
private java.awt.Composite composite
-
clipShape
private java.awt.Shape clipShape
-
backgroundColor
private java.awt.Color backgroundColor
-
copyInfo
private final PdfBoxGraphics2D.CopyInfo copyInfo
-
bbox
final org.apache.pdfbox.pdmodel.common.PDRectangle bbox
-
saveCounter
private int saveCounter
-
copyList
private final java.util.List<PdfBoxGraphics2D.CopyInfo> copyList
-
ENABLE_CHILD_CREATING_DEBUG
public static boolean ENABLE_CHILD_CREATING_DEBUG
Global Flag: If set to true the Callstack when creating a context is recorded.Note: Setting this to true will slow down the library. Use this only for debugging.
-
drawControlEnv
private final IPdfBoxGraphics2DDrawControl.IDrawControlEnv drawControlEnv
-
ENABLE_DEBUG_UNKOWN_STROKE
private static final boolean ENABLE_DEBUG_UNKOWN_STROKE
Interal debugflag to see if an unkown stroke is mapped- See Also:
- Constant Field Values
-
imageEncoderEnv
final IPdfBoxGraphics2DImageEncoder.IPdfBoxGraphics2DImageEncoderEnv imageEncoderEnv
-
fontDrawerEnv
private final IPdfBoxGraphics2DFontTextDrawer.IFontTextDrawerEnv fontDrawerEnv
-
paintEnv
private final PdfBoxGraphics2D.PaintEnvImpl paintEnv
-
colorMapperEnv
final IPdfBoxGraphics2DColorMapper.IColorMapperEnv colorMapperEnv
-
paintApplyResult
private final PdfBoxGraphics2D.PaintApplyResult paintApplyResult
-
renderingHints
private final java.util.Map<java.awt.RenderingHints.Key,java.lang.Object> renderingHints
-
ENABLE_DEBUG_INTERNAL_CLIP
private static final boolean ENABLE_DEBUG_INTERNAL_CLIP
Internal Debug flag.- See Also:
- Constant Field Values
-
hasPathOnStream
private boolean hasPathOnStream
Do we currently have an active path on the content stream, which has not been closed?We need this flag to avoid to clip twice if both the plaint applyer needs to clip, and we have some clipping. If at the end we try to clip with an empty path, then Acrobat Reader does not like that and draws nothing.
-
-
Constructor Detail
-
PdfBoxGraphics2D
public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, int pixelWidth, int pixelHeight) throws java.io.IOException
Create a PDfBox Graphics2D. This size is used for the BBox of the XForm. So everything drawn outside the rectangle (0x0)-(pixelWidth,pixelHeight) will be clipped.Note: pixelWidth and pixelHeight only define the size of the coordinate space within this Graphics2D. They do not affect how big the XForm is finally displayed in the PDF.
- Parameters:
document
- The document the graphics should be used to create a XForm in.pixelWidth
- the width in pixel of the drawing area.pixelHeight
- the height in pixel of the drawing area.- Throws:
java.io.IOException
- if something goes wrong with writing into the content stream of thePDDocument
.
-
PdfBoxGraphics2D
public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, float pixelWidth, float pixelHeight) throws java.io.IOException
Create a PDfBox Graphics2D. This size is used for the BBox of the XForm. So everything drawn outside the rectangle (0x0)-(pixelWidth,pixelHeight) will be clipped.Note: pixelWidth and pixelHeight only define the size of the coordinate space within this Graphics2D. They do not affect how big the XForm is finally displayed in the PDF.
- Parameters:
document
- The document the graphics should be used to create a XForm in.pixelWidth
- the width in pixel of the drawing area.pixelHeight
- the height in pixel of the drawing area.- Throws:
java.io.IOException
- if something goes wrong with writing into the content stream of thePDDocument
.
-
PdfBoxGraphics2D
public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.common.PDRectangle bbox) throws java.io.IOException
- Parameters:
document
- The document the graphics should be used to create a XForm in.bbox
- Bounding Box of the graphics- Throws:
java.io.IOException
- when something goes wrong with writing into the content stream of thePDDocument
.
-
PdfBoxGraphics2D
PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.common.PDRectangle bbox, PdfBoxGraphics2D parentGfx) throws java.io.IOException
- Throws:
java.io.IOException
-
PdfBoxGraphics2D
private PdfBoxGraphics2D(PdfBoxGraphics2D gfx) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
setColorMapper
public void setColorMapper(IPdfBoxGraphics2DColorMapper colorMapper)
Set a new color mapper.- Parameters:
colorMapper
- the color mapper which maps Color to PDColor.
-
setImageEncoder
public void setImageEncoder(IPdfBoxGraphics2DImageEncoder imageEncoder)
Set a new image encoder- Parameters:
imageEncoder
- the image encoder, which encodes an image as PDImageXForm.
-
setPaintApplier
public void setPaintApplier(IPdfBoxGraphics2DPaintApplier paintApplier)
Set a new paint applier. You should always derive your custom paint applier from theIPdfBoxGraphics2DPaintApplier
and just extend the paint mapping for custom paint.If the paint you map is a paint from a standard library, and you can implement the mapping using reflection please feel free to send a pull request to extend the default paint mapper.
- Parameters:
paintApplier
- the paint applier responsible for mapping the paint correctly
-
setDrawControl
public void setDrawControl(IPdfBoxGraphics2DDrawControl drawControl)
Set a new draw control. This allows you to influence fill() and draw() operations. drawString() is only influence if the text is drawn as vector shape.- Parameters:
drawControl
- the draw control
-
setFontTextDrawer
public void setFontTextDrawer(IPdfBoxGraphics2DFontTextDrawer fontTextDrawer)
Set an optional text drawer. By default, all text is vectorized and drawn using vector shapes. To embed fonts into a PDF file it is necessary to have the underlying TTF file. The java.awt.Font class does not provide that. The FontTextDrawer must perform the java.awt.Font <=> PDFont mapping and also must perform the text layout. If it can not map the text or font correctly, the font drawing falls back to vectoring the text.- Parameters:
fontTextDrawer
- The text drawer, which can draw text using fonts
-
getResources
public org.apache.pdfbox.pdmodel.PDResources getResources()
Sometimes you need to access the PDResources and add special resources to it for some stuff (e.g. patterns of embedded PDFs or simmilar). For that you need the PDResources associated with the XForm.It's identlical with getXFormObject().getResources(), with the difference beeing that you can access it while the Graphics2D is not yet disposed.
- Returns:
- the PDResources of the resulting XForm
-
getXFormObject
public org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject getXFormObject()
*AFTER* you have disposed() this Graphics2D you can access the XForm- Returns:
- the PDFormXObject which resulted in this graphics
-
gatherContext
private java.lang.String gatherContext()
-
disposeDanglingChildGraphics
public void disposeDanglingChildGraphics()
Sometimes the users ofcreate()
don't correctlydispose()
the child graphics they create. And you may not always be able to fix this uses, as it may be in some 3rdparty library. In this case this method can help you. It will cleanup all dangling child graphics. The child graphics can not be used after that. This method is a workaround for a buggy old code. You should only use it if you have to.
Note: You can only call this method on the "main" graphics, not on a child created with
create()
-
disposeCopies
private static void disposeCopies(java.util.List<PdfBoxGraphics2D.CopyInfo> cl)
-
dispose
public void dispose()
- Specified by:
dispose
in classjava.awt.Graphics
-
draw
public void draw(java.awt.Shape s)
- Specified by:
draw
in classjava.awt.Graphics2D
-
applyStroke
private void applyStroke(java.awt.Stroke strokeToApply) throws java.io.IOException
Internal usage only!- Parameters:
strokeToApply
- the stroke we should apply on the stream- Throws:
java.io.IOException
-
calculateTransformedLength
private float calculateTransformedLength(float length, java.awt.geom.AffineTransform tf)
-
getCurrentEffectiveTransform
private java.awt.geom.AffineTransform getCurrentEffectiveTransform()
-
drawImage
public void drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)
- Specified by:
drawImage
in classjava.awt.Graphics2D
-
drawRenderedImage
public void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
- Specified by:
drawRenderedImage
in classjava.awt.Graphics2D
-
drawRenderableImage
public void drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
- Specified by:
drawRenderableImage
in classjava.awt.Graphics2D
-
drawString
public void drawString(java.lang.String str, int x, int y)
- Specified by:
drawString
in classjava.awt.Graphics2D
-
drawString
public void drawString(java.lang.String str, float x, float y)
- Specified by:
drawString
in classjava.awt.Graphics2D
-
drawString
public void drawString(java.text.AttributedCharacterIterator iterator, int x, int y)
- Specified by:
drawString
in classjava.awt.Graphics2D
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)
- Specified by:
drawImage
in classjava.awt.Graphics2D
-
drawImage
public boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
- Specified by:
drawImage
in classjava.awt.Graphics
-
drawStringUsingShapes
private void drawStringUsingShapes(java.text.AttributedCharacterIterator iterator, float x, float y)
-
drawString
public void drawString(java.text.AttributedCharacterIterator iterator, float x, float y)
- Specified by:
drawString
in classjava.awt.Graphics2D
-
drawStringUsingText
private void drawStringUsingText(java.text.AttributedCharacterIterator iterator, float x, float y) throws java.io.IOException, java.awt.FontFormatException
- Throws:
java.io.IOException
java.awt.FontFormatException
-
contentStreamSaveState
private void contentStreamSaveState() throws java.io.IOException
- Throws:
java.io.IOException
-
contentStreamRestoreState
private void contentStreamRestoreState() throws java.io.IOException
- Throws:
java.io.IOException
-
drawGlyphVector
public void drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)
- Specified by:
drawGlyphVector
in classjava.awt.Graphics2D
-
fill
public void fill(java.awt.Shape s)
- Specified by:
fill
in classjava.awt.Graphics2D
-
walkAndFillFromApplyPaintResult
private void walkAndFillFromApplyPaintResult(java.awt.Shape shapeToFill, PdfBoxGraphics2D.PaintApplyResult result) throws java.io.IOException
- Throws:
java.io.IOException
-
walkAndFillShape
private void walkAndFillShape(java.awt.Shape shapeToFill) throws java.io.IOException
- Throws:
java.io.IOException
-
fill
private void fill(boolean useEvenOdd) throws java.io.IOException
- Throws:
java.io.IOException
-
applyShadingAsColor
private void applyShadingAsColor(org.apache.pdfbox.pdmodel.graphics.shading.PDShading shading) throws java.io.IOException
- Throws:
java.io.IOException
-
applyPaint
private PdfBoxGraphics2D.PaintApplyResult applyPaint(java.awt.Shape shapeToDraw) throws java.io.IOException
- Throws:
java.io.IOException
-
applyPaint
private PdfBoxGraphics2D.PaintApplyResult applyPaint(java.awt.Paint paintToApply, java.awt.Shape shapeToDraw) throws java.io.IOException
- Throws:
java.io.IOException
-
hit
public boolean hit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)
- Specified by:
hit
in classjava.awt.Graphics2D
-
getDeviceConfiguration
public java.awt.GraphicsConfiguration getDeviceConfiguration()
- Specified by:
getDeviceConfiguration
in classjava.awt.Graphics2D
-
setComposite
public void setComposite(java.awt.Composite comp)
- Specified by:
setComposite
in classjava.awt.Graphics2D
-
setPaint
public void setPaint(java.awt.Paint paint)
- Specified by:
setPaint
in classjava.awt.Graphics2D
-
setStroke
public void setStroke(java.awt.Stroke stroke)
- Specified by:
setStroke
in classjava.awt.Graphics2D
-
setRenderingHint
public void setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)
- Specified by:
setRenderingHint
in classjava.awt.Graphics2D
-
getRenderingHint
public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
- Specified by:
getRenderingHint
in classjava.awt.Graphics2D
-
setRenderingHints
public void setRenderingHints(java.util.Map<?,?> hints)
- Specified by:
setRenderingHints
in classjava.awt.Graphics2D
-
addRenderingHints
public void addRenderingHints(java.util.Map<?,?> hints)
- Specified by:
addRenderingHints
in classjava.awt.Graphics2D
-
getRenderingHints
public java.awt.RenderingHints getRenderingHints()
- Specified by:
getRenderingHints
in classjava.awt.Graphics2D
-
create
public PdfBoxGraphics2D create()
Creates a copy of this graphics object. Please calldispose()
always on the copy after you have finished drawing with it.
Never draw both in this copy and its parent graphics at the same time, as they all write to the same content stream. This will create a broken PDF content stream. You should get anIllegalStateException
if you do so, but better just don't try.
The copy allows you to have different transforms, paints, etc. than the parent graphics context without affecting the parent. You may also call create() on a copy, but always remember to calldispose()
in reverse order.- Specified by:
create
in classjava.awt.Graphics
- Returns:
- a copy of this Graphics.
-
drawInMarkedContentSequence
public void drawInMarkedContentSequence(org.apache.pdfbox.cos.COSName tagName, IPdfBoxGraphics2DMarkedContentDrawer drawer)
Draw on the Graphics2D and enclose the drawing command with a BMC/EMC content marking pair. See the PDF Spec about "Marked Content" for details.- Parameters:
tagName
- A COSName for to tag the marked contentdrawer
- is called with a (child) graphics to draw on. Please do *not* dispose() this graphics. Just draw on it. Any state changes on the given graphics will be reset after the drawing is finished
-
drawInMarkedContentSequence
public void drawInMarkedContentSequence(org.apache.pdfbox.cos.COSName tagName, org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList properties, IPdfBoxGraphics2DMarkedContentDrawer drawer)
Draw on the Graphics2D and enclose the drawing command with a BDC/EMC content marking pair. See the PDF Spec about "Marked Content" for details.- Parameters:
tagName
- A COSName for to tag the marked contentproperties
- The properties to put by the marked sequencedrawer
- is called with a (child) graphics to draw on. Please do *not* dispose() this graphics. Just draw on it. Any state changes on the given graphics will be reset after the drawing is finished
-
create
public PdfBoxGraphics2D create(int x, int y, int width, int height)
- Overrides:
create
in classjava.awt.Graphics
-
translate
public void translate(int x, int y)
- Specified by:
translate
in classjava.awt.Graphics2D
-
getColor
public java.awt.Color getColor()
- Specified by:
getColor
in classjava.awt.Graphics
-
setColor
public void setColor(java.awt.Color color)
- Specified by:
setColor
in classjava.awt.Graphics
-
setPaintMode
public void setPaintMode()
- Specified by:
setPaintMode
in classjava.awt.Graphics
-
setXORMode
public void setXORMode(java.awt.Color c1)
XOR Mode is currently not implemented as it's not possible in PDF. This mode is ignored.- Specified by:
setXORMode
in classjava.awt.Graphics
- Parameters:
c1
- the XORMode Color
-
getFont
public java.awt.Font getFont()
- Specified by:
getFont
in classjava.awt.Graphics
-
setFont
public void setFont(java.awt.Font font)
- Specified by:
setFont
in classjava.awt.Graphics
-
getFontMetrics
public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
- Specified by:
getFontMetrics
in classjava.awt.Graphics
-
getClipBounds
public java.awt.Rectangle getClipBounds()
- Specified by:
getClipBounds
in classjava.awt.Graphics
-
clipRect
public void clipRect(int x, int y, int width, int height)
- Specified by:
clipRect
in classjava.awt.Graphics
-
setClip
public void setClip(int x, int y, int width, int height)
- Specified by:
setClip
in classjava.awt.Graphics
-
getClip
public java.awt.Shape getClip()
- Specified by:
getClip
in classjava.awt.Graphics
-
setClip
public void setClip(java.awt.Shape clip)
- Specified by:
setClip
in classjava.awt.Graphics
-
internalClip
void internalClip(boolean useEvenOdd) throws java.io.IOException
Perform a clip, but only if we really have an active clipping path- Parameters:
useEvenOdd
- true when we should use the evenOdd rule.- Throws:
java.io.IOException
-
isFinite
private static boolean isFinite(float f)
Float#isFinite() is JDK 8+. We just copied the trivial implementation here. When we require JDK 8+ we can just drop this method and replace it bei Float#isFinite()
-
isFinite
private static boolean isFinite(float[] coords, int count)
- Returns:
- true when all required values are finite
-
markPathIsOnStream
void markPathIsOnStream()
Set an internal flag that some path - which may be added from the paint applyer to the content stream or by walkShape() - is on the content stream. We can then safely clip() if there is a path on the content stream.
-
walkShape
private boolean walkShape(java.awt.Shape clip) throws java.io.IOException
Walk the path and return true if we need to use the even odd winding rule.- Returns:
- true if we need to use the even odd winding rule
- Throws:
java.io.IOException
-
checkNoCopyActive
private void checkNoCopyActive()
-
gatherDebugCopyInfo
private static java.lang.String gatherDebugCopyInfo(PdfBoxGraphics2D gfx)
-
throwException
static <T> T throwException(java.lang.Exception e)
Internal helper function- Parameters:
e
- exception to rethrow
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy)
- Specified by:
copyArea
in classjava.awt.Graphics
-
drawLine
public void drawLine(int x1, int y1, int x2, int y2)
- Specified by:
drawLine
in classjava.awt.Graphics
-
fillRect
public void fillRect(int x, int y, int width, int height)
- Specified by:
fillRect
in classjava.awt.Graphics
-
drawRect
public void drawRect(int x, int y, int width, int height)
- Overrides:
drawRect
in classjava.awt.Graphics
-
clearRect
public void clearRect(int x, int y, int width, int height)
- Specified by:
clearRect
in classjava.awt.Graphics
-
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
- Specified by:
drawRoundRect
in classjava.awt.Graphics
-
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
- Specified by:
fillRoundRect
in classjava.awt.Graphics
-
drawOval
public void drawOval(int x, int y, int width, int height)
- Specified by:
drawOval
in classjava.awt.Graphics
-
fillOval
public void fillOval(int x, int y, int width, int height)
- Specified by:
fillOval
in classjava.awt.Graphics
-
drawArc
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
- Specified by:
drawArc
in classjava.awt.Graphics
-
fillArc
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
- Specified by:
fillArc
in classjava.awt.Graphics
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
- Specified by:
drawPolyline
in classjava.awt.Graphics
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
- Specified by:
drawPolygon
in classjava.awt.Graphics
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
- Specified by:
fillPolygon
in classjava.awt.Graphics
-
translate
public void translate(double tx, double ty)
- Specified by:
translate
in classjava.awt.Graphics2D
-
rotate
public void rotate(double theta)
- Specified by:
rotate
in classjava.awt.Graphics2D
-
rotate
public void rotate(double theta, double x, double y)
- Specified by:
rotate
in classjava.awt.Graphics2D
-
scale
public void scale(double sx, double sy)
- Specified by:
scale
in classjava.awt.Graphics2D
-
shear
public void shear(double shx, double shy)
- Specified by:
shear
in classjava.awt.Graphics2D
-
transform
public void transform(java.awt.geom.AffineTransform Tx)
- Specified by:
transform
in classjava.awt.Graphics2D
-
setTransform
public void setTransform(java.awt.geom.AffineTransform Tx)
- Specified by:
setTransform
in classjava.awt.Graphics2D
-
getTransform
public java.awt.geom.AffineTransform getTransform()
- Specified by:
getTransform
in classjava.awt.Graphics2D
-
getPaint
public java.awt.Paint getPaint()
- Specified by:
getPaint
in classjava.awt.Graphics2D
-
getComposite
public java.awt.Composite getComposite()
- Specified by:
getComposite
in classjava.awt.Graphics2D
-
setBackground
public void setBackground(java.awt.Color color)
- Specified by:
setBackground
in classjava.awt.Graphics2D
-
getBackground
public java.awt.Color getBackground()
- Specified by:
getBackground
in classjava.awt.Graphics2D
-
getStroke
public java.awt.Stroke getStroke()
- Specified by:
getStroke
in classjava.awt.Graphics2D
-
clip
public void clip(java.awt.Shape shape)
- Specified by:
clip
in classjava.awt.Graphics2D
-
getFontRenderContext
public java.awt.font.FontRenderContext getFontRenderContext()
- Specified by:
getFontRenderContext
in classjava.awt.Graphics2D
-
-