-
Notifications
You must be signed in to change notification settings - Fork 216
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
Consistent text rendering failures- "Text layouting failed" #614
Comments
Interesting. Where can I find this font? |
Wow! That was weird bug. You have been able to hit resvg text layout limitation which I haven't had time to fix. The problem is that your SVG text: <text x="135" y="60">
<tspan class="name font">ItsMeAlfie0</tspan>
<tspan class="discriminator font">#0001</tspan>
</text> would be parsed as: <text x="135" y="60">
<tspan font-family="Mojang, sans-serif" font-size="25px" fill="#FFFFFF">ItsMeAlfie0</tspan>
<tspan font-family="Roboto" font-size="12px" fill="#FFFFFF"> </tspan> <!-- yes, the space between tspans is significant -->
<tspan font-family="Mojang, sans-serif" font-size="10px" fill="#CCCCCC">#0001</tspan>
</text> And since you haven't set the font for whitespaces - it would fallback to the default one, which is Roboto in your case. Now, resvg would try to shape your string using two fonts: Mojang and Roboto. And Roboto support ligatures substitution, so I will try to fix it, but in the mean time you can easily fix this from your side by setting |
Wow, that's kind of insane! Thanks for taking the time to help out with this! I'll add the workaround to the library asap. |
I'm hitting this problem in a slightly different scenario and trying to investigate, but here is what I know so far:
P.S. thanks for the awesome lib! Having to do any processing on SVG from scratch would be a nightmare :) |
Yes, would have to find some time to figure it out.
What do you mean by that? Do you have a minimal example?
Do you have a minimal example of this? Whitespaces handling in SVG is very complex and unintuitive. |
Also, it might help if you create a directory that contains all of the fonts that are needed for reproduction, and run |
@LaurenzV Roboto is known to have this issue. |
Thanks @RazrFalcon for quick response. First the repro - added zip file with both the command I use as well as the SVG and the Google TTFs folder. Now about the two piece The way I understand it, the whitespace between the consecutive I've tried two things to fix this issue, but having zero idea about the intricacies of the SVG text handling, pretty sure my approaches are way too naive to work... Also, this is the first time I have ever looked at any rust source, so pardon my axe swinging ;) What I tried so far:
So this is where I am at this point. Once again - thanks for taking time to look into this, really appreciate your work. |
This is not supported. resvg supports only basic CSS 2 selectors. As for whitespaces - I'm not sure what is the problem here. resvg renders this SVG just fine (excluding the fonts bug). Why do you care about whitespaces to begin with? Because you try to render it yourself? Then you have to mimic how usvg converts text into paths. Which is super complicated. If you plan to parse SVG and render text yourself - just give up. It would not work. You have to flatten text and render paths. There are no parsing bugs here. usvg parses this SVG correctly. |
Sorry - I didn't give context for why I care about this detail and I am not claiming there is any bug at all - just a feature to handle glyph merging that is not yet implemented. Basically I'm trying to use usvg to pre-process user-supplied SVG files into something that can be sent to the CNC software, i.e. flatten text and complex shapes primarily. I'm doing torture-tests to understand the level of compatibility and what to ask customers to bring. While doing this, I bumped into the glyph merging issue. It is relatively easy to explain to the customer that e.g. only TTF fonts or Google fonts are supported, but explaining to them that, in some rare cases the fonts with glyph substitution will fail is not so easy. So I investigated why this specific failure is triggered when I don't seem to have mixed fonts in a single line. Here, I found that the whitespace is implicitly added with a different font and causes this issue. My first instinct was to "fix" it so that mixed fonts do not trigger this situation in general, or at least it doesn't blow up if there are no intentional mixed fonts in the same line. This way, it would be easier to specify what the customers could bring and what is not supported. This seems to be a rabbithole though. Hopefully this explains my thinking a bit. So, if the double rendering of tspan is how it is supposed to work, perhaps another option (for me) would be to pre-pre-process the SVG file and just kill those unintended whitespaces, may be even check for fonts with glyph substitution and reject the file (I'm already collecting fonts ahead of time from javascript). Or ideally, we could try to implement this whole glyph merging support properly, if you give me some pointers on what to look out for. |
Whitespaces handling is totally unrelated to this issue. It just happens to trigger it. There are different ways to do it.
There are no double rendering. There are no whitespaces during rendering to begin with. Only paths.
Are there any other types of fonts than TrueType? 😄 |
Again, sorry for the wording :) Since I'm using usvg and not full resvg, for me - the rendering means generation of paths. This happens in outline_chunk and the loop runs twice for each The offer still stands - if you have an idea of how you want this problem fixed, I'm ready to give it a shot.
Edited: my lack of rust knowledge again :) apparently this crate is a library and all the necessary symbols are already exported. Sorry for the noise. |
I'm trying to fix the problem myself, but it's hard. I'm not really sure how it should be handled. |
Couple of random thoughts, looking from a distance :)
|
Took almost a year, but should be fixed now. The solution is meh, but I don't have any better ideas at the moment. |
It's very hard to do for mixed order text. There are plans to avoid shaping the whole string for each font (#486), but I have no idea if it is even possible. Way out of my expertise.
That's basically what the new code does. And I'm still not very sure how correct it is.
This is not how SVG works. Also, there are no lines in SVG 1. SVG 2 does have lines now, but I'm not sure anyone actually supports them. Overall, this is not a hard problem if we have only left-to-right text, but we don't. If you want to understand what kind of monstrosity SVG text is - check out this example. Here, one |
Amazing work! Thanks Yevhenii! |
Thank you, RazrFalcon! |
…of them produces ligatures. Closes #614
…of them produces ligatures. Closes #614
i am using resvg to render rank cards for a Discord service. Sometimes, some usernames will fail to render, despite using very similar settings, including fonts, to the other text on the page, which has
no problems rendering. The code that does this is available at randomairborne/experienced/xpd-rank-card. What has me confused here is that some text
with some settings works, but other text doesn't- and a different name will have different results.
Examples:
broken svg
working svg
broken render
working render
The text was updated successfully, but these errors were encountered: