Package com.orsonpdf
Class GraphicsStream
- java.lang.Object
-
- com.orsonpdf.PDFObject
-
- com.orsonpdf.Stream
-
- com.orsonpdf.GraphicsStream
-
public class GraphicsStream extends Stream
AStream
that contains graphics for the PDF document that can be generated via thePDFGraphics2D
class. ThePage
class will create aGraphicsStream
instance to represent its content. You won't normally interact directly with this class, it is intended that thePDFGraphics2D
class drives the calls to the methods of this class.
-
-
Field Summary
Fields Modifier and Type Field Description private int
alpha
The most recent alpha transparency value (in the range 0 to 255).private float
alphaFactor
private java.io.ByteArrayOutputStream
content
The stream content.private java.awt.Font
font
The most recent font applied.private java.text.DecimalFormat
geometryFormat
The decimal formatter for coordinates of geometrical shapes.private Page
page
The page the graphics stream belongs to.private java.awt.geom.AffineTransform
prevTransInv
private java.text.DecimalFormat
transformFormat
The 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 void
addContent(java.lang.String s)
(package private) void
applyAlpha(int alpha)
Applies the alpha transparency.(package private) void
applyClip(java.awt.Shape clip)
Applies the specified clip to the current clip.(package private) void
applyComposite(java.awt.AlphaComposite alphaComp)
Applies the specified alpha composite.(package private) void
applyFillColor(java.awt.Color c)
Applies a color for filling.(package private) void
applyFillGradient(java.awt.GradientPaint gp)
Applies aGradientPaint
for filling.(package private) void
applyFillGradient(java.awt.RadialGradientPaint rgp)
Applies aRadialGradientPaint
for filling.(package private) 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)
).(package private) void
applyStroke(java.awt.Stroke s)
Applies a stroke.(package private) void
applyStrokeColor(java.awt.Color c)
Applies a color for stroking.(package private) void
applyStrokeGradient(java.awt.GradientPaint gp)
Applies aGradientPaint
for stroking.(package private) void
applyStrokeGradient(java.awt.RadialGradientPaint rgp)
Applies aRadialGradientPaint
for stroking.(package private) void
applyTextTransform(java.awt.geom.AffineTransform t)
Applies a text transform.(package private) void
applyTransform(java.awt.geom.AffineTransform t)
Applies a graphics transform.(package private) 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)
.(package private) void
drawLine(java.awt.geom.Line2D line)
Draws the specified line.(package private) void
drawPath2D(java.awt.geom.Path2D path)
Draws the specified path.(package private) void
drawString(java.lang.String text, float x, float y)
Draws a string at the specified location.(package private) void
fillPath2D(java.awt.geom.Path2D path)
Fills the specified path.private java.lang.String
geomDP(double d)
private java.lang.String
getPDFPath(java.awt.geom.Path2D path)
A utility method to convert aPath2D
instance to a PDF path string.byte[]
getRawStreamData()
Returns the raw data for the stream.(package private) void
popGraphicsState()
Pops the graphics state that was previously pushed onto the stack.(package private) void
pushGraphicsState()
Pushes the current graphics state onto a stack for later retrieval.(package private) void
setTransform(java.awt.geom.AffineTransform t)
Sets the transform.private java.lang.String
transformDP(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 (null
not 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 (null
not permitted).
-
setTransform
void setTransform(java.awt.geom.AffineTransform t)
Sets the transform.- Parameters:
t
- the transform (null
not permitted).
-
applyTextTransform
void applyTextTransform(java.awt.geom.AffineTransform t)
Applies a text transform.- Parameters:
t
- the transform (null
not permitted).
-
applyClip
void applyClip(java.awt.Shape clip)
Applies the specified clip to the current clip.- Parameters:
clip
- the clip (null
not permitted).
-
applyStroke
void applyStroke(java.awt.Stroke s)
Applies a stroke. If the stroke is not an instance ofBasicStroke
this method will do nothing.- Parameters:
s
- the stroke.
-
applyStrokeColor
void applyStrokeColor(java.awt.Color c)
Applies a color for stroking.- Parameters:
c
- the color (null
not permitted).
-
applyFillColor
void applyFillColor(java.awt.Color c)
Applies a color for filling.- Parameters:
c
- the color (null
not permitted).
-
applyStrokeGradient
void applyStrokeGradient(java.awt.GradientPaint gp)
Applies aGradientPaint
for stroking.- Parameters:
gp
- the gradient paint (null
not permitted).
-
applyStrokeGradient
void applyStrokeGradient(java.awt.RadialGradientPaint rgp)
Applies aRadialGradientPaint
for stroking.- Parameters:
rgp
- the gradient paint (null
not permitted).
-
applyFillGradient
void applyFillGradient(java.awt.GradientPaint gp)
Applies aGradientPaint
for filling.- Parameters:
gp
- the gradient paint (null
not permitted).
-
applyFillGradient
void applyFillGradient(java.awt.RadialGradientPaint rgp)
Applies aRadialGradientPaint
for filling.- Parameters:
rgp
- the gradient paint (null
not permitted).
-
applyComposite
void applyComposite(java.awt.AlphaComposite alphaComp)
Applies the specified alpha composite.- Parameters:
alphaComp
- the alpha composite (null
permitted).
-
applyAlpha
void applyAlpha(int alpha)
Applies the alpha transparency.- Parameters:
alpha
- the new alpha value (in the range0
to255
).
-
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 (null
not permitted).
-
drawPath2D
void drawPath2D(java.awt.geom.Path2D path)
Draws the specified path.- Parameters:
path
- the path (null
not permitted).
-
fillPath2D
void fillPath2D(java.awt.geom.Path2D path)
Fills the specified path.- Parameters:
path
- the path (null
not 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 aPath2D
instance to a PDF path string.- Parameters:
path
- the path (null
not permitted).- Returns:
- The string.
-
getRawStreamData
public byte[] getRawStreamData()
Description copied from class:Stream
Returns the raw data for the stream.- Specified by:
getRawStreamData
in classStream
- Returns:
- The raw data for the stream.
-
-