org.apache.fop.svg

Class PDFDocumentGraphics2D


public class PDFDocumentGraphics2D
extends PDFGraphics2D

This class is a wrapper for the PDFGraphics2D that is used to create a full document around the pdf rendering from PDFGraphics2D.
Version:
$Id: PDFDocumentGraphics2D.java 542237 2007-05-28 14:31:24Z jeremias $
Author:
Keiron Liddle
See Also:
PDFGraphics2D

Field Summary

static int
DEFAULT_NATIVE_DPI
Default device resolution (300dpi is a resonable quality for most purposes)
static int
NORMAL_PDF_RESOLUTION
Normal PDF resolution (72dpi)
protected Shape
initialClip
Initial clipping area, used to restore to original setting when a new page is started.
protected AffineTransform
initialTransform
Initial transformation matrix, used to restore to original setting when a new page is started.

Fields inherited from class org.apache.fop.svg.PDFGraphics2D

baseLevel, currentFontName, currentFontSize, currentStream, fontInfo, graphicsState, jpegCount, outputStream, ovFontState, pageRef, pdfDoc, resourceContext

Constructor Summary

PDFDocumentGraphics2D()
Create a new PDFDocumentGraphics2D.
PDFDocumentGraphics2D(boolean textAsShapes)
Create a new PDFDocumentGraphics2D.
PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream, int width, int height)
Create a new PDFDocumentGraphics2D.
PDFDocumentGraphics2D(PDFDocumentGraphics2D g)
This constructor supports the create method

Method Summary

protected void
closePage()
Closes the current page and adds it to the PDF file.
Graphics
create()
Creates a new Graphics object that is a copy of this Graphics object.
void
drawString(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.
protected void
preparePainting()
void
setBackgroundColor(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(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

addJpegImage, addLink, applyColor, applyPaint, applyStroke, applyUnknownPaint, checkTransparencyAllowed, copyArea, create, dispose, doDrawing, draw, drawImage, drawImage, drawRenderableImage, drawRenderedImage, drawString, drawString, fill, getBaseTransform, getBuffer, getDeviceConfiguration, getFontMetrics, getString, handleIOException, preparePainting, processPathIterator, setGraphicContext, setOutputStream, setOverrideFontState, setPDFState, setXORMode, writeClip

Field Details

DEFAULT_NATIVE_DPI

public static final int DEFAULT_NATIVE_DPI
Default device resolution (300dpi is a resonable quality for most purposes)
Field Value:
300

NORMAL_PDF_RESOLUTION

public static final int NORMAL_PDF_RESOLUTION
Normal PDF resolution (72dpi)
Field Value:
72

initialClip

protected Shape initialClip
Initial clipping area, used to restore to original setting when a new page is started.

initialTransform

protected AffineTransform initialTransform
Initial transformation matrix, used to restore to original setting when a new page is started.

Constructor Details

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(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,
                             OutputStream stream,
                             int width,
                             int height)
            throws 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
height - the height of the document

PDFDocumentGraphics2D

public PDFDocumentGraphics2D(PDFDocumentGraphics2D g)
This constructor supports the create method
Parameters:
g - the pdf document graphics to make a copy of

Method Details

closePage

protected void closePage()
Closes the current page and adds it to the PDF file.

create

public Graphics create()
Creates a new Graphics object that is a copy of this Graphics object.
Overrides:
create in interface PDFGraphics2D
Returns:
a new graphics context that is a copy of this graphics context.

drawString

public void drawString(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 interface PDFGraphics2D
Parameters:
s - the string to draw
x - the x position
y - the y position

finish

public void finish()
            throws 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.

getDeviceDPI

public float getDeviceDPI()
Returns:
the device resolution (in dpi) for rendering.

getFontInfo

public FontInfo getFontInfo()
Get the font info for this pdf document.
Returns:
the font information

getPDFContext

public PDFContext getPDFContext()
Return the PDFContext for this instance.
Returns:
the PDFContext

getPDFDocument

public PDFDocument getPDFDocument()
Get the pdf document created by this class.
Returns:
the pdf document

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.

preparePainting

protected void preparePainting()
Overrides:
preparePainting in interface PDFGraphics2D

setBackgroundColor

public void setBackgroundColor(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

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)

setFontInfo

public void setFontInfo(FontInfo fontInfo)
Sets the font info for this PDF document.
Parameters:
fontInfo - the font info object with all the fonts

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 page
h - the height of the page

setupDefaultFontInfo

public void setupDefaultFontInfo()
Setup a default FontInfo instance if none has been setup before.

setupDocument

public void setupDocument(OutputStream stream,
                          int width,
                          int height)
            throws IOException
Setup the document.
Parameters:
stream - the output stream to write the document
width - the width of the page
height - the height of the page

startPage

protected void startPage()
            throws IOException
Called to prepare a new page

Copyright 1999-2007 The Apache Software Foundation. All Rights Reserved.