[PoC] Implement a SVGGraphics for exporting figures to SVG#952
[PoC] Implement a SVGGraphics for exporting figures to SVG#952ptziegler wants to merge 1 commit intoeclipse-gef:masterfrom
Conversation
75c8a26 to
f141637
Compare
| FontData fd = font.getFontData()[0]; | ||
| int height = fd.getHeight(); | ||
| if (DPI != 72) { | ||
| height = fd.getHeight() * DPI / 72; | ||
| } |
There was a problem hiding this comment.
This seems to be the inverse of #944. A DPI of 72 is the default for SVGs, so we need to scale the SWT font. Otherwise texts appear too small, just like what you can see in the initial screenshot.
d5a734b to
064039b
Compare
| private void updateSize(Shape shape) { | ||
| Shape transformed = currentState.affineTransform.createTransformedShape(shape); | ||
| documentSize.add(transformed.getBounds2D()); | ||
| gc.setSVGCanvasSize(documentSize.getSize()); | ||
| } |
There was a problem hiding this comment.
I'm not quite sure if there's a better way to keep track of the actual size of the SVG document. The problem: If no size is specified, the root node will be initialized with size 300x150. When creating an SWT image using this SVG, its size will also be 300x150.
064039b to
c773b47
Compare
|
@ptziegler do you think this or any extended SVG support could be something for a Google Summer of Code project or are you in principle done and within a few hours this is completed? |
…f#952 This creates a new org.eclipse.draw2d.svg project that allows the user to export the contents of a FigureCanvas directly to an SVG.
c773b47 to
4f334c6
Compare
…f#952 This creates a new org.eclipse.draw2d.svg project that allows the user to export the contents of a FigureCanvas directly to an SVG.
4f334c6 to
14d6cbc
Compare
|
@azoitl You can get a rough idea of the missing functionality by looking at which methods in I think the much more time-consuming task will be testing all of this. I've already started with the simple example that covers a lot of the possible combinations. But there are also the unit-tests that need to be finished. I'm also not sure if this is really a rewarding topic for a student... There are a lot of steps you need to take before you can even see anything. And then you need to somehow verify whether the generated SVG is actually correct. Just look at the hurdles in my example, where I created the SVG, converted the SVG to an SWT image and then drew the image. |
…f#952 This creates a new org.eclipse.draw2d.svg project that allows the user to export the contents of a FigureCanvas directly to an SVG.
14d6cbc to
945017d
Compare
|
To be honest I haven't up to now not looked at your code. But you are right as you are already so far this is not a good topic for a GSoC project. Not sure if this is the right place to discuss but would the opposite be something: An SVG Figure that would draw an SVG using gc primitives or even turn it into figures/editparts? |
So you want to parse the SVG and then create "SVG" figures for all elements in this document? Conceptually, this shouldn't be a problem. But to me that sounds like an "SVG Editor" and not something that really fits into this PR. Perhaps this is something that could be turned into a new example editor? The "Shapes" editor does something similar, right? You'd "only" need to swap out the persistence layer and add some SVG code generation for the shapes and then you're already on a good track. At least this part should fit into the scope of a GSoC project. WindowBuilder does something similar, except that we have a Swing/SWT container as source. So it's definitely possible. |
|
I think I was not clear I didn't mean to create an SVG output using SVG. But using SVGs as base for edit parts and figures but not to render them to an image but draw them with Draw 2d as you may would do it in a web-based editor. |
|
So you still want to parse the SVG. But instead of each figure storing e.g. a screenshot of the SVG object, you want to extract the attributes and then convert them into something our could be represented as a That would probably work as well. I just have some minor concerns about whether all cases are as simple as that. At the very least, the challenge should be limited to a fixed number of supported shapes. Otherwise that can easily spiral out of control when trying to support all possible ways you can abuse an SVG. |
|
@ptziegler yes this is what I had in mind. But most probably SVG has to much that would not map well to Draw2d/SWT so I'm not sure if it is a good idea. I created a discussion for GSoC to not create not more noise here. |

This creates a new org.eclipse.draw2d.svg project that allows the user to export the contents of a
FigureCanvasdirectly to an SVG.