Repository navigation
Conversation
|
Preview is being built... Preview will be available at https://egui-pr-preview.github.io/pr/8804-fix/fallback-font-baseline View snapshot changes at kitdiff |
b51e3da to
3284487
Compare
|
The workflow runs on this PR are sitting in What I can check locally on 1.95.0 is green:
On the 45 snapshot changes: they are one pixel of emoji movement each. The PR description has a per-image breakdown — latin text does not move at all. |
|
I tested this PR with a minimal repro: egui 0.37.0 defaults, no The baseline fix works: CJK now sits on the Latin baseline with both fonts. With Consolas, the old centering term actually pushed CJK 4 px down, because It also removes the steps in But with Consolas, the CJK ink reaches the top edge of the highlight (screenshot pixels):
The root cause is that the ideographs rise above the row. Consolas' This predates the PR, but it is the remaining half of the problem. Growing the row to fit the fallback face (as #8824 does) would fix it, and splitting the line gap evenly (CSS half-leading) would balance the box. Cascadia Mono has a larger ascent (12.06 px) and no line gap, so the box looks fine there. 5× zoom. Left: before, right: this PR. Top: Consolas, bottom: Cascadia Mono.
|
3284487 to
ccdc8f8
Compare
|
Thanks for the careful measurement — that matches what I see, and the pixel table is a much better argument than anything in the PR description. Two updates since your comment: The PR is rebased. It had started conflicting with Your "one rect instead of five" observation still holds on the new base, and it matters slightly more now. On the remaining half, I agree with your diagnosis, and I don't think it should be folded into this PR:
This PR is deliberately the narrow half: after it, every glyph in a row shares the primary face's baseline, which is the invariant the other two changes need before either can be discussed on its own. If a follow-up issue for the row-growth case would help, I'm happy to open one with your Consolas repro attached so the two halves can be reviewed separately — or go ahead and file it yourself if you'd rather own the repro. One caveat on the regenerated snapshots: they were produced on macOS, and CI on this PR has still never run — the workflow runs are waiting for a maintainer to approve them — so none of this has been exercised on Linux yet. |
`glyph.pos.y` was the ascent of whichever face the glyph happened to be found in (`font_face_ascent`), plus a term centering that face's box inside the row. So a row that mixed scripts put its glyphs on several different baselines, and a face much taller than the primary one — a CJK fallback, say — had its glyphs pushed above the row, clipping their tops. Use the primary face's `font_ascent` for every glyph instead: that is the baseline of the section's row, and every glyph belongs on it. The existing CSS-style centering of the glyph inside an explicit `line_height` is unchanged. Adds a test asserting that a latin glyph and a fallback-font glyph in the same row share one y position. The 44 updated kittest snapshots only move emoji icons down by one pixel, which is the expected consequence: they used to be centered against the primary face instead of sitting on its baseline. Closes emilk#8802.
ccdc8f8 to
3327c42
Compare
|
Pushed a cleanup pass on the branch. The behaviour is unchanged; only the size of the change got smaller:
Re-verified on the new head: |

glyph.pos.ywas computed fromfont_face_ascentplus a term centering the face box in the row. Glyphs from a fallback face therefore sat on their own baseline, and a face much taller than the primary one (CJK: 1.5em, versus 1.15em for the default latin font) was pushed above the row, clipping the top of its glyphs.Glyph::posis documented as "Baseline position, relative to the row. pos.y is the same for all chars of the sameTextFormat", so this makes the code match that contract:Effect
"H国👋"at 40px,pixels_per_point = 1.0, CJK fallback = Hiragino Sans GB:H(primary face)国(CJK fallback)👋(emoji fallback)font_face_ascent == font_ascentfor the primary face).[-5, 32](top outside the 46px row, so clipped) to[4, 41](inside).Snapshot changes
45 snapshots are touched, which looks like a lot for a one-line change. It is one pixel of movement, on emoji only:
oid/sizechange rather than as an image.Diffing the actual images (base vs. head, per pixel) confirms latin text does not move at all — the only difference is the icon sitting 1px lower:
widget_gallery_light_x1.pngdemos/Painting.pngdemos/Scrolling.pngdemos/Table.pngdemos/Text Layout.pngVisual diff of every snapshot: kitdiff.
Test
glyphs_from_different_faces_share_one_baselinenow checks every glyph of a row against the baseline of the primary face, rather than merely checking that the glyphs agree with each other. It first asserts that a fallback face with different metrics was actually used, so it can't pass trivially. Without the fix it fails with[37.0, 37.0, 36.0].cargo test -p epaint --features monochrome_emoji_fonts: 96 passedcargo test -p egui --all-features: 286 passedcargo fmt --check,cargo clippy -p epaint --all-targets --features monochrome_emoji_fonts -- -D warnings,scripts/lint.py: cleanNote that this only fixes the baseline. A row containing a tall fallback face still keeps the primary row height; growing the row to fit it is a separate change (as noted in #5126).
Fixes #8802