Package com.orsonpdf
Class GraphicsStream
- java.lang.Object
-
- com.orsonpdf.PDFObject
-
- com.orsonpdf.Stream
-
- com.orsonpdf.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)(package private) voidapplyAlpha(int alpha)Applies the alpha transparency.(package private) voidapplyClip(java.awt.Shape clip)Applies the specified clip to the current clip.(package private) voidapplyComposite(java.awt.AlphaComposite alphaComp)Applies the specified alpha composite.(package private) voidapplyFillColor(java.awt.Color c)Applies a color for filling.(package private) voidapplyFillGradient(java.awt.GradientPaint gp)Applies aGradientPaintfor filling.(package private) voidapplyFillGradient(java.awt.RadialGradientPaint rgp)Applies aRadialGradientPaintfor filling.(package private) 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)).(package private) voidapplyStroke(java.awt.Stroke s)Applies a stroke.(package private) voidapplyStrokeColor(java.awt.Color c)Applies a color for stroking.(package private) voidapplyStrokeGradient(java.awt.GradientPaint gp)Applies aGradientPaintfor stroking.(package private) voidapplyStrokeGradient(java.awt.RadialGradientPaint rgp)Applies aRadialGradientPaintfor stroking.(package private) voidapplyTextTransform(java.awt.geom.AffineTransform t)Applies a text transform.(package private) voidapplyTransform(java.awt.geom.AffineTransform t)Applies a graphics transform.(package private) voiddrawImage(java.awt.Image img, int x, int y, int w, int h)Draws the specified image into the rectangle(x, y, w, h).(package private) voiddrawLine(java.awt.geom.Line2D line)Draws the specified line.(package private) voiddrawPath2D(java.awt.geom.Path2D path)Draws the specified path.(package private) voiddrawString(java.lang.String text, float x, float y)Draws a string at the specified location.(package private) 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.(package private) voidpopGraphicsState()Pops the graphics state that was previously pushed onto the stack.(package private) voidpushGraphicsState()Pushes the current graphics state onto a stack for later retrieval.(package private) voidsetTransform(java.awt.geom.AffineTransform t)Sets the transform.private java.lang.StringtransformDP(double d)-
Methods inherited from class com.orsonpdf.Stream
addFilter, createDictionary, getObjectBytes, removeFilters
-
Methods inherited from class com.orsonpdf.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
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
void pushGraphicsState()
Pushes the current graphics state onto a stack for later retrieval.
-
popGraphicsState
void popGraphicsState()
Pops the graphics state that was previously pushed onto the stack.
-
applyTransform
void applyTransform(java.awt.geom.AffineTransform t)
Applies a graphics transform.- Parameters:
t- the transform (nullnot permitted).
-
setTransform
void setTransform(java.awt.geom.AffineTransform t)
Sets the transform.- Parameters:
t- the transform (nullnot permitted).
-
applyTextTransform
void applyTextTransform(java.awt.geom.AffineTransform t)
Applies a text transform.- Parameters:
t- the transform (nullnot permitted).
-
applyClip
void applyClip(java.awt.Shape clip)
Applies the specified clip to the current clip.- Parameters:
clip- the clip (nullnot permitted).
-
applyStroke
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
void applyStrokeColor(java.awt.Color c)
Applies a color for stroking.- Parameters:
c- the color (nullnot permitted).
-
applyFillColor
void applyFillColor(java.awt.Color c)
Applies a color for filling.- Parameters:
c- the color (nullnot permitted).
-
applyStrokeGradient
void applyStrokeGradient(java.awt.GradientPaint gp)
Applies aGradientPaintfor stroking.- Parameters:
gp- the gradient paint (nullnot permitted).
-
applyStrokeGradient
void applyStrokeGradient(java.awt.RadialGradientPaint rgp)
Applies aRadialGradientPaintfor stroking.- Parameters:
rgp- the gradient paint (nullnot permitted).
-
applyFillGradient
void applyFillGradient(java.awt.GradientPaint gp)
Applies aGradientPaintfor filling.- Parameters:
gp- the gradient paint (nullnot permitted).
-
applyFillGradient
void applyFillGradient(java.awt.RadialGradientPaint rgp)
Applies aRadialGradientPaintfor filling.- Parameters:
rgp- the gradient paint (nullnot permitted).
-
applyComposite
void applyComposite(java.awt.AlphaComposite alphaComp)
Applies the specified alpha composite.- Parameters:
alphaComp- the alpha composite (nullpermitted).
-
applyAlpha
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
void drawLine(java.awt.geom.Line2D line)
Draws the specified line.- Parameters:
line- the line (nullnot permitted).
-
drawPath2D
void drawPath2D(java.awt.geom.Path2D path)
Draws the specified path.- Parameters:
path- the path (nullnot permitted).
-
fillPath2D
void fillPath2D(java.awt.geom.Path2D path)
Fills the specified path.- Parameters:
path- the path (nullnot permitted).
-
applyFont
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
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
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.
-
-