Package com.orsonpdf
Class PDFGraphics2D
- java.lang.Object
-
- java.awt.Graphics
-
- java.awt.Graphics2D
-
- com.orsonpdf.PDFGraphics2D
-
public final class PDFGraphics2D extends java.awt.Graphics2DAGraphics2Dimplementation that writes to PDF format. For typical usage, see the documentation for thePDFDocumentclass.For some demos of the use of this class, please check out the JFree Demos project at GitHub (https://github.com/jfree/jfree-demos).
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.geom.Arc2DarcAn instance that is lazily instantiated in draw/fillArc and then subsequently reused to avoid creating a lot of garbage.private java.awt.Colorbackgroundprivate java.awt.ShapeclipThe user clip (can be null).private java.awt.Colorcolorprivate java.awt.Compositecompositeprivate java.awt.GraphicsConfigurationdeviceConfigurationprivate java.awt.Fontfontprivate java.awt.font.FontRenderContextfontRenderContextThe font render context.private GraphicsStreamgsThe content created by the Graphics2D instance.(package private) intheightprivate java.awt.RenderingHintshintsRendering hints (all ignored).private java.awt.image.BufferedImageimageA hidden image used for font metrics.private java.awt.geom.Line2DlineAn instance that is lazily instantiated in drawLine and then subsequently reused to avoid creating a lot of garbage.(package private) java.awt.geom.AffineTransformoriginalTransformWhen an instance is created via thecreate()method, a copy of the transform in effect is retained so it can be restored once the child instance is disposed.private java.awt.geom.Ellipse2DovalAn instance that is lazily instantiated in draw/fillOval and then subsequently reused to avoid creating a lot of garbage.private java.awt.Paintpaint(package private) java.awt.geom.Rectangle2DrectAn instance that is lazily instantiated in fillRect and then subsequently reused to avoid creating a lot of garbage.private java.awt.geom.RoundRectangle2DroundRectAn instance that is lazily instantiated in draw/fillRoundRect and then subsequently reused to avoid creating a lot of garbage.private java.awt.Strokestrokeprivate java.awt.geom.AffineTransformtransform(package private) intwidth
-
Constructor Summary
Constructors Constructor Description PDFGraphics2D(GraphicsStream gs, int width, int height)Creates a new instance ofPDFGraphics2D.PDFGraphics2D(GraphicsStream gs, int width, int height, boolean skipJava2DTransform)Creates a new instance ofPDFGraphics2D.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRenderingHints(java.util.Map<?,?> hints)Adds all the supplied rendering hints.voidclearRect(int x, int y, int width, int height)Clears the specified rectangle by filling it with the current background color.voidclip(java.awt.Shape s)Clips to the intersection of the current clipping region and the specified shape.voidclipRect(int x, int y, int width, int height)Clips to the intersection of the current clipping region and the specified rectangle.voidcopyArea(int x, int y, int width, int height, int dx, int dy)This method does nothing.java.awt.Graphicscreate()Returns a newPDFGraphics2Dinstance that is a copy of this instance.voiddispose()Performs any actions required when the graphics instance is finished with.voiddraw(java.awt.Shape s)Draws the specified shape with the currentpaintandstroke.voiddrawArc(int x, int y, int width, int height, int startAngle, int arcAngle)Draws an arc contained within the rectangle(x, y, width, height), starting atstartAngleand continuing througharcAngledegrees using the currentpaintandstroke.voiddrawGlyphVector(java.awt.font.GlyphVector g, float x, float y)Draws the specified glyph vector at the location(x, y).voiddrawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)Draws the image resulting from applying theBufferedImageOpto the specified image at the location(x, y).booleandrawImage(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)Draws part of an image (defined by the source rectangle(sx1, sy1, sx2, sy2)) into the destination rectangle(dx1, dy1, dx2, dy2).booleandrawImage(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)Draws part of an image (defined by the source rectangle(sx1, sy1, sx2, sy2)) into the destination rectangle(dx1, dy1, dx2, dy2).booleandrawImage(java.awt.Image img, int x, int y, int w, int h, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)Draws an image to the rectangle(x, y, w, h)(scaling it if required), first filling the background with the specified color.booleandrawImage(java.awt.Image img, int x, int y, int w, int h, java.awt.image.ImageObserver observer)Draws the image into the rectangle defined by(x, y, w, h).booleandrawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)Draws an image at the location(x, y).booleandrawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)Draws an image at the location(x, y).booleandrawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver observer)Draws an image with the specified transform.voiddrawLine(int x1, int y1, int x2, int y2)Draws a line from(x1, y1)to(x2, y2)using the currentpaintandstroke.voiddrawOval(int x, int y, int width, int height)Draws an oval framed by the rectangle(x, y, width, height)using the currentpaintandstroke.voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws the specified polygon using the currentpaintandstroke.voiddrawPolyline(int[] xPoints, int[] yPoints, int nPoints)Draws the specified multi-segment line using the currentpaintandstroke.voiddrawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)Draws the renderable image.voiddrawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)Draws the rendered image.voiddrawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Draws a rectangle with rounded corners using the currentpaintandstroke.voiddrawString(java.lang.String str, float x, float y)Draws a string at(x, y).voiddrawString(java.lang.String str, int x, int y)Draws a string at(x, y).voiddrawString(java.text.AttributedCharacterIterator iterator, float x, float y)Draws a string of attributed characters at(x, y).voiddrawString(java.text.AttributedCharacterIterator iterator, int x, int y)Draws a string of attributed characters at(x, y).voidfill(java.awt.Shape s)Fills the specified shape with the currentpaint.voidfillArc(int x, int y, int width, int height, int startAngle, int arcAngle)Fills an arc contained within the rectangle(x, y, width, height), starting atstartAngleand continuing througharcAngledegrees, using the currentpaintvoidfillOval(int x, int y, int width, int height)Fills an oval framed by the rectangle(x, y, width, height).voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints)Fills the specified polygon using the currentpaint.voidfillRect(int x, int y, int width, int height)Fills the specified rectangle with the currentpaint.voidfillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Fills a rectangle with rounded corners.java.awt.ColorgetBackground()Returns the background color.java.awt.ShapegetClip()Returns the user clipping region.java.awt.RectanglegetClipBounds()Returns the bounds of the user clipping region.java.awt.ColorgetColor()Returns the foreground color.java.awt.CompositegetComposite()Returns the current composite.java.awt.GraphicsConfigurationgetDeviceConfiguration()Returns the device configuration associated with thisGraphics2D.java.awt.FontgetFont()Returns the current font used for drawing text.java.awt.FontMetricsgetFontMetrics(java.awt.Font f)Returns the font metrics for the specified font.java.awt.font.FontRenderContextgetFontRenderContext()Returns the font render context.java.awt.PaintgetPaint()Returns the paint used to draw or fill shapes (or text).java.lang.ObjectgetRenderingHint(java.awt.RenderingHints.Key hintKey)Returns the current value for the specified hint.java.awt.RenderingHintsgetRenderingHints()Returns a copy of the rendering hints.java.awt.StrokegetStroke()Returns the current stroke (used when drawing shapes).java.awt.geom.AffineTransformgetTransform()Returns a copy of the current transform.booleanhit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)Returnstrueif the rectangle (in device space) intersects with the shape (the interior, ifonStrokeis false, otherwise the stroked outline of the shape).private java.awt.ShapeinvTransformedClip(java.awt.Shape clip)voidrotate(double theta)Applies a rotation (anti-clockwise) about(0, 0).voidrotate(double theta, double x, double y)Applies a rotation (anti-clockwise) about(x, y).voidscale(double sx, double sy)Applies a scale transformation.private voidsetArc(int x, int y, int width, int height, int startAngle, int arcAngle)Sets the attributes of the reusableArc2Dobject that is used bydrawArc(int, int, int, int, int, int)andfillArc(int, int, int, int, int, int)methods.voidsetBackground(java.awt.Color color)Sets the background color.voidsetClip(int x, int y, int width, int height)Sets the user clipping region to the specified rectangle.voidsetClip(java.awt.Shape shape)Sets the user clipping region.voidsetColor(java.awt.Color c)Sets the foreground color.voidsetComposite(java.awt.Composite comp)Sets the composite (onlyAlphaCompositeis handled).voidsetFont(java.awt.Font font)Sets the font to be used for drawing text.private voidsetOval(int x, int y, int width, int height)Sets the attributes of the reusableEllipse2Dobject that is used by thedrawOval(int, int, int, int)andfillOval(int, int, int, int)methods.voidsetPaint(java.awt.Paint paint)Sets the paint used to draw or fill shapes (or text).voidsetPaintMode()Does nothing in thisPDFGraphics2Dimplementation.private voidsetRect(int x, int y, int width, int height)Sets the attributes of the reusableRectangle2Dobject that is used by theGraphics.drawRect(int, int, int, int)andfillRect(int, int, int, int)methods.voidsetRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)Sets the value for a hint.voidsetRenderingHints(java.util.Map<?,?> hints)Sets the rendering hints to the specified collection.private voidsetRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Sets the attributes of the reusableRoundRectangle2Dobject that is used by thedrawRoundRect(int, int, int, int, int, int)andfillRoundRect(int, int, int, int, int, int)methods.voidsetStroke(java.awt.Stroke s)Sets the stroke that will be used to draw shapes.voidsetTransform(java.awt.geom.AffineTransform t)Sets the transform.voidsetXORMode(java.awt.Color c)Does nothing in thisPDFGraphics2Dimplementation.voidshear(double shx, double shy)Applies a shear transformation.voidtransform(java.awt.geom.AffineTransform t)Applies this transform to the existing transform by concatenating it.voidtranslate(double tx, double ty)Applies the translation(tx, ty).voidtranslate(int tx, int ty)Applies the translation(tx, ty).
-
-
-
Field Detail
-
width
int width
-
height
int height
-
hints
private java.awt.RenderingHints hints
Rendering hints (all ignored).
-
paint
private java.awt.Paint paint
-
color
private java.awt.Color color
-
background
private java.awt.Color background
-
composite
private java.awt.Composite composite
-
stroke
private java.awt.Stroke stroke
-
transform
private java.awt.geom.AffineTransform transform
-
clip
private java.awt.Shape clip
The user clip (can be null).
-
font
private java.awt.Font font
-
image
private final java.awt.image.BufferedImage image
A hidden image used for font metrics.
-
line
private java.awt.geom.Line2D line
An instance that is lazily instantiated in drawLine and then subsequently reused to avoid creating a lot of garbage.
-
rect
java.awt.geom.Rectangle2D rect
An instance that is lazily instantiated in fillRect and then subsequently reused to avoid creating a lot of garbage.
-
roundRect
private java.awt.geom.RoundRectangle2D roundRect
An instance that is lazily instantiated in draw/fillRoundRect and then subsequently reused to avoid creating a lot of garbage.
-
oval
private java.awt.geom.Ellipse2D oval
An instance that is lazily instantiated in draw/fillOval and then subsequently reused to avoid creating a lot of garbage.
-
arc
private java.awt.geom.Arc2D arc
An instance that is lazily instantiated in draw/fillArc and then subsequently reused to avoid creating a lot of garbage.
-
gs
private GraphicsStream gs
The content created by the Graphics2D instance.
-
deviceConfiguration
private java.awt.GraphicsConfiguration deviceConfiguration
-
fontRenderContext
private final java.awt.font.FontRenderContext fontRenderContext
The font render context. The fractional metrics flag solves the glyph positioning issue identified by Christoph Nahr: http://news.kynosarges.org/2014/06/28/glyph-positioning-in-jfreesvg-orsonpdf/
-
originalTransform
java.awt.geom.AffineTransform originalTransform
When an instance is created via thecreate()method, a copy of the transform in effect is retained so it can be restored once the child instance is disposed. See issue #4 at GitHub.
-
-
Constructor Detail
-
PDFGraphics2D
public PDFGraphics2D(GraphicsStream gs, int width, int height)
Creates a new instance ofPDFGraphics2D. You won't normally create this directly, instead you will call thePage.getGraphics2D()method.- Parameters:
gs- the graphics stream (nullnot permitted).width- the width.height- the height.
-
PDFGraphics2D
public PDFGraphics2D(GraphicsStream gs, int width, int height, boolean skipJava2DTransform)
Creates a new instance ofPDFGraphics2D. You won't normally create this directly, instead you will call thePage.getGraphics2D()method.- Parameters:
gs- the graphics stream (nullnot permitted).width- the width.height- the height.skipJava2DTransform- a flag that allows the PDF to Java2D transform to be skipped (used for watermarks which are appended to an existing stream that already has the transform).
-
-
Method Detail
-
create
public java.awt.Graphics create()
Returns a newPDFGraphics2Dinstance that is a copy of this instance.- Specified by:
createin classjava.awt.Graphics- Returns:
- A new graphics object.
-
getPaint
public java.awt.Paint getPaint()
Returns the paint used to draw or fill shapes (or text). The default value isColor.WHITE.- Specified by:
getPaintin classjava.awt.Graphics2D- Returns:
- The paint (never
null). - See Also:
setPaint(java.awt.Paint)
-
setPaint
public void setPaint(java.awt.Paint paint)
Sets the paint used to draw or fill shapes (or text). Ifpaintis an instance ofColor, this method will also update the current color attribute (seegetColor()). If you passnullto this method, it does nothing (in accordance with the JDK specification).- Specified by:
setPaintin classjava.awt.Graphics2D- Parameters:
paint- the paint (nullis permitted but ignored).- See Also:
getPaint()
-
getColor
public java.awt.Color getColor()
Returns the foreground color. This method exists for backwards compatibility in AWT, you should normally use thegetPaint()method instead.- Specified by:
getColorin classjava.awt.Graphics- Returns:
- The foreground color (never
null). - See Also:
getPaint()
-
setColor
public void setColor(java.awt.Color c)
Sets the foreground color. This method exists for backwards compatibility in AWT, you should normally use thesetPaint(java.awt.Paint)method.- Specified by:
setColorin classjava.awt.Graphics- Parameters:
c- the color (nullpermitted but ignored).- See Also:
setPaint(java.awt.Paint)
-
getBackground
public java.awt.Color getBackground()
Returns the background color. The default value isColor.BLACK. This is used by theclearRect(int, int, int, int)method.- Specified by:
getBackgroundin classjava.awt.Graphics2D- Returns:
- The background color (possibly
null). - See Also:
setBackground(java.awt.Color)
-
setBackground
public void setBackground(java.awt.Color color)
Sets the background color. This is used by theclearRect(int, int, int, int)method. The reference implementation allowsnullfor the background color so we allow that too (but for that case, theclearRect()method will do nothing).- Specified by:
setBackgroundin classjava.awt.Graphics2D- Parameters:
color- the color (nullpermitted).- See Also:
getBackground()
-
getComposite
public java.awt.Composite getComposite()
Returns the current composite.- Specified by:
getCompositein classjava.awt.Graphics2D- Returns:
- The current composite (never
null). - See Also:
setComposite(java.awt.Composite)
-
setComposite
public void setComposite(java.awt.Composite comp)
Sets the composite (onlyAlphaCompositeis handled).- Specified by:
setCompositein classjava.awt.Graphics2D- Parameters:
comp- the composite (nullnot permitted).- See Also:
getComposite()
-
getStroke
public java.awt.Stroke getStroke()
Returns the current stroke (used when drawing shapes).- Specified by:
getStrokein classjava.awt.Graphics2D- Returns:
- The current stroke (never
null). - See Also:
setStroke(java.awt.Stroke)
-
setStroke
public void setStroke(java.awt.Stroke s)
Sets the stroke that will be used to draw shapes. OnlyBasicStrokeis supported.- Specified by:
setStrokein classjava.awt.Graphics2D- Parameters:
s- the stroke (nullnot permitted).- See Also:
getStroke()
-
getRenderingHint
public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
Returns the current value for the specified hint. See thePDFHintsclass for details of the supported hints.- Specified by:
getRenderingHintin classjava.awt.Graphics2D- Parameters:
hintKey- the hint key (nullpermitted, but the result will benullalso).- Returns:
- The current value for the specified hint (possibly
null). - See Also:
setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)
-
setRenderingHint
public void setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)Sets the value for a hint. See thePDFHintsclass for details of the supported hints.- Specified by:
setRenderingHintin classjava.awt.Graphics2D- Parameters:
hintKey- the hint key.hintValue- the hint value.- See Also:
getRenderingHint(java.awt.RenderingHints.Key)
-
getRenderingHints
public java.awt.RenderingHints getRenderingHints()
Returns a copy of the rendering hints. Modifying the returned copy will have no impact on the state of thisGraphics2Dinstance.- Specified by:
getRenderingHintsin classjava.awt.Graphics2D- Returns:
- The rendering hints (never
null). - See Also:
setRenderingHints(java.util.Map)
-
setRenderingHints
public void setRenderingHints(java.util.Map<?,?> hints)
Sets the rendering hints to the specified collection.- Specified by:
setRenderingHintsin classjava.awt.Graphics2D- Parameters:
hints- the new set of hints (nullnot permitted).- See Also:
getRenderingHints()
-
addRenderingHints
public void addRenderingHints(java.util.Map<?,?> hints)
Adds all the supplied rendering hints.- Specified by:
addRenderingHintsin classjava.awt.Graphics2D- Parameters:
hints- the hints (nullnot permitted).
-
invTransformedClip
private java.awt.Shape invTransformedClip(java.awt.Shape clip)
-
draw
public void draw(java.awt.Shape s)
Draws the specified shape with the currentpaintandstroke. There is direct handling forLine2DandPath2Dinstances. All other shapes are mapped to aGeneralPathand then drawn (effectively asPath2Dobjects).- Specified by:
drawin classjava.awt.Graphics2D- Parameters:
s- the shape (nullnot permitted).- See Also:
fill(java.awt.Shape)
-
fill
public void fill(java.awt.Shape s)
Fills the specified shape with the currentpaint. There is direct handling forPath2Dinstances. All other shapes are mapped to aGeneralPathand then filled.- Specified by:
fillin classjava.awt.Graphics2D- Parameters:
s- the shape (nullnot permitted).- See Also:
draw(java.awt.Shape)
-
getFont
public java.awt.Font getFont()
Returns the current font used for drawing text.- Specified by:
getFontin classjava.awt.Graphics- Returns:
- The current font (never
null). - See Also:
setFont(java.awt.Font)
-
setFont
public void setFont(java.awt.Font font)
Sets the font to be used for drawing text.- Specified by:
setFontin classjava.awt.Graphics- Parameters:
font- the font (nullis permitted but ignored).- See Also:
getFont()
-
getFontMetrics
public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
Returns the font metrics for the specified font.- Specified by:
getFontMetricsin classjava.awt.Graphics- Parameters:
f- the font.- Returns:
- The font metrics.
-
getFontRenderContext
public java.awt.font.FontRenderContext getFontRenderContext()
Returns the font render context. The implementation here returns theFontRenderContextfor an image that is maintained internally (as forgetFontMetrics(java.awt.Font)).- Specified by:
getFontRenderContextin classjava.awt.Graphics2D- Returns:
- The font render context.
-
drawString
public void drawString(java.lang.String str, int x, int y)Draws a string at(x, y). The start of the text at the baseline level will be aligned with the(x, y)point.- Specified by:
drawStringin classjava.awt.Graphics2D- Parameters:
str- the string (nullnot permitted).x- the x-coordinate.y- the y-coordinate.- See Also:
drawString(java.lang.String, float, float)
-
drawString
public void drawString(java.lang.String str, float x, float y)Draws a string at(x, y). The start of the text at the baseline level will be aligned with the(x, y)point.- Specified by:
drawStringin classjava.awt.Graphics2D- Parameters:
str- the string (nullnot permitted).x- the x-coordinate.y- the y-coordinate.
-
drawString
public void drawString(java.text.AttributedCharacterIterator iterator, int x, int y)Draws a string of attributed characters at(x, y). The call is delegated todrawString(java.text.AttributedCharacterIterator, float, float).- Specified by:
drawStringin classjava.awt.Graphics2D- Parameters:
iterator- an iterator for the characters.x- the x-coordinate.y- the x-coordinate.
-
drawString
public void drawString(java.text.AttributedCharacterIterator iterator, float x, float y)Draws a string of attributed characters at(x, y).LIMITATION: in the current implementation, the string is drawn using the current font and the formatting is ignored.
- Specified by:
drawStringin classjava.awt.Graphics2D- Parameters:
iterator- an iterator over the characters (nullnot permitted).x- the x-coordinate.y- the y-coordinate.
-
drawGlyphVector
public void drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)Draws the specified glyph vector at the location(x, y).- Specified by:
drawGlyphVectorin classjava.awt.Graphics2D- Parameters:
g- the glyph vector (nullnot permitted).x- the x-coordinate.y- the y-coordinate.
-
translate
public void translate(int tx, int ty)Applies the translation(tx, ty). This call is delegated totranslate(double, double).- Specified by:
translatein classjava.awt.Graphics2D- Parameters:
tx- the x-translation.ty- the y-translation.- See Also:
translate(double, double)
-
translate
public void translate(double tx, double ty)Applies the translation(tx, ty).- Specified by:
translatein classjava.awt.Graphics2D- Parameters:
tx- the x-translation.ty- the y-translation.
-
rotate
public void rotate(double theta)
Applies a rotation (anti-clockwise) about(0, 0).- Specified by:
rotatein classjava.awt.Graphics2D- Parameters:
theta- the rotation angle (in radians).
-
rotate
public void rotate(double theta, double x, double y)Applies a rotation (anti-clockwise) about(x, y).- Specified by:
rotatein classjava.awt.Graphics2D- Parameters:
theta- the rotation angle (in radians).x- the x-coordinate.y- the y-coordinate.
-
scale
public void scale(double sx, double sy)Applies a scale transformation.- Specified by:
scalein classjava.awt.Graphics2D- Parameters:
sx- the x-scaling factor.sy- the y-scaling factor.
-
shear
public void shear(double shx, double shy)Applies a shear transformation. This is equivalent to the following call to thetransformmethod:-
transform(AffineTransform.getShearInstance(shx, shy));
- Specified by:
shearin classjava.awt.Graphics2D- Parameters:
shx- the x-shear factor.shy- the y-shear factor.
-
-
transform
public void transform(java.awt.geom.AffineTransform t)
Applies this transform to the existing transform by concatenating it.- Specified by:
transformin classjava.awt.Graphics2D- Parameters:
t- the transform (nullnot permitted).
-
getTransform
public java.awt.geom.AffineTransform getTransform()
Returns a copy of the current transform.- Specified by:
getTransformin classjava.awt.Graphics2D- Returns:
- A copy of the current transform (never
null). - See Also:
setTransform(java.awt.geom.AffineTransform)
-
setTransform
public void setTransform(java.awt.geom.AffineTransform t)
Sets the transform.- Specified by:
setTransformin classjava.awt.Graphics2D- Parameters:
t- the new transform (nullpermitted, resets to the identity transform).- See Also:
getTransform()
-
hit
public boolean hit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)Returnstrueif the rectangle (in device space) intersects with the shape (the interior, ifonStrokeis false, otherwise the stroked outline of the shape).- Specified by:
hitin classjava.awt.Graphics2D- Parameters:
rect- a rectangle (in device space).s- the shape.onStroke- test the stroked outline only?- Returns:
- A boolean.
-
getDeviceConfiguration
public java.awt.GraphicsConfiguration getDeviceConfiguration()
Returns the device configuration associated with thisGraphics2D.- Specified by:
getDeviceConfigurationin classjava.awt.Graphics2D- Returns:
- The graphics configuration.
-
setPaintMode
public void setPaintMode()
Does nothing in thisPDFGraphics2Dimplementation.- Specified by:
setPaintModein classjava.awt.Graphics
-
setXORMode
public void setXORMode(java.awt.Color c)
Does nothing in thisPDFGraphics2Dimplementation.- Specified by:
setXORModein classjava.awt.Graphics- Parameters:
c- ignored
-
getClip
public java.awt.Shape getClip()
Returns the user clipping region. The initial default value isnull.- Specified by:
getClipin classjava.awt.Graphics- Returns:
- The user clipping region (possibly
null). - See Also:
setClip(java.awt.Shape)
-
setClip
public void setClip(java.awt.Shape shape)
Sets the user clipping region.- Specified by:
setClipin classjava.awt.Graphics- Parameters:
shape- the new user clipping region (nullpermitted).- See Also:
getClip()
-
getClipBounds
public java.awt.Rectangle getClipBounds()
Returns the bounds of the user clipping region. If the user clipping region isnull, this method will returnnull.- Specified by:
getClipBoundsin classjava.awt.Graphics- Returns:
- The clip bounds (possibly
null). - See Also:
getClip()
-
clip
public void clip(java.awt.Shape s)
Clips to the intersection of the current clipping region and the specified shape.According to the Oracle API specification, this method will accept a
nullargument, but there is an open bug report (since 2004) that suggests this is wrong:- Specified by:
clipin classjava.awt.Graphics2D- Parameters:
s- the clip shape (nullnot permitted).
-
clipRect
public void clipRect(int x, int y, int width, int height)Clips to the intersection of the current clipping region and the specified rectangle.- Specified by:
clipRectin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.
-
setClip
public void setClip(int x, int y, int width, int height)Sets the user clipping region to the specified rectangle.- Specified by:
setClipin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.- See Also:
getClip()
-
drawLine
public void drawLine(int x1, int y1, int x2, int y2)Draws a line from(x1, y1)to(x2, y2)using the currentpaintandstroke.- Specified by:
drawLinein classjava.awt.Graphics- Parameters:
x1- the x-coordinate of the start point.y1- the y-coordinate of the start point.x2- the x-coordinate of the end point.y2- the x-coordinate of the end point.
-
fillRect
public void fillRect(int x, int y, int width, int height)Fills the specified rectangle with the currentpaint.- Specified by:
fillRectin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the rectangle width.height- the rectangle height.
-
clearRect
public void clearRect(int x, int y, int width, int height)Clears the specified rectangle by filling it with the current background color. If the background color isnull, this method will do nothing.- Specified by:
clearRectin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.- See Also:
getBackground()
-
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Draws a rectangle with rounded corners using the currentpaintandstroke.- Specified by:
drawRoundRectin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.arcWidth- the arc-width.arcHeight- the arc-height.- See Also:
fillRoundRect(int, int, int, int, int, int)
-
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Fills a rectangle with rounded corners.- Specified by:
fillRoundRectin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.arcWidth- the arc-width.arcHeight- the arc-height.
-
drawOval
public void drawOval(int x, int y, int width, int height)Draws an oval framed by the rectangle(x, y, width, height)using the currentpaintandstroke.- Specified by:
drawOvalin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.- See Also:
fillOval(int, int, int, int)
-
fillOval
public void fillOval(int x, int y, int width, int height)Fills an oval framed by the rectangle(x, y, width, height).- Specified by:
fillOvalin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.- See Also:
drawOval(int, int, int, int)
-
drawArc
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)Draws an arc contained within the rectangle(x, y, width, height), starting atstartAngleand continuing througharcAngledegrees using the currentpaintandstroke.- Specified by:
drawArcin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.startAngle- the start angle in degrees, 0 = 3 o'clock.arcAngle- the angle (anticlockwise) in degrees.- See Also:
fillArc(int, int, int, int, int, int)
-
fillArc
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)Fills an arc contained within the rectangle(x, y, width, height), starting atstartAngleand continuing througharcAngledegrees, using the currentpaint- Specified by:
fillArcin classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.startAngle- the start angle in degrees, 0 = 3 o'clock.arcAngle- the angle (anticlockwise) in degrees.- See Also:
drawArc(int, int, int, int, int, int)
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)Draws the specified multi-segment line using the currentpaintandstroke.- Specified by:
drawPolylinein classjava.awt.Graphics- Parameters:
xPoints- the x-points.yPoints- the y-points.nPoints- the number of points to use for the polyline.
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws the specified polygon using the currentpaintandstroke.- Specified by:
drawPolygonin classjava.awt.Graphics- Parameters:
xPoints- the x-points.yPoints- the y-points.nPoints- the number of points to use for the polygon.- See Also:
fillPolygon(int[], int[], int)
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)Fills the specified polygon using the currentpaint.- Specified by:
fillPolygonin classjava.awt.Graphics- Parameters:
xPoints- the x-points.yPoints- the y-points.nPoints- the number of points to use for the polygon.- See Also:
drawPolygon(int[], int[], int)
-
drawImage
public boolean drawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver observer)Draws an image with the specified transform. Note that theobsis ignored.- Specified by:
drawImagein classjava.awt.Graphics2D- Parameters:
img- the image.xform- the transform (nullpermitted).observer- the image observer (ignored).- Returns:
trueif the image is drawn.
-
drawImage
public void drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)Draws the image resulting from applying theBufferedImageOpto the specified image at the location(x, y).- Specified by:
drawImagein classjava.awt.Graphics2D- Parameters:
img- the image.op- the operation.x- the x-coordinate.y- the y-coordinate.
-
drawRenderedImage
public void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)Draws the rendered image. Whenimgisnullthis method does nothing.- Specified by:
drawRenderedImagein classjava.awt.Graphics2D- Parameters:
img- the image (nullpermitted).xform- the transform.
-
drawRenderableImage
public void drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)Draws the renderable image.- Specified by:
drawRenderableImagein classjava.awt.Graphics2D- Parameters:
img- the renderable image.xform- the transform.
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)Draws an image at the location(x, y). Note that theobserveris ignored.- Specified by:
drawImagein classjava.awt.Graphics- Parameters:
img- the image.x- the x-coordinate.y- the y-coordinate.observer- ignored.- Returns:
trueif the image is drawn.
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, int w, int h, java.awt.image.ImageObserver observer)Draws the image into the rectangle defined by(x, y, w, h). Note that theobserveris ignored (it is not useful in this context).- Specified by:
drawImagein classjava.awt.Graphics- Parameters:
img- the image.x- the x-coordinate.y- the y-coordinate.w- the width.h- the height.observer- ignored.- Returns:
trueif the image is drawn.
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)Draws an image at the location(x, y). Note that theobserveris ignored.- Specified by:
drawImagein classjava.awt.Graphics- Parameters:
img- the image.x- the x-coordinate.y- the y-coordinate.bgcolor- the background color (nullpermitted).observer- ignored.- Returns:
trueif the image is drawn.
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, int w, int h, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)Draws an image to the rectangle(x, y, w, h)(scaling it if required), first filling the background with the specified color. Note that theobserveris ignored.- Specified by:
drawImagein classjava.awt.Graphics- Parameters:
img- the image.x- the x-coordinate.y- the y-coordinate.w- the width.h- the height.bgcolor- the background color (nullpermitted).observer- ignored.- Returns:
trueif the image is drawn.
-
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)Draws part of an image (defined by the source rectangle(sx1, sy1, sx2, sy2)) into the destination rectangle(dx1, dy1, dx2, dy2). Note that theobserveris ignored.- Specified by:
drawImagein classjava.awt.Graphics- Parameters:
img- the image.dx1- the x-coordinate for the top left of the destination.dy1- the y-coordinate for the top left of the destination.dx2- the x-coordinate for the bottom right of the destination.dy2- the y-coordinate for the bottom right of the destination.sx1- the x-coordinate for the top left of the source.sy1- the y-coordinate for the top left of the source.sx2- the x-coordinate for the bottom right of the source.sy2- the y-coordinate for the bottom right of the source.- Returns:
trueif the image is drawn.
-
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)Draws part of an image (defined by the source rectangle(sx1, sy1, sx2, sy2)) into the destination rectangle(dx1, dy1, dx2, dy2). The destination rectangle is first cleared by filling it with the specifiedbgcolor. Note that theobserveris ignored.- Specified by:
drawImagein classjava.awt.Graphics- Parameters:
img- the image.dx1- the x-coordinate for the top left of the destination.dy1- the y-coordinate for the top left of the destination.dx2- the x-coordinate for the bottom right of the destination.dy2- the y-coordinate for the bottom right of the destination.sx1- the x-coordinate for the top left of the source.sy1- the y-coordinate for the top left of the source.sx2- the x-coordinate for the bottom right of the source.sy2- the y-coordinate for the bottom right of the source.bgcolor- the background color (nullpermitted).observer- ignored.- Returns:
trueif the image is drawn.
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy)This method does nothing. The operation assumes that the output is in bitmap form, which is not the case for PDF, so we silently ignore this method call.- Specified by:
copyAreain classjava.awt.Graphics- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width of the area.height- the height of the area.dx- the delta x.dy- the delta y.
-
dispose
public void dispose()
Performs any actions required when the graphics instance is finished with. Here we restore the transform on the graphics stream if this instance was created via thecreate()method. See issue #4 at GitHub for background info.- Specified by:
disposein classjava.awt.Graphics
-
setRect
private void setRect(int x, int y, int width, int height)Sets the attributes of the reusableRectangle2Dobject that is used by theGraphics.drawRect(int, int, int, int)andfillRect(int, int, int, int)methods.- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.
-
setRoundRect
private void setRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Sets the attributes of the reusableRoundRectangle2Dobject that is used by thedrawRoundRect(int, int, int, int, int, int)andfillRoundRect(int, int, int, int, int, int)methods.- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.arcWidth- the arc width.arcHeight- the arc height.
-
setOval
private void setOval(int x, int y, int width, int height)Sets the attributes of the reusableEllipse2Dobject that is used by thedrawOval(int, int, int, int)andfillOval(int, int, int, int)methods.- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.
-
setArc
private void setArc(int x, int y, int width, int height, int startAngle, int arcAngle)Sets the attributes of the reusableArc2Dobject that is used bydrawArc(int, int, int, int, int, int)andfillArc(int, int, int, int, int, int)methods.- Parameters:
x- the x-coordinate.y- the y-coordinate.width- the width.height- the height.startAngle- the start angle in degrees, 0 = 3 o'clock.arcAngle- the angle (anticlockwise) in degrees.
-
-