-
Notifications
You must be signed in to change notification settings - Fork 405
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
Text width is calculated incorrectly when highpdi is enabled in Love 12.0 #1923
Comments
In the first example I believe 7 is more correct than 8 - the text shaper (Harfbuzz) produces an un-rounded value of 7.2. GlyphData:getAdvance and the other variant of Font:getWidth don't go through the text shaper. I'll do more investigation when I have more time but it's possible the end result to fix this issue will be using the (new) text shaper in more places as well as making APIs to encourage people to use it rather than going behind its back and trying to calculate things manually. |
Thanks for the reply. Here's an example of what I use glyph data for. For the same reason, I only use getting the size for a single character. I'm sorry if I don't explain well and make mistakes in the text. I do not speak English very well. |
It doesn't yet, but it's planned for 12.0. :) |
I figured out the reason why 'ffff' splits into 'ff' pairs in Harfbuzz.
Here's more information: |
I found another strange behavior: local font = love.graphics.getFont()
local _, wrapped = font:getWrap('Приветff', 1000)
print(#wrapped) -- 2
local _, wrapped = font:getWrap('Приветfff', 1000)
print(#wrapped) -- 1 |
Just documenting this here for the future since I haven't figured out the right solution yet: this is caused by the |
The number of character in a cluster can be clavulated by checking the cluster of the next glyph, see https://harfbuzz.github.io/a-clustering-example-for-levels-0-and-1.html |
Yeah, it gets a little complicated in user code when there are multiple fonts and multiple runs of text though, because the next glyph isn't available from an index increment in that case. It would be way simpler (and easier to understand what's going on in general) if harfbuzz provided a start/count or begin/end range instead of just the start, but alas... |
It is little complicated, but I don’t see why multiple fonts makes it more so. HarfBuzz works on one run at time and all output values are local to that, the other runs don’t concern the current run. |
Providing a range wouldn’t be any easier because the relationship is more complicated than that. When there is decomposition, multiple glyphs can have the same cluster, and with re-ordering you can have a multi-character multi-glyph cluster (glyphs G to G+N1 belong to characters C to C+N2). |
That's not the case in this situation, where you can't know the total number of input unicode values in the last glyph of a run without knowing where the next run starts. Unless I'm missing an API? |
That is correct, so the mapping of glyphs to input character indices should ideally be done right after shaping where all the needed information is present. |
Right, this adds complexity to user code where it doesn't seem like it would be strictly necessary if harfbuzz had slight changes in its APIs. Harfbuzz provides an incomplete mapping of glyphs to character indices, so I have to add user code to make the mapping complete. As you can see, this has already resulted in bugs :( |
HarfBuzz is API and ABI stable, so no change is possible (only new APIs), but also there is no better solution. The glyph <-> character relationship can be one to one, one to many, many to one and many to many. The current API can already handle all of this at the expense of slightly complicated user code. Any new API would need to handle all of it as well. |
|
I understand that released code is hard to change, but that doesn't mean an API is the best version of what it can be, just that there's more friction to any improvement. The current |
Please forward you suggestions to https://github.com/harfbuzz/harfbuzz/issues |
The text width is calculated incorrectly when highpdi is enabled. Here are the examples I tested with the default font:
And an example of another mistake:
In computeGlyphPositions function string
'ffff'
splits into'ff'
pairs, so when calculating the width love code calculates and rounds the value for a pair of characters likefloorf((glyphpos.x_advance >> 6) / dpiScales[0] + 0.5f)
. That's why there is a difference if you calculate each character individually.The text was updated successfully, but these errors were encountered: