aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/platform/macos/font.rs
diff options
context:
space:
mode:
authorAndreu Botella <abotella@igalia.com>2024-05-02 09:17:32 +0200
committerGitHub <noreply@github.com>2024-05-02 07:17:32 +0000
commit8ec5344f70dd1d556cacd72d778924048b0b1154 (patch)
treec75a6ef98c1085cf5f6da9f38c91c3ee573b4038 /components/gfx/platform/macos/font.rs
parent928214518cc2ed44112295c7aae675fc29f5a50b (diff)
downloadservo-8ec5344f70dd1d556cacd72d778924048b0b1154.tar.gz
servo-8ec5344f70dd1d556cacd72d778924048b0b1154.zip
feat: Support font-relative `ch` and `ic` units (#32171)
* feat: Support font-relative `ch` and `ic` units After #31966, which made it possible for the first time to resolve font-relative CSS units, this change adds support for the `ch` and `ic` units. One difference with the `ex` unit that was added in that PR is that these units must reflect the advance width of a character (the zero digit in the case of `ch`, and the CJK water radical for `ic`) as it would be rendered by the current font group. This means that the size of these units don't only depend on the first available font, in the case where that font does not contain a glyph for that character. This is implemented by adding the advance width for these two characters as optional fields of `FontMetrics`, so the advance width computation happens in advance. Then, when the font metrics are queried as part of unit resolution, the font group is searched for the first font containing that character. This change only implements support for these units in upright typesetting modes, since Servo does not yet have support for vertical writing modes. This means that many of the WPT tests that test for the behavior of these units with vertical writing modes do not pass. This change also makes a number of WPT tests pass, which relied on the `ch` and `ic` units. It, however, also makes the test `/css/css-text/white-space/text-wrap-balance-overflow-002.html` fail, since it tests `text-wrap: balance`, which Servo does not yet implement, and it was only previously passing by chance due to the previous behavior of these units. * Revert Python 3.10-related changes to wss * Fix formatting * Remove test expectation
Diffstat (limited to 'components/gfx/platform/macos/font.rs')
-rw-r--r--components/gfx/platform/macos/font.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs
index 7844ecb9089..c6e009ffae8 100644
--- a/components/gfx/platform/macos/font.rs
+++ b/components/gfx/platform/macos/font.rs
@@ -259,11 +259,15 @@ impl PlatformFontMethods for PlatformFont {
let line_gap = (ascent + descent + leading + 0.5).floor();
let max_advance = Au::from_f64_px(self.ctfont.bounding_box().size.width);
- let average_advance = self
+ let zero_horizontal_advance = self
.glyph_index('0')
.and_then(|idx| self.glyph_h_advance(idx))
- .map(Au::from_f64_px)
- .unwrap_or(max_advance);
+ .map(Au::from_f64_px);
+ let ic_horizontal_advance = self
+ .glyph_index('\u{6C34}')
+ .and_then(|idx| self.glyph_h_advance(idx))
+ .map(Au::from_f64_px);
+ let average_advance = zero_horizontal_advance.unwrap_or(max_advance);
let metrics = FontMetrics {
underline_size: Au::from_f64_au(underline_thickness),
@@ -286,6 +290,8 @@ impl PlatformFontMethods for PlatformFont {
max_advance,
average_advance,
line_gap: Au::from_f64_px(line_gap),
+ zero_horizontal_advance,
+ ic_horizontal_advance,
};
debug!(
"Font metrics (@{} pt): {:?}",