Community
Participate
Working Groups
Build Identifier: Graphity Images never scale the contained org.eclipse.swt.graphics.Image to fit the given Bounds of the Graphiti Image. Instead the org.eclipse.swt.graphics.Image is clipped at the Graphiti Image's bounds. This is even the case if StretchH and/or StretchV of the Image is set to true Reproducible: Always Steps to Reproduce: 1. Create an Image with StretchH and StretchV = true 2. Resize the Image 3.
Resizing of images was never requested before, that might be the reason for the absence of an implementation in class PictogramElementDelegate. Unfortunately the SWT class Image itself offers no solution, but there are articles with workarounds: http://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Scaling http://www.eclipse.org/articles/Article-Image-Viewer/Image_viewer.html http://aniszczyk.org/2007/08/09/resizing-images-using-swt/ They are all based on newly created (scaled) images. Ambitious solutions should avoid nasty flickering, which is discussed as well.
Out-of-scope for Juno, unless there are contributions in this area
I had a little time. Following this http://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Scaling I was able to create a resizing Image. I don't think it is wise to provide my solution as a patch because I made it work without patching the graphiti api by using a subclass of PlatformGraphicsAlgorithm to insert ScalingGFImageFigure as a Subclass of GFImageFigure. Currently the ScalingGFImageFigure always scales proportionally. But I can come up wit a version that respects Strech and Proportional setting easily if needed. Currently ScalingGFImageFigure looks like that: import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; import org.eclipse.graphiti.platform.ga.IGraphicsAlgorithmRenderer; import org.eclipse.graphiti.ui.internal.figures.GFImageFigure; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.widgets.Display; public class ScalingGFImageFigure extends GFImageFigure implements IGraphicsAlgorithmRenderer { private GraphicsAlgorithm localGA; public ScalingGFImageFigure(GraphicsAlgorithm graphicsAlgorithm) { super(graphicsAlgorithm); // copy because ga is private in super class this.localGA = graphicsAlgorithm; } @Override public void setImage(Image image) { if (image != null) { // get image data form default image ImageData fullImageData = image.getImageData(); //scale according to size of ga int width = fullImageData.width; int height = fullImageData.height; double scalefactorX = (double) localGA.getWidth() / (double) width; double scalefactorY = (double) localGA.getHeight() / (double) height; double actualScalefactor = 0; if (scalefactorX < scalefactorY) { actualScalefactor = scalefactorX; } else { actualScalefactor = scalefactorY; } // create scaled image Image fillImage = new Image(Display.getCurrent(), fullImageData.scaledTo((int) (width * actualScalefactor), (int) (height * actualScalefactor))); super.setImage(fillImage); } else { super.setImage(image); } } }
(In reply to comment #3) > I had a little time. > Following this > http://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Scaling > I was able to create a resizing Image. > > I don't think it is wise to provide my solution as a patch because I made it > work without patching the graphiti api by using a subclass of > PlatformGraphicsAlgorithm to insert ScalingGFImageFigure as a Subclass of > GFImageFigure. > Currently the ScalingGFImageFigure always scales proportionally. But I can come > up wit a version that respects Strech and Proportional setting easily if > needed. > Veit, this looks really good from having a first look. Would anything speak against building that directly into GFImageFigure, so all users would benefit? If not, would you provide that as a patch to GFIMageFigure (maybe extended with stretch and proportional)? Thanks, Michael
Created attachment 209798 [details] Images Example
Created attachment 209799 [details] Scaling GFImageFigure Patch against 0.9.0
Hi Michael, here's the requested Patch. The GFImageFigure now respects the settings in strech and proportional. The Example tries to indicate the behavior for different settings. Feel free to come back to me for any questions. Cheers, Veit
Veit, thanks for this contribution! I have check-in the changes to master and pushed it to Eclipse. - Patch for the new functionality: commit 8771b53919d45a6cf9de2d71dd8901a5ceec29ea Author: mwenz <michael.wenz@sap.com> 2012-01-20 16:08:58 Committer: mwenz <michael.wenz@sap.com> 2012-01-20 16:08:58 Parent: e7801ef2bcd27a2b0d7b24e91975f51485a5345a (Bug 368146: Exception during SVG export - enable rotating an ellipse) Child: 9601eca7fc0b9f40dba54d6f6de24ecb2d402ffe (Bug 342869 - Added sample in Sketch) Branches: origin/master, master - Test functionality in Sketch tool: commit 9601eca7fc0b9f40dba54d6f6de24ecb2d402ffe Author: mwenz <michael.wenz@sap.com> 2012-01-23 16:51:29 Committer: mwenz <michael.wenz@sap.com> 2012-01-23 16:51:29 Parent: 8771b53919d45a6cf9de2d71dd8901a5ceec29ea (Bug 342869 - Applied patch) Child: a6f98cbd47f586cc5802c63ee665af272bb0b77e (Bug 342869 - Updated headers) Branches: origin/master, master
Is O.K.
Bookkeeping: Set target release
Part of Graphiti 0.9.0 (Eclipse Juno)