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

@ -75,7 +75,6 @@ pub struct PlatformFont {
face: ReentrantMutex<FT_Face>,
requested_face_size: Au,
actual_face_size: Au,
can_do_fast_shaping: bool,
}
// FT_Face can be used in multiple threads, but from only one thread at a time.
@ -135,15 +134,12 @@ impl PlatformFontMethods for PlatformFont {
Some(requested_size) => (requested_size, face.set_size(requested_size)?),
None => (Au::zero(), Au::zero()),
};
let can_do_fast_shaping =
face.has_table(KERN) && !face.has_table(GPOS) && !face.has_table(GSUB);
Ok(PlatformFont {
face: ReentrantMutex::new(face),
font_data: data,
requested_face_size,
actual_face_size,
can_do_fast_shaping,
})
}
@ -215,10 +211,6 @@ impl PlatformFontMethods for PlatformFont {
fixed_26_dot_6_to_float(delta.x) * self.unscalable_font_metrics_scale()
}
fn can_do_fast_shaping(&self) -> bool {
self.can_do_fast_shaping
}
fn glyph_h_advance(&self, glyph: GlyphId) -> Option<FractionalPixel> {
let face = self.face.lock();
assert!(!face.is_null());

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 {

View file

@ -211,11 +211,6 @@ impl PlatformFontMethods for PlatformFont {
Some(f)
}
/// Can this font do basic horizontal LTR shaping without Harfbuzz?
fn can_do_fast_shaping(&self) -> bool {
self.face.has_kerning_pairs()
}
fn glyph_h_kerning(&self, first_glyph: GlyphId, second_glyph: GlyphId) -> FractionalPixel {
let adjustment = self
.face