diff options
author | Andreu Botella <abotella@igalia.com> | 2024-05-02 09:17:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 07:17:32 +0000 |
commit | 8ec5344f70dd1d556cacd72d778924048b0b1154 (patch) | |
tree | c75a6ef98c1085cf5f6da9f38c91c3ee573b4038 /components/gfx/platform/windows/font.rs | |
parent | 928214518cc2ed44112295c7aae675fc29f5a50b (diff) | |
download | servo-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/windows/font.rs')
-rw-r--r-- | components/gfx/platform/windows/font.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/components/gfx/platform/windows/font.rs b/components/gfx/platform/windows/font.rs index ce28d0f378b..5debd0c64fa 100644 --- a/components/gfx/platform/windows/font.rs +++ b/components/gfx/platform/windows/font.rs @@ -232,6 +232,15 @@ impl PlatformFontMethods for PlatformFont { // is pulled out here for clarity let leading = dm.ascent - dm.capHeight; + let zero_horizontal_advance = self + .glyph_index('0') + .and_then(|idx| self.glyph_h_advance(idx)) + .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 metrics = FontMetrics { underline_size: au_from_du(dm.underlineThickness as i32), underline_offset: au_from_du_s(dm.underlinePosition as i32), @@ -245,6 +254,8 @@ impl PlatformFontMethods for PlatformFont { max_advance: au_from_pt(0.0), // FIXME average_advance: au_from_pt(0.0), // FIXME line_gap: au_from_du_s((dm.ascent + dm.descent + dm.lineGap as u16) as i32), + zero_horizontal_advance, + ic_horizontal_advance, }; debug!("Font metrics (@{} pt): {:?}", self.em_size * 12., metrics); metrics |