-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Introduce descender
and ascender
for font metrics + fix several text rendering issues
#8781
Conversation
a427a2e
to
e242e8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zmiao very excited for this to land!
Looking at the third render test, I don't see a difference in the before vs. after photo. What am I missing?
Also, is it expected that vertical text will have differing gaps above/below characters depending on the character and the font?
It looks like there's too little space under the g
, though perhaps there's not much we can or should do about that.
It also looks like there's not enough space under the p
/ too much space under the o
. If characters are placed vertically, we may want to offset so that the space between characters begins after the descent line if there is a descender, rather than using the true baseline.
I think the eye is looking for the space between where one character ends and the next one starts to be even, and the idea of a baseline is basically moot when there's only a single character in the line.
@chloekraw for your concern about the third picture,
my intention of this is to show that there is no obvious rendering differences for vertical layout texts. Since the fix is mainly for horizontal text dis-aligned problem. Right now all the vertical texts aligned with the middle line of the shaping box.
This could be anther text shaping issue to fix later in the future.
Baseline is necessary even if there is only one character, we need to use baseline for creating glyph, and also taking baseline into account for |
@zmiao gotcha, thanks! I misunderstood the scope of your pr.
Makes sense! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Two nits / questions:
- It's unfortunate that this PR would add 36 MB of test data, practically doubling the size of the repo. Can we reduce this in any way?
- If
ascender
anddescender
are font-level attributes, do we have to save those in each glyph? Can we refactor the code to avoid the redundancy?
Hi @mourner, for your concern:
Thanks for providing this information. The *.pbf data I added is intended to test some characters I used in the test. I will remove some characters so that corresponding pbf file could be erased.
This is a good suggestion! I will adapt the code. Thanks! |
@chloekraw one updates, actually this patch will also fix vertical text dis-alignment if there are multiple font scales in one line. Please check my updated test result picture. |
11e6323
to
3483745
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question I have is whether this will affect local glyph generation adversely and by how much?
The PR looks great otherwise, barring a couple small notes
Thanks @zmiao, looks great. So to be clear, how did you fix this issue? Does this PR only fix vertical text misalignment if all text is CJK and uses the same font family? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good! I only have that one actual concern and a couple nits.
And a general question: It looks like a font range pbf shares one ascender and descender. Is this because a range never has multiple fonts in it?
Good question. It won't affect individual glyph generation, it still uses the hardcoded value. But I am concerning that if it is possible for the following case:
So from this point of view, |
I cross checked the node-fontnik implementation mapbox/node-fontnik#160, for glyphs inside the same font-face, they share the same Do you agree about it? @ansis and @asheemmamoowala? |
This fix is working for mixed fonts. But to be honest, the vertical text misalignment is not fully fixed yet, if there are multiple lines inside the vertical text, and fonts are mixed, the look of the vertical shaped text is still not good. My fix in this pr for the vertical dis-alignment is just replacing the hardcoded |
@zmiao Since local glyphs don't have these extra font metrics (baseline, ascender and descender) will the alignment between server generated and locally generated glyphs be worse that it is now? |
I talked with the team, so for the same font, all the glyphs shall be either local rasterized or fetched. If it is local rasterized, for gl-native, the If it is fetched from server, then the So all in all, it won't become worse, the worst case would just be using the hardcoded baseline, which is the same behavior before this fix. |
@ansis , updates about your question:
yes, it is true. For the same fontstack, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Remove duplicates render tests Fix confilicts
…K symbols and punctuations update comments
fix flow and lint errors code clean
Fix error
update expectations Update test ignore list
…es, such as p, g, y, etc. Fix vertical text shaping with ZWSP and punctuations. additional fix
Update render tests
Fix unit tests
0042541
to
d02ec2d
Compare
@ChrisLoer thank you very much for your comment, for your concerns:
I run the benchmark tests, the result seems good:
|
…ext rendering issues (mapbox#8781) * Introduce descender+ascender, fix fonts dis-alignment * Fix failing tests * Add glyph baseine checker * Update render test * Update font baseline, make vertical mode applying with font baseline * Fix failing tests * Update render test case source position * Move ascender/descender to font level attributes, remove non-necessary pbf files * Add new glyph pbfs Remove duplicates render tests Fix confilicts * rename the inner callback parameter naming * gl-native parity: Extend Ideographs rasterization range to include CJK symbols and punctuations update comments * Adjust text shaping fix flow and lint errors code clean * Fix shaping.test contents parsing Fix error * Update render tests expectation update expectations Update test ignore list * Fix vertical text rendering with 'text-offset' property * Fix text shaping for characters that have very big part below baselines, such as p, g, y, etc. Fix vertical text shaping with ZWSP and punctuations. additional fix * Update test expectations * Fix text rendering when both 'text-rotate' and 'text-offset' is set * Update render tests * Fix text rendering for line labels * Enable ignored render tests regarding text rendering Update render tests * Make ascender and descender optional * Update render tests * Update shaping.js logic * Update render test expectations * Update shaping.test Fix unit tests * Fix review comments * fix typo
This pr is covering:
descender
andascender
for font metrics, which are important for aligning text baselines when mixed fonts are used.This pr will only load
descender
andascender
for fonts loaded from server-side ( background: Expose ascender/descender metadata properties in protobuf node-fontnik#160 will introduce new metadata ascender and descender, it would help fix the issue Use font-provided metadata to determine glyph baseline position #191. This pr only covers reading data from pbf and partially replacing hardcoded baseline for fixing mixed fonts dis-alignment ). Support for loading metrics for local fonts is not implemented yet.p
,g
,y
, etc.text-offset
property:text-offset
property is broken for CJK text in vertical writing mode #10687text-offset
andtext-rotate
are setFollow-up:
Introduce font metrics for local glyph generation (TinySDF).
Fix issue #8560
Launch Checklist