}
SVGUserAgent ua = new SVGUserAgent(
pxToMillimeter,
new AffineTransform());
GVTBuilder builder = new GVTBuilder();
final BridgeContext ctx = new BridgeContext(ua);
//Build the GVT tree
final GraphicsNode root;
try {
root = builder.build(ctx, svg.getDocument());
} catch (Exception e) {
throw new ImageException("GVT tree could not be built for SVG graphic", e);
}
//Create the painter
Graphics2DImagePainter painter = new Graphics2DImagePainter() {
public void paint(Graphics2D g2d, Rectangle2D area) {
// If no viewbox is defined in the svg file, a viewbox of 100x100 is
// assumed, as defined in SVGUserAgent.getViewportSize()
float iw = (float) ctx.getDocumentSize().getWidth();
float ih = (float) ctx.getDocumentSize().getHeight();
float w = (float) area.getWidth();
float h = (float) area.getHeight();
g2d.translate(area.getX(), area.getY());
g2d.scale(w / iw, h / ih);