Class AbstractIFPainter<T extends IFDocumentHandler>
- java.lang.Object
-
- org.apache.fop.render.intermediate.AbstractIFPainter<T>
-
- All Implemented Interfaces:
IFPainter
- Direct Known Subclasses:
AFPPainter,Java2DPainter,PCLPainter,PDFPainter,PSPainter
public abstract class AbstractIFPainter<T extends IFDocumentHandler> extends java.lang.Object implements IFPainter
Abstract base class for IFPainter implementations.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringINSTREAM_OBJECT_URInon-URI that can be used in feedback messages that an image is an instream-objectprotected IFStatestateHolds the intermediate format state
-
Constructor Summary
Constructors Constructor Description AbstractIFPainter(T documentHandler)Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.MapcreateDefaultImageProcessingHints(org.apache.xmlgraphics.image.loader.ImageSessionContext sessionContext)Creates the default map of processing hints for the image loading framework.protected abstract RenderingContextcreateRenderingContext()Creates a new RenderingContext instance.voiddrawBorderRect(java.awt.Rectangle rect, BorderProps top, BorderProps bottom, BorderProps left, BorderProps right, java.awt.Color innerBackgroundColor)Draws a border rectangle.protected voiddrawImage(org.apache.xmlgraphics.image.loader.Image image, java.awt.Rectangle rect, RenderingContext context)Draws an image using a suitable image handler.protected voiddrawImage(org.apache.xmlgraphics.image.loader.Image image, java.awt.Rectangle rect, RenderingContext context, boolean convert, java.util.Map additionalHints)Draws an image using a suitable image handler.protected voiddrawImageUsingDocument(org.w3c.dom.Document doc, java.awt.Rectangle rect)Default drawing method for handling a foreign object in the form of a DOM document.protected voiddrawImageUsingImageHandler(org.apache.xmlgraphics.image.loader.ImageInfo info, java.awt.Rectangle rect)Loads a preloaded image and draws it using a suitable image handler.protected voiddrawImageUsingURI(java.lang.String uri, java.awt.Rectangle rect)Default drawing method for handling an image referenced by a URI.voiddrawLine(java.awt.Point start, java.awt.Point end, int width, java.awt.Color color, RuleStyle style)Draws a line.voiddrawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp, java.lang.String text, boolean nextIsSpace)IFContextgetContext()Returns the intermediate format context object.protected TgetDocumentHandler()protected FontInfogetFontInfo()protected java.lang.StringgetFontKey(FontTriplet triplet)protected org.apache.xmlgraphics.image.loader.ImageInfogetImageInfo(java.lang.String uri)Returns an ImageInfo instance for the given URI.protected java.awt.RectanglegetLineBoundingBox(java.awt.Point start, java.awt.Point end, int width)Calculates the bounding box for a line.protected FOUserAgentgetUserAgent()Returns the user agent.protected booleanhasOnlySolidBorders(BorderProps top, BorderProps bottom, BorderProps left, BorderProps right)Indicates whether the given border segments (if present) have only solid borders, i.e.booleanisBackgroundRequired(BorderProps bpsBefore, BorderProps bpsAfter, BorderProps bpsStart, BorderProps bpsEnd)TODO Painter-specific rounded borders logic required background drawing to be made optional.voidsetFont(java.lang.String family, java.lang.String style, java.lang.Integer weight, java.lang.String variant, java.lang.Integer size, java.awt.Color color)Updates the current font.voidstartGroup(java.awt.geom.AffineTransform[] transforms, java.lang.String layer)Starts a new group of graphical elements.voidstartViewport(java.awt.geom.AffineTransform[] transforms, java.awt.Dimension size, java.awt.Rectangle clipRect)Starts a new viewport, establishing a new coordinate system.static java.awt.geom.AffineTransformtoPoints(java.awt.geom.AffineTransform transform)Converts a transformation matrix from millipoints to points.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.fop.render.intermediate.IFPainter
clipBackground, clipRect, drawImage, drawImage, drawText, endGroup, endViewport, fillRect, startGroup, startViewport
-
-
-
-
Field Detail
-
INSTREAM_OBJECT_URI
protected static final java.lang.String INSTREAM_OBJECT_URI
non-URI that can be used in feedback messages that an image is an instream-object- See Also:
- Constant Field Values
-
state
protected IFState state
Holds the intermediate format state
-
-
Constructor Detail
-
AbstractIFPainter
public AbstractIFPainter(T documentHandler)
Default constructor.
-
-
Method Detail
-
getFontKey
protected java.lang.String getFontKey(FontTriplet triplet) throws IFException
- Throws:
IFException
-
getContext
public IFContext getContext()
Returns the intermediate format context object.- Returns:
- the context object
-
getFontInfo
protected FontInfo getFontInfo()
-
getDocumentHandler
protected T getDocumentHandler()
-
getUserAgent
protected FOUserAgent getUserAgent()
Returns the user agent.- Returns:
- the user agent
-
startViewport
public void startViewport(java.awt.geom.AffineTransform[] transforms, java.awt.Dimension size, java.awt.Rectangle clipRect) throws IFExceptionStarts a new viewport, establishing a new coordinate system. A viewport has a size and can optionally be clipped. Corresponds to SVG's svg element.- Specified by:
startViewportin interfaceIFPainter- Parameters:
transforms- a series of transformation matrices establishing the new coordinate systemsize- the size of the viewportclipRect- the clipping rectangle (may be null)- Throws:
IFException- if an error occurs while handling this element
-
startGroup
public void startGroup(java.awt.geom.AffineTransform[] transforms, java.lang.String layer) throws IFExceptionStarts a new group of graphical elements. Corresponds to SVG's g element.- Specified by:
startGroupin interfaceIFPainter- Parameters:
transforms- a series of transformation matrices establishing the new coordinate systemlayer- an optional layer label (or null if none)- Throws:
IFException- if an error occurs while handling this element
-
createRenderingContext
protected abstract RenderingContext createRenderingContext()
Creates a new RenderingContext instance.- Returns:
- the new rendering context.
-
drawImageUsingImageHandler
protected void drawImageUsingImageHandler(org.apache.xmlgraphics.image.loader.ImageInfo info, java.awt.Rectangle rect) throws org.apache.xmlgraphics.image.loader.ImageException, java.io.IOExceptionLoads a preloaded image and draws it using a suitable image handler.- Parameters:
info- the information object of the preloaded imagerect- the rectangle in which to paint the image- Throws:
org.apache.xmlgraphics.image.loader.ImageException- if there's an error while processing the imagejava.io.IOException- if there's an I/O error while loading the image
-
createDefaultImageProcessingHints
protected java.util.Map createDefaultImageProcessingHints(org.apache.xmlgraphics.image.loader.ImageSessionContext sessionContext)
Creates the default map of processing hints for the image loading framework.- Parameters:
sessionContext- the session context for access to resolution information- Returns:
- the default processing hints
-
drawImage
protected void drawImage(org.apache.xmlgraphics.image.loader.Image image, java.awt.Rectangle rect, RenderingContext context) throws java.io.IOException, org.apache.xmlgraphics.image.loader.ImageExceptionDraws an image using a suitable image handler.- Parameters:
image- the image to be painted (it needs to of a supported image flavor)rect- the rectangle in which to paint the imagecontext- a suitable rendering context- Throws:
java.io.IOException- in case of an I/O error while handling/writing the imageorg.apache.xmlgraphics.image.loader.ImageException- if an error occurs while converting the image to a suitable format
-
drawImage
protected void drawImage(org.apache.xmlgraphics.image.loader.Image image, java.awt.Rectangle rect, RenderingContext context, boolean convert, java.util.Map additionalHints) throws java.io.IOException, org.apache.xmlgraphics.image.loader.ImageExceptionDraws an image using a suitable image handler.- Parameters:
image- the image to be painted (it needs to of a supported image flavor)rect- the rectangle in which to paint the imagecontext- a suitable rendering contextconvert- true to run the image through image conversion if that is necessaryadditionalHints- additional image processing hints- Throws:
java.io.IOException- in case of an I/O error while handling/writing the imageorg.apache.xmlgraphics.image.loader.ImageException- if an error occurs while converting the image to a suitable format
-
getImageInfo
protected org.apache.xmlgraphics.image.loader.ImageInfo getImageInfo(java.lang.String uri)
Returns an ImageInfo instance for the given URI. If there's an error, null is returned. The caller can assume that any exceptions have already been handled properly. The caller simply skips painting anything in this case.- Parameters:
uri- the URI identifying the image- Returns:
- the ImageInfo instance or null if there has been an error.
-
drawImageUsingURI
protected void drawImageUsingURI(java.lang.String uri, java.awt.Rectangle rect)Default drawing method for handling an image referenced by a URI.- Parameters:
uri- the image's URIrect- the rectangle in which to paint the image
-
drawImageUsingDocument
protected void drawImageUsingDocument(org.w3c.dom.Document doc, java.awt.Rectangle rect)Default drawing method for handling a foreign object in the form of a DOM document.- Parameters:
doc- the DOM document containing the foreign objectrect- the rectangle in which to paint the image
-
drawBorderRect
public void drawBorderRect(java.awt.Rectangle rect, BorderProps top, BorderProps bottom, BorderProps left, BorderProps right, java.awt.Color innerBackgroundColor) throws IFExceptionDraws a border rectangle. The border segments are specified throughBorderPropsinstances.- Specified by:
drawBorderRectin interfaceIFPainter- Parameters:
rect- the rectangle's coordinates and extenttop- the border segment on the top edgebottom- the border segment on the bottom edgeleft- the border segment on the left edgeright- the border segment on the right edgeinnerBackgroundColor- the color of the inner background- Throws:
IFException- if an error occurs while handling this event
-
hasOnlySolidBorders
protected boolean hasOnlySolidBorders(BorderProps top, BorderProps bottom, BorderProps left, BorderProps right)
Indicates whether the given border segments (if present) have only solid borders, i.e. could be painted in a simplified fashion keeping the output file smaller.- Parameters:
top- the border segment on the top edgebottom- the border segment on the bottom edgeleft- the border segment on the left edgeright- the border segment on the right edge- Returns:
- true if any border segment has a non-solid border style
-
drawLine
public void drawLine(java.awt.Point start, java.awt.Point end, int width, java.awt.Color color, RuleStyle style) throws IFExceptionDraws a line. NOTE: Currently, only horizontal lines are implemented!- Specified by:
drawLinein interfaceIFPainter- Parameters:
start- the start point of the lineend- the end point of the linewidth- the line widthcolor- the line colorstyle- the line style (using the Constants.EN_* constants for the rule-style property)- Throws:
IFException- if an error occurs while handling this event
-
getLineBoundingBox
protected java.awt.Rectangle getLineBoundingBox(java.awt.Point start, java.awt.Point end, int width)Calculates the bounding box for a line. Currently, only horizontal and vertical lines are needed and supported.- Parameters:
start- the starting point of the line (coordinates in mpt)end- the ending point of the line (coordinates in mpt)width- the line width (in mpt)- Returns:
- the bounding box (coordinates in mpt)
-
setFont
public void setFont(java.lang.String family, java.lang.String style, java.lang.Integer weight, java.lang.String variant, java.lang.Integer size, java.awt.Color color) throws IFExceptionUpdates the current font.- Specified by:
setFontin interfaceIFPainter- Parameters:
family- the font family (or null if there's no change)style- the font style (or null if there's no change)weight- the font weight (or null if there's no change)variant- the font variant (or null if there's no change)size- the font size (or null if there's no change)color- the text color (or null if there's no change)- Throws:
IFException- if an error occurs while handling this event
-
toPoints
public static java.awt.geom.AffineTransform toPoints(java.awt.geom.AffineTransform transform)
Converts a transformation matrix from millipoints to points.- Parameters:
transform- the transformation matrix (in millipoints)- Returns:
- the converted transformation matrix (in points)
-
isBackgroundRequired
public boolean isBackgroundRequired(BorderProps bpsBefore, BorderProps bpsAfter, BorderProps bpsStart, BorderProps bpsEnd)
TODO Painter-specific rounded borders logic required background drawing to be made optional. A future refactoring of the rounded borders code should aim to make the need for this abstraction obsolete- Specified by:
isBackgroundRequiredin interfaceIFPainter- Parameters:
bpsBefore- the before borderbpsAfter- the after borderbpsStart- the start borderbpsEnd- the end border- Returns:
- true if and only if background drawing is required
-
drawText
public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp, java.lang.String text, boolean nextIsSpace) throws IFException- Specified by:
drawTextin interfaceIFPainter- Throws:
IFException
-
-