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

Ensure leading spaces are rendered in <text> tags #131

Closed
hrbrmstr opened this issue Feb 22, 2021 · 1 comment · Fixed by #144
Closed

Ensure leading spaces are rendered in <text> tags #131

hrbrmstr opened this issue Feb 22, 2021 · 1 comment · Fixed by #144

Comments

@hrbrmstr
Copy link

hrbrmstr commented Feb 22, 2021

This:

image

has stretched out characters due to leading spaces that R properly calculates textLength for 👍🏽

<text x='131.01' y='100.03' style='font-size: 11.04px; font-weight: 300; fill: #E1E1E1; font-family: Inter; font-feature-settings: "calt" 1,"tnum" 1,"case" 1,"dlig" 1,"ss01" 1,"kern" 1,"zero" 0,"salt" 0;' textLength='150.57px' lengthAdjust='spacingAndGlyphs'>&lt;- A fairly useless annotation</text>
<text x='131.01' y='111.62' style='font-size: 11.04px; font-weight: 300; fill: #E1E1E1; font-family: Inter; font-feature-settings: "calt" 1,"tnum" 1,"case" 1,"dlig" 1,"ss01" 1,"kern" 1,"zero" 0,"salt" 0;' textLength='157.15px' lengthAdjust='spacingAndGlyphs'>       that uses the custom Inter</text>
<text x='131.01' y='123.21' style='font-size: 11.04px; font-weight: 300; fill: #E1E1E1; font-family: Inter; font-feature-settings: "calt" 1,"tnum" 1,"case" 1,"dlig" 1,"ss01" 1,"kern" 1,"zero" 0,"salt" 0;' textLength='124.20px' lengthAdjust='spacingAndGlyphs'>          variant by default.</text>

but SVG renders won't actually render the leading spaces unless they are told not to:

<text x='131.01' y='111.62' style='white-space: pre; font-size: 11.04px; font-weight: 300; fill: #E1E1E1; font-family: Inter; font-feature-settings: "calt" 1,"tnum" 1,"case" 1,"dlig" 1,"ss01" 1,"kern" 1,"zero" 0,"salt" 0;' textLength='157.15px' lengthAdjust='spacingAndGlyphs'>       that uses the custom Inter</text>
<text x='131.01' y='123.21' style='white-space: pre; font-size: 11.04px; font-weight: 300; fill: #E1E1E1; font-family: Inter; font-feature-settings: "calt" 1,"tnum" 1,"case" 1,"dlig" 1,"ss01" 1,"kern" 1,"zero" 0,"salt" 0;' textLength='124.20px' lengthAdjust='spacingAndGlyphs'>          variant by default.</text>

image

Either a warning or documentation to such effect might be useful or an {svglite} option to have leading <text> spaces rendered (i.e. set white-space: pre; in the style attribute).

I can help do either but wanted to have this up as an issue for discussion.

@hrbrmstr hrbrmstr changed the title substitute non-breaking space for regular space in leading spaces in <text> tags Ensure leading spaces are rendered in <text> tags Feb 22, 2021
@thomasp85
Copy link
Member

I think the right course forward is to simply add white-space: pre; in the top-level style block... I was unaware of how svg handled leading spaces, but for svglite to create true R output it needs to honour leading spaces...

You are welcome to do a PR, but I can do it as well

hrbrmstr added a commit to hrbrmstr/svglite that referenced this issue Feb 23, 2021
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 a pull request may close this issue.

2 participants