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

SVG letter-spacing is calculated wrongly #5192

Closed
teohhanhui opened this issue Aug 23, 2018 · 10 comments · Fixed by #5258
Closed

SVG letter-spacing is calculated wrongly #5192

teohhanhui opened this issue Aug 23, 2018 · 10 comments · Fixed by #5258

Comments

@teohhanhui
Copy link

teohhanhui commented Aug 23, 2018

Version

master @ 2a476e4 (did npm run build to build dist)

Test Case

https://fabricjs-issue-svg-letter-spacing.netlify.com/

Steps to reproduce

  1. Load SVG which uses letter-spacing and transform

Expected Behavior

letter-spacing is not affected by transform

Actual Behavior

letter-spacing is affected by transform

Looks like a similar bug happened in Chrome before: https://stackoverflow.com/questions/36132450/chrome-v49-letter-spacing-in-svg-with-transform-matrix/36764459

@teohhanhui
Copy link
Author

letter-spacing support was introduced in #3718

@asturur
Copy link
Member

asturur commented Aug 23, 2018

can you link the SVG?
fabric letterspacing is affected by transform. and it will be.

@teohhanhui
Copy link
Author

teohhanhui commented Aug 23, 2018

You mean charSpacing, right? Then we cannot use it for SVG / CSS letter-spacing. At least not directly like it is now. Because that breaks SVG.

@asturur
Copy link
Member

asturur commented Aug 23, 2018

So regarding:
letter-spacing is not affected by transform
I do not understand where this come from.

Letter spacing is affected by transform, indeed i put a scale 0.2 on the SVG and the letter-spacing is reduced to mantain proportions.

image

There are 2 bugs here:

  1. fabric interprets the number as .em, while being without unit should be 5px.
  2. at the moment of parsing the fontSize is considered 16px, that throws out calculations.

If we could know that at this point fontSize is 220px, this would parse correctly

@teohhanhui
Copy link
Author

Sorry about my misunderstanding of the problem. And thanks for investigating! :)

@teohhanhui teohhanhui changed the title SVG letter-spacing should not be affected by transform SVG letter-spacing is calculated wrongly Sep 19, 2018
@teohhanhui
Copy link
Author

teohhanhui commented Sep 22, 2018

Anyway, I've just realized that in the sample SVGs I've provided, the letter-spacing CSS property has an invalid(?) value (it cannot be unit-less?), while the letter-spacing SVG attribute (which could be unit-less) is poorly supported: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/letter-spacing#Usage_Note

Seems like Adobe Illustrator generates invalid(?) values on SVG export.

EDIT: Looks like it's actually unclear whether unit-less values should be allowed in such cases: https://jwatt.org/svg/authoring/#specifying-units

@asturur
Copy link
Member

asturur commented Sep 23, 2018

well now works better!

@teohhanhui
Copy link
Author

Indeed. But there's still another rendering issue in the second sample SVG. I'm not quite sure what's going on. It's around the multiple <tspan> with x and y attributes.

@asturur
Copy link
Member

asturur commented Sep 23, 2018

tspans are unsopperted yet

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

Successfully merging a pull request may close this issue.

2 participants