-
Notifications
You must be signed in to change notification settings - Fork 37
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
Markdown elements are broken up by word in SVG output #95
Comments
I've seen it for a long time and the worst part of this, is that it messes up the text/spacing alignment. |
Can someone confirm that this is still an issue in the current CRAN versions of ggtext and gridtext? |
I just tried a code of mine, where I set a bold font face, now with |
Yes, what this issue is about, breaking strings of text into words, is still the case and is not related to the recent R 4.2.0 bug. It is due to the algorithm gridtext uses to layout text. It does it word by word. When I wrote the package this was basically the only way I could get this done. A better algorithm would assemble strings letter by letter, calculating font metrics along the way. This would require the entire layouting code to be rewritten. It also would have to be written in C or C++ to get acceptable speed. This is not on my todo list at this time. At some point I experimented with a layouting engine in Rust, and I got this part to work, but again that should be seen as an experiment and not something I'm currently pushing forward. If anybody wants to take this one I'm happy to provide pointers. |
I should clarify that my ideal scenario for an SVG output for my own use would be a single
<text x='38.16' y='31.23' style='font-size: 11.00px; font-family: Arial;' lengthAdjust='spacingAndGlyphs'>
Longer subtitles can help people <tspan style="font-weight: bold;">understand the take-home message,</tspan> even if they aren't able to understand the rest of the plot.
</text> I'm not sure how feasible this is if I'm not sure I can contribute substantial work right now, but it's something we might be able to contribute effort to next year depending on how things go (I'm thinking ahead a bit on our own needs in filing this!). But it sounds like other folks might be more concerned about the alignment issues than the word splitting itself. |
Specifically, this allows for using non-breaking space ("\u00A0", " ") in text which is preserved when using SVG output. Connects to: - <wilkelab#35>, - <wilkelab/ggtext#95>.
Specifically, this allows for using non-breaking space ("\u00A0", " ") in text which is preserved when using SVG output. Connects to: - <wilkelab#35>, - <wilkelab/ggtext#95>.
This might be out of scope since it's specifically an interaction with
{svglite}
(and ofc because development is frozen on this), but I'll pop it in anyway for documentation purposes!When
element_markdown
is applied to a text element, that element is broken up word-by-word when saved with{svglite}
, even if there aren't any changes in formatting within the element.That's not a problem visually, but it does make it more difficult to edit the SVG in programs like Illustrator, since you essentially have to delete and replace the text element.
Here's a reprex with a subtitle that is rendered as (1) a plain text, and (2) a rich text grob:
The subtitle in
test1.svg
is:While in
test2.svg
it's:(Apologies for the long block;
<details>
doesn't contain this well!)The text was updated successfully, but these errors were encountered: