Class Java2DPainter

All Implemented Interfaces:
IFPainter

public class Java2DPainter extends AbstractIFPainter<IFDocumentHandler>
IFPainter implementation that paints on a Graphics2D instance.
  • Field Details

    • ifContext

      protected IFContext ifContext
      the IF context
    • fontInfo

      protected FontInfo fontInfo
      The font information
    • g2dState

      protected Java2DGraphicsState g2dState
      The current state, holds a Graphics2D and its context
  • Constructor Details

    • Java2DPainter

      public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo)
      Main constructor.
      Parameters:
      g2d - the target Graphics2D instance
      context - the IF context
      fontInfo - the font information
    • Java2DPainter

      public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFDocumentHandler documentHandler)
    • Java2DPainter

      public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state)
      Special constructor for embedded use (when another painter uses Java2DPainter to convert part of a document into a bitmap, for example).
      Parameters:
      g2d - the target Graphics2D instance
      context - the IF context
      fontInfo - the font information
      state - the IF state object
    • Java2DPainter

      public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state, IFDocumentHandler documentHandler)
  • Method Details

    • getContext

      public IFContext getContext()
      Returns the intermediate format context object.
      Overrides:
      getContext in class AbstractIFPainter<IFDocumentHandler>
      Returns:
      the context object
    • getFontInfo

      protected FontInfo getFontInfo()
      Returns the associated FontInfo object.
      Overrides:
      getFontInfo in class AbstractIFPainter<IFDocumentHandler>
      Returns:
      the font info
    • getState

      protected Java2DGraphicsState getState()
      Returns the Java2D graphics state.
      Returns:
      the graphics state
    • startViewport

      public void startViewport(AffineTransform transform, 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.
      Parameters:
      transform - the transformation matrix 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
    • endViewport

      public void endViewport() throws IFException
      Ends the current viewport and restores the previous coordinate system.
      Throws:
      IFException - if an error occurs while handling this element
    • startGroup

      public void startGroup(AffineTransform transform, String layer) throws IFException
      Starts a new group of graphical elements. Corresponds to SVG's g element.
      Parameters:
      transform - the transformation matrix establishing the new coordinate system
      layer - an optional layer label (or null if none)
      Throws:
      IFException - if an error occurs while handling this element
    • endGroup

      public void endGroup() throws IFException
      Ends the current group and restores the previous coordinate system (and layer).
      Throws:
      IFException - if an error occurs while handling this element
    • drawImage

      public void drawImage(String uri, Rectangle rect) throws IFException
      Draws an image identified by a URI inside a given rectangle. This is the equivalent to an fo:external-graphic in XSL-FO.
      Parameters:
      uri - the image's URI
      rect - the rectangle in which the image shall be painted
      Throws:
      IFException - if an error occurs while handling this event
    • createRenderingContext

      protected RenderingContext createRenderingContext()
      Creates a new RenderingContext instance.
      Specified by:
      createRenderingContext in class AbstractIFPainter<IFDocumentHandler>
      Returns:
      the new rendering context.
    • drawImage

      public void drawImage(Document doc, Rectangle rect) throws IFException
      Draws an image (represented by a DOM document) inside a given rectangle. This is the equivalent to an fo:instream-foreign-object in XSL-FO.
      Parameters:
      doc - the DOM document containing the foreign object
      rect - the rectangle in which the image shall be painted
      Throws:
      IFException - if an error occurs while handling this event
    • clipRect

      public void clipRect(Rectangle rect) throws IFException
      Restricts the current clipping region with the given rectangle.
      Parameters:
      rect - the rectangle's coordinates and extent
      Throws:
      IFException - if an error occurs while handling this event
    • clipBackground

      public void clipBackground(Rectangle rect, BorderProps bpsBefore, BorderProps bpsAfter, BorderProps bpsStart, BorderProps bpsEnd) throws IFException
      Restricts the current clipping region to the inner border.
      Parameters:
      rect - the rectangle's coordinates and extent
      bpsBefore - the border segment on the before-side (top)
      bpsAfter - the border segment on the after-side (bottom)
      bpsStart - the border segment on the start-side (left)
      bpsEnd - the border segment on the end-side (right)
      Throws:
      IFException - if an error occurs while handling this event
    • fillRect

      public void fillRect(Rectangle rect, Paint fill) throws IFException
      Fills a rectangular area.
      Parameters:
      rect - the rectangle's coordinates and extent
      fill - the fill paint
      Throws:
      IFException - if an error occurs while handling this event
    • drawBorderRect

      public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom, BorderProps left, BorderProps right) throws IFException
      Throws:
      IFException
    • 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
      Overrides:
      drawLine in class AbstractIFPainter<IFDocumentHandler>
      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
    • drawText

      public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp, String text) throws IFException
      Draws text. The initial coordinates (x and y) point to the starting point at the normal baseline of the font. The parameters letterSpacing, wordSpacing and the array dx are optional and can be used to influence character positioning (for example, for kerning).
      Parameters:
      x - X-coordinate of the starting point of the text
      y - Y-coordinate of the starting point of the text
      letterSpacing - additional spacing between characters (may be 0)
      wordSpacing - additional spacing between words (may be 0)
      dp - an array of 4-tuples, expressing [X,Y] placment adjustments and [X,Y] advancement adjustments, in that order (may be null); if not null, then adjustments.length must be the same as text.length()
      text - the text
      Throws:
      IFException - if an error occurs while handling this event
    • saveGraphicsState

      protected void saveGraphicsState()
      Saves the current graphics state on the stack.
    • restoreGraphicsState

      protected void restoreGraphicsState()
      Restores the last graphics state from the stack.