fonts: Remove the per-FontGroup cached fallback font (#35705)

Instead of keeping a per-FontGroup cache of the previously used fallback
font, cache this value in the caller of `FontGroup::find_by_codepoint`.
The problem with caching this value in the `FontGroup` is that it can
make one layout different from the next.

Still, it is important to cache the value somewhere so that, for
instance, Chinese character don't have to continuously walk through the
entire fallback list when laying out. The heuristic here is to try to
last used font first if the `Script`s match. At the very least this
should make one layout consistent with the next.

Fixes #35704.
Fixes #35697.
Fixes #35689.
Fixes #35679.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-02-28 15:33:21 +01:00 committed by GitHub
parent 06d4272462
commit f949d2adc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 43 additions and 38 deletions

View file

@ -210,7 +210,7 @@ impl TextRunScanner {
.unwrap_or_else(|| {
let space_width = font_group
.write()
.find_by_codepoint(font_context, ' ', None)
.find_by_codepoint(font_context, ' ', None, None)
.and_then(|font| {
font.glyph_index(' ')
.map(|glyph_id| font.glyph_h_advance(glyph_id))
@ -252,10 +252,12 @@ impl TextRunScanner {
let (mut start_position, mut end_position) = (0, 0);
for (byte_index, character) in text.char_indices() {
if !character.is_control() {
let font =
font_group
.write()
.find_by_codepoint(font_context, character, None);
let font = font_group.write().find_by_codepoint(
font_context,
character,
None,
None,
);
let bidi_level = match bidi_levels {
Some(levels) => levels[*paragraph_bytes_processed],