- java.lang.Object
-
- org.jfree.pdf.internal.PDFObject
-
- org.jfree.pdf.stream.Stream
-
- org.jfree.pdf.stream.GraphicsStream
-
public class GraphicsStream extends Stream
AStreamthat contains graphics for the PDF document that can be generated via thePDFGraphics2Dclass. ThePageclass will create aGraphicsStreaminstance to represent its content. You won't normally interact directly with this class, it is intended that thePDFGraphics2Dclass drives the calls to the methods of this class.
-
-
Field Summary
Fields Modifier and Type Field Description private intalphaThe most recent alpha transparency value (in the range 0 to 255).private floatalphaFactorprivate java.io.ByteArrayOutputStreamcontentThe stream content.private java.awt.FontfontThe most recent font applied.private java.text.DecimalFormatgeometryFormatThe decimal formatter for coordinates of geometrical shapes.private PagepageThe page the graphics stream belongs to.private java.awt.geom.AffineTransformprevTransInvprivate java.text.DecimalFormattransformFormatThe decimal formatter for transform matrices.
-
Constructor Summary
Constructors Constructor Description GraphicsStream(int number, Page page)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddContent(java.lang.String s)private voidapplyAlpha(int alpha)Applies the alpha transparency.voidapplyClip(java.awt.Shape clip)Applies the specified clip to the current clip.voidapplyComposite(java.awt.AlphaComposite alphaComp)Applies the specified alpha composite.voidapplyFillColor(java.awt.Color c)Applies a color for filling.voidapplyFillGradient(java.awt.GradientPaint gp)Applies aGradientPaintfor filling.voidapplyFillGradient(java.awt.RadialGradientPaint rgp)Applies aRadialGradientPaintfor filling.voidapplyFont(java.awt.Font font)Applies the specified font (in fact, no change is made to the stream until the next call todrawString(java.lang.String, float, float)).voidapplyStroke(java.awt.Stroke s)Applies a stroke.voidapplyStrokeColor(java.awt.Color c)Applies a color for stroking.voidapplyStrokeGradient(java.awt.GradientPaint gp)Applies aGradientPaintfor stroking.voidapplyStrokeGradient(java.awt.RadialGradientPaint rgp)Applies aRadialGradientPaintfor stroking.private voidapplyTextTransform(java.awt.geom.AffineTransform t)Applies a text transform.voidapplyTransform(java.awt.geom.AffineTransform t)Applies a graphics transform.voiddrawImage(java.awt.Image img, int x, int y, int w, int h)Draws the specified image into the rectangle(x, y, w, h).voiddrawLine(java.awt.geom.Line2D line)Draws the specified line.voiddrawPath2D(java.awt.geom.Path2D path)Draws the specified path.voiddrawString(java.lang.String text, float x, float y)Draws a string at the specified location.voidfillPath2D(java.awt.geom.Path2D path)Fills the specified path.private java.lang.StringgeomDP(double d)private java.lang.StringgetPDFPath(java.awt.geom.Path2D path)A utility method to convert aPath2Dinstance to a PDF path string.byte[]getRawStreamData()Returns the raw data for the stream.voidpopGraphicsState()Pops the graphics state that was previously pushed onto the stack.voidpushGraphicsState()Pushes the current graphics state onto a stack for later retrieval.voidsetTransform(java.awt.geom.AffineTransform t)Sets the transform.private java.lang.StringtransformDP(double d)-
Methods inherited from class org.jfree.pdf.stream.Stream
addFilter, createDictionary, getObjectBytes, removeFilters
-
Methods inherited from class org.jfree.pdf.internal.PDFObject
getGeneration, getNumber, getReference, toPDFBytes
-
-
-
-
Field Detail
-
page
private Page page
The page the graphics stream belongs to. We need this reference to our "parent" so that we can access fonts in the document.
-
content
private java.io.ByteArrayOutputStream content
The stream content.
-
font
private java.awt.Font font
The most recent font applied.
-
alpha
private int alpha
The most recent alpha transparency value (in the range 0 to 255).
-
prevTransInv
private java.awt.geom.AffineTransform prevTransInv
-
geometryFormat
private java.text.DecimalFormat geometryFormat
The decimal formatter for coordinates of geometrical shapes.
-
transformFormat
private java.text.DecimalFormat transformFormat
The decimal formatter for transform matrices.
-
alphaFactor
private float alphaFactor
-
-
Constructor Detail
-
GraphicsStream
public GraphicsStream(int number, Page page)Creates a new instance.- Parameters:
number- the PDF object number.page- the parent page (nullnot permitted).
-
-
Method Detail
-
addContent
private void addContent(java.lang.String s)
-
pushGraphicsState
public void pushGraphicsState()
Pushes the current graphics state onto a stack for later retrieval.
-
popGraphicsState
public void popGraphicsState()
Pops the graphics state that was previously pushed onto the stack.
-
applyTransform
public void applyTransform(java.awt.geom.AffineTransform t)
Applies a graphics transform.- Parameters:
t- the transform (nullnot permitted).
-
setTransform
public void setTransform(java.awt.geom.AffineTransform t)
Sets the transform.- Parameters:
t- the transform (nullnot permitted).
-
applyTextTransform
private void applyTextTransform(java.awt.geom.AffineTransform t)
Applies a text transform.- Parameters:
t- the transform (nullnot permitted).
-
applyClip
public void applyClip(java.awt.Shape clip)
Applies the specified clip to the current clip.- Parameters:
clip- the clip (nullnot permitted).
-
applyStroke
public void applyStroke(java.awt.Stroke s)
Applies a stroke. If the stroke is not an instance ofBasicStrokethis method will do nothing.- Parameters:
s- the stroke.
-
applyStrokeColor
public void applyStrokeColor(java.awt.Color c)
Applies a color for stroking.- Parameters:
c- the color (nullnot permitted).
-
applyFillColor
public void applyFillColor(java.awt.Color c)
Applies a color for filling.- Parameters:
c- the color (nullnot permitted).
-
applyStrokeGradient
public void applyStrokeGradient(java.awt.GradientPaint gp)
Applies aGradientPaintfor stroking.- Parameters:
gp- the gradient paint (nullnot permitted).
-
applyStrokeGradient
public void applyStrokeGradient(java.awt.RadialGradientPaint rgp)
Applies aRadialGradientPaintfor stroking.- Parameters:
rgp- the gradient paint (nullnot permitted).
-
applyFillGradient
public void applyFillGradient(java.awt.GradientPaint gp)
Applies aGradientPaintfor filling.- Parameters:
gp- the gradient paint (nullnot permitted).
-
applyFillGradient
public void applyFillGradient(java.awt.RadialGradientPaint rgp)
Applies aRadialGradientPaintfor filling.- Parameters:
rgp- the gradient paint (nullnot permitted).
-
applyComposite
public void applyComposite(java.awt.AlphaComposite alphaComp)
Applies the specified alpha composite.- Parameters:
alphaComp- the alpha composite (nullpermitted).
-
applyAlpha
private void applyAlpha(int alpha)
Applies the alpha transparency.- Parameters:
alpha- the new alpha value (in the range0to255).
-
geomDP
private java.lang.String geomDP(double d)
-
transformDP
private java.lang.String transformDP(double d)
-
drawLine
public void drawLine(java.awt.geom.Line2D line)
Draws the specified line.- Parameters:
line- the line (nullnot permitted).
-
drawPath2D
public void drawPath2D(java.awt.geom.Path2D path)
Draws the specified path.- Parameters:
path- the path (nullnot permitted).
-
fillPath2D
public void fillPath2D(java.awt.geom.Path2D path)
Fills the specified path.- Parameters:
path- the path (nullnot permitted).
-
applyFont
public void applyFont(java.awt.Font font)
Applies the specified font (in fact, no change is made to the stream until the next call todrawString(java.lang.String, float, float)).- Parameters:
font- the font.
-
drawString
public void drawString(java.lang.String text, float x, float y)Draws a string at the specified location.- Parameters:
text- the text.x- the x-coordinate.y- the y-coordinate.
-
drawImage
public void drawImage(java.awt.Image img, int x, int y, int w, int h)Draws the specified image into the rectangle(x, y, w, h).- Parameters:
img- the image.x- the x-coordinate of the destination.y- the y-coordinate of the destination.w- the width of the destination.h- the height of the destination.
-
getPDFPath
private java.lang.String getPDFPath(java.awt.geom.Path2D path)
A utility method to convert aPath2Dinstance to a PDF path string.- Parameters:
path- the path (nullnot permitted).- Returns:
- The string.
-
getRawStreamData
public byte[] getRawStreamData()
Description copied from class:StreamReturns the raw data for the stream.- Specified by:
getRawStreamDatain classStream- Returns:
- The raw data for the stream.
-
-