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 Object
implements IFPainter
Abstract base class for IFPainter implementations.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Map
createDefaultImageProcessingHints
(org.apache.xmlgraphics.image.loader.ImageSessionContext sessionContext) Creates the default map of processing hints for the image loading framework.protected abstract RenderingContext
Creates a new RenderingContext instance.void
drawBorderRect
(Rectangle rect, BorderProps top, BorderProps bottom, BorderProps left, BorderProps right, Color innerBackgroundColor) Draws a border rectangle.protected void
drawImage
(org.apache.xmlgraphics.image.loader.Image image, Rectangle rect, RenderingContext context) Draws an image using a suitable image handler.protected void
drawImage
(org.apache.xmlgraphics.image.loader.Image image, Rectangle rect, RenderingContext context, boolean convert, Map additionalHints) Draws an image using a suitable image handler.protected void
drawImageUsingDocument
(Document doc, Rectangle rect) Default drawing method for handling a foreign object in the form of a DOM document.protected void
drawImageUsingImageHandler
(org.apache.xmlgraphics.image.loader.ImageInfo info, Rectangle rect) Loads a preloaded image and draws it using a suitable image handler.protected void
drawImageUsingURI
(String uri, Rectangle rect) Default drawing method for handling an image referenced by a URI.void
Draws a line.protected boolean
drawSVGText
(MultiByteFont multiByteFont, FontTriplet triplet, int x, int y, String text, IFState state) void
drawText
(int x, int y, int letterSpacing, int wordSpacing, int[][] dp, String text, boolean nextIsSpace) Returns the intermediate format context object.protected T
protected FontInfo
protected String
getFontKey
(FontTriplet triplet) protected org.apache.xmlgraphics.image.loader.ImageInfo
getImageInfo
(String uri) Returns an ImageInfo instance for the given URI.protected Rectangle
getLineBoundingBox
(Point start, Point end, int width) Calculates the bounding box for a line.protected FOUserAgent
Returns the user agent.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.boolean
isBackgroundRequired
(BorderProps bpsBefore, BorderProps bpsAfter, BorderProps bpsStart, BorderProps bpsEnd) TODO Painter-specific rounded borders logic required background drawing to be made optional.void
Updates the current font.void
startGroup
(AffineTransform[] transforms, String layer) Starts a new group of graphical elements.void
startViewport
(AffineTransform[] transforms, Dimension size, Rectangle clipRect) Starts a new viewport, establishing a new coordinate system.static AffineTransform
toPoints
(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 Details
-
INSTREAM_OBJECT_URI
non-URI that can be used in feedback messages that an image is an instream-object- See Also:
-
state
Holds the intermediate format state
-
-
Constructor Details
-
AbstractIFPainter
Default constructor.
-
-
Method Details
-
getFontKey
- Throws:
IFException
-
getContext
Returns the intermediate format context object.- Returns:
- the context object
-
getFontInfo
-
getDocumentHandler
-
getUserAgent
Returns the user agent.- Returns:
- the user agent
-
startViewport
public void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect) throws IFException Starts 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:
startViewport
in 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
Starts a new group of graphical elements. Corresponds to SVG's g element.- Specified by:
startGroup
in 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
Creates a new RenderingContext instance.- Returns:
- the new rendering context.
-
drawImageUsingImageHandler
protected void drawImageUsingImageHandler(org.apache.xmlgraphics.image.loader.ImageInfo info, Rectangle rect) throws org.apache.xmlgraphics.image.loader.ImageException, IOException Loads 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 imageIOException
- if there's an I/O error while loading the image
-
createDefaultImageProcessingHints
protected 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, Rectangle rect, RenderingContext context) throws IOException, org.apache.xmlgraphics.image.loader.ImageException Draws 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:
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, Rectangle rect, RenderingContext context, boolean convert, Map additionalHints) throws IOException, org.apache.xmlgraphics.image.loader.ImageException Draws 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:
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
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
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
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(Rectangle rect, BorderProps top, BorderProps bottom, BorderProps left, BorderProps right, Color innerBackgroundColor) throws IFException Draws a border rectangle. The border segments are specified throughBorderProps
instances.- Specified by:
drawBorderRect
in 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(Point start, Point end, int width, Color color, RuleStyle style) throws IFException Draws a line. NOTE: Currently, only horizontal lines are implemented!- Specified by:
drawLine
in 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
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(String family, String style, Integer weight, String variant, Integer size, Color color) throws IFException Updates the current font.- Specified by:
setFont
in 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
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:
isBackgroundRequired
in 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, String text, boolean nextIsSpace) throws IFException - Specified by:
drawText
in interfaceIFPainter
- Throws:
IFException
-
drawSVGText
protected boolean drawSVGText(MultiByteFont multiByteFont, FontTriplet triplet, int x, int y, String text, IFState state) throws IFException - Throws:
IFException
-