org.apache.fop.render.intermediate

## 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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String` | `INSTREAM_OBJECT_URI` non-URI that can be used in feedback messages that an image is an instream-object
    `protected IFState` | `state` Holds the intermediate format state

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractIFPainter(T documentHandler)` Default constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Map` | `createDefaultImageProcessingHints(org.apache.xmlgraphics.image.loader.ImageSessionContext sessionContext)` Creates the default map of processing hints for the image loading framework.
    `protected abstract RenderingContext` | `createRenderingContext()` 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` | `drawLine(Point start, Point end, int width, Color color, RuleStyle style)` 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)`
    `IFContext` | `getContext()` Returns the intermediate format context object.
    `protected T` | `getDocumentHandler()`
    `protected FontInfo` | `getFontInfo()`
    `protected String` | `getFontKey(FontTriplet triplet)`
    `protected org.apache.xmlgraphics.image.loader.Image` | `getImageForSupportedFlavors(org.apache.xmlgraphics.image.loader.ImageInfo info)`
    `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` | `getUserAgent()` 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` | `setFont(String family, String style, Integer weight, String variant, Integer size, Color color)` 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 Detail

    - #### INSTREAM_OBJECT_URI

          protected static final 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 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(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 interface `IFPainter`
      Parameters:
        `transforms` - a series of transformation matrices establishing the new coordinate system
        `size` - the size of the viewport
        `clipRect` - the clipping rectangle (may be null)
      Throws:
        `IFException` - if an error occurs while handling this element

    - #### startGroup

          public void startGroup(AffineTransform[] transforms,
                                 String layer)
                          throws IFException

      Starts a new group of graphical elements. Corresponds to SVG's g element.
      Specified by:
        `startGroup` in interface `IFPainter`
      Parameters:
        `transforms` - a series of transformation matrices establishing the new coordinate system
        `layer` - 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,
                                                    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 image
        `rect` - the rectangle in which to paint the image
      Throws:
        `org.apache.xmlgraphics.image.loader.ImageException` - if there's an error while processing the image
        `IOException` - if there's an I/O error while loading the image

    - #### getImageForSupportedFlavors

          protected org.apache.xmlgraphics.image.loader.Image getImageForSupportedFlavors(org.apache.xmlgraphics.image.loader.ImageInfo info)

    - #### 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 image
        `context` - a suitable rendering context
      Throws:
        `IOException` - in case of an I/O error while handling/writing the image
        `org.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 image
        `context` - a suitable rendering context
        `convert` - true to run the image through image conversion if that is necessary
        `additionalHints` - additional image processing hints
      Throws:
        `IOException` - in case of an I/O error while handling/writing the image
        `org.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(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(String uri,
                                           Rectangle rect)

      Default drawing method for handling an image referenced by a URI.
      Parameters:
        `uri` - the image's URI
        `rect` - the rectangle in which to paint the image

    - #### drawImageUsingDocument

          protected void drawImageUsingDocument(Document doc,
                                                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 object
        `rect` - 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 through `BorderProps` instances.
      Specified by:
        `drawBorderRect` in interface `IFPainter`
      Parameters:
        `rect` - the rectangle's coordinates and extent
        `top` - the border segment on the top edge
        `bottom` - the border segment on the bottom edge
        `left` - the border segment on the left edge
        `right` - the border segment on the right edge
        `innerBackgroundColor` - 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 edge
        `bottom` - the border segment on the bottom edge
        `left` - the border segment on the left edge
        `right` - 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 interface `IFPainter`
      Parameters:
        `start` - the start point of the line
        `end` - the end point of the line
        `width` - the line width
        `color` - the line color
        `style` - 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 Rectangle getLineBoundingBox(Point start,
                                                 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(String family,
                              String style,
                              Integer weight,
                              String variant,
                              Integer size,
                              Color color)
                       throws IFException

      Updates the current font.
      Specified by:
        `setFont` in interface `IFPainter`
      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 AffineTransform toPoints(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:
        `isBackgroundRequired` in interface `IFPainter`
      Parameters:
        `bpsBefore` - the before border
        `bpsAfter` - the after border
        `bpsStart` - the start border
        `bpsEnd` - 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 interface `IFPainter`
      Throws:
        `IFException`

    - #### drawSVGText

          protected boolean drawSVGText(MultiByteFont multiByteFont,
                                        FontTriplet triplet,
                                        int x,
                                        int y,
                                        String text,
                                        IFState state)
                                 throws IFException

      Throws:
        `IFException`

Copyright © 2025 Apache Software Foundation. All rights reserved.