use of org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo in project tmdmaker by tmdmaker.
the class GraphicsToGraphics2DAdaptor method drawRenderedImage.
/* (non-Javadoc)
* @see org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.DrawableRenderedImage#drawRenderedImage(org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage, org.eclipse.draw2d.geometry.Rectangle, org.eclipse.gmf.runtime.draw2d.ui.render.RenderingListener)
*/
public RenderedImage drawRenderedImage(RenderedImage srcImage, Rectangle rect, RenderingListener listener) {
RenderInfo info = srcImage.getRenderInfo();
info.setValues(rect.width, rect.height, info.shouldMaintainAspectRatio(), info.shouldAntiAlias(), info.getBackgroundColor(), info.getForegroundColor());
RenderedImage img = srcImage.getNewRenderedImage(info);
BufferedImage bufImg = (BufferedImage) img.getAdapter(BufferedImage.class);
if (bufImg == null) {
bufImg = ImageConverter.convert(img.getSWTImage());
}
// Translate the Coordinates
int x = rect.x + transX;
int y = rect.y + transY + rect.height - bufImg.getHeight();
checkState();
getGraphics2D().drawImage(bufImg, new AffineTransform(1f, 0f, 0f, 1f, x, y), null);
return img;
}
use of org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo in project tmdmaker by tmdmaker.
the class GraphicsSVG method drawRenderedImage.
/* (non-Javadoc)
* @see org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor#drawRenderedImage(org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage, org.eclipse.draw2d.geometry.Rectangle, org.eclipse.gmf.runtime.draw2d.ui.render.RenderingListener)
*/
public RenderedImage drawRenderedImage(RenderedImage srcImage, Rectangle rect, RenderingListener listener) {
// Check for a change in the state
checkState();
// Get the Tree Manager
DOMTreeManager treeManager = getSVGGraphics2D().getDOMTreeManager();
Point trans = getTranslationOffset();
// Get the Root element of the SVG document to export
if (srcImage instanceof SVGImage) {
Document document = ((SVGImage) srcImage).getDocument();
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
document = DOMUtilities.deepCloneDocument(document, impl);
if (document instanceof SVGOMDocument) {
RenderInfo info = srcImage.getRenderInfo();
if (info != null && info.getBackgroundColor() != null && info.getForegroundColor() != null) {
SVGColorConverter.getInstance().replaceDocumentColors((SVGOMDocument) document, new Color(info.getBackgroundColor().red, info.getBackgroundColor().green, info.getBackgroundColor().blue), new Color(info.getForegroundColor().red, info.getForegroundColor().green, info.getForegroundColor().blue));
}
}
Element root = document.getDocumentElement();
// Create a "deep" copy of the document
Element toAppend = (Element) doc.importNode(root, true);
// Modify the X Attribute
toAppend.setAttributeNS(null, SVGConstants.SVG_X_ATTRIBUTE, String.valueOf(rect.x + trans.x));
// Modify the Y Attribute
toAppend.setAttributeNS(null, SVGConstants.SVG_Y_ATTRIBUTE, String.valueOf(rect.y + trans.y));
// Modify the Width Attribute
toAppend.setAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE, String.valueOf(rect.width));
// Modify the Height Attribute
toAppend.setAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE, String.valueOf(rect.height));
treeManager.appendGroup(toAppend, null);
return srcImage;
} else {
return super.drawRenderedImage(srcImage, rect, listener);
}
}
Aggregations