DOMImplementation impl;
impl = (DOMImplementation)hints.get(KEY_DOM_IMPLEMENTATION);
// impl = SVGDOMImplementation.getDOMImplementation();
document = DOMUtilities.deepCloneDocument(document, impl);
if (uri != null) {
ParsedURL url = new ParsedURL(uri);
((SVGOMDocument)document).setParsedURL(url);
}
}
if (hints.containsKey(KEY_WIDTH))
width = ((Float)hints.get(KEY_WIDTH)).floatValue();
if (hints.containsKey(KEY_HEIGHT))
height = ((Float)hints.get(KEY_HEIGHT)).floatValue();
SVGOMDocument svgDoc = (SVGOMDocument)document;
SVGSVGElement root = svgDoc.getRootElement();
ctx = createBridgeContext(svgDoc);
// build the GVT tree
builder = new GVTBuilder();
// flag that indicates if the document is dynamic
boolean isDynamic =
hints.containsKey(KEY_EXECUTE_ONLOAD) &&
((Boolean)hints.get(KEY_EXECUTE_ONLOAD)).booleanValue();
GraphicsNode gvtRoot;
try {
if (isDynamic)
ctx.setDynamicState(BridgeContext.DYNAMIC);
gvtRoot = builder.build(ctx, svgDoc);
// dispatch an 'onload' event if needed
if (ctx.isDynamic()) {
BaseScriptingEnvironment se;
se = new BaseScriptingEnvironment(ctx);
se.loadScripts();
se.dispatchSVGLoadEvent();
if (hints.containsKey(KEY_SNAPSHOT_TIME)) {
float t =
((Float) hints.get(KEY_SNAPSHOT_TIME)).floatValue();
ctx.getAnimationEngine().setCurrentTime(t);
} else if (ctx.isSVG12()) {
float t = SVGUtilities.convertSnapshotTime(root, null);
ctx.getAnimationEngine().setCurrentTime(t);
}
}
} catch (BridgeException ex) {
ex.printStackTrace();
throw new TranscoderException(ex);
}
// get the 'width' and 'height' attributes of the SVG document
float docWidth = (float)ctx.getDocumentSize().getWidth();
float docHeight = (float)ctx.getDocumentSize().getHeight();
setImageSize(docWidth, docHeight);
// compute the preserveAspectRatio matrix
AffineTransform Px;
// take the AOI into account if any
if (hints.containsKey(KEY_AOI)) {
Rectangle2D aoi = (Rectangle2D)hints.get(KEY_AOI);
// transform the AOI into the image's coordinate system
Px = new AffineTransform();
double sx = width / aoi.getWidth();
double sy = height / aoi.getHeight();
double scale = Math.min(sx,sy);
Px.scale(scale, scale);
double tx = -aoi.getX() + (width/scale - aoi.getWidth())/2;
double ty = -aoi.getY() + (height/scale -aoi.getHeight())/2;
Px.translate(tx, ty);
// take the AOI transformation matrix into account
// we apply first the preserveAspectRatio matrix
curAOI = aoi;
} else {
String ref = new ParsedURL(uri).getRef();
// XXX Update this to use the animated value of 'viewBox' and
// 'preserveAspectRatio'.
String viewBox = root.getAttributeNS
(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);