PDF Clown
0.1.2

org.pdfclown.documents.contents.composition
Class PrimitiveComposer

java.lang.Object
  extended by org.pdfclown.documents.contents.composition.PrimitiveComposer

public final class PrimitiveComposer
extends Object

Content stream primitive composer.

It provides the basic (primitive) operations described by the PDF specification for graphics content composition.

This class leverages the object-oriented content stream modelling infrastructure, which encompasses 1st-level content stream objects (operations), 2nd-level content stream objects (graphics objects) and full graphics state support.

Since:
0.0.4
Version:
0.1.2, 09/24/12
Author:
Stefano Chizzolini (http://www.stefanochizzolini.it)

Constructor Summary
PrimitiveComposer(ContentScanner scanner)
           
PrimitiveComposer(IContentContext context)
           
 
Method Summary
 ContentObject add(ContentObject object)
          Adds a content object.
 void applyMatrix(double a, double b, double c, double d, double e, double f)
          Applies a transformation to the coordinate system from user space to device space [PDF:1.6:4.3.3].
 void applyState(ExtGState state)
          Applies the specified state parameters [PDF:1.6:4.3.4].
 void applyState(PdfName name)
          Applies the specified state parameters [PDF:1.6:4.3.4].
 CompositeObject begin(CompositeObject object)
          Adds a composite object beginning it.
 MarkedContent beginLayer(LayerEntity layer)
          Begins a new layered-content sequence [PDF:1.6:4.10.2].
 MarkedContent beginLayer(PdfName layerName)
          Begins a new layered-content sequence [PDF:1.6:4.10.2].
 LocalGraphicsState beginLocalState()
          Begins a new nested graphics state context [PDF:1.6:4.3.1].
 MarkedContent beginMarkedContent(PdfName tag)
          Begins a new marked-content sequence [PDF:1.6:10.5].
 MarkedContent beginMarkedContent(PdfName tag, PdfName propertyListName)
          Begins a new marked-content sequence [PDF:1.6:10.5].
 MarkedContent beginMarkedContent(PdfName tag, PropertyList propertyList)
          Begins a new marked-content sequence [PDF:1.6:10.5].
 void clip()
          Modifies the current clipping path by intersecting it with the current path [PDF:1.6:4.4.1].
 void closePath()
          Closes the current subpath by appending a straight line segment from the current point to the starting point of the subpath [PDF:1.6:4.4.1].
 void drawArc(RectangularShape location, double startAngle, double endAngle)
          Draws a circular arc.
 void drawArc(RectangularShape location, double startAngle, double endAngle, double branchWidth, double branchRatio)
          Draws an arc.
 void drawCurve(Point2D endPoint, Point2D startControl, Point2D endControl)
          Draws a cubic Bezier curve from the current point [PDF:1.6:4.4.1].
 void drawCurve(Point2D startPoint, Point2D endPoint, Point2D startControl, Point2D endControl)
          Draws a cubic Bezier curve [PDF:1.6:4.4.1].
 void drawEllipse(RectangularShape location)
          Draws an ellipse.
 void drawLine(Point2D endPoint)
          Draws a line from the current point [PDF:1.6:4.4.1].
 void drawLine(Point2D startPoint, Point2D endPoint)
          Draws a line [PDF:1.6:4.4.1].
 void drawPolygon(Point2D[] points)
          Draws a polygon.
 void drawPolyline(Point2D[] points)
          Draws a multiple line.
 void drawRectangle(RectangularShape location)
          Draws a rectangle [PDF:1.6:4.4.1].
 void drawRectangle(RectangularShape location, double radius)
          Draws a rounded rectangle.
 void drawSpiral(Point2D center, double startAngle, double endAngle, double branchWidth, double branchRatio)
          Draws a spiral.
 void end()
          Ends the current (innermostly-nested) composite object.
 void fill()
          Fills the path using the current color [PDF:1.6:4.4.2].
 void fillStroke()
          Fills and then strokes the path using the current colors [PDF:1.6:4.4.2].
 void flush()
          Serializes the contents into the content stream.
 ContentScanner getScanner()
          Gets the content stream scanner.
 ContentScanner.GraphicsState getState()
          Gets the current graphics state [PDF:1.6:4.3].
 void rotate(double angle)
          Applies a rotation to the coordinate system from user space to device space [PDF:1.6:4.2.2].
 void rotate(double angle, Point2D origin)
          Applies a rotation to the coordinate system from user space to device space [PDF:1.6:4.2.2].
 void scale(double ratioX, double ratioY)
          Applies a scaling to the coordinate system from user space to device space [PDF:1.6:4.2.2].
 void setCharSpace(double value)
          Sets the character spacing parameter [PDF:1.6:5.2.1].
 void setFillColor(Color<?> value)
          Sets the nonstroking color value [PDF:1.6:4.5.7].
 void setFont(Font value, double size)
          Sets the font [PDF:1.6:5.2].
 void setFont(PdfName name, double size)
          Sets the font [PDF:1.6:5.2].
 void setLineCap(LineCapEnum value)
          Sets the line cap style [PDF:1.6:4.3.2].
 void setLineDash(LineDash value)
          Sets the line dash pattern [PDF:1.6:4.3.2].
 void setLineJoin(LineJoinEnum value)
          Sets the line join style [PDF:1.6:4.3.2].
 void setLineWidth(double value)
          Sets the line width [PDF:1.6:4.3.2].
 void setMatrix(double a, double b, double c, double d, double e, double f)
          Sets the transformation of the coordinate system from user space to device space [PDF:1.6:4.3.3].
 void setMiterLimit(double value)
          Sets the miter limit [PDF:1.6:4.3.2].
 void setScanner(ContentScanner value)
           
 void setStrokeColor(Color<?> value)
          Sets the stroking color value [PDF:1.6:4.5.7].
 void setTextLead(double value)
          Sets the text leading [PDF:1.6:5.2.4].
 void setTextRenderMode(TextRenderModeEnum value)
          Sets the text rendering mode [PDF:1.6:5.2.5].
 void setTextRise(double value)
          Sets the text rise [PDF:1.6:5.2.6].
 void setTextScale(double value)
          Sets the text horizontal scaling [PDF:1.6:5.2.3].
 void setWordSpace(double value)
          Sets the word spacing [PDF:1.6:5.2.2].
 Quad showText(String value)
          Shows the specified text on the page at the current location [PDF:1.6:5.3.2].
 Link showText(String value, Action action)
          Shows the link associated to the specified text on the page at the current location.
 Quad showText(String value, Point2D location)
          Shows the specified text on the page at the specified location [PDF:1.6:5.3.2].
 Link showText(String value, Point2D location, Action action)
          Shows the link associated to the specified text on the page at the specified location.
 Quad showText(String value, Point2D location, XAlignmentEnum xAlignment, YAlignmentEnum yAlignment, double rotation)
          Shows the specified text on the page at the specified location [PDF:1.6:5.3.2].
 Link showText(String value, Point2D location, XAlignmentEnum xAlignment, YAlignmentEnum yAlignment, double rotation, Action action)
          Shows the link associated to the specified text on the page at the specified location.
 void showXObject(PdfName name)
          Shows the specified external object [PDF:1.6:4.7].
 void showXObject(PdfName name, Point2D location)
          Shows the specified external object at the specified position [PDF:1.6:4.7].
 void showXObject(PdfName name, Point2D location, Dimension2D size)
          Shows the specified external object at the specified position [PDF:1.6:4.7].
 void showXObject(PdfName name, Point2D location, Dimension2D size, XAlignmentEnum xAlignment, YAlignmentEnum yAlignment, double rotation)
          Shows the specified external object at the specified position [PDF:1.6:4.7].
 void showXObject(XObject value)
          Shows the specified external object [PDF:1.6:4.7].
 void showXObject(XObject value, Point2D location)
          Shows the specified external object at the specified position [PDF:1.6:4.7].
 void showXObject(XObject value, Point2D location, Dimension2D size)
          Shows the specified external object at the specified position [PDF:1.6:4.7].
 void showXObject(XObject value, Point2D location, Dimension2D size, XAlignmentEnum xAlignment, YAlignmentEnum yAlignment, double rotation)
          Shows the specified external object at the specified position [PDF:1.6:4.7].
 void startPath(Point2D startPoint)
          Begins a subpath [PDF:1.6:4.4.1].
 void stroke()
          Strokes the path using the current color [PDF:1.6:4.4.2].
 void translate(double distanceX, double distanceY)
          Applies a translation to the coordinate system from user space to device space [PDF:1.6:4.2.2].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrimitiveComposer

public PrimitiveComposer(ContentScanner scanner)

PrimitiveComposer

public PrimitiveComposer(IContentContext context)
Method Detail

add

public ContentObject add(ContentObject object)
Adds a content object.

Returns:
The added content object.

applyMatrix

public void applyMatrix(double a,
                        double b,
                        double c,
                        double d,
                        double e,
                        double f)
Applies a transformation to the coordinate system from user space to device space [PDF:1.6:4.3.3].

The transformation is applied to the current transformation matrix (CTM) by concatenation, i.e. it doesn't replace it.

Parameters:
a - Item 0,0 of the matrix.
b - Item 0,1 of the matrix.
c - Item 1,0 of the matrix.
d - Item 1,1 of the matrix.
e - Item 2,0 of the matrix.
f - Item 2,1 of the matrix.
See Also:
setMatrix(double,double,double,double,double,double)

applyState

public void applyState(PdfName name)
Applies the specified state parameters [PDF:1.6:4.3.4].

Parameters:
name - Resource identifier of the state parameters object.

applyState

public void applyState(ExtGState state)
Applies the specified state parameters [PDF:1.6:4.3.4].

The value is checked for presence in the current resource dictionary: if it isn't available, it's automatically added. If you need to avoid such a behavior, use #applyState(PdfName).

Parameters:
state - State parameters object.

begin

public CompositeObject begin(CompositeObject object)
Adds a composite object beginning it.

Returns:
Added composite object.
See Also:
end()

beginLayer

public MarkedContent beginLayer(LayerEntity layer)
Begins a new layered-content sequence [PDF:1.6:4.10.2].

Parameters:
layer - Layer entity enclosing the layered content.
Returns:
Added layered-content sequence.
See Also:
end()

beginLayer

public MarkedContent beginLayer(PdfName layerName)
Begins a new layered-content sequence [PDF:1.6:4.10.2].

Parameters:
layerName - Resource identifier of the LayerEntity enclosing the layered content.
Returns:
Added layered-content sequence.
See Also:
end()

beginLocalState

public LocalGraphicsState beginLocalState()
Begins a new nested graphics state context [PDF:1.6:4.3.1].

Returns:
Added local graphics state object.
See Also:
end()

beginMarkedContent

public MarkedContent beginMarkedContent(PdfName tag)
Begins a new marked-content sequence [PDF:1.6:10.5].

Parameters:
tag - Marker indicating the role or significance of the marked content.
Returns:
Added marked-content sequence.
See Also:
end()

beginMarkedContent

public MarkedContent beginMarkedContent(PdfName tag,
                                        PropertyList propertyList)
Begins a new marked-content sequence [PDF:1.6:10.5].

Parameters:
tag - Marker indicating the role or significance of the marked content.
propertyList - PropertyList describing the marked content.
Returns:
Added marked-content sequence.
See Also:
end()

beginMarkedContent

public MarkedContent beginMarkedContent(PdfName tag,
                                        PdfName propertyListName)
Begins a new marked-content sequence [PDF:1.6:10.5].

Parameters:
tag - Marker indicating the role or significance of the marked content.
propertyListName - Resource identifier of the PropertyList describing the marked content.
Returns:
Added marked-content sequence.
See Also:
end()

clip

public void clip()
Modifies the current clipping path by intersecting it with the current path [PDF:1.6:4.4.1].

It can be validly called only just before painting the current path.


closePath

public void closePath()
Closes the current subpath by appending a straight line segment from the current point to the starting point of the subpath [PDF:1.6:4.4.1].


drawArc

public void drawArc(RectangularShape location,
                    double startAngle,
                    double endAngle)
Draws a circular arc.

Parameters:
location - Arc location.
startAngle - Starting angle.
endAngle - Ending angle.
See Also:
stroke()

drawArc

public void drawArc(RectangularShape location,
                    double startAngle,
                    double endAngle,
                    double branchWidth,
                    double branchRatio)
Draws an arc.

Parameters:
location - Arc location.
startAngle - Starting angle.
endAngle - Ending angle.
branchWidth - Distance between the spiral branches. '0' value degrades to a circular arc.
branchRatio - Linear coefficient applied to the branch width. '1' value degrades to a constant branch width.
See Also:
stroke()

drawCurve

public void drawCurve(Point2D endPoint,
                      Point2D startControl,
                      Point2D endControl)
Draws a cubic Bezier curve from the current point [PDF:1.6:4.4.1].

Parameters:
endPoint - Ending point.
startControl - Starting control point.
endControl - Ending control point.
See Also:
stroke()

drawCurve

public void drawCurve(Point2D startPoint,
                      Point2D endPoint,
                      Point2D startControl,
                      Point2D endControl)
Draws a cubic Bezier curve [PDF:1.6:4.4.1].

Parameters:
startPoint - Starting point.
endPoint - Ending point.
startControl - Starting control point.
endControl - Ending control point.
See Also:
stroke()

drawEllipse

public void drawEllipse(RectangularShape location)
Draws an ellipse.

Parameters:
location - Ellipse location.
See Also:
fill(), fillStroke(), stroke()

drawLine

public void drawLine(Point2D endPoint)
Draws a line from the current point [PDF:1.6:4.4.1].

Parameters:
endPoint - Ending point.
See Also:
stroke()

drawLine

public void drawLine(Point2D startPoint,
                     Point2D endPoint)
Draws a line [PDF:1.6:4.4.1].

Parameters:
startPoint - Starting point.
endPoint - Ending point.
See Also:
stroke()

drawPolygon

public void drawPolygon(Point2D[] points)
Draws a polygon.

A polygon is the same as a multiple line except that it's a closed path.

Parameters:
points - Points.
See Also:
fill(), fillStroke(), stroke()

drawPolyline

public void drawPolyline(Point2D[] points)
Draws a multiple line.

Parameters:
points - Points.
See Also:
stroke()

drawRectangle

public void drawRectangle(RectangularShape location)
Draws a rectangle [PDF:1.6:4.4.1].

Parameters:
location - Rectangle location.
See Also:
fill(), fillStroke(), stroke()

drawRectangle

public void drawRectangle(RectangularShape location,
                          double radius)
Draws a rounded rectangle.

Parameters:
location - Rectangle location.
radius - Vertex radius, '0' value degrades to squared vertices.
See Also:
fill(), fillStroke(), stroke()

drawSpiral

public void drawSpiral(Point2D center,
                       double startAngle,
                       double endAngle,
                       double branchWidth,
                       double branchRatio)
Draws a spiral.

Parameters:
center - Spiral center.
startAngle - Starting angle.
endAngle - Ending angle.
branchWidth - Distance between the spiral branches.
branchRatio - Linear coefficient applied to the branch width.
See Also:
stroke()

end

public void end()
Ends the current (innermostly-nested) composite object.

See Also:
begin(CompositeObject)

fill

public void fill()
Fills the path using the current color [PDF:1.6:4.4.2].

See Also:
setFillColor(Color)

fillStroke

public void fillStroke()
Fills and then strokes the path using the current colors [PDF:1.6:4.4.2].

See Also:
setFillColor(Color), setStrokeColor(Color)

flush

public void flush()
Serializes the contents into the content stream.


getScanner

public ContentScanner getScanner()
Gets the content stream scanner.


getState

public ContentScanner.GraphicsState getState()
Gets the current graphics state [PDF:1.6:4.3].


rotate

public void rotate(double angle)
Applies a rotation to the coordinate system from user space to device space [PDF:1.6:4.2.2].

Parameters:
angle - Rotational counterclockwise angle.
See Also:
applyMatrix(double,double,double,double,double,double)

rotate

public void rotate(double angle,
                   Point2D origin)
Applies a rotation to the coordinate system from user space to device space [PDF:1.6:4.2.2].

Parameters:
angle - Rotational counterclockwise angle.
origin - Rotational pivot point; it becomes the new coordinates origin.
See Also:
applyMatrix(double,double,double,double,double,double)

scale

public void scale(double ratioX,
                  double ratioY)
Applies a scaling to the coordinate system from user space to device space [PDF:1.6:4.2.2].

Parameters:
ratioX - Horizontal scaling ratio.
ratioY - Vertical scaling ratio.
See Also:
applyMatrix(double,double,double,double,double,double)

setCharSpace

public void setCharSpace(double value)
Sets the character spacing parameter [PDF:1.6:5.2.1].


setFillColor

public void setFillColor(Color<?> value)
Sets the nonstroking color value [PDF:1.6:4.5.7].

See Also:
setStrokeColor(Color)

setFont

public void setFont(PdfName name,
                    double size)
Sets the font [PDF:1.6:5.2].

Parameters:
name - Resource identifier of the font.
size - Scaling factor (points).

setFont

public void setFont(Font value,
                    double size)
Sets the font [PDF:1.6:5.2].

The value is checked for presence in the current resource dictionary: if it isn't available, it's automatically added. If you need to avoid such a behavior, use setFont(PdfName,double).

Parameters:
value - Font.
size - Scaling factor (points).

setTextScale

public void setTextScale(double value)
Sets the text horizontal scaling [PDF:1.6:5.2.3].


setTextLead

public void setTextLead(double value)
Sets the text leading [PDF:1.6:5.2.4].


setLineCap

public void setLineCap(LineCapEnum value)
Sets the line cap style [PDF:1.6:4.3.2].


setLineDash

public void setLineDash(LineDash value)
Sets the line dash pattern [PDF:1.6:4.3.2].


setLineJoin

public void setLineJoin(LineJoinEnum value)
Sets the line join style [PDF:1.6:4.3.2].


setLineWidth

public void setLineWidth(double value)
Sets the line width [PDF:1.6:4.3.2].


setMatrix

public void setMatrix(double a,
                      double b,
                      double c,
                      double d,
                      double e,
                      double f)
Sets the transformation of the coordinate system from user space to device space [PDF:1.6:4.3.3].

The transformation replaces the current transformation matrix (CTM).

Parameters:
a - Item 0,0 of the matrix.
b - Item 0,1 of the matrix.
c - Item 1,0 of the matrix.
d - Item 1,1 of the matrix.
e - Item 2,0 of the matrix.
f - Item 2,1 of the matrix.
See Also:
applyMatrix(double,double,double,double,double,double)

setMiterLimit

public void setMiterLimit(double value)
Sets the miter limit [PDF:1.6:4.3.2].


setScanner

public void setScanner(ContentScanner value)
See Also:
getScanner()

setStrokeColor

public void setStrokeColor(Color<?> value)
Sets the stroking color value [PDF:1.6:4.5.7].

See Also:
setFillColor(Color)

setTextRenderMode

public void setTextRenderMode(TextRenderModeEnum value)
Sets the text rendering mode [PDF:1.6:5.2.5].


setTextRise

public void setTextRise(double value)
Sets the text rise [PDF:1.6:5.2.6].


setWordSpace

public void setWordSpace(double value)
Sets the word spacing [PDF:1.6:5.2.2].


showText

public Quad showText(String value)
Shows the specified text on the page at the current location [PDF:1.6:5.3.2].

Parameters:
value - Text to show.
Returns:
Bounding box vertices in default user space units.

showText

public Link showText(String value,
                     Action action)
Shows the link associated to the specified text on the page at the current location.

Parameters:
value - Text to show.
action - Action to apply when the link is activated.
Returns:
Link.

showText

public Quad showText(String value,
                     Point2D location)
Shows the specified text on the page at the specified location [PDF:1.6:5.3.2].

Parameters:
value - Text to show.
location - Position at which showing the text.
Returns:
Bounding box vertices in default user space units.

showText

public Link showText(String value,
                     Point2D location,
                     Action action)
Shows the link associated to the specified text on the page at the specified location.

Parameters:
value - Text to show.
location - Position at which showing the text.
action - Action to apply when the link is activated.
Returns:
Link.

showText

public Quad showText(String value,
                     Point2D location,
                     XAlignmentEnum xAlignment,
                     YAlignmentEnum yAlignment,
                     double rotation)
Shows the specified text on the page at the specified location [PDF:1.6:5.3.2].

Parameters:
value - Text to show.
location - Anchor position at which showing the text.
xAlignment - Horizontal alignment.
yAlignment - Vertical alignment.
rotation - Rotational counterclockwise angle.
Returns:
Bounding box vertices in default user space units.

showText

public Link showText(String value,
                     Point2D location,
                     XAlignmentEnum xAlignment,
                     YAlignmentEnum yAlignment,
                     double rotation,
                     Action action)
Shows the link associated to the specified text on the page at the specified location.

Parameters:
value - Text to show.
location - Anchor position at which showing the text.
xAlignment - Horizontal alignment.
yAlignment - Vertical alignment.
rotation - Rotational counterclockwise angle.
action - Action to apply when the link is activated.
Returns:
Link.

showXObject

public void showXObject(PdfName name)
Shows the specified external object [PDF:1.6:4.7].

Parameters:
name - Resource identifier of the external object.

showXObject

public void showXObject(XObject value)
Shows the specified external object [PDF:1.6:4.7].

The value is checked for presence in the current resource dictionary: if it isn't available, it's automatically added. If you need to avoid such a behavior, use #showXObject(PdfName).

Parameters:
value - External object.

showXObject

public void showXObject(PdfName name,
                        Point2D location)
Shows the specified external object at the specified position [PDF:1.6:4.7].

Parameters:
name - Resource identifier of the external object.
location - Position at which showing the external object.

showXObject

public void showXObject(XObject value,
                        Point2D location)
Shows the specified external object at the specified position [PDF:1.6:4.7].

The value is checked for presence in the current resource dictionary: if it isn't available, it's automatically added. If you need to avoid such a behavior, use #showXObject(PdfName,Point2D).

Parameters:
value - External object.
location - Position at which showing the external object.

showXObject

public void showXObject(PdfName name,
                        Point2D location,
                        Dimension2D size)
Shows the specified external object at the specified position [PDF:1.6:4.7].

Parameters:
name - Resource identifier of the external object.
location - Position at which showing the external object.
size - Size of the external object.

showXObject

public void showXObject(XObject value,
                        Point2D location,
                        Dimension2D size)
Shows the specified external object at the specified position [PDF:1.6:4.7].

The value is checked for presence in the current resource dictionary: if it isn't available, it's automatically added. If you need to avoid such a behavior, use showXObject(PdfName,Point2D,Dimension2D).

Parameters:
value - External object.
location - Position at which showing the external object.
size - Size of the external object.

showXObject

public void showXObject(PdfName name,
                        Point2D location,
                        Dimension2D size,
                        XAlignmentEnum xAlignment,
                        YAlignmentEnum yAlignment,
                        double rotation)
Shows the specified external object at the specified position [PDF:1.6:4.7].

Parameters:
name - Resource identifier of the external object.
location - Position at which showing the external object.
size - Size of the external object.
xAlignment - Horizontal alignment.
yAlignment - Vertical alignment.
rotation - Rotational counterclockwise angle.

showXObject

public void showXObject(XObject value,
                        Point2D location,
                        Dimension2D size,
                        XAlignmentEnum xAlignment,
                        YAlignmentEnum yAlignment,
                        double rotation)
Shows the specified external object at the specified position [PDF:1.6:4.7].

The value is checked for presence in the current resource dictionary: if it isn't available, it's automatically added. If you need to avoid such a behavior, use showXObject(PdfName,...).

Parameters:
value - External object.
location - Position at which showing the external object.
size - Size of the external object.
xAlignment - Horizontal alignment.
yAlignment - Vertical alignment.
rotation - Rotational counterclockwise angle.

startPath

public void startPath(Point2D startPoint)
Begins a subpath [PDF:1.6:4.4.1].

Parameters:
startPoint - Starting point.

stroke

public void stroke()
Strokes the path using the current color [PDF:1.6:4.4.2].

See Also:
setStrokeColor(Color)

translate

public void translate(double distanceX,
                      double distanceY)
Applies a translation to the coordinate system from user space to device space [PDF:1.6:4.2.2].

Parameters:
distanceX - Horizontal distance.
distanceY - Vertical distance.
See Also:
applyMatrix(double,double,double,double,double,double)

PDF Clown
0.1.2

Project home page

Copyright © 2006-2013 Stefano Chizzolini. Some Rights Reserved.
This documentation is available under the terms of the GNU Free Documentation License.