Skip to content

Commit cac63e2

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

File tree

2 files changed

+31
-37
lines changed

2 files changed

+31
-37
lines changed

src/hb/ot/mod.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::buffer::GlyphPropsFlags;
22
use super::ot_layout::TableIndex;
3-
use super::{common::TagExt, set_digest::hb_set_digest_t};
3+
use super::{common::TagExt};
44
use crate::hb::hb_tag_t;
55
use crate::hb::ot_layout_gsubgpos::MappingCache;
66
use crate::hb::tables::TableOffsets;
@@ -16,8 +16,9 @@ use read_fonts::{
1616
varc::{Condition, CoverageTable},
1717
variations::{DeltaSetIndex, ItemVariationStore},
1818
},
19-
types::{BigEndian, F2Dot14, GlyphId, Offset32},
20-
FontData, FontRef, ReadError, ResolveOffset, TableProvider,
19+
types::{F2Dot14, GlyphId},
20+
collections::int_set::U32Set,
21+
FontRef, ReadError, TableProvider,
2122
};
2223

2324
pub mod contextual;
@@ -29,7 +30,7 @@ pub struct OtCache {
2930
pub gsub: LookupCache,
3031
pub gpos: LookupCache,
3132
pub gdef_glyph_props_cache: MappingCache,
32-
pub gdef_mark_set_digests: Vec<hb_set_digest_t>,
33+
pub gdef_mark_sets: Vec<U32Set>,
3334
}
3435

3536
impl OtCache {
@@ -50,12 +51,29 @@ impl OtCache {
5051
cache
5152
})
5253
.unwrap_or_default();
53-
let mut gdef_mark_set_digests = Vec::new();
54+
let mut gdef_mark_sets = Vec::new();
5455
if let Ok(gdef) = font.gdef() {
5556
if let Some(Ok(mark_sets)) = gdef.mark_glyph_sets_def() {
56-
gdef_mark_set_digests.extend(mark_sets.coverages().iter().map(|set| {
57+
gdef_mark_sets.extend(mark_sets.coverages().iter().map(|set| {
5758
set.ok()
58-
.map(|coverage| hb_set_digest_t::from_coverage(&coverage))
59+
.map(|coverage| {
60+
let mut set = U32Set::empty();
61+
62+
// TODO Move somewhere in Coverage.
63+
match coverage {
64+
CoverageTable::Format1(table) => {
65+
for glyph in table.glyph_array() {
66+
set.insert(glyph.get().into());
67+
}
68+
}
69+
CoverageTable::Format2(table) => {
70+
for range in table.range_records() {
71+
set.insert_range(range.start_glyph_id().into()..=range.end_glyph_id().into());
72+
}
73+
}
74+
}
75+
set
76+
})
5977
.unwrap_or_default()
6078
}));
6179
}
@@ -64,7 +82,7 @@ impl OtCache {
6482
gsub,
6583
gpos,
6684
gdef_glyph_props_cache: MappingCache::new(),
67-
gdef_mark_set_digests,
85+
gdef_mark_sets,
6886
}
6987
}
7088
}
@@ -106,25 +124,17 @@ pub struct GdefTable<'a> {
106124
table: Option<Gdef<'a>>,
107125
classes: Option<ClassDef<'a>>,
108126
mark_classes: Option<ClassDef<'a>>,
109-
mark_sets: Option<(FontData<'a>, &'a [BigEndian<Offset32>])>,
110127
}
111128

112129
impl<'a> GdefTable<'a> {
113130
fn new(font: &FontRef<'a>, table_offsets: &TableOffsets) -> Self {
114131
if let Some(gdef) = table_offsets.gdef.resolve_table::<Gdef>(font) {
115132
let classes = gdef.glyph_class_def().transpose().ok().flatten();
116133
let mark_classes = gdef.mark_attach_class_def().transpose().ok().flatten();
117-
let mark_sets = gdef
118-
.mark_glyph_sets_def()
119-
.transpose()
120-
.ok()
121-
.flatten()
122-
.map(|sets| (sets.offset_data(), sets.coverage_offsets()));
123134
Self {
124135
table: Some(gdef),
125136
classes,
126137
mark_classes,
127-
mark_sets,
128138
}
129139
} else {
130140
Self::default()
@@ -138,7 +148,7 @@ pub struct OtTables<'a> {
138148
pub gpos: Option<GposTable<'a>>,
139149
pub gdef: GdefTable<'a>,
140150
pub gdef_glyph_props_cache: &'a MappingCache,
141-
pub gdef_mark_set_digests: &'a [hb_set_digest_t],
151+
pub gdef_mark_sets: &'a [U32Set],
142152
pub coords: &'a [F2Dot14],
143153
pub var_store: Option<ItemVariationStore<'a>>,
144154
pub value_context: ValueContext<'a>,
@@ -187,7 +197,7 @@ impl<'a> OtTables<'a> {
187197
gpos,
188198
gdef,
189199
gdef_glyph_props_cache: &cache.gdef_glyph_props_cache,
190-
gdef_mark_set_digests: &cache.gdef_mark_set_digests,
200+
gdef_mark_sets: &cache.gdef_mark_sets,
191201
var_store,
192202
coords,
193203
value_context,
@@ -235,20 +245,10 @@ impl<'a> OtTables<'a> {
235245
}
236246

237247
pub fn is_mark_glyph(&self, glyph_id: u32, set_index: u16) -> bool {
238-
if self
239-
.gdef_mark_set_digests
248+
self
249+
.gdef_mark_sets
240250
.get(set_index as usize)
241-
.is_some_and(|digest| digest.may_have_glyph(glyph_id.into()))
242-
{
243-
self.gdef
244-
.mark_sets
245-
.as_ref()
246-
.and_then(|(data, offsets)| Some((data, offsets.get(set_index as usize)?.get())))
247-
.and_then(|(data, offset)| offset.resolve::<CoverageTable>(*data).ok())
248-
.is_some_and(|coverage| coverage.get(glyph_id).is_some())
249-
} else {
250-
false
251-
}
251+
.is_some_and(|set| set.contains(glyph_id.into()))
252252
}
253253

254254
pub fn table_data_and_lookups(

src/hb/set_digest.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ impl hb_set_digest_t {
2525
Self { masks: [0; N] }
2626
}
2727

28-
pub fn from_coverage(coverage: &CoverageTable) -> Self {
29-
let mut digest = Self::new();
30-
digest.add_coverage(coverage);
31-
digest
32-
}
33-
3428
pub fn _clear(&mut self) {
3529
self.masks = [0; N];
3630
}

0 commit comments

Comments
 (0)