Class ImageTool

java.lang.Object
java.util.Observable
com.nomagic.magicreport.engine.Tool
com.nomagic.magicreport.engine.tools.ImageTool
All Implemented Interfaces:
ITool, IVariable, Serializable, Cloneable

@OpenApiAll public class ImageTool extends Tool
A tool provides functions for manipulate image.
Since:
July 02, 2008
See Also:
  • Field Details

  • Constructor Details

    • ImageTool

      public ImageTool()
      Prevent empty initiate.
    • ImageTool

      public ImageTool(ITemplateEngine engine)
      Create an image tool with engine.
      Parameters:
      engine - default global engine
  • Method Details

    • setSeparateChar

      public void setSeparateChar(String separateChar)
      Set separate character for printing image path.
      For example.
      "/" or "\"
      Parameters:
      separateChar - character for printing image path.
    • scale

      public Image scale(Image image, double sxy)
      Convenience method to scale equally in height and width.
      Parameters:
      image - the image to be scaled.
      sxy - the scaling factor for both height and width
      Returns:
      the scaled image
      See Also:
    • scale

      public Image scale(Image image, double sx, double sy)
      Return the image after scaling transformation. Subsequent rendering is resized according to the specified scaling factors relative to the previous scaling.

      Note: new image id is ${old.id}-${sx},${sy}

      Parameters:
      image - report image
      sx - the amount by which X coordinates in subsequent rendering operations are multiplied relative to previous rendering operations.
      sy - the amount by which Y coordinates in subsequent rendering operations are multiplied relative to previous rendering operations.
      Returns:
      the image after scaling transformation.
      See Also:
    • setSize

      public Image setSize(Image image, int width, int height)
      Return the image from specified width and height.
      Parameters:
      image - report image
      width - the new width for this image object
      height - the new height for this image object
      Returns:
      the image with new size
      See Also:
    • setSize

      public Image setSize(Image image, String width, String height)
      Scale the image by the given width/height measurements.
      Parameters:
      image - the image to be scaled.
      width - the width as in, cm, mm, pt or px
      height - the height as in, cm, mm, pt or px
      Returns:
      the scaled image
      See Also:
    • setSize

      public Image setSize(Image image, String width, String height, boolean overrideAutoSizing)
      Scale the image by the given width/height measurements.
      Parameters:
      image - the image to be scaled.
      width - the width as in, cm, mm, pt or px
      height - the height as in, cm, mm, pt or px
      overrideAutoSizing - setSize function will override AutoImageResizing function when true; otherwise, AutoImageResizing option will override set size.
      Returns:
      the scaled image
      See Also:
    • setWidth

      public Image setWidth(Image image, int width)
      Return the image from specified width. Keep image ratio when transform.
      Parameters:
      image - report image
      width - the new width for this image object
      Returns:
      the image with new size
    • setWidth

      public Image setWidth(Image image, int width, boolean keepratio)
      Return the image from specified width. If keep ratio is specified, the image will be scaled with proper ratio.
      Parameters:
      image - report image
      width - the new width for this image object
      keepratio - keep image ratio when true; otherwise false
      Returns:
      the image with new size
      See Also:
    • setWidth

      public Image setWidth(Image image, String width)
      Scale the image by the given width measurements, keeping the ratio.
      Parameters:
      image - the image to be scaled.
      width - the width as in, cm, mm, pt or px
      Returns:
      the scaled image
      See Also:
    • setWidth

      public Image setWidth(Image image, String width, boolean keepRatio)
      Scale the image by the given width measurement, and keep ratio if set.
      Parameters:
      image - the image to be scaled.
      width - the width as in, cm, mm, pt or px
      keepRatio - keeps image ratio if set to true
      Returns:
      the scaled image
      See Also:
    • setHeight

      public Image setHeight(Image image, int height)
      Return the image from specified height. Keep image ratio when transform.
      Parameters:
      image - report image
      height - the new height for this image object
      Returns:
      the image with new size
      See Also:
    • setHeight

      public Image setHeight(Image image, int height, boolean keepratio)
      Return the image from specified height. If keep ratio is specified, the image will be scaled with proper ratio.
      Parameters:
      image - report image
      height - the new height for this image object
      keepratio - keep image ratio when true; otherwise false
      Returns:
      the image with new size
      See Also:
    • setHeight

      public Image setHeight(Image image, String height)
      Scale the image by the given height measurement, keeping the ratio.
      Parameters:
      image - the image to be scaled.
      height - the height as in, cm, mm, pt or px
      Returns:
      the scaled image
      See Also:
    • setHeight

      public Image setHeight(Image image, String height, boolean keepRatio)
      Scale the image by the given height measurement, and keep ratio if set.
      Parameters:
      image - the image to be scaled.
      height - the height as in, cm, mm, pt or px
      keepRatio - keeps image ratio if set to true
      Returns:
      the scaled image
      See Also:
    • rotateRight

      public Image rotateRight(Image image)
      Return the image transformed with clockwise rotation transformation.
      Parameters:
      image - report image
      Returns:
      the transformed image
      See Also:
    • rotateLeft

      public Image rotateLeft(Image image)
      Return the image transform with clockwise rotation transformation.
      Parameters:
      image - report image
      Returns:
      the transformed image
      See Also:
    • setDPI

      public ITool.Void setDPI(int newDpi)
      Sets the DPI value for this document.
      Parameters:
      newDpi - the new dpi value, default is 96.
      Returns:
      nothing
    • getDPI

      public int getDPI()
    • setScalingQuality

      public ITool.Void setScalingQuality(int quality)
      Sets the image scaling quality.
      Parameters:
      quality - a quality level value from 1-5;
      Returns:
      nothing
      See Also:
    • measureToPixel

      public int measureToPixel(String measure)
    • measureToPixel

      public int measureToPixel(Image image, String measure)
      Transforms measurements into pixel count.
      Parameters:
      measure - the measurement in inches, cm, mm or pixels
      Returns:
      the measure in pixels
    • include

      public Image include(String location) throws MalformedURLException
      Include an external image from local file or URL into report.
      
          $image.include('c:/my document/logo.gif')
          $image.include('http://www.magicdraw.com/images/product_boxes/MD.gif')
       
      Parameters:
      location - an image location. Location format can be either URI or system file.
      Returns:
      the report image
      Throws:
      MalformedURLException - invalid location format
    • copy

      public Image copy(String location) throws MalformedURLException
      Copy an external image from local file or URL into report.
      
       $image.copy('c:/my document/logo.gif')
       $image.copy('http://www.magicdraw.com/images/product_boxes/MD.gif')
       
      Parameters:
      location - an image location. Location format can be either URI or system file.
      Returns:
      the report image
      Throws:
      MalformedURLException - invalid location format
    • calculatePaperWidthHeight

      protected float[] calculatePaperWidthHeight()
      Deprecated.
      Calculate the paper width and height.
      Returns:
      array of paper width and height
    • getPaperBounds

      protected Rectangle getPaperBounds()
      Calculate the paper bounds.
      Returns:
      the bounds of paper
    • getPaperBounds

      protected Rectangle getPaperBounds(Image image)
      Calculate the paper bounds.
      Returns:
      the bounds of paper
    • createFormatterWrapper

      protected IFormatterWrapper createFormatterWrapper(Class<?> engineClass)
      Create the formatter wrapper from given engine class.
      Parameters:
      engineClass - the engine class
      Returns:
      IFormatterWrapper
    • split

      public List<Image> split(Image image)
      Split the image into rows and columns with automatic number of rows and columns, and draw each chunked image from left-to-right and top-to-bottom.
      Parameters:
      image - the original image.
      Returns:
      the array of splitted image order by left-to-right and top-to-bottom.
      See Also:
    • split

      public List<Image> split(Image image, int cols, int rows)
      Split the image into rows and columns, and draw each chunked image from left-to-right and top-to-bottom. *

      Note:

      Parameters:
      image - the original image.
      cols - number of columns. Specifies PAPER_SIZE to automatic calculate number of columns from paper width.
      rows - number of rows. Specifies PAPER_SIZE to automatic calculate number of rows from paper height.
      Returns:
      the array of splitted image order by left-to-right and top-to-bottom.
    • createSilentImage

      public ITool.Void createSilentImage(Image image)
      Create image and do not return any path.
      Parameters:
      image - an image to be created
      Returns:
      Void
    • createImageWithRelativePath

      public ITool.RetainedString createImageWithRelativePath(Image image)
      Export image and return relative path of image file.
      This method is suitable for TXT, HTML and XML template only.
      Use the method with above template types, the image would be exported on a file system and return relative path.
      Use the method with other template types, the image would be exported in a report output and return INVALID path.
      Parameters:
      image - an image to be created
      Returns:
      relative path of image file
    • createImageWithAbsolutePath

      public ITool.RetainedString createImageWithAbsolutePath(Image image)
      Export image and return absolute path of the file.
      This method is suitable for TXT, HTML and XML template only.
      Use the method with above template types, the image would be exported on a file system and return absolute path.
      Use the method with other template types, the image would be exported in a report output and return INVALID path.
      Parameters:
      image - an image to be created
      Returns:
      absolute path and image file
    • createImageWithAbsolutePath

      public ITool.RetainedString createImageWithAbsolutePath(Image image, boolean includeURI)
      Export image and return absolute path of the file.
      This method is suitable for TXT, HTML and XML template only.
      Use the method with above template types, the image would be exported on a file system and return absolute path.
      Use the method with other template types, the image would be exported in a report output and return INVALID path.
      Parameters:
      image - an image to be created
      includeURI - true to include uri in path
      Returns:
      absolute path and image file
    • getRelativePath

      public ITool.RetainedString getRelativePath(Image image)
      Return a possible relative path of image file.
      This method does not export an image.
      It returns a possible relative path that the image should be exported to.
      This method is suitable for TXT, HTML and XML template only.
      Use the method with above template types, it will return relative path.
      Use the method with other template types, it will return INVALID path.
      Parameters:
      image - an image
      Returns:
      relative path of image
    • getAbsolutePath

      public ITool.RetainedString getAbsolutePath(Image image)
      Return an absolute path of image file.
      This method does not export an image.
      It return a possible absolute path that the image should be exported to.
      This method is suitable for TXT, HTML and XML template only.
      Use the method with above template types, it will return absolute path.
      Use the method with other template types, it will return INVALID path.
      Parameters:
      image - an image
      Returns:
      absolute path of image
    • getAbsolutePath

      public ITool.RetainedString getAbsolutePath(Image image, boolean includeURI)
      Return an absolute path of image file.
      This method does not export an image.
      It return a possible absolute path that the image should be exported to.
      This method is suitable for TXT, HTML and XML template only.
      Use the method with above template types, it will return absolute path.
      Use the method with other template types, it will return INVALID path.
      Parameters:
      image - an image
      includeURI - true to include uri in path
      Returns:
      absolute path of image
    • getImageProperty

      public ImageTool.ImageProperty getImageProperty(Image image)
      Get ImageProperty object
      Parameters:
      image - current image
      Returns:
      image with its properties
    • limitImageSize

      public Image limitImageSize(Image image)
      Limit image size to paper page size.
      Parameters:
      image - image
      Returns:
      resized image
    • limitImageSize

      public Image limitImageSize(Image image, String maximumWidth, String maximumHeight)
      Limit image size to paper page size and maximum size.
      Parameters:
      image - image
      maximumWidth - maximum width of image as in, cm, mm, pt or px
      maximumHeight - maximum height of image as in, cm, mm, pt or px
      Returns:
      resized image
    • limitImageSize

      public Image limitImageSize(Image image, int maximumWidthPixel, int maximumHeightPixel)
      Limit image size to paper page size and maximum size.
      Parameters:
      image - image
      maximumWidthPixel - maximum width of image as pixel number
      maximumHeightPixel - maximum height of image as pixel number
      Returns:
      resized image