|
fop 0.95 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.fop.render.AbstractRenderer
org.apache.fop.render.PrintRenderer
org.apache.fop.render.AbstractPathOrientedRenderer
org.apache.fop.render.afp.AFPRenderer
public class AFPRenderer
This is an implementation of a FOP Renderer that renders areas to AFP.
A renderer is primarily designed to convert a given area tree into the output document format. It should be able to produce pages and fill the pages with the text and graphical content. Usually the output is sent to an output stream. Some output formats may support extra information that is not available from the area tree or depends on the destination of the document. Each renderer is given an area tree to render to its output format. The area tree is simply a representation of the pages and the placement of text and graphical objects on those pages.
The renderer will be given each page as it is ready and an output stream to write the data out. All pages are supplied in the order they appear in the document. In order to save memory it is possible to render the pages out of order. Any page that is not ready to be rendered is setup by the renderer first so that it can reserve a space or reference for when the page is ready to be rendered.The renderer is responsible for managing the output format and associated data and flow.
Each renderer is totally responsible for its output format. Because font metrics (and therefore layout) are obtained in two different ways depending on the renderer, the renderer actually sets up the fonts being used. The font metrics are used during the layout process to determine the size of characters.
The render context is used by handlers. It contains information about the current state of the renderer, such as the page, the position, and any other miscellaneous objects that are required to draw into the page.
A renderer is created by implementing the Renderer interface. However, the AbstractRenderer does most of what is needed, including iterating through the tree parts, so it is this that is extended. This means that this object only need to implement the basic functionality such as text, images, and lines. AbstractRenderer's methods can easily be overridden to handle things in a different way or do some extra processing.
The relevant AreaTree structures that will need to be rendered are Page, Viewport, Region, Span, Block, Line, Inline. A renderer implementation renders each individual page, clips and aligns child areas to a viewport, handle all types of inline area, text, image etc and draws various lines and rectangles.
Note: There are specific extensions that have been added to the FO. They are specific to their location within the FO and have to be processed accordingly (ie. at the start or end of the page).
Field Summary |
---|
Fields inherited from class org.apache.fop.render.PrintRenderer |
---|
fontInfo, fontList, fontResolver |
Fields inherited from class org.apache.fop.render.AbstractRenderer |
---|
containingBPPosition, containingIPPosition, currentBPPosition, currentIPPosition, currentPageViewport, log, userAgent |
Fields inherited from interface org.apache.fop.render.Renderer |
---|
ROLE |
Constructor Summary | |
---|---|
AFPRenderer()
Constructor for AFPRenderer. |
Method Summary | |
---|---|
void |
beginTextObject()
Indicates the beginning of a text object. |
java.util.List |
breakOutOfStateStack()
Breaks out of the state stack to handle fixed block-containers. |
void |
clip()
Clip using the current path. |
void |
clipRect(float x,
float y,
float width,
float height)
Clip using a rectangular area. |
void |
closePath()
Closes the current subpath by appending a straight line segment from the current point to the starting point of the subpath. |
protected void |
concatenateTransformationMatrix(java.awt.geom.AffineTransform at)
Concatenates the current transformation matrix with the given one, therefore establishing a new coordinate system. |
protected static void |
convertToGrayScaleImage(ImageObject io,
byte[] raw,
int width,
int height,
int bitsPerPixel)
Converts a byte array containing 24 bit RGB image data to a grayscale image. |
protected RendererContext |
createRendererContext(int x,
int y,
int width,
int height,
java.util.Map foreignAttributes)
Creates a RendererContext for an image. |
void |
drawBorderLine(float x1,
float y1,
float x2,
float y2,
boolean horz,
boolean startOrBefore,
int style,
java.awt.Color col)
Draw a border segment of an XSL-FO style border. |
void |
drawBufferedImage(java.awt.image.RenderedImage image,
int imageResolution,
int x,
int y,
int w,
int h)
Draws a BufferedImage to AFP. |
void |
drawImage(java.lang.String uri,
java.awt.geom.Rectangle2D pos,
java.util.Map foreignAttributes)
Draw an image at the indicated location. |
void |
endTextObject()
Indicates the end of a text object. |
void |
endVParea()
Signals exit from a viewport area. |
void |
fillRect(float x,
float y,
float width,
float height)
Fill a rectangular area. |
Graphics2DAdapter |
getGraphics2DAdapter()
|
java.lang.String |
getMimeType()
Get the MIME type of the renderer. |
int |
getResolution()
Returns the output/device resolution. |
void |
lineTo(float x,
float y)
Appends a straight line segment from the current point to (x, y). |
void |
moveTo(float x,
float y)
Moves the current point to (x, y), omitting any connecting line segment. |
void |
preparePage(PageViewport page)
Prepare a page for rendering. |
void |
processOffDocumentItem(OffDocumentItem odi)
Tells the renderer to process an item not explicitly placed on the document (e.g., PDF bookmarks). |
protected void |
renderBlockViewport(BlockViewport bv,
java.util.List children)
Renders a block viewport. |
protected void |
renderFlow(NormalFlow flow)
Renders a flow reference area. |
void |
renderImage(Image image,
java.awt.geom.Rectangle2D pos)
Renders an image area. |
void |
renderLeader(Leader area)
Render leader area. |
void |
renderPage(PageViewport pageViewport)
Tells the renderer to render a particular page. |
protected void |
renderReferenceArea(Block block)
Renders a block area that represents a reference area. |
void |
renderRegionViewport(RegionViewport port)
Renders a region viewport. |
void |
renderSpace(SpaceArea space)
Render the given SpaceArea. |
void |
renderText(TextArea text)
Render the given TextArea. |
void |
renderWord(WordArea word)
Render the given WordArea. |
void |
restoreGraphicsState()
Restores the last graphics state of the rendering engine. |
void |
restoreStateStackAfterBreakOut(java.util.List breakOutList)
Restores the state stack after a break out. |
void |
saveGraphicsState()
Saves the graphics state of the rendering engine. |
void |
setBitsPerPixel(int bitsPerPixel)
Sets the number of bits used per pixel |
void |
setColorImages(boolean colorImages)
Sets whether images are color or not |
void |
setLandscapeRotation(int rotation)
Sets the rotation to be used for landsacpe pages, valid values are 0, 90, 180, 270 (default). |
void |
setPortraitRotation(int rotation)
Sets the rotation to be used for portrait pages, valid values are 0 (default), 90, 180, 270. |
void |
setResolution(int resolution)
Sets the output/device resolution |
void |
setupFontInfo(FontInfo inFontInfo)
Set up the font info |
void |
setUserAgent(FOUserAgent agent)
Set the User Agent. |
void |
startRenderer(java.io.OutputStream outputStream)
Initiates the rendering phase. |
void |
startVParea(CTM ctm,
java.awt.geom.Rectangle2D clippingRect)
Establishes a new viewport area. |
void |
stopRenderer()
Signals the end of the rendering phase. |
boolean |
supportsOutOfOrder()
Check if this renderer supports out of order rendering. |
void |
updateColor(java.awt.Color col,
boolean fill)
Establishes a new foreground or fill color. |
static void |
writeImage(java.awt.image.RenderedImage image,
java.io.OutputStream out)
Writes a RenderedImage to an OutputStream as raw sRGB bitmaps. |
Methods inherited from class org.apache.fop.render.AbstractPathOrientedRenderer |
---|
drawBackAndBorders, drawBorders, drawImage, handleBlockTraits, handleRegionTraits, renderForeignObject, renderInlineAreaBackAndBorders, renderTextDecoration, renderViewport |
Methods inherited from class org.apache.fop.render.PrintRenderer |
---|
addFontList, getFontFromArea, getFontResolver, getInternalFontNameForArea, lightenColor, renderDocument, setFontList |
Methods inherited from class org.apache.fop.render.AbstractRenderer |
---|
convertTitleToString, getCurrentPageViewport, getImageAdapter, getUserAgent, mptToPt, ptToMpt, renderBeforeFloat, renderBlock, renderBlocks, renderBodyRegion, renderCharacter, renderContainer, renderFootnote, renderInlineArea, renderInlineBlockParent, renderInlineParent, renderInlineSpace, renderLineArea, renderMainReference, renderPageAreas, renderRegion, renderXML, startPageSequence, startPageSequence |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AFPRenderer()
Method Detail |
---|
public void setupFontInfo(FontInfo inFontInfo)
setupFontInfo
in interface Renderer
setupFontInfo
in class PrintRenderer
inFontInfo
- font info to set uppublic void setUserAgent(FOUserAgent agent)
setUserAgent
in interface Renderer
setUserAgent
in class AbstractRenderer
agent
- The User Agentpublic void startRenderer(java.io.OutputStream outputStream) throws java.io.IOException
startRenderer
in interface Renderer
startRenderer
in class AbstractRenderer
outputStream
- The OutputStream to use for output
java.io.IOException
- If an I/O error occurspublic void stopRenderer() throws java.io.IOException
stopRenderer
in interface Renderer
stopRenderer
in class AbstractRenderer
java.io.IOException
- If an I/O error occurspublic boolean supportsOutOfOrder()
supportsOutOfOrder
in interface Renderer
supportsOutOfOrder
in class AbstractRenderer
public void preparePage(PageViewport page)
Renderer.renderPage(PageViewport)
.
preparePage
in interface Renderer
preparePage
in class AbstractRenderer
page
- The page viewport to usepublic void processOffDocumentItem(OffDocumentItem odi)
processOffDocumentItem
in interface Renderer
processOffDocumentItem
in class AbstractRenderer
odi
- The off-document item to be renderedpublic Graphics2DAdapter getGraphics2DAdapter()
getGraphics2DAdapter
in interface Renderer
getGraphics2DAdapter
in class AbstractRenderer
public void startVParea(CTM ctm, java.awt.geom.Rectangle2D clippingRect)
startVParea
in class AbstractRenderer
ctm
- the coordinate transformation matrix to useclippingRect
- the clipping rectangle if the viewport should be clipping,
null if no clipping is performed.public void endVParea()
endVParea
in class AbstractRenderer
public void renderRegionViewport(RegionViewport port)
The region may clip the area and it establishes a position from where the region is placed.
renderRegionViewport
in class AbstractRenderer
port
- The region viewport to be renderedprotected void renderBlockViewport(BlockViewport bv, java.util.List children)
renderBlockViewport
in class AbstractPathOrientedRenderer
bv
- The block viewportchildren
- The children to render within the block viewportprotected void renderReferenceArea(Block block)
renderReferenceArea
in class AbstractPathOrientedRenderer
block
- the block areaprotected void renderFlow(NormalFlow flow)
renderFlow
in class AbstractPathOrientedRenderer
flow
- The flow reference areaprotected void concatenateTransformationMatrix(java.awt.geom.AffineTransform at)
concatenateTransformationMatrix
in class AbstractPathOrientedRenderer
at
- the transformation matrix to process (coordinates in points)public void renderPage(PageViewport pageViewport)
renderPage
in interface Renderer
renderPage
in class AbstractRenderer
pageViewport
- The page to be renderedpublic void clip()
clip
in class AbstractPathOrientedRenderer
public void clipRect(float x, float y, float width, float height)
clipRect
in class AbstractPathOrientedRenderer
x
- the x coordinate (in points)y
- the y coordinate (in points)width
- the width of the rectangle (in points)height
- the height of the rectangle (in points)public void moveTo(float x, float y)
moveTo
in class AbstractPathOrientedRenderer
x
- x coordinatey
- y coordinatepublic void lineTo(float x, float y)
lineTo
in class AbstractPathOrientedRenderer
x
- x coordinatey
- y coordinatepublic void closePath()
closePath
in class AbstractPathOrientedRenderer
public void fillRect(float x, float y, float width, float height)
fillRect
in class AbstractPathOrientedRenderer
x
- the x coordinatey
- the y coordinatewidth
- the width of the rectangleheight
- the height of the rectanglepublic void drawBorderLine(float x1, float y1, float x2, float y2, boolean horz, boolean startOrBefore, int style, java.awt.Color col)
drawBorderLine
in class AbstractPathOrientedRenderer
x1
- starting x coordinatey1
- starting y coordinatex2
- ending x coordinatey2
- ending y coordinatehorz
- true for horizontal border segments, false for vertical border segmentsstartOrBefore
- true for border segments on the start or before edge,
false for end or after.style
- the border style (one of Constants.EN_DASHED etc.)col
- the color for the border segmentprotected RendererContext createRendererContext(int x, int y, int width, int height, java.util.Map foreignAttributes)
createRendererContext
in class PrintRenderer
x
- the x coordinate (in millipoints)y
- the y coordinate (in millipoints)width
- the width of the image (in millipoints)height
- the height of the image (in millipoints)foreignAttributes
- a Map or foreign attributes, may be null
public void drawImage(java.lang.String uri, java.awt.geom.Rectangle2D pos, java.util.Map foreignAttributes)
drawImage
in class AbstractPathOrientedRenderer
uri
- the URI/URL of the imagepos
- the position of the imageforeignAttributes
- an optional Map with foreign attributes, may be nullpublic static void writeImage(java.awt.image.RenderedImage image, java.io.OutputStream out) throws java.io.IOException
image
- the RenderedImageout
- the OutputStream
java.io.IOException
- In case of an I/O error.public void drawBufferedImage(java.awt.image.RenderedImage image, int imageResolution, int x, int y, int w, int h)
image
- the RenderedImageimageResolution
- the resolution of the BufferedImagex
- the x coordinate (in mpt)y
- the y coordinate (in mpt)w
- the width of the viewport (in mpt)h
- the height of the viewport (in mpt)public void updateColor(java.awt.Color col, boolean fill)
updateColor
in class AbstractPathOrientedRenderer
col
- the color to apply (null skips this operation)fill
- true to set the fill color, false for the foreground colorpublic java.util.List breakOutOfStateStack()
breakOutOfStateStack
in class AbstractPathOrientedRenderer
public void restoreStateStackAfterBreakOut(java.util.List breakOutList)
restoreStateStackAfterBreakOut
in class AbstractPathOrientedRenderer
breakOutList
- the state stack to restore.public void saveGraphicsState()
saveGraphicsState
in class AbstractPathOrientedRenderer
public void restoreGraphicsState()
restoreGraphicsState
in class AbstractPathOrientedRenderer
public void beginTextObject()
beginTextObject
in class AbstractPathOrientedRenderer
public void endTextObject()
endTextObject
in class AbstractPathOrientedRenderer
public void renderImage(Image image, java.awt.geom.Rectangle2D pos)
renderImage
in class AbstractRenderer
image
- The imagepos
- The target position of the image
(todo) Make renderImage() protectedpublic void renderText(TextArea text)
renderText
in class AbstractRenderer
text
- the text to renderpublic void renderWord(WordArea word)
renderWord
in class AbstractRenderer
word
- the word to renderpublic void renderSpace(SpaceArea space)
renderSpace
in class AbstractRenderer
space
- the space to renderpublic void renderLeader(Leader area)
renderLeader
in class AbstractRenderer
area
- the leader area to renderpublic void setPortraitRotation(int rotation)
rotation
- The rotation in degrees.public void setLandscapeRotation(int rotation)
rotation
- The rotation in degrees.public java.lang.String getMimeType()
getMimeType
in interface Renderer
getMimeType
in class AbstractRenderer
protected static void convertToGrayScaleImage(ImageObject io, byte[] raw, int width, int height, int bitsPerPixel)
io
- the target image objectraw
- the buffer containing the RGB image datawidth
- the width of the image in pixelsheight
- the height of the image in pixelsbitsPerPixel
- the number of bits to use per pixelpublic void setBitsPerPixel(int bitsPerPixel)
bitsPerPixel
- number of bits per pixelpublic void setColorImages(boolean colorImages)
colorImages
- color image outputpublic void setResolution(int resolution)
resolution
- the output resolution (dpi)public int getResolution()
|
fop 0.95 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |