Skip to content

Commit ce60f0c

Browse files
committed
WIP [GDEF] Use a bit-set for representing mark-filtering-sets
HB does this.
1 parent 9afb24e commit ce60f0c

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/hb/ot/mod.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::ot_layout::TableIndex;
2-
use super::{common::TagExt, set_digest::hb_set_digest_t};
2+
use super::{common::TagExt};
33
use crate::hb::hb_tag_t;
44
use crate::hb::ot_layout_gsubgpos::MappingCache;
55
use alloc::vec::Vec;
@@ -14,6 +14,7 @@ use read_fonts::{
1414
variations::{DeltaSetIndex, ItemVariationStore},
1515
},
1616
types::{BigEndian, F2Dot14, GlyphId, Offset32},
17+
collections::int_set::BitSet,
1718
FontData, FontRef, ReadError, ResolveOffset, TableProvider,
1819
};
1920

@@ -25,7 +26,7 @@ pub mod lookup;
2526
pub struct OtCache {
2627
pub gsub: LookupCache,
2728
pub gpos: LookupCache,
28-
pub gdef_mark_set_digests: Vec<hb_set_digest_t>,
29+
pub gdef_mark_sets: Vec<BitSet>,
2930
}
3031

3132
impl OtCache {
@@ -46,20 +47,36 @@ impl OtCache {
4647
cache
4748
})
4849
.unwrap_or_default();
49-
let mut gdef_mark_set_digests = Vec::new();
50+
let mut gdef_mark_sets = Vec::new();
5051
if let Ok(gdef) = font.gdef() {
5152
if let Some(Ok(mark_sets)) = gdef.mark_glyph_sets_def() {
52-
gdef_mark_set_digests.extend(mark_sets.coverages().iter().map(|set| {
53+
gdef_mark_sets.extend(mark_sets.coverages().iter().map(|set| {
5354
set.ok()
54-
.map(|coverage| hb_set_digest_t::from_coverage(&coverage))
55+
.map(|coverage| {
56+
let mut set = BitSet::empty();
57+
58+
match coverage {
59+
CoverageTable::Format1(table) => {
60+
for glyph in table.glyph_array() {
61+
set.insert(glyph.get().into());
62+
}
63+
}
64+
CoverageTable::Format2(table) => {
65+
for range in table.range_records() {
66+
set.insert_range(range.start_glyph_id().into()..=range.end_glyph_id().into());
67+
}
68+
}
69+
}
70+
set
71+
})
5572
.unwrap_or_default()
5673
}));
5774
}
5875
}
5976
Self {
6077
gsub,
6178
gpos,
62-
gdef_mark_set_digests,
79+
gdef_mark_sets,
6380
}
6481
}
6582
}
@@ -132,7 +149,7 @@ pub struct OtTables<'a> {
132149
pub gsub: Option<GsubTable<'a>>,
133150
pub gpos: Option<GposTable<'a>>,
134151
pub gdef: GdefTable<'a>,
135-
pub gdef_mark_set_digests: &'a [hb_set_digest_t],
152+
pub gdef_mark_sets: &'a [BitSet],
136153
pub coords: &'a [F2Dot14],
137154
pub var_store: Option<ItemVariationStore<'a>>,
138155
}
@@ -164,7 +181,7 @@ impl<'a> OtTables<'a> {
164181
gsub,
165182
gpos,
166183
gdef,
167-
gdef_mark_set_digests: &cache.gdef_mark_set_digests,
184+
gdef_mark_sets: &cache.gdef_mark_sets,
168185
var_store,
169186
coords,
170187
}
@@ -189,20 +206,10 @@ impl<'a> OtTables<'a> {
189206
}
190207

191208
pub fn is_mark_glyph(&self, glyph_id: u32, set_index: u16) -> bool {
192-
if self
193-
.gdef_mark_set_digests
209+
self
210+
.gdef_mark_sets
194211
.get(set_index as usize)
195-
.is_some_and(|digest| digest.may_have_glyph(glyph_id.into()))
196-
{
197-
self.gdef
198-
.mark_sets
199-
.as_ref()
200-
.and_then(|(data, offsets)| Some((data, offsets.get(set_index as usize)?.get())))
201-
.and_then(|(data, offset)| offset.resolve::<CoverageTable>(*data).ok())
202-
.is_some_and(|coverage| coverage.get(glyph_id).is_some())
203-
} else {
204-
false
205-
}
212+
.is_some_and(|set| set.contains(glyph_id.into()))
206213
}
207214

208215
pub fn table_data_and_lookups(

0 commit comments

Comments
 (0)