use of org.apache.batik.gvt.CanvasGraphicsNode in project yamcs-studio by yamcs.
the class SVGHandler method getCanvasGraphicsNode.
protected CanvasGraphicsNode getCanvasGraphicsNode(GraphicsNode gn) {
if (!(gn instanceof CompositeGraphicsNode)) {
return null;
}
CompositeGraphicsNode cgn = (CompositeGraphicsNode) gn;
List<?> children = cgn.getChildren();
if (children.size() == 0) {
return null;
}
gn = (GraphicsNode) children.get(0);
if (!(gn instanceof CanvasGraphicsNode)) {
return null;
}
return (CanvasGraphicsNode) gn;
}
use of org.apache.batik.gvt.CanvasGraphicsNode in project yamcs-studio by yamcs.
the class SVGHandler method doRender.
protected void doRender() {
if (disposed) {
return;
}
updateMatrix();
changeColor(colorToChange, colorToApply);
gvtRoot = builder.build(bridgeContext, svgDocument);
// get the 'width' and 'height' attributes of the SVG document
float width = 400, height = 400;
float docWidth = (float) bridgeContext.getDocumentSize().getWidth();
float docHeight = (float) bridgeContext.getDocumentSize().getHeight();
if (canvasWidth > 0 && canvasHeight > 0) {
width = canvasWidth;
height = canvasHeight;
} else if (canvasHeight > 0) {
width = (docWidth * canvasHeight) / docHeight;
height = canvasHeight;
} else if (canvasWidth > 0) {
width = canvasWidth;
height = (docHeight * canvasWidth) / docWidth;
} else {
width = docWidth;
height = docHeight;
}
// compute the preserveAspectRatio matrix
AffineTransform renderingTransform = null;
AffineTransform Px = null;
SVGSVGElement root = svgDocument.getRootElement();
String viewBox = root.getAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
if (viewBox != null && viewBox.length() != 0) {
String aspectRatio = root.getAttributeNS(null, SVGConstants.SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE);
Px = ViewBox.getPreserveAspectRatioTransform(root, viewBox, aspectRatio, width, height, bridgeContext);
} else {
// no viewBox has been specified, create a scale transform
float xscale = width / docWidth;
float yscale = height / docHeight;
float scale = Math.min(xscale, yscale);
Px = AffineTransform.getScaleInstance(scale, scale);
}
Shape curAOI = new Rectangle2D.Float(0, 0, width, height);
CanvasGraphicsNode cgn = getCanvasGraphicsNode(gvtRoot);
if (cgn != null) {
cgn.setViewingTransform(Px);
renderingTransform = new AffineTransform();
} else {
renderingTransform = Px;
}
if (renderer != null) {
renderer.dispose();
renderer = null;
}
renderer = createImageRenderer();
int w = (int) (curAOI.getBounds().width + 0.5);
int h = (int) (curAOI.getBounds().height + 0.5);
renderer.updateOffScreen(w, h);
renderer.setTree(gvtRoot);
renderer.setTransform(renderingTransform);
renderer.setDoubleBuffered(false);
renderer.clearOffScreen();
renderer.repaint(curAOI);
if (updateManager != null) {
updateManager.setGVTRoot(gvtRoot);
}
needRender = false;
}
Aggregations