Hi all, Involved in a big C++ software project (virtual reality engine) I tried to integrate batik into our system for real-time svg rendering (as it is the only working open-source svg renderer available - to my knowledge anyway - if you know better, PLEASE inform me, thx !).
Therefore I used JNI to bridge batik to our system. I have create an "SVGLayer" Java class (right, the name is not very pertinent... :) It was just a prototype...) which uses batik to load an svg document (in its constructor) and render it inside a "scene" area, based on a given scale, rotation, position in the scene and global scene dimensions. To do that, it will compute the exact shape of the rendering result, in the scene coord space (by scaling/rotating/translating the svg document's rectangular bounding box, then clipping the resulting bounding box wrt. the scene boundaries) and apply to that shape the inverse transform, which gives the area to be rendered, in the svg document coord space (thanks to this, only the effectively visible part of the svg doc will be rendered). Finally the rendering buffer can be retrieved (dimensions and data) as an int array (32-bit RGBA pixels) so you can use it in any other software to blend it in your own creations, for instance. Unfortunately for us, the performance is far from enough for our needs. But I hope it can at least help someone else ! ;) Here is the SVGLayer's class javadoc + the source file. If you are interested, I can also send a C++ sample prog showing how to use it through JNI (it works fine but it needs some extra reformatting work, so I'll do it only if there is interest for it). The good news is that JNI data transfer doesn't diminish overall performance that much, so it is pretty usable and fast if you don't need a high real-time framerate. And of course you get the excellent batik rendering quality (antialiasing etc.) ! BTW, it is not designed to support dynamic svg docs (scripting, animations,...) so I really don't know what happens if you run it on one of those... Hope this helps, any comments, suggestions, critics, requests for additional details, build scripts... welcome ! See ya, Willy. Xavier Wielemans - alterface http://www.alterface.com
SVGLayer.java
Description: Binary data
com.alterface.scenario
|
Constructor Summary | |
SVGLayer(java.lang.String svgFile)
Constructs a new SVGLayer. |
Method Summary | |
int |
getDataBufferHeight()
Gets REAL data buffer height. |
int |
getDataBufferWidth()
Gets REAL data buffer width. |
int |
getDataBufferXOffset()
Gets data buffer offset in the X direction. |
int |
getDataBufferYOffset()
Gets the layer's data buffer offset in the Y direction. |
int |
getDocHeight()
Gets the document height |
int |
getDocWidth()
Gets the document width |
int |
getImgHeight()
Gets the current rendered image height |
int |
getImgWidth()
Gets the current rendered image width |
int |
getImgXOffset()
Gets image offset in the X direction. |
int |
getImgYOffset()
Gets image offset in the Y direction. |
static void |
main(java.lang.String[] args)
Main method (for testing purposes only) |
int[] |
render()
Renders the SVG layer. |
void |
setRotation(double angle)
Sets the layer's rotation angle |
void |
setScale(java.awt.geom.Point2D.Double scale)
Sets the layer's scale |
void |
setScenePosition(java.awt.Point position)
Sets the layer position in the scene. |
void |
setSceneSize(java.awt.Point size)
Sets the scene size. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
SVGLayer
public SVGLayer(java.lang.String svgFile)
- Constructs a new SVGLayer.
- Parameters:
svgFile
- source file containing the SVG description
Method Detail |
main
public static final void main(java.lang.String[] args)
- Main method (for testing purposes only)
setScale
public void setScale(java.awt.geom.Point2D.Double scale)
- Sets the layer's scale
- Parameters:
scale
- the new x/y scale at which the layer is to be rendered
setRotation
public void setRotation(double angle)
- Sets the layer's rotation angle
- Parameters:
angle
- the new rotation angle at which the layer is to be rendered
setSceneSize
public void setSceneSize(java.awt.Point size)
- Sets the scene size.
This information, along with the scene position of the layer, will be used
to clip document shape so that only visible parts will actually be rendered.
- Parameters:
size
- the new x/y size of the scene in which the svg document is to be rendered.
setScenePosition
public void setScenePosition(java.awt.Point position)
- Sets the layer position in the scene.
This information, along with the scene size, will be used
to clip document shape so that only visible parts will actually be rendered.
- Parameters:
position
- the new x/y position of the document's center point in the scene.
getDocWidth
public int getDocWidth()
- Gets the document width
- Returns:
- the source document's width (as an int)
getDocHeight
public int getDocHeight()
- Gets the document height
- Returns:
- the source document's layer's height (as an int)
getImgWidth
public int getImgWidth()
- Gets the current rendered image width
- Returns:
- the current width of the rendered image, taking into account current scale/rotation, scene size and scene position.
getImgHeight
public int getImgHeight()
- Gets the current rendered image height
- Returns:
- the current height of the rendered image, taking into account current scale/rotation, scene size and scene position.
getDataBufferWidth
public int getDataBufferWidth()
- Gets REAL data buffer width.
The data buffer is often actually larger than the image !
In that case, the data buffer offset indicates the X/Y translation
between top-left corners of image and data buffer.
so that both origins match.
NB: updated at each rendering.
- Returns:
- the actual width of the data buffer returned by 'render()'.
getDataBufferHeight
public int getDataBufferHeight()
- Gets REAL data buffer height.
The data buffer is often actually larger than the image !
In that case, the data buffer offset indicates the X/Y translation
between top-left corners of image and data buffer.
NB: updated at each rendering.
- Returns:
- the actual height of the data buffer returned by 'render()'.
getDataBufferXOffset
public int getDataBufferXOffset()
- Gets data buffer offset in the X direction.
It is equal to the X position of the image top-left corner pixel
in the data buffer.
NB: updated at each rendering.
- Returns:
- the image X offset into the data buffer
getDataBufferYOffset
public int getDataBufferYOffset()
- Gets the layer's data buffer offset in the Y direction.
It is equal to the Y position of the image top-left corner pixel
in the data buffer.
NB: updated at each rendering.
- Returns:
- the image Y offset into the data buffer
getImgXOffset
public int getImgXOffset()
- Gets image offset in the X direction.
It is equal to the X position of the document center
in the image.
NB: updated at each rendering.
- Returns:
- the document center X offset into the image
getImgYOffset
public int getImgYOffset()
- Gets image offset in the Y direction.
It is equal to the Y position of the document center
in the image.
NB: updated at each rendering.
- Returns:
- the document center Y offset into the image
render
public int[] render()
- Renders the SVG layer.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]