Class RTFFormatter

java.lang.Object
com.nomagic.magicreport.format.DefaultFormatter
com.nomagic.magicreport.format.RTFFormatter
All Implemented Interfaces:
IFormatter

@OpenApiAll public class RTFFormatter extends DefaultFormatter
This class provides implementation for RTF format output. Extend from DefaultFormatter, this class provide additional support for BufferedImage, and RTF escaped characters.
Since:
Jun 11, 2007 10:49:57 PM
Version:
1.0 Jun 11, 2007
  • Field Details

    • HMM_PER_INCH

      public static final float HMM_PER_INCH
      The number of hundredths of millimeters (0.01 mm) in an inch.
      See Also:
    • TWIPS_PER_INCH

      public static final float TWIPS_PER_INCH
      The number of twips in an inch.
      See Also:
    • MAX_WIDTH_IN_PIXELS

      public static final float MAX_WIDTH_IN_PIXELS
      The number of appropriate max image width in pixels.
      See Also:
    • MAX_HEIGHT_IN_PIXELS

      public static final float MAX_HEIGHT_IN_PIXELS
      The number of appropriate max image height in pixels.
      See Also:
    • LINKED_PICTURE

      public static final String LINKED_PICTURE
      The image property indicates that image will be temporary stored as a link during process and it will be replaced with binary data in post-process.
      See Also:
    • WMF_PLACEABLE_HEADER_SIZE

      protected static final int WMF_PLACEABLE_HEADER_SIZE
      The number of WMF header length.
      See Also:
  • Constructor Details

    • RTFFormatter

      public RTFFormatter(Properties properties)
      Create a RTF formatter with with specific properties.
      Parameters:
      properties - template properties
  • Method Details

    • format

      public Object format(Object value)
      Convert an Object value into RTF format.
      Specified by:
      format in interface IFormatter
      Overrides:
      format in class DefaultFormatter
      Parameters:
      value - converting value
      Returns:
      object in default format.
    • createImage

      protected ITool.RetainedString createImage(Image image) throws IOException
      Create a RTF image string from given Image object.
      Parameters:
      image - an Image object
      Returns:
      The String in RTF image format.
      Throws:
      IOException - when IO error occurs
    • createImage

      protected ITool.RetainedString createImage(Image image, int width, int height, int flag) throws IOException
      Create a RTF image string from given Image object.
      Parameters:
      image - an Image object
      width - the target image width
      height - the target image height
      flag - scaling image flag
      Returns:
      The String in RTF image format.
      Throws:
      IOException - when IO error occurs
    • createImageHeader

      protected ITool.RetainedString createImageHeader(Image image, int width, int height, int flag)
      Create an image header.
      Parameters:
      image - Image object
      width - target image width
      height - target image height
      flag - target image flag
      Returns:
      image header
      See Also:
    • createImageBody

      public long createImageBody(Image image, Writer writer) throws IOException
      Create image body to writer.
      Parameters:
      image - an Image object
      writer - the writer
      Returns:
      total written characters
      Throws:
      IOException - if exception occurs
    • createImageFooter

      protected ITool.RetainedString createImageFooter(Image image, int width, int height, int flag)
      Create an image footer.
      Parameters:
      image - Image object
      width - target image width
      height - target image height
      flag - target image flag
      Returns:
      image footer
      See Also:
    • createImageProperty

      protected ITool.RetainedString createImageProperty(float w, float h, int flag)
    • createImageProperty

      protected ITool.RetainedString createImageProperty(Image image, float w, float h, int flag)
      Calculate Property of image.
      
       picscalex - scale in x
       picscaley - scale in y
       picw - Width of image(0.01 mm)
       pich - Height of image(0.01 mm)
       picwgoal - Width of image(twips)
       pichgoal - Height of image(twips)
       
      
       Units Used
       ----------
       1 Twip = 1/20 Point
       1 Point = 1/72 Inch
       1 Twip = 1/1440 Inch
       
       1 Inch = 2.54 cm
       1 Inch = 25.4 mm
       1 Inch = 2540 (0.01)mm
       
      Parameters:
      w - image width
      h - image height
      flag - scaling image flag
      Returns:
      String property of image in rtf tag
    • getImageFormat

      protected String getImageFormat(Image image)
      Return the image format.
      Parameters:
      image - the Image
      Returns:
      the image format
    • getPageSize

      public float[] getPageSize()
      Calculation for total paper width and total paper height after minus margin of page in twips.
      Returns:
      float[] array of paper width and paper height
    • isLargeImage

      protected boolean isLargeImage(Image image)
      Compare the width and height of the image and paper if the image is greater than paper, it's considered as large image.
      Parameters:
      image - image want to compare with paper
      Returns:
      true if image is larger than paper size
    • createBookmark

      protected ITool.RetainedString createBookmark(Bookmark bookmark) throws IOException
      Create a RTF bookmark string from given Bookmark object.
      Parameters:
      bookmark - an Bookmark object
      Returns:
      The String in RTF bookmark format.
      Throws:
      IOException - when IO error occurs
    • createLink

      protected ITool.RetainedString createLink(Link link) throws IOException
      Create a RTF link string from given Link object.
      Parameters:
      link - an Link object
      Returns:
      The String in RTF link format.
      Throws:
      IOException - when IO error occurs