com.xmlmind.fo.graphic
Class GraphicFactoryImpl

java.lang.Object
  extended by com.xmlmind.fo.graphic.GraphicFactoryBase
      extended by com.xmlmind.fo.graphic.GraphicFactoryImpl
All Implemented Interfaces:
GraphicFactory

public final class GraphicFactoryImpl
extends GraphicFactoryBase

An implementation of GraphicFactory based on ImageIO. This means that this factory supports at least the following formats: "image/bmp" (Java 1.5+), "image/gif", "image/png", "image/jpeg". However this factory only allows to save images as JPEG or PNG files.


Field Summary
 
Fields inherited from class com.xmlmind.fo.graphic.GraphicFactoryBase
factoryName
 
Constructor Summary
GraphicFactoryImpl()
          Constructs a factory leveraging ImageIO.
 
Method Summary
 Graphic convertGraphic(Graphic graphic, String format, double xScale, double yScale, Object clientData, GraphicEnv env)
          Converts specified graphic to specified format, while optionally rescaling it.
 Graphic createGraphic(String location, String format, Object clientData, GraphicEnv env)
          Creates a graphic which represents the illustration stored as specified location.
 String[] getInputFormats()
          Returns the list of input MIME types supported by GraphicFactory.createGraphic(java.lang.String, java.lang.String, java.lang.Object, com.xmlmind.fo.graphic.GraphicEnv).
 String[] getOutputFormats()
          Returns the list of output MIME types supported by GraphicFactory.convertGraphic(com.xmlmind.fo.graphic.Graphic, java.lang.String, double, double, java.lang.Object, com.xmlmind.fo.graphic.GraphicEnv).
static BufferedImage scaleImage(BufferedImage image, double xScale, double yScale)
          Returns a scaled instance of specified image.
static void writeImage(BufferedImage image, double xRes, double yRes, String format, File outFile)
          Save specified image to specified file.
 
Methods inherited from class com.xmlmind.fo.graphic.GraphicFactoryBase
getName, getParameter, setParameter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphicFactoryImpl

public GraphicFactoryImpl()
Constructs a factory leveraging ImageIO.

Method Detail

getInputFormats

public String[] getInputFormats()
Description copied from interface: GraphicFactory
Returns the list of input MIME types supported by GraphicFactory.createGraphic(java.lang.String, java.lang.String, java.lang.Object, com.xmlmind.fo.graphic.GraphicEnv).


getOutputFormats

public String[] getOutputFormats()
Description copied from interface: GraphicFactory
Returns the list of output MIME types supported by GraphicFactory.convertGraphic(com.xmlmind.fo.graphic.Graphic, java.lang.String, double, double, java.lang.Object, com.xmlmind.fo.graphic.GraphicEnv).

In order to be useful to XMLmind XSL-FO Converter, a factory must return one or more of "image/png", "image/x-wmf", "image/x-emf".


createGraphic

public Graphic createGraphic(String location,
                             String format,
                             Object clientData,
                             GraphicEnv env)
                      throws Exception
Description copied from interface: GraphicFactory
Creates a graphic which represents the illustration stored as specified location.

IMPORTANT: the created Graphic must bear the resolution information stored in the source located by location. If this source does not contain any resolution information then the resolution fields of created Graphic must be set to 0.

Parameters:
location - location of the graphic file. The string form of an URL. May be a "data:" URL.
format - MIME type of the image to be created. This format is guaranteed to be listed by GraphicFactory.getInputFormats().
clientData - opaque client data to be associated with the newly created graphic
env - services provided by XMLmind XSL-FO Converter
Returns:
a newly created graphic
Throws:
Exception - if, for any reason, this method fails

convertGraphic

public Graphic convertGraphic(Graphic graphic,
                              String format,
                              double xScale,
                              double yScale,
                              Object clientData,
                              GraphicEnv env)
                       throws Exception
Description copied from interface: GraphicFactory
Converts specified graphic to specified format, while optionally rescaling it.

Even when there is apparently nothing to do (that is, same format, no scaling), this method saves a copy of graphic and returns the saved copy. This method never returns graphic.

IMPORTANT: if graphic has resolution information and if image format format allows to store this information, then this resolution information must be stored in the source of the newly created Graphic.

Parameters:
graphic - graphic to be converted
format - MIME type of the image to be created. This format is guaranteed to be listed by GraphicFactory.getOutputFormats().
xScale - scaling factor to apply to the width of graphic
yScale - scaling factor to apply to the height of graphic
clientData - opaque client data to be associated with the newly created graphic
env - services provided by XMLmind XSL-FO Converter
Returns:
a newly created graphic
Throws:
Exception - if, for any reason, this method fails

scaleImage

public static BufferedImage scaleImage(BufferedImage image,
                                       double xScale,
                                       double yScale)
Returns a scaled instance of specified image.

This helper function is intented to be used to implement not only this factory, but also other factories.

Parameters:
image - image to be scaled
xScale - scaling factor to apply to the width of image
yScale - scaling factor to apply to the height of image
Returns:
scaled image

writeImage

public static void writeImage(BufferedImage image,
                              double xRes,
                              double yRes,
                              String format,
                              File outFile)
                       throws Exception
Save specified image to specified file.

This helper function is intented to be used to implement not only this factory, but also other factories.

Parameters:
image - image to be saved
xRes - horizontal resolution of image in DPI. A negative or null number means unknown.
yRes - vertical resolution of image in DPI. A negative or null number means unknown.
format - output MIME type. Example: "image/png".
outFile - save file
Throws:
Exception - if, for any reason, this method fails