|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xhtmlrenderer.swing.Java2DRenderer
public class Java2DRenderer
Renders an XML files, formatted with CSS, as an image. Input is a document in the form of file or URL, and output is a BufferedImage. A Java2DRenderer is not intended to be re-used for multiple document sources; just create new Java2DRenderers for each one you need. Java2DRenderer is not thread-safe. Standard usage pattern is
File xhtml = ... Java2DRenderer rend = new Java2DRenderer(xhtml); BufferedImage image = rend.getImage();
The document is not loaded, and layout and render don't take place, until #getImage(int) is called.
Subsequent calls to getImage() don't result in a reload; create a new Java2DRenderer instance to do so.
As with RootPanel, you can access the
SharedContext instance that will be used by this renderer and change settings
to control the rendering process; use getSharedContext().
By default, this renderer will render to an RGB image which does not support transparency. To use another type
of BufferedImage, either set the image type using setBufferedImageType(int) before calling
getImage(), or else override the createBufferedImage(int, int) to have full control over
the image we render to.
Not thread-safe.
ITextRenderer| Constructor Summary | |
|---|---|
Java2DRenderer(Document doc,
int width,
int height)
Creates a new instance pointing to the given Document. |
|
Java2DRenderer(File file,
int width)
Creates a new instance for a given File. |
|
Java2DRenderer(File file,
int width,
int height)
Creates a new instance for a given File. |
|
Java2DRenderer(String url,
int width)
Renderer for a given URL (which is also used as the base) and a specified width; height is calculated automatically. |
|
Java2DRenderer(String url,
int width,
int height)
Renderer for a given URL and a specified width; height is calculated automatically. |
|
Java2DRenderer(String url,
String baseurl,
int width)
Renderer for a given URL and a specified width; height is calculated automatically. |
|
Java2DRenderer(String url,
String baseUrl,
int width,
int height)
Creates a new instance for a given URL. |
|
| Method Summary | |
|---|---|
protected BufferedImage |
createBufferedImage(int width,
int height)
Returns a BufferedImage using the specified width and height. |
BufferedImage |
getImage()
Renders the XML document if necessary and returns the resulting image. |
SharedContext |
getSharedContext()
Returns the SharedContext to be used by renderer. |
void |
setBufferedImageType(int bufferedImageType)
Sets the type for the BufferedImage used as output for this renderer; must be one of the values from BufferedImage allowed in that class' constructor as a type argument. |
void |
setRenderingHints(Map hints)
Sets the rendering hints to apply to the Graphics2D instance used by the renderer; see Graphics2D.setRenderingHints(java.util.Map). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Java2DRenderer(String url,
String baseUrl,
int width,
int height)
#getImage(int) is called for
the first time.
url - The location of the document to be rendered.baseurl - The base url for the document, against which relative paths are resolved.width - Target width, in pixels, for the image; required to provide horizontal bounds for the layout.
public Java2DRenderer(File file,
int width,
int height)
throws IOException
#getImage(int) is called for
the first time.
file - The file to be rendered.width - Target width, in pixels, for the image; required to provide horizontal bounds for the layout.height - Target height, in pixels, for the image
IOException
public Java2DRenderer(Document doc,
int width,
int height)
#getImage(int) is called for
the first time.
doc - The document to be rendered.width - Target width, in pixels, for the image; required to provide horizontal bounds for the layout.height - Target height, in pixels, for the image.
public Java2DRenderer(File file,
int width)
throws IOException
#getImage(int) is called for
the first time.
file - The file to be rendered.width - Target width, in pixels, for the image; required to provide horizontal bounds for the layout.
Heght is calculated based on content
IOException
public Java2DRenderer(String url,
int width)
url - The location of the document to be rendered.width - Target width, in pixels, for the image; required to provide horizontal bounds for the layout.
Heght is calculated based on content
public Java2DRenderer(String url,
String baseurl,
int width)
url - The location of the document to be rendered.baseurl - The base url for the document, against which relative paths are resolved.width - Target width, in pixels, for the image; required to provide horizontal bounds for the layout.
Heght is calculated based on content
public Java2DRenderer(String url,
int width,
int height)
url - The location of the document to be rendered.baseurl - The base url for the document, against which relative paths are resolved.width - Target width, in pixels, for the image; required to provide horizontal bounds for the layout.height - Target height, in pixels, for the image| Method Detail |
|---|
public void setRenderingHints(Map hints)
Graphics2D.setRenderingHints(java.util.Map). The Map need not specify values for all
properties; any settings in this map will be applied as override to the default settings, and will
not replace the entire Map for the Graphics2D instance.
hints - values to override in default rendering hints for Graphics2D we are rendering topublic void setBufferedImageType(int bufferedImageType)
BufferedImage allowed in that class' constructor as a type argument. See docs for
the type parameter in BufferedImage.BufferedImage(int, int, int). Defaults to RGB with
no support for transparency. The type is used when the image is first created, so to change the default type
do so before calling getImage().
bufferedImageType - the BufferedImage type to be used to create the image on which the document
will be rendered.public SharedContext getSharedContext()
getImage() is called to tune the rendering process.
public BufferedImage getImage()
#getImage(int) with the target width.
protected BufferedImage createBufferedImage(int width,
int height)
setBufferedImageType(int), or else RGB if none if specified.
width - target widthheight - target height
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||