-
Notifications
You must be signed in to change notification settings - Fork 24
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
String measurement incorrect? #143
Comments
Here's my sessionInfo:
|
I think I know what is happening, but I don't know how to fix it. The kanji characters aren't present in the default font, so the device falls back to the "PingFang SC" family which does have them, and uses a font from that family to draw them. However, it doesn't use metrics based on that family when calculating to overall string metric in The |
Here's a function that does better at calculating the measurements for strings that have font substitution. I think it does a good enough job for my needs, but for
|
Thanks for the detailed exploration. It is right that the logic path of rendering and string dimension calculations diverge - I'll look into a fix for this so fallback fonts are correctly handled |
So, having poked at this for some time I've come to the conclusion that there is no "real" fix for it. The main issue is that the R graphic engine is measuring the total height of a string by iterating over each character in the string, asking the dimensions for it, and compounding that information. This approach is flawed as the text shaping might change the 1-to-1 relationship between the string and the glyphs rendered. One issue is the fallback problems you are reporting, but various ligatures could also result in different ascenders and descenders and it is impossible to get this correct when queried one character at a time... The best way to get the measurements accurately is to use |
Thanks for looking into this. Just one quick question: is there a good source of documentation (maybe including a diagram) for the actual meaning of the
but the |
There is not... the R facing text shaping functions in systemfonts and textshaping have always been slightly experimental and for tinkering while me and Paul discussed a better text rendering API for the graphics engine |
I'm trying to draw text to a bitmap (for an
rgl
update) and finding that the reported dimensions of the drawn text are sometimes inaccurate. For example:Created on 2023-09-26 with reprex v2.0.2
This reports that the 3 strings descend by 0, 13, and 1 pixels respectively, and produces this image on my system:
Clearly the kanji string
"東京"
descends below the baseline. If I zoom in, I see a descent of 6 pixels. Is this a bug?The text was updated successfully, but these errors were encountered: