Skip to content
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

gfx: Derive line-through metrics for fonts on MacOS #31756

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions components/gfx/platform/macos/font.rs
Expand Up @@ -278,6 +278,9 @@ impl FontHandleMethods for FontHandle {
}

fn metrics(&self) -> FontMetrics {
// TODO(mrobinson): Gecko first tries to get metrics from the SFNT tables via
// HarfBuzz and only afterward falls back to platform APIs. We should do something
// similar here. This will likely address issue #201 mentioned below.
let bounding_rect: CGRect = self.ctfont.bounding_box();
let ascent = self.ctfont.ascent();
let descent = self.ctfont.descent();
Expand All @@ -294,18 +297,24 @@ impl FontHandleMethods for FontHandle {
.map(Au::from_f64_px)
.unwrap_or(max_advance);

let underline_size = au_from_pt(self.ctfont.underline_thickness());
let x_height = au_from_pt(self.ctfont.x_height() * scale);

let metrics = FontMetrics {
underline_size: au_from_pt(self.ctfont.underline_thickness()),
underline_size,
// TODO(Issue #201): underline metrics are not reliable. Have to pull out of font table
// directly.
//
// see also: https://bugs.webkit.org/show_bug.cgi?id=16768
// see also: https://bugreports.qt-project.org/browse/QTBUG-13364
underline_offset: au_from_pt(self.ctfont.underline_position()),
strikeout_size: Au(0), // FIXME(Issue #942)
strikeout_offset: Au(0), // FIXME(Issue #942)
// There is no way to get these from CoreText or CoreGraphics APIs, so
// derive them from the other font metrics. These should eventually be
// found in the font tables directly when #201 is fixed.
strikeout_size: underline_size,
strikeout_offset: x_height.scale_by(0.5) + underline_size.scale_by(0.5),
leading: au_from_pt(leading),
x_height: au_from_pt(self.ctfont.x_height() * scale),
x_height,
em_size,
ascent: au_from_pt(ascent * scale),
descent: au_from_pt(descent * scale),
Expand Down
1 change: 0 additions & 1 deletion components/layout_2020/display_list/mod.rs
Expand Up @@ -410,7 +410,6 @@ impl Fragment {
{
let mut rect = rect;
rect.origin.y += Length::from(font_metrics.ascent - font_metrics.strikeout_offset);
// XXX(ferjm) This does not work on MacOS #942
rect.size.height = Length::new(font_metrics.strikeout_size.to_nearest_pixel(dppx));
self.build_display_list_for_text_decoration(fragment, builder, &rect, &color);
}
Expand Down