|Export to Image - negative coordinates problem [message #897985]
||Wed, 25 July 2012 14:48
| Alexandre Torres
Registered: July 2009
Hi, I want to export the entire diagram to JPG or BMP formats. I followed the tips on http://blog.eclipse-tips.com/2008/03/exporting-gef-figure-to-image.html|
The first problem I faced was the clipping. This export method applied to my GraphicalEditorWithFlyoutPalette only exports the visible part of my diagram.
I find out an workaround, by setting the bounds of the graphical Viewer figure to the bounds of the PRINTABLE_LAYERS figure before exporting.
It works fine to what is beyond the printing window. But if I have any figure on negative x or y, it will not be exported.
So, what I can't figure out is how to translate the exporting window so that the entire printable area will be printed. I tried to translate the Printable layer (rootFigure variable) but with no success.
I noticied that if I scroll the figure, by hand, to (0,0) before exporting, it works fine BUT it exports the scroll bars...
ScrollingGraphicalViewer graphicalViewer= ...
String saveLocation= ...
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) graphicalViewer.getEditPartRegistry().get(LayerManager.ID);
IFigure rootFigure = ((LayerManager) rootEditPart).getLayer( LayerConstants.PRINTABLE_LAYERS);
Rectangle rootFigureBounds = rootFigure.getBounds();
Control figureCanvas = graphicalViewer.getControl();
// ENLARGE figureCanvas
org.eclipse.swt.graphics.Rectangle scBounds = figureCanvas.getBounds(); // store original
org.eclipse.swt.graphics.Rectangle swRect = new org.eclipse.swt.graphics.Rectangle(rootFigureBounds.x,rootFigureBounds.y,rootFigureBounds.width,rootFigureBounds.height);
figureCanvas.setBounds(swRect); // I guess that negative x,y will not work for SWT control
// Back to the original code
Image img = new Image(Display.getDefault(), rootFigureBounds.width, rootFigureBounds.height); // tried to enlarge this with no success
//Image img = new Image(Display.getDefault(), swRect); //this won't work either
GC imageGC = new GC(img);
ImageLoader imgLoader = new ImageLoader();
// restore the bounds
I think I'm really close... anyone knows what is missing?
Powered by FUDForum
. Page generated in 0.01682 seconds