fonts: Make fast shaping determination platform-independent (#33540)

This makes the determination of whether or not to use fast shaping
platform independent. Previously it was less stringent for Windows,
leading to using it in cases where a font had a GSUB or GPOS table --
which broke proper shaping.

In addition, the test is made platform independent and expanded to be
more complete.

Finally, comments are added indicating that "fast shaping" will be
removed.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-09-25 12:00:36 +02:00 committed by GitHub
parent 6f797709cf
commit 64f32f7ab3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 129 additions and 116 deletions

View file

@ -26,7 +26,7 @@ use super::core_text_font_cache::CoreTextFontCache;
use crate::{
map_platform_values_to_style_values, FontIdentifier, FontMetrics, FontTableMethods,
FontTableTag, FontTemplateDescriptor, FractionalPixel, GlyphId, PlatformFontMethods, CBDT,
COLR, GPOS, GSUB, KERN, SBIX,
COLR, KERN, SBIX,
};
const KERN_PAIR_LEN: usize = 6;
@ -59,7 +59,6 @@ pub struct PlatformFont {
/// data stays alive of the lifetime of this struct.
_data: Arc<Vec<u8>>,
h_kern_subtable: Option<CachedKernTable>,
can_do_fast_shaping: bool,
}
// From https://developer.apple.com/documentation/coretext:
@ -189,12 +188,8 @@ impl PlatformFontMethods for PlatformFont {
_data: data,
ctfont: core_text_font.clone_with_font_size(size),
h_kern_subtable: None,
can_do_fast_shaping: false,
};
handle.h_kern_subtable = handle.find_h_kern_subtable();
handle.can_do_fast_shaping = handle.h_kern_subtable.is_some() &&
handle.table_for_tag(GPOS).is_none() &&
handle.table_for_tag(GSUB).is_none();
Ok(handle)
}
@ -239,10 +234,6 @@ impl PlatformFontMethods for PlatformFont {
0.0
}
fn can_do_fast_shaping(&self) -> bool {
self.can_do_fast_shaping
}
fn glyph_h_advance(&self, glyph: GlyphId) -> Option<FractionalPixel> {
let glyphs = [glyph as CGGlyph];
let advance = unsafe {