/** * Should be called when SVG document has been changed. It will be re-rendered and figure will be * repainted. */ public void contentChanged() { getDocument(); if (transcoder != null) { transcoder.contentChanged(); } repaint(); }
public void setAreaOfInterest(Rectangle2D value) { getDocument(); if (transcoder != null) { transcoder.setCanvasAreaOfInterest(value); } repaint(); }
protected final Document getDocument() { if (failedToLoadDocument) { return null; } if (transcoder == null) { loadDocument(); } return transcoder == null ? null : transcoder.getDocument(); }
@Override protected void paintFigure(Graphics graphics) { super.paintFigure(graphics); Document document = getDocument(); if (document == null) { return; } Image image = null; try { Rectangle r = getClientArea(); transcoder.setCanvasSize( specifyCanvasWidth ? r.width : -1, specifyCanvasHeight ? r.height : -1); updateRenderingHints(graphics); BufferedImage awtImage = transcoder.getBufferedImage(); if (awtImage != null) { image = toSWT(Display.getCurrent(), awtImage); graphics.drawImage(image, r.x, r.y); } } finally { if (image != null) { image.dispose(); } } }
/** Reads color value from the document. */ protected Color getColor(Element element, String attributeName) { if (getDocument() == null || getDocument() != element.getOwnerDocument()) { return null; } Color color = null; // Make sure that CSSEngine is available. BridgeContext ctx = transcoder.initCSSEngine(); try { color = SVGUtils.toSWTColor(element, attributeName); } finally { if (ctx != null) { ctx.dispose(); } } return color; }
private void updateRenderingHints(Graphics graphics) { { int aa = SWT.DEFAULT; try { aa = graphics.getAntialias(); } catch (Exception e) { // not supported } Object aaHint; if (aa == SWT.ON) { aaHint = RenderingHints.VALUE_ANTIALIAS_ON; } else if (aa == SWT.OFF) { aaHint = RenderingHints.VALUE_ANTIALIAS_OFF; } else { aaHint = RenderingHints.VALUE_ANTIALIAS_DEFAULT; } if (transcoder.getRenderingHints().get(RenderingHints.KEY_ANTIALIASING) != aaHint) { transcoder.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, aaHint); transcoder.contentChanged(); } } { int aa = SWT.DEFAULT; try { aa = graphics.getTextAntialias(); } catch (Exception e) { // not supported } Object aaHint; if (aa == SWT.ON) { aaHint = RenderingHints.VALUE_TEXT_ANTIALIAS_ON; } else if (aa == SWT.OFF) { aaHint = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; } else { aaHint = RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT; } if (transcoder.getRenderingHints().get(RenderingHints.KEY_TEXT_ANTIALIASING) != aaHint) { transcoder.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, aaHint); transcoder.contentChanged(); } } }
public final Rectangle2D getAreaOfInterest() { getDocument(); return transcoder == null ? null : transcoder.getCanvasAreaOfInterest(); }