Class TXTRenderer

All Implemented Interfaces:
Constants, Renderer

public class TXTRenderer extends AbstractPathOrientedRenderer

Renderer that renders areas to plain text.

This work was authored by Art Welch and Mark Lillywhite (mark-fop@inomial.com) [to use the new Renderer interface].

  • Field Details

    • LINE_LEADING

      public static final int LINE_LEADING
      Leading of line containing Courier font size of 10pt.
      See Also:
    • CHAR_HEIGHT

      public static final int CHAR_HEIGHT
      Height of one symbol in Courier font size of 10pt.
      See Also:
    • CHAR_WIDTH

      public static final int CHAR_WIDTH
      Width of one symbol in Courier font size of 10pt.
      See Also:
  • Constructor Details

    • TXTRenderer

      public TXTRenderer(FOUserAgent userAgent)
      Constructs a newly allocated TXTRenderer object.
      Parameters:
      userAgent - the user agent that contains configuration details. This cannot be null.
  • Method Details

    • getMimeType

      public String getMimeType()
      Get the MIME type of the renderer.
      Returns:
      The MIME type of the renderer, may return null if not applicable.
    • setEncoding

      public void setEncoding(String encoding)
      Sets the encoding of the target file.
      Parameters:
      encoding - the encoding, null to select the default encoding (UTF-8)
    • isLayInside

      public boolean isLayInside(int x, int y)
      Indicates if point (x, y) lay inside currentPage.
      Parameters:
      x - x coordinate
      y - y coordinate
      Returns:
      true if point lay inside page
    • addChar

      protected void addChar(int x, int y, char ch, boolean ischar)
      Add char to text buffer.
      Parameters:
      x - x coordinate
      y - y coordinate
      ch - char to add
      ischar - boolean, repersenting is character adding to text buffer
    • putChar

      protected void putChar(int x, int y, char ch, boolean ischar)
      Add char to text or background buffer.
      Parameters:
      x - x coordinate
      y - x coordinate
      ch - char to add
      ischar - indicates if it char or background
    • addString

      protected void addString(int row, int col, String s)
      Adds string to text buffer (charData).

      Chars of string map in turn.

      Parameters:
      row - x coordinate
      col - y coordinate
      s - string to add
    • renderText

      protected void renderText(TextArea area)
      Render TextArea to Text.
      Overrides:
      renderText in class AbstractRenderer
      Parameters:
      area - inline area to render
    • renderPage

      public void renderPage(PageViewport page) throws IOException, FOPException
      Tells the renderer to render a particular page. A renderer typically responds by packing up the current page and writing it immediately to the output device.
      Specified by:
      renderPage in interface Renderer
      Overrides:
      renderPage in class AbstractRenderer
      Parameters:
      page - The page to be rendered
      Throws:
      IOException - if an I/O error occurs
      FOPException - if a FOP interal error occurs.
    • startRenderer

      public void startRenderer(OutputStream os) throws IOException
      Initiates the rendering phase. This must only be called once for a rendering. If stopRenderer is called then this may be called again for a new document rendering.
      Specified by:
      startRenderer in interface Renderer
      Overrides:
      startRenderer in class AbstractRenderer
      Parameters:
      os - The OutputStream to use for output
      Throws:
      IOException - If an I/O error occurs
    • stopRenderer

      public void stopRenderer() throws IOException
      Signals the end of the rendering phase. The renderer should reset to an initial state and dispose of any resources for the completed rendering.
      Specified by:
      stopRenderer in interface Renderer
      Overrides:
      stopRenderer in class AbstractRenderer
      Throws:
      IOException - If an I/O error occurs
    • restoreStateStackAfterBreakOut

      protected void restoreStateStackAfterBreakOut(List breakOutList)
      Does nothing. Restores the state stack after a break out.
      Specified by:
      restoreStateStackAfterBreakOut in class AbstractPathOrientedRenderer
      Parameters:
      breakOutList - the state stack to restore.
    • breakOutOfStateStack

      protected List breakOutOfStateStack()
      Does nothing.
      Specified by:
      breakOutOfStateStack in class AbstractPathOrientedRenderer
      Returns:
      null the saved state stack to recreate later
    • saveGraphicsState

      protected void saveGraphicsState()
      Does nothing. Saves the graphics state of the rendering engine.
      Specified by:
      saveGraphicsState in class AbstractPathOrientedRenderer
    • restoreGraphicsState

      protected void restoreGraphicsState()
      Does nothing. Restores the last graphics state of the rendering engine.
      Specified by:
      restoreGraphicsState in class AbstractPathOrientedRenderer
    • beginTextObject

      protected void beginTextObject()
      Does nothing. Indicates the beginning of a text object.
      Specified by:
      beginTextObject in class AbstractPathOrientedRenderer
    • endTextObject

      protected void endTextObject()
      Does nothing. Indicates the end of a text object.
      Specified by:
      endTextObject in class AbstractPathOrientedRenderer
    • clip

      protected void clip()
      Does nothing. Clip using the current path.
      Specified by:
      clip in class AbstractPathOrientedRenderer
    • clipRect

      protected void clipRect(float x, float y, float width, float height)
      Does nothing. Clip using a rectangular area.
      Specified by:
      clipRect in class AbstractPathOrientedRenderer
      Parameters:
      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)
    • moveTo

      protected void moveTo(float x, float y)
      Does nothing. Moves the current point to (x, y), omitting any connecting line segment.
      Specified by:
      moveTo in class AbstractPathOrientedRenderer
      Parameters:
      x - x coordinate
      y - y coordinate
    • lineTo

      protected void lineTo(float x, float y)
      Does nothing. Appends a straight line segment from the current point to (x, y). The new current point is (x, y).
      Specified by:
      lineTo in class AbstractPathOrientedRenderer
      Parameters:
      x - x coordinate
      y - y coordinate
    • closePath

      protected void closePath()
      Does nothing. Closes the current subpath by appending a straight line segment from the current point to the starting point of the subpath.
      Specified by:
      closePath in class AbstractPathOrientedRenderer
    • fillRect

      protected void fillRect(float x, float y, float width, float height)
      Fills a rectangular area with the current filling char. Fill a rectangular area.
      Specified by:
      fillRect in class AbstractPathOrientedRenderer
      Parameters:
      x - the x coordinate
      y - the y coordinate
      width - the width of the rectangle
      height - the height of the rectangle
    • updateColor

      protected void updateColor(Color col, boolean fill)
      Changes current filling char. Establishes a new foreground or fill color.
      Specified by:
      updateColor in class AbstractPathOrientedRenderer
      Parameters:
      col - the color to apply (null skips this operation)
      fill - true to set the fill color, false for the foreground color
    • drawImage

      protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes)
      Draw an image at the indicated location.
      Specified by:
      drawImage in class AbstractPathOrientedRenderer
      Parameters:
      url - the URI/URL of the image
      pos - the position of the image
      foreignAttributes - an optional Map with foreign attributes, may be null
    • renderImage

      public void renderImage(Image image, Rectangle2D pos)
      Fills image rectangle with a IMAGE_CHAR.
      Overrides:
      renderImage in class AbstractRenderer
      Parameters:
      image - the base image
      pos - the position of the image
    • toMilli

      protected int toMilli(float x)
      Returns the closest integer to the multiplication of a number and 1000.
      Parameters:
      x - the value of the argument, multiplied by 1000 and rounded
      Returns:
      the value of the argument multiplied by 1000 and rounded to the nearest integer
    • drawBorderLine

      protected void drawBorderLine(float x1, float y1, float x2, float y2, boolean horz, boolean startOrBefore, int style, Color col)
      Draw a border segment of an XSL-FO style border.
      Specified by:
      drawBorderLine in class AbstractPathOrientedRenderer
      Parameters:
      x1 - starting x coordinate
      y1 - starting y coordinate
      x2 - ending x coordinate
      y2 - ending y coordinate
      horz - true for horizontal border segments, false for vertical border segments
      startOrBefore - 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 segment
    • drawBackAndBorders

      protected void drawBackAndBorders(Area area, float startx, float starty, float width, float height)
      Draw the background and borders. This draws the background and border traits for an area given the position.
      Overrides:
      drawBackAndBorders in class AbstractPathOrientedRenderer
      Parameters:
      area - the area to get the traits from
      startx - the start x position
      starty - the start y position
      width - the width of the area
      height - the height of the area
    • startVParea

      protected void startVParea(CTM ctm, Rectangle clippingRect)
      Establishes a new viewport area.
      Specified by:
      startVParea in class AbstractRenderer
      Parameters:
      ctm - the coordinate transformation matrix to use
      clippingRect - the clipping rectangle if the viewport should be clipping, null if no clipping is performed.
    • endVParea

      protected void endVParea()
      Signals exit from a viewport area. Subclasses can restore transformation matrices valid before the viewport area was started.
      Specified by:
      endVParea in class AbstractRenderer
    • startLayer

      protected void startLayer(String layer)
      Establish new optional content group layer.
      Specified by:
      startLayer in class AbstractRenderer
      Parameters:
      layer - name of layer
    • endLayer

      protected void endLayer()
      Finish current optional content group layer.
      Specified by:
      endLayer in class AbstractRenderer
    • concatenateTransformationMatrix

      protected void concatenateTransformationMatrix(AffineTransform at)
      Concatenates the current transformation matrix with the given one, therefore establishing a new coordinate system.
      Specified by:
      concatenateTransformationMatrix in class AbstractPathOrientedRenderer
      Parameters:
      at - the transformation matrix to process (coordinates in points)