if (log.isDebugEnabled()) {
log.debug("Generating SVG at " + deviceResolution + "dpi.");
}
final float uaResolution = userAgent.getSourceResolution();
SVGUserAgent ua = new SVGUserAgent(userAgent, new AffineTransform());
//Scale for higher resolution on-the-fly images from Batik
double s = uaResolution / deviceResolution;
AffineTransform resolutionScaling = new AffineTransform();
resolutionScaling.scale(s, s);
//Controls whether text painted by Batik is generated using text or path operations
boolean strokeText = false;
Configuration cfg = pdfInfo.cfg;
if (cfg != null) {
strokeText = cfg.getChild("stroke-text", true).getValueAsBoolean(strokeText);
}
BridgeContext ctx = new PDFBridgeContext(ua,
(strokeText ? null : pdfInfo.fi),
userAgent.getFactory().getImageManager(),
userAgent.getImageSessionContext(),
new AffineTransform());
//Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine)
//to it.
Document clonedDoc = BatikUtil.cloneSVGDocument(doc);
GraphicsNode root;
try {
GVTBuilder builder = new GVTBuilder();
root = builder.build(ctx, clonedDoc);
} catch (Exception e) {
SVGEventProducer eventProducer = SVGEventProducer.Provider.get(
context.getUserAgent().getEventBroadcaster());
eventProducer.svgNotBuilt(this, e, getDocumentURI(doc));
return;
}
// get the 'width' and 'height' attributes of the SVG document
float w = (float)ctx.getDocumentSize().getWidth() * 1000f;
float h = (float)ctx.getDocumentSize().getHeight() * 1000f;
float sx = pdfInfo.width / w;
float sy = pdfInfo.height / h;
//Scaling and translation for the bounding box of the image
AffineTransform scaling = new AffineTransform(
sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f);
//Transformation matrix that establishes the local coordinate system for the SVG graphic
//in relation to the current coordinate system
AffineTransform imageTransform = new AffineTransform();
imageTransform.concatenate(scaling);
imageTransform.concatenate(resolutionScaling);
/*
* Clip to the svg area.
* Note: To have the svg overlay (under) a text area then use
* an fo:block-container