Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 442268

Summary: SVG images not properly displayed
Product: [Modeling] Sirius Reporter: Emmanuel Billaud <billaud.emmanuel>
Component: DiagramAssignee: Pierre-Charles David <pierre-charles.david>
Status: CLOSED FIXED QA Contact: Florian Barbin <florian.barbin>
Severity: normal    
Priority: P3 CC: florian.barbin, jessy.mallet, laurent.redor, pierre-charles.david
Version: 1.0.0Keywords: triaged
Target Milestone: 4.0.0   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/64731
https://git.eclipse.org/r/64733
https://git.eclipse.org/r/66132
https://git.eclipse.org/r/66131
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=bb031978234dcdfb85512d67640b1e063870a9cb
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=3406ee32a1f643604bdcf998aee00a16f2690fda
https://git.eclipse.org/r/66317
https://git.eclipse.org/r/66316
https://git.eclipse.org/r/66315
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=84c5183ef0e3296da08828a2b1ed48db7d05ca26
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=208418a8db5681c36c52800da01163464e589409
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=a37147db68ae3003c9d379b2411dad96244d9d12
https://git.eclipse.org/r/66906
https://git.eclipse.org/r/66905
https://git.eclipse.org/r/66904
https://git.eclipse.org/r/66903
https://git.eclipse.org/r/66928
https://git.eclipse.org/r/66927
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=aec781c3deb92d7659512ffdcc8b3dc5d97030e1
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=47e7573e73d4a130b74f3d1e03ed51a905e7d119
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=a4ce04159734e26350ff87408932216500e0ddb0
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=c008499e5956922de4d7091e890222b62eb4f979
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=36ccc7b9f424913c5197af9148d24b9acbf80c30
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=ffd657406aa9f5d2fbfa67e6b422d1e0e1e15052
https://git.eclipse.org/r/67063
https://git.eclipse.org/r/67062
https://git.eclipse.org/r/67061
https://git.eclipse.org/r/67066
https://git.eclipse.org/r/67069
https://git.eclipse.org/r/67068
https://git.eclipse.org/r/67067
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=08dcd2af0d5d69d65a505278b14439656dc19a55
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=69ab78cbbeee444e3592898637d983272f15cf63
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=89aaf8ac55fb02d2e0007a4a26a42f10d2706c45
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=a7ecf8f13b7ecd7d4b17ef288a89965dc4c35657
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=026e070ad198948a5d776c3e631d71ae0ac63b07
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=c530ac267dcf8e7779fbc06e4c710fa397d488b7
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=c024e70ab53d41e7c8c2f4665999c6cad3be0d74
https://git.eclipse.org/r/68151
https://git.eclipse.org/r/68150
https://git.eclipse.org/r/68149
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=64c89ccdd9352a18cf481a964c6c4a6b5f1b4deb
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=4c5e96f4b45919ccbba25eafdf56f9077fe1bbde
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=8e89137623cfab73e00a871685a977b2443ddd57
https://git.eclipse.org/r/70349
https://git.eclipse.org/r/70348
https://git.eclipse.org/r/70350
https://git.eclipse.org/r/70484
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=5f957f75c7fb8c8a632b0a90047096eee4975dc2
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=7b763b843f91c6c591ae91653eb429d5917665f2
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=7a5b79b6415e87b1bffc071440bf2ce2f679c3b6
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=e7db12d5b124a33ec7cc9bf986b39d923ecae829
Whiteboard:
Attachments:
Description Flags
Project and patch
none
Correctly formatted patch none

Description Emmanuel Billaud CLA 2014-08-21 10:07:55 EDT
Created attachment 246207 [details]
Project and patch

On the diagram, at zoom > 100%, the rendering of a SVG file is equivalent to a PNG file.
I'm working on eclipse Kepler.

To reproduce this bug, I used the get-started project, with the current head of git repository (e4ee76).
Attachments :
* man.svg : the svg to copy in the 'icons' folder of the plug-in 'org.eclipse.sirius.sample.basicfamily.design' ;
* basicfamily.odesign : the design modified to take into account the SVG ;
* SvgProject : a basic project to show the problem ;
* SVG.patch : a proposition of correction.


What happens ?
In the 'paintFigure' method of the 'AbstractCachedSVGFigure' class (package org.eclipse.sirius.diagram.ui.tools.api.figure), the image to display is retrieve from cached images. But, the 'getClientArea()' method returns always the same value (zoom is not taken into account) : the image is always the same.

By considering the scale (getContextKey and getCachedImage), the image is good.
By changing the drawImage to call on graphics, the image is correctly positionned on the diagram (the former one did the scaling, so the image had a good size, but a bad 'resolution').

For me, this is a hack, and I have the feeling that getClientArea shall return a Rectangle with scale taken into account. Am I wrong ?

Note :
When exporting diagram as SVG file, the SVG images are drawn like PNG. It seems that the method in charge of copying the image (CopyToImageUtil.copyToImage(DiagramEditPart, IPath, ImageFileFormat, IProgressMonitor)) uses the 'paintFigure' method instead of using the SVG file. But this is GMF code.
Comment 1 Laurent Redor CLA 2014-08-25 08:55:11 EDT
The patch is not well formated (inverse patch). To facilitate the review process, I wanted to create a gerrit, with you as author but it's not possible: 
"error: The author does not have a Gerrit account.
All authors must either be a commiter on the project, or have a current CLA on file.
Please see http://wiki.eclipse.org/CLA"

Is it possible for you to create this gerrit commit? It's not mandatory, but it simplifies the "patch" application to test it.

The problem of your solution is that the memory footprint can be strongly impacted (one image cache by SVG by zoom level).
Comment 2 Emmanuel Billaud CLA 2014-08-25 10:32:23 EDT
Created attachment 246315 [details]
Correctly formatted patch
Comment 3 Pierre-Charles David CLA 2014-12-11 07:57:02 EST
Related to this, it seems that GMF Tooling has a figure here:

http://git.eclipse.org/c/gmf-tooling/org.eclipse.gmf-tooling.git/tree/plugins/org.eclipse.gmf.runtime.lite.svg/src/org/eclipse/gmf/runtime/lite/svg/SVGFigure.java

which, from a quick reading of the code (I have not tested it) re-renders the SVG itself on each Draw2D paintFigure() call. This would avoid having to deal with a cache, at the cost of runtime performance. Only actual tests and measures on concrete cases could tell us which approach is best.

It may be possible to test this without touching Sirius itself by using the existing extension points to provide a custom edit part which uses this specific figure implementation.
Comment 4 Jessy Mallet CLA 2015-01-21 11:49:30 EST
currently working on it
Comment 5 Pierre-Charles David CLA 2015-09-22 04:19:50 EDT
I've restarted work on this in the last few days, and have some preliminary results (not published anywhere yet). Unfortunately a real, complete solution which takes all the trade-offs into account (rendering quality, rendering time, memory consumption) is more impacting and risky that what we can push this late in the cycle. We may push a fix for an SWT resource leak detected while working on this code, but the actual improvement of SVG rendering will have to wait.
Comment 6 Eclipse Genie CLA 2016-01-20 03:27:40 EST
New Gerrit change created: https://git.eclipse.org/r/64731
Comment 7 Eclipse Genie CLA 2016-01-20 03:40:52 EST
New Gerrit change created: https://git.eclipse.org/r/64733
Comment 8 Eclipse Genie CLA 2016-02-08 10:23:40 EST
New Gerrit change created: https://git.eclipse.org/r/66132
Comment 9 Eclipse Genie CLA 2016-02-08 10:23:43 EST
New Gerrit change created: https://git.eclipse.org/r/66131
Comment 12 Eclipse Genie CLA 2016-02-10 11:10:17 EST
New Gerrit change created: https://git.eclipse.org/r/66317
Comment 13 Eclipse Genie CLA 2016-02-10 11:10:19 EST
New Gerrit change created: https://git.eclipse.org/r/66316
Comment 14 Eclipse Genie CLA 2016-02-10 11:10:20 EST
New Gerrit change created: https://git.eclipse.org/r/66315
Comment 18 Eclipse Genie CLA 2016-02-19 05:36:57 EST
New Gerrit change created: https://git.eclipse.org/r/66906
Comment 19 Eclipse Genie CLA 2016-02-19 05:37:01 EST
New Gerrit change created: https://git.eclipse.org/r/66905
Comment 20 Eclipse Genie CLA 2016-02-19 05:37:03 EST
New Gerrit change created: https://git.eclipse.org/r/66904
Comment 21 Eclipse Genie CLA 2016-02-19 05:37:05 EST
New Gerrit change created: https://git.eclipse.org/r/66903
Comment 22 Eclipse Genie CLA 2016-02-19 09:12:15 EST
New Gerrit change created: https://git.eclipse.org/r/66928
Comment 23 Eclipse Genie CLA 2016-02-19 09:12:17 EST
New Gerrit change created: https://git.eclipse.org/r/66927
Comment 30 Eclipse Genie CLA 2016-02-22 10:13:47 EST
New Gerrit change created: https://git.eclipse.org/r/67063
Comment 31 Eclipse Genie CLA 2016-02-22 10:13:51 EST
New Gerrit change created: https://git.eclipse.org/r/67062
Comment 32 Eclipse Genie CLA 2016-02-22 10:13:52 EST
New Gerrit change created: https://git.eclipse.org/r/67061
Comment 33 Eclipse Genie CLA 2016-02-22 10:20:09 EST
New Gerrit change created: https://git.eclipse.org/r/67066
Comment 34 Eclipse Genie CLA 2016-02-22 10:20:12 EST
New Gerrit change created: https://git.eclipse.org/r/67069
Comment 35 Eclipse Genie CLA 2016-02-22 10:20:13 EST
New Gerrit change created: https://git.eclipse.org/r/67068
Comment 36 Eclipse Genie CLA 2016-02-22 10:20:15 EST
New Gerrit change created: https://git.eclipse.org/r/67067
Comment 44 Eclipse Genie CLA 2016-03-10 09:03:40 EST
New Gerrit change created: https://git.eclipse.org/r/68151
Comment 45 Eclipse Genie CLA 2016-03-10 09:03:46 EST
New Gerrit change created: https://git.eclipse.org/r/68150
Comment 46 Eclipse Genie CLA 2016-03-10 09:03:54 EST
New Gerrit change created: https://git.eclipse.org/r/68149
Comment 50 Eclipse Genie CLA 2016-04-11 05:47:30 EDT
New Gerrit change created: https://git.eclipse.org/r/70349
Comment 51 Eclipse Genie CLA 2016-04-11 05:47:36 EDT
New Gerrit change created: https://git.eclipse.org/r/70348
Comment 52 Eclipse Genie CLA 2016-04-11 05:47:38 EDT
New Gerrit change created: https://git.eclipse.org/r/70350
Comment 53 Eclipse Genie CLA 2016-04-12 11:14:15 EDT
New Gerrit change created: https://git.eclipse.org/r/70484
Comment 58 Pierre-Charles David CLA 2016-04-18 04:09:05 EDT
Fixed.

There are some issues with Batik mis-handling some SVG files, but there are not introduced by this change, they are just more easily triggered once you use more SVGs. Not sure we can do anything about it though, except try to understand better what kind of SVG features make Batik crash and document it.

A new system property has been added, org.eclipse.sirius.diagram.ui.svg.maxCacheSizeMB, to configure the maximum size (in MB) to use to cache pre-rendered SVGs. The current default value is 50, which means 50MB. The default value and the configuration mechanism itself may change before the final release.
Comment 59 Pierre-Charles David CLA 2016-06-24 08:02:54 EDT
Available in Sirius 4.0.0.