Skip to content

[PoC] Implement a SVGGraphics for exporting figures to SVG#952

Draft
ptziegler wants to merge 1 commit intoeclipse-gef:masterfrom
ptziegler:svg-graphics
Draft

[PoC] Implement a SVGGraphics for exporting figures to SVG#952
ptziegler wants to merge 1 commit intoeclipse-gef:masterfrom
ptziegler:svg-graphics

Conversation

@ptziegler
Copy link
Copy Markdown
Contributor

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

@ptziegler
Copy link
Copy Markdown
Contributor Author

image

@ptziegler ptziegler force-pushed the svg-graphics branch 2 times, most recently from 75c8a26 to f141637 Compare January 10, 2026 22:21
Comment on lines +396 to +400
FontData fd = font.getFontData()[0];
int height = fd.getHeight();
if (DPI != 72) {
height = fd.getHeight() * DPI / 72;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ptziegler ptziegler force-pushed the svg-graphics branch 3 times, most recently from d5a734b to 064039b Compare January 11, 2026 00:01
Comment on lines +107 to +111
private void updateSize(Shape shape) {
Shape transformed = currentState.affineTransform.createTransformedShape(shape);
documentSize.add(transformed.getBounds2D());
gc.setSVGCanvasSize(documentSize.getSize());
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@azoitl
Copy link
Copy Markdown
Contributor

azoitl commented Jan 28, 2026

@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?

ptziegler added a commit to ptziegler/gef-classic that referenced this pull request Jan 28, 2026
…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.
ptziegler added a commit to ptziegler/gef-classic that referenced this pull request Jan 28, 2026
…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.
@ptziegler
Copy link
Copy Markdown
Contributor Author

ptziegler commented Jan 28, 2026

@azoitl You can get a rough idea of the missing functionality by looking at which methods in AWTGraphics still throw a NotImplementedException (9 methods). The only noteworthy task is the clipping, but the rest should be rather trivial.

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.
@azoitl
Copy link
Copy Markdown
Contributor

azoitl commented Jan 29, 2026

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?

@ptziegler
Copy link
Copy Markdown
Contributor Author

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.

@azoitl
Copy link
Copy Markdown
Contributor

azoitl commented Jan 29, 2026

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.

@ptziegler
Copy link
Copy Markdown
Contributor Author

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 Graphics class can understand? e.g. something like this

<rect
    style="fill:#000000"
    id="rect1"
    width="10"
    height="10"
    x="1"
    y="1" />

could be represented as a RectangleFigure with a black foreground color and bounds (1, 1, 10, 10)?

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.

@azoitl
Copy link
Copy Markdown
Contributor

azoitl commented Jan 31, 2026

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants