diff options
| author | Max <me@mkor.je> | 2024-10-30 15:29:15 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-30 15:29:15 +0000 |
| commit | f85faf957ff6067e0b6f20a3d27388cc4549a330 (patch) | |
| tree | 5ece60cc7ffce75a76d1653f6aef4ec189612c85 /crates/typst-layout/src/math/mod.rs | |
| parent | 2634a8402cdbd2443edf27abeb4ee6bafb70f5bd (diff) | |
Add `math.accent` support for `flac` and `dtls` OpenType features (#5202)
Diffstat (limited to 'crates/typst-layout/src/math/mod.rs')
| -rw-r--r-- | crates/typst-layout/src/math/mod.rs | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/crates/typst-layout/src/math/mod.rs b/crates/typst-layout/src/math/mod.rs index b3dde977..32059cef 100644 --- a/crates/typst-layout/src/math/mod.rs +++ b/crates/typst-layout/src/math/mod.rs @@ -13,7 +13,8 @@ mod stretch; mod text; mod underover; -use ttf_parser::gsub::SubstitutionSubtable; +use rustybuzz::Feature; +use ttf_parser::Tag; use typst_library::diag::{bail, SourceResult}; use typst_library::engine::Engine; use typst_library::foundations::{Content, NativeElement, Packed, Resolve, StyleChain}; @@ -369,7 +370,9 @@ struct MathContext<'a, 'v, 'e> { ttf: &'a ttf_parser::Face<'a>, table: ttf_parser::math::Table<'a>, constants: ttf_parser::math::Constants<'a>, - ssty_table: Option<ttf_parser::gsub::AlternateSubstitution<'a>>, + dtls_table: Option<GlyphwiseSubsts<'a>>, + flac_table: Option<GlyphwiseSubsts<'a>>, + ssty_table: Option<GlyphwiseSubsts<'a>>, glyphwise_tables: Option<Vec<GlyphwiseSubsts<'a>>>, space_width: Em, // Mutable. @@ -389,26 +392,17 @@ impl<'a, 'v, 'e> MathContext<'a, 'v, 'e> { let gsub_table = font.ttf().tables().gsub; let constants = math_table.constants.unwrap(); - let ssty_table = gsub_table - .and_then(|gsub| { - gsub.features - .find(ttf_parser::Tag::from_bytes(b"ssty")) - .and_then(|feature| feature.lookup_indices.get(0)) - .and_then(|index| gsub.lookups.get(index)) - }) - .and_then(|ssty| ssty.subtables.get::<SubstitutionSubtable>(0)) - .and_then(|ssty| match ssty { - SubstitutionSubtable::Alternate(alt_glyphs) => Some(alt_glyphs), - _ => None, - }); + let feat = |tag: &[u8; 4]| { + GlyphwiseSubsts::new(gsub_table, Feature::new(Tag::from_bytes(tag), 0, ..)) + }; let features = features(styles); - let glyphwise_tables = gsub_table.map(|gsub| { + let glyphwise_tables = Some( features .into_iter() - .filter_map(|feature| GlyphwiseSubsts::new(gsub, feature)) - .collect() - }); + .filter_map(|feature| GlyphwiseSubsts::new(gsub_table, feature)) + .collect(), + ); let ttf = font.ttf(); let space_width = ttf @@ -422,10 +416,12 @@ impl<'a, 'v, 'e> MathContext<'a, 'v, 'e> { locator, region: Region::new(base, Axes::splat(false)), font, - ttf: font.ttf(), + ttf, table: math_table, constants, - ssty_table, + dtls_table: feat(b"dtls"), + flac_table: feat(b"flac"), + ssty_table: feat(b"ssty"), glyphwise_tables, space_width, fragments: vec![], |
