Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'textLength' attribute to <svg:tspan> elements in SVG export #44

Closed
sailingKieler opened this issue Jun 17, 2020 · 9 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@sailingKieler
Copy link
Member

sailingKieler commented Jun 17, 2020

SVG exports of diagrams suffer (and will always suffer) from the different text renderings on different machines, and worse, even in different browsers on the same machine.

I just figured out that the SVG elements <text> and <tspan> offer the attributes textLength and lengthAdjust, which I wasn't aware of. See also https://codepen.io/tigt/post/more-robust-svg-text-with-lengthadjust-and-font-size-adjust

Hence, it would be valuable to add the designated textLength value to the generated SVG output and check whether that improves the portability of SVG exports.

@sailingKieler sailingKieler added the enhancement New feature or request label Jun 17, 2020
@NiklasRentzCAU
Copy link
Member

I also already had this problem when implementing the rendering of KText elements for the Sprotty-based viewer of KLighD. For that platform, I implemented the SVG rendering with that attribute here as well, however, I found out that also may cause a slightly inconsistent look between glyphs in different texts on other platforms not natively supporting the font. A solution for optimal consistency would be to only use open and free-to-use fonts and include them in the viewer and the SVGs directly.

If you find another solution that preserves the texts in the SVG (not rasterizing them or converting them to paths), please let me know.

@sailingKieler
Copy link
Member Author

I found out that also may cause a slightly inconsistent look between glyphs in different texts on other platforms not natively supporting the font

That's for sure, but we're hopefully getting closer...

If you find another solution that preserves the texts in the SVG (not rasterizing them or converting them to paths), please let me know.

Ok, but I guess that will never happen :-/

@sailingKieler sailingKieler self-assigned this Jul 8, 2020
@sailingKieler
Copy link
Member Author

I did some experiments with the generation of the textLength attribute for <tspan> elements.
Sadly Chromium messes up the rendering for multi <tspan> texts, at least for me in version 83.0.4103.116 on OSX:

Bildschirmfoto 2020-07-13 um 15 18 17

more precisely only the last <tspan> element in the row seems to apply the textLength property properly.
(here with font Monaco (OSX, monospace), the first one is added without the textLength property as reference)

This seems to be documented here: https://bugs.chromium.org/p/chromium/issues/detail?id=375258

Consequence: I'm thinking about dropping the <tspan> approach and generating a group of <text> elements

@sailingKieler
Copy link
Member Author

Btw. Firefox seem to not handle textLength for nested <tspan>s at all.

@NiklasRentzCAU
Copy link
Member

This is exactly why I also opted to only use <text> and no <tspan>s in the Sprotty implementation. Again, I suggest looking at my implementation linked above, as it handles exactly this problem as well.

@sailingKieler
Copy link
Member Author

Again, I suggest looking at my implementation linked above, as it handles exactly this problem as well.

Unfortunately, that's only partly helpful. On the one hand I'm not trained in reading tsx, and the freeHEP SVG builder has its own sophistications on the other hand. Thanks anyway ;-)

sailingKieler added a commit that referenced this issue Jul 15, 2020
…tion to enable the generation of 'textLength' property values for '<text>' elements in SVGs (#44)

 * added flag in 'KlighdPaintContext',
 * added checkbox in 'SaveAsImageDiaglog' and related export data records
 * moved some recently misplaced properties from 'SVGOffscreenRenderer' to 'IOffscreenRenderer'
sailingKieler added a commit that referenced this issue Jul 15, 2020
…SVG exporter to generate multi-line texts as a group of <text> elements instead of <tspan> elements (#44)

* abolished generation of '<tspan>' elements entirely
* updated 'FreeHEPSVGOffscreenRenderingTest'
sailingKieler added a commit that referenced this issue Jul 16, 2020
…SVG exporter to generate multi-line texts as a group of <text> elements instead of <tspan> elements (#44)

* abolished generation of '<tspan>' elements entirely
* updated 'FreeHEPSVGOffscreenRenderingTest'
sailingKieler added a commit that referenced this issue Jul 16, 2020
…tion to enable the generation of 'textLength' property values for '<text>' elements in SVGs (#44)

 * added flag in 'KlighdPaintContext',
 * added checkbox in 'SaveAsImageDiaglog' and related export data records
 * moved some recently misplaced properties from 'SVGOffscreenRenderer' to 'IOffscreenRenderer'
sailingKieler added a commit that referenced this issue Jul 16, 2020
…SVG exporter to generate multi-line texts as a group of <text> elements instead of <tspan> elements (#44)

* abolished generation of '<tspan>' elements entirely
* updated 'FreeHEPSVGOffscreenRenderingTest'
sailingKieler added a commit that referenced this issue Jul 16, 2020
…SVG exporter to generate multi-line texts as a group of <text> elements instead of <tspan> elements (#44)

* abolished generation of '<tspan>' elements entirely
* updated 'FreeHEPSVGOffscreenRenderingTest'
@sailingKieler
Copy link
Member Author

With the changes listed above the generated SVG is

Bildschirmfoto 2020-07-16 um 12 22 37

sailingKieler added a commit that referenced this issue Aug 3, 2020
…ents in changes for #44 as suggested by reviewers
sailingKieler added a commit that referenced this issue Aug 3, 2020
…ents in changes for #44 as suggested by reviewers
NiklasRentzCAU pushed a commit that referenced this issue Sep 18, 2020
…tion to enable the generation of 'textLength' property values for '<text>' elements in SVGs (#44)

 * added flag in 'KlighdPaintContext',
 * added checkbox in 'SaveAsImageDiaglog' and related export data records
 * moved some recently misplaced properties from 'SVGOffscreenRenderer' to 'IOffscreenRenderer'
NiklasRentzCAU pushed a commit that referenced this issue Sep 18, 2020
…SVG exporter to generate multi-line texts as a group of <text> elements instead of <tspan> elements (#44)

* abolished generation of '<tspan>' elements entirely
* updated 'FreeHEPSVGOffscreenRenderingTest'
NiklasRentzCAU pushed a commit that referenced this issue Sep 18, 2020
@sailingKieler
Copy link
Member Author

@NiklasRentzCAU, @soerendomroes we can close this, right?

@NiklasRentzCAU
Copy link
Member

Yes, the PR for this issue is merged into master and we did not notics any further problems regarding this issue.
Closing now.

sailingKieler added a commit that referenced this issue Jan 28, 2021
…space: pre' styling for multi-line text label in the freehep-based SVG generation

appears to me like some collateral damage of the solution of #44,
updated tests
sailingKieler added a commit that referenced this issue Aug 17, 2021
…space: pre' styling for multi-line text label in the freehep-based SVG generation

appears to me like some collateral damage of the solution of #44,
updated tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants