Package org.apache.fop.svg
Class PDFDocumentGraphics2D
- java.lang.Object
-
- java.awt.Graphics
-
- java.awt.Graphics2D
-
- org.apache.xmlgraphics.java2d.AbstractGraphics2D
-
- org.apache.fop.svg.PDFGraphics2D
-
- org.apache.fop.svg.PDFDocumentGraphics2D
-
- All Implemented Interfaces:
java.lang.Cloneable
,NativeImageHandler
public class PDFDocumentGraphics2D extends PDFGraphics2D
This class is a wrapper for thePDFGraphics2D
that is used to create a full document around the PDF rendering fromPDFGraphics2D
.- See Also:
PDFGraphics2D
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.fop.svg.PDFGraphics2D
PDFGraphics2D.TransparencyIgnoredEventListener
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_NATIVE_DPI
Default device resolution (300dpi is a resonable quality for most purposes)protected java.awt.Shape
initialClip
Initial clipping area, used to restore to original setting when a new page is started.protected java.awt.geom.AffineTransform
initialTransform
Initial transformation matrix, used to restore to original setting when a new page is started.static int
NORMAL_PDF_RESOLUTION
Normal PDF resolution (72dpi)-
Fields inherited from class org.apache.fop.svg.PDFGraphics2D
baseLevel, colorHandler, currentFontName, currentFontSize, currentStream, fontInfo, nativeCount, outputStream, ovFontState, pageRef, paintingState, pdfDoc, resourceContext
-
-
Constructor Summary
Constructors Constructor Description PDFDocumentGraphics2D()
Create a new PDFDocumentGraphics2D.PDFDocumentGraphics2D(boolean textAsShapes)
Create a new PDFDocumentGraphics2D.PDFDocumentGraphics2D(boolean textAsShapes, java.io.OutputStream stream, int width, int height)
Create a new PDFDocumentGraphics2D.PDFDocumentGraphics2D(PDFDocumentGraphics2D g)
This constructor supports the create method
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closePage()
Closes the current page and adds it to the PDF file.java.awt.Graphics
create()
Creates a newGraphics
object that is a copy of thisGraphics
object.void
drawString(java.lang.String s, float x, float y)
Draw a string to the pdf document.void
finish()
The rendering process has finished.float
getDeviceDPI()
FontInfo
getFontInfo()
Get the font info for this pdf document.PDFContext
getPDFContext()
Return the PDFContext for this instance.PDFDocument
getPDFDocument()
Get the pdf document created by this class.void
nextPage()
Is called to prepare the PDFDocumentGraphics2D for the next page to be painted.void
nextPage(int width, int height)
Is called to prepare the PDFDocumentGraphics2D for the next page to be painted.protected void
preparePainting()
This method is used by PDFDocumentGraphics2D to prepare a new page if necessary.void
setBackgroundColor(java.awt.Color col)
Set the background of the pdf document.void
setDeviceDPI(float deviceDPI)
Set the device resolution for rendering.void
setFontInfo(FontInfo fontInfo)
Sets the font info for this PDF document.void
setSVGDimension(float w, float h)
Set the dimensions of the svg document that will be drawn.void
setupDefaultFontInfo()
Setup a default FontInfo instance if none has been setup before.void
setupDocument(java.io.OutputStream stream, int width, int height)
Setup the document.protected void
startPage()
Called to prepare a new page-
Methods inherited from class org.apache.fop.svg.PDFGraphics2D
addLink, addNativeImage, applyAlpha, applyColor, applyPaint, applyStroke, applyUnknownPaint, copyArea, dispose, doDrawing, draw, drawImage, drawImage, drawInnerRenderedImage, drawRenderableImage, drawRenderedImage, fill, getBaseTransform, getBuffer, getDeviceConfiguration, getFontMetrics, getInternalFontForAWTFont, getPageReference, getString, handleIOException, isMultiByteFont, isTransparencyAllowed, processPathIterator, registerFunction, registerPattern, registerShading, setGraphicContext, setOutputStream, setOverrideFontState, setPaintingState, setXORMode, updateCurrentFont, writeClip
-
Methods inherited from class org.apache.xmlgraphics.java2d.AbstractGraphics2D
addRenderingHints, clearRect, clip, clipRect, drawArc, drawGlyphVector, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, drawString, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, getBackground, getClip, getClipBounds, getColor, getComposite, getFont, getFontRenderContext, getGraphicContext, getPaint, getRenderingHint, getRenderingHints, getStroke, getTransform, hit, rotate, rotate, scale, setBackground, setClip, setClip, setColor, setComposite, setFont, setPaint, setPaintMode, setRenderingHint, setRenderingHints, setStroke, setTransform, shear, transform, translate, translate
-
-
-
-
Field Detail
-
NORMAL_PDF_RESOLUTION
public static final int NORMAL_PDF_RESOLUTION
Normal PDF resolution (72dpi)- See Also:
- Constant Field Values
-
DEFAULT_NATIVE_DPI
public static final int DEFAULT_NATIVE_DPI
Default device resolution (300dpi is a resonable quality for most purposes)- See Also:
- Constant Field Values
-
initialClip
protected java.awt.Shape initialClip
Initial clipping area, used to restore to original setting when a new page is started.
-
initialTransform
protected java.awt.geom.AffineTransform initialTransform
Initial transformation matrix, used to restore to original setting when a new page is started.
-
-
Constructor Detail
-
PDFDocumentGraphics2D
public PDFDocumentGraphics2D(boolean textAsShapes)
Create a new PDFDocumentGraphics2D. This is used to create a new pdf document, the height, width and output stream can be setup later. For use by the transcoder which needs font information for the bridge before the document size is known. The resulting document is written to the stream after rendering.- Parameters:
textAsShapes
- set this to true so that text will be rendered using curves and not the font.
-
PDFDocumentGraphics2D
public PDFDocumentGraphics2D(boolean textAsShapes, java.io.OutputStream stream, int width, int height) throws java.io.IOException
Create a new PDFDocumentGraphics2D. This is used to create a new pdf document of the given height and width. The resulting document is written to the stream after rendering.- Parameters:
textAsShapes
- set this to true so that text will be rendered using curves and not the font.stream
- the stream that the final document should be written to.width
- the width of the document (in points)height
- the height of the document (in points)- Throws:
java.io.IOException
- an io exception if there is a problem writing to the output stream
-
PDFDocumentGraphics2D
public PDFDocumentGraphics2D()
Create a new PDFDocumentGraphics2D. This is used to create a new pdf document. For use by the transcoder which needs font information for the bridge before the document size is known. The resulting document is written to the stream after rendering. This constructor is Avalon-style.
-
PDFDocumentGraphics2D
public PDFDocumentGraphics2D(PDFDocumentGraphics2D g)
This constructor supports the create method- Parameters:
g
- the pdf document graphics to make a copy of
-
-
Method Detail
-
setupDocument
public void setupDocument(java.io.OutputStream stream, int width, int height) throws java.io.IOException
Setup the document.- Parameters:
stream
- the output stream to write the documentwidth
- the width of the pageheight
- the height of the page- Throws:
java.io.IOException
- an io exception if there is a problem writing to the output stream
-
setupDefaultFontInfo
public void setupDefaultFontInfo()
Setup a default FontInfo instance if none has been setup before.
-
setDeviceDPI
public void setDeviceDPI(float deviceDPI)
Set the device resolution for rendering. Will take effect at the start of the next page.- Parameters:
deviceDPI
- the device resolution (in dpi)
-
getDeviceDPI
public float getDeviceDPI()
- Returns:
- the device resolution (in dpi) for rendering.
-
setFontInfo
public void setFontInfo(FontInfo fontInfo)
Sets the font info for this PDF document.- Parameters:
fontInfo
- the font info object with all the fonts
-
getFontInfo
public FontInfo getFontInfo()
Get the font info for this pdf document.- Returns:
- the font information
-
getPDFDocument
public PDFDocument getPDFDocument()
Get the pdf document created by this class.- Returns:
- the pdf document
-
getPDFContext
public PDFContext getPDFContext()
Return the PDFContext for this instance.- Returns:
- the PDFContext
-
setSVGDimension
public void setSVGDimension(float w, float h)
Set the dimensions of the svg document that will be drawn. This is useful if the dimensions of the svg document are different from the pdf document that is to be created. The result is scaled so that the svg fits correctly inside the pdf document.- Parameters:
w
- the width of the pageh
- the height of the page
-
setBackgroundColor
public void setBackgroundColor(java.awt.Color col)
Set the background of the pdf document. This is used to set the background for the pdf document Rather than leaving it as the default white.- Parameters:
col
- the background colour to fill
-
nextPage
public void nextPage()
Is called to prepare the PDFDocumentGraphics2D for the next page to be painted. Basically, this closes the current page. A new page is prepared as soon as painting starts.
-
nextPage
public void nextPage(int width, int height)
Is called to prepare the PDFDocumentGraphics2D for the next page to be painted. Basically, this closes the current page. A new page is prepared as soon as painting starts. This method allows to start the new page (and following pages) with a different page size.- Parameters:
width
- the width of the new page (in points)height
- the height of the new page (in points)
-
closePage
protected void closePage()
Closes the current page and adds it to the PDF file.
-
preparePainting
protected void preparePainting()
This method is used by PDFDocumentGraphics2D to prepare a new page if necessary.- Overrides:
preparePainting
in classPDFGraphics2D
-
startPage
protected void startPage() throws java.io.IOException
Called to prepare a new page- Throws:
java.io.IOException
- if starting the new page fails due to I/O errors.
-
finish
public void finish() throws java.io.IOException
The rendering process has finished. This should be called after the rendering has completed as there is no other indication it is complete. This will then write the results to the output stream.- Throws:
java.io.IOException
- an io exception if there is a problem writing to the output stream
-
create
public java.awt.Graphics create()
Creates a newGraphics
object that is a copy of thisGraphics
object.- Overrides:
create
in classPDFGraphics2D
- Returns:
- a new graphics context that is a copy of this graphics context.
-
drawString
public void drawString(java.lang.String s, float x, float y)
Draw a string to the pdf document. This either draws the string directly or if drawing text as shapes it converts the string into shapes and draws that.- Overrides:
drawString
in classPDFGraphics2D
- Parameters:
s
- the string to drawx
- the x positiony
- the y position- See Also:
AbstractGraphics2D.setPaint(java.awt.Paint)
,Graphics.setColor(java.awt.Color)
,Graphics.setFont(java.awt.Font)
,AbstractGraphics2D.setTransform(java.awt.geom.AffineTransform)
,AbstractGraphics2D.setComposite(java.awt.Composite)
,AbstractGraphics2D.setClip(int, int, int, int)
-
-