Package org.apache.fop.render.pdf
Class PDFContentGenerator
java.lang.Object
org.apache.fop.render.pdf.PDFContentGenerator
Generator class encapsulating all object references and state necessary to generate a
PDF content stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PDFPaintingStatedrawing stateprotected PDFTextUtilText generation utility holding the current font statusprotected static final booleanControls whether comments are written to the PDF stream. -
Constructor Summary
ConstructorsConstructorDescriptionPDFContentGenerator(PDFDocument document, OutputStream out, PDFResourceContext resourceContext) Main constructor.PDFContentGenerator(PDFDocument document, OutputStream out, PDFResourceContext resourceContext, IFContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds content to the stream.protected voidbeginMarkedContentSequence(String structElemType, int mcid) Begins a new marked content sequence (BDC or BMC).protected voidbeginMarkedContentSequence(String structElemType, int mcid, String actualText) Begins a new marked content sequence (BDC or BMC).protected voidIndicates the beginning of a text object.protected voidbeginTextObject(String structElemType, int mcid) Indicates the beginning of a marked-content text object.protected voidbeginTextObject(String structElemType, int mcid, String actualText) Indicates the beginning of a marked-content text object.voidIntersects the current clip region with the given rectangle.protected voidWrites out a comment.voidconcatenate(AffineTransform transform) Concatenates the given transformation matrix with the current one.protected voidIndicates the end of a text object.voidFlushes all queued PDF objects ready to be written to the output stream.static final Stringformat(float value) Formats a float value (normally coordinates in points) as Strings.Returns the applicable resource context for the generator.Returns the output stream the PDF document is written to.Returns the applicable resource context for the generator.getState()Returns thePDFPaintingStateassociated with this instance.Returns thePDFStreamassociated with this instance.Returns thePDFTextUtilassociated with this instance.voidplaceImage(float x, float y, float w, float h, PDFXObject xobj) Places a previously registered image at a certain place on the page.voidplaceImage(float x, float y, float w, float h, PDFXObject xobj, String structElemType, int mcid) Places a previously registered image at a certain place on the page, bracketing it as a marked-content sequence.voidplaceImage(AffineTransform at, String stream) voidResets the current character spacing (Tc) value to zero.protected voidSame asrestoreGraphicsState(boolean), withtrueas a parameter.protected voidrestoreGraphicsState(boolean popState) Restored the graphics state valid before the previoussaveGraphicsState().protected voidSame asrestoreGraphicsState(), additionally ending the current marked content sequence if any.protected voidSave graphics state.protected voidsaveGraphicsState(String layer) Save graphics state with optional layer.protected voidsaveGraphicsState(String structElemType, int sequenceNum) Save graphics state.voidEstablishes a new foreground or fill color.protected voidsetColor(Color col, boolean fill, StringBuffer pdf) Establishes a new foreground or fill color.voidEstablishes a new foreground or fill color.voidupdateCharacterSpacing(float value) Sets the current character spacing (Tc) value.voidupdateColor(Color col, boolean fill, StringBuffer pdf) Establishes a new foreground or fill color.voidupdateLineWidth(float width) Sets the current line width in points.
-
Field Details
-
WRITE_COMMENTS
protected static final boolean WRITE_COMMENTSControls whether comments are written to the PDF stream.- See Also:
-
currentState
drawing state -
textutil
Text generation utility holding the current font status
-
-
Constructor Details
-
PDFContentGenerator
public PDFContentGenerator(PDFDocument document, OutputStream out, PDFResourceContext resourceContext) Main constructor. Creates a new PDF stream and additional helper classes for text painting and state management.- Parameters:
document- the PDF documentout- the output stream the PDF document is generated toresourceContext- the resource context
-
PDFContentGenerator
public PDFContentGenerator(PDFDocument document, OutputStream out, PDFResourceContext resourceContext, IFContext context)
-
-
Method Details
-
getAffineTransform
-
getDocument
Returns the applicable resource context for the generator.- Returns:
- the resource context
-
getOutputStream
Returns the output stream the PDF document is written to.- Returns:
- the output stream
-
getResourceContext
Returns the applicable resource context for the generator.- Returns:
- the resource context
-
getStream
Returns thePDFStreamassociated with this instance.- Returns:
- the PDF stream
-
getState
Returns thePDFPaintingStateassociated with this instance.- Returns:
- the PDF state
-
getTextUtil
Returns thePDFTextUtilassociated with this instance.- Returns:
- the text utility
-
flushPDFDoc
Flushes all queued PDF objects ready to be written to the output stream.- Throws:
IOException- if an error occurs while flushing the PDF objects
-
comment
Writes out a comment.- Parameters:
text- text for the comment
-
saveGraphicsState
protected void saveGraphicsState()Save graphics state. -
saveGraphicsState
Save graphics state with optional layer. -
saveGraphicsState
Save graphics state.- Parameters:
structElemType- an element typesequenceNum- a sequence number
-
beginMarkedContentSequence
Begins a new marked content sequence (BDC or BMC). IfstructElemTypeis null, a BMC operator with an "Artifact" tag is generated. Otherwise, a BDC operator withstructElemTypeas a tag is generated, and the given mcid stored in its property list.- Parameters:
structElemType- the type of the associated structure elementmcid- the marked content identifier
-
beginMarkedContentSequence
Begins a new marked content sequence (BDC or BMC). IfstructElemTypeis null, a BMC operator with an "Artifact" tag is generated. Otherwise, a BDC operator withstructElemTypeas a tag is generated, and the given mcid and actual text are stored in its property list.- Parameters:
structElemType- the type of the associated structure elementmcid- the marked content identifieractualText- the replacement text for the marked content
-
restoreGraphicsState
protected void restoreGraphicsState(boolean popState) Restored the graphics state valid before the previoussaveGraphicsState().- Parameters:
popState- true if the state should also be popped, false if only the PDF command should be issued
-
restoreGraphicsState
protected void restoreGraphicsState()Same asrestoreGraphicsState(boolean), withtrueas a parameter. -
restoreGraphicsStateAccess
protected void restoreGraphicsStateAccess()Same asrestoreGraphicsState(), additionally ending the current marked content sequence if any. -
beginTextObject
protected void beginTextObject()Indicates the beginning of a text object. -
beginTextObject
Indicates the beginning of a marked-content text object.- Parameters:
structElemType- structure element typemcid- sequence number- See Also:
-
beginTextObject
Indicates the beginning of a marked-content text object.- Parameters:
structElemType- structure element typemcid- sequence numberactualText- the replacement text for the marked content- See Also:
-
endTextObject
protected void endTextObject()Indicates the end of a text object. -
concatenate
Concatenates the given transformation matrix with the current one.- Parameters:
transform- the transformation matrix (in points)
-
clipRect
Intersects the current clip region with the given rectangle.- Parameters:
rect- the clip rectangle
-
add
Adds content to the stream.- Parameters:
content- the PDF content
-
format
Formats a float value (normally coordinates in points) as Strings.- Parameters:
value- the value- Returns:
- the formatted value
-
updateLineWidth
public void updateLineWidth(float width) Sets the current line width in points.- Parameters:
width- line width in points
-
updateCharacterSpacing
public void updateCharacterSpacing(float value) Sets the current character spacing (Tc) value.- Parameters:
value- the Tc value (in unscaled text units)
-
resetCharacterSpacing
public void resetCharacterSpacing()Resets the current character spacing (Tc) value to zero. -
setColor
Establishes a new foreground or fill color.- Parameters:
col- the color to applyfill- true to set the fill color, false for the foreground colorstream- the PDFStream to write the PDF code to
-
setColor
Establishes a new foreground or fill color.- Parameters:
col- the color to applyfill- true to set the fill color, false for the foreground color
-
setColor
Establishes a new foreground or fill color. In contrast to updateColor this method does not check the PDFState for optimization possibilities.- Parameters:
col- the color to applyfill- true to set the fill color, false for the foreground colorpdf- StringBuffer to write the PDF code to, if null, the code is written to the current stream.
-
updateColor
Establishes a new foreground or fill color.- Parameters:
col- the color to apply (null skips this operation)fill- true to set the fill color, false for the foreground colorpdf- StringBuffer to write the PDF code to, if null, the code is written to the current stream.
-
placeImage
Places a previously registered image at a certain place on the page.- Parameters:
x- X coordinatey- Y coordinatew- width for imageh- height for imagexobj- the image XObject
-
placeImage
-
placeImage
public void placeImage(float x, float y, float w, float h, PDFXObject xobj, String structElemType, int mcid) Places a previously registered image at a certain place on the page, bracketing it as a marked-content sequence.- Parameters:
x- X coordinatey- Y coordinatew- width for imageh- height for imagexobj- the image XObjectstructElemType- structure element typemcid- sequence number- See Also:
-