Skip to content

Commit bd0ddd9

Browse files
committed
use new set digest in fontations
1 parent 2ef33d7 commit bd0ddd9

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed

src/hb/fonta/ot/gpos/pair.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ fn find_second_glyph<'a>(
111111
hi = mid;
112112
} else {
113113
let set = pair_pos.pair_sets().get(set_index).ok()?;
114-
return Some((
115-
set.pair_value_records().get(mid).ok()?,
116-
set.offset_data(),
117-
));
114+
return Some((set.pair_value_records().get(mid).ok()?, set.offset_data()));
118115
}
119116
}
120117
None

src/hb/fonta/ot/lookup_cache.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::hb::set_digest::{hb_set_digest_ext, hb_set_digest_t};
2+
13
use super::super::SetDigest;
24
use alloc::vec::Vec;
35
use core::ops::Range;
@@ -206,8 +208,10 @@ impl LookupCache {
206208
}
207209
let subtable = subtable_info.materialize(data.table_data.as_bytes())?;
208210
let (coverage, coverage_offset) = subtable.coverage_and_offset()?;
209-
subtable_info.digest.insert_coverage(&coverage);
210-
entry.digest.insert_coverage(&coverage);
211+
add_coverage_to_digest(&coverage, &mut subtable_info.digest);
212+
add_coverage_to_digest(&coverage, &mut entry.digest);
213+
// subtable_info.digest.insert_coverage(&coverage);
214+
// entry.digest.insert_coverage(&coverage);
211215
subtable_info.coverage_offset = coverage_offset;
212216
self.subtables.push(subtable_info);
213217
entry.subtables_count += 1;
@@ -241,6 +245,24 @@ fn is_reversed(table_data: FontData, lookup: &Lookup<()>, lookup_offset: usize)
241245
}
242246
}
243247

248+
fn add_coverage_to_digest(coverage: &CoverageTable, digest: &mut hb_set_digest_t) {
249+
match coverage {
250+
CoverageTable::Format1(table) => {
251+
for glyph in table.glyph_array() {
252+
digest.add(ttf_parser::GlyphId(glyph.get().to_u32() as _));
253+
}
254+
}
255+
CoverageTable::Format2(table) => {
256+
for range in table.range_records() {
257+
let first = range.start_glyph_id().to_u32();
258+
let last = range.end_glyph_id().to_u32();
259+
let [first, last] = [first, last].map(|gid| ttf_parser::GlyphId(gid as _));
260+
digest.add_range(first, last);
261+
}
262+
}
263+
}
264+
}
265+
244266
/// Current state of a lookup cache entry.
245267
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
246268
#[repr(u8)]
@@ -256,7 +278,7 @@ pub enum LookupState {
256278
}
257279

258280
/// Cached information about a lookup.
259-
#[derive(Copy, Clone, Default, Debug)]
281+
#[derive(Clone, Default, Debug)]
260282
pub struct LookupInfo {
261283
/// Current state of this lookup info entry.
262284
pub state: LookupState,
@@ -272,7 +294,7 @@ pub struct LookupInfo {
272294
pub subtables_count: u16,
273295
/// Bloom filter representing the set of glyphs from the primary
274296
/// coverage of all subtables in the lookup.
275-
pub digest: SetDigest,
297+
pub digest: hb_set_digest_t,
276298
}
277299

278300
impl LookupInfo {
@@ -283,7 +305,7 @@ impl LookupInfo {
283305
}
284306

285307
/// Cached information about a subtable.
286-
#[derive(Copy, Clone, Debug)]
308+
#[derive(Clone, Debug)]
287309
pub struct SubtableInfo {
288310
/// Byte offset to the subtable from the base of the GSUB or GPOS
289311
/// table.
@@ -296,7 +318,7 @@ pub struct SubtableInfo {
296318
pub is_subst: bool,
297319
/// Original lookup type.
298320
pub lookup_type: u8,
299-
pub digest: SetDigest,
321+
pub digest: hb_set_digest_t,
300322
}
301323

302324
impl SubtableInfo {

src/hb/fonta/ot/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::hb::{
22
ot_layout::LayoutLookup,
33
ot_layout_gsubgpos::{Apply, OT::hb_ot_apply_context_t},
4+
set_digest::hb_set_digest_ext,
45
};
56
use skrifa::raw::{
67
tables::{gdef::Gdef, variations::ItemVariationStore},
@@ -44,19 +45,19 @@ impl LayoutLookup for LookupInfo {
4445
self.props
4546
}
4647

47-
fn covers(&self, glyph: ttf_parser::GlyphId) -> bool {
48-
self.digest.may_contain(glyph.0)
49-
}
50-
5148
fn is_reverse(&self) -> bool {
5249
self.is_reversed
5350
}
51+
52+
fn digest(&self) -> &crate::hb::set_digest::hb_set_digest_t {
53+
&self.digest
54+
}
5455
}
5556

5657
impl Apply for LookupInfo {
5758
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
5859
let glyph = ctx.buffer.cur(0).as_glyph();
59-
if !self.covers(glyph) {
60+
if !self.digest.may_have_glyph(glyph) {
6061
return None;
6162
}
6263
let (table_data, lookups) = if self.is_subst {
@@ -68,7 +69,7 @@ impl Apply for LookupInfo {
6869
};
6970
let subtables = lookups.subtables(self)?;
7071
for subtable_info in subtables {
71-
if !subtable_info.digest.may_contain(glyph.0) {
72+
if !subtable_info.digest.may_have_glyph(glyph) {
7273
continue;
7374
}
7475
// if subtable_info

src/hb/set_digest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ttf_parser::GlyphId;
55
// harfbuzz.
66
type mask_t = u64;
77

8-
pub trait hb_set_digest_ext: Clone {
8+
pub trait hb_set_digest_ext: Clone + Default {
99
type A;
1010
// Instead of `init()`
1111
fn new() -> Self;
@@ -17,7 +17,7 @@ pub trait hb_set_digest_ext: Clone {
1717
fn may_have_glyph(&self, g: GlyphId) -> bool;
1818
}
1919

20-
#[derive(Clone)]
20+
#[derive(Clone, Default, Debug)]
2121
pub struct hb_set_digest_bits_pattern_t<const shift: u8> {
2222
mask: mask_t,
2323
}
@@ -112,7 +112,7 @@ impl<const shift: u8> hb_set_digest_ext for hb_set_digest_bits_pattern_t<shift>
112112
}
113113
}
114114

115-
#[derive(Clone)]
115+
#[derive(Clone, Default, Debug)]
116116
pub struct hb_set_digest_combiner_t<head_t, tail_t>
117117
where
118118
head_t: hb_set_digest_ext,

tests/shaping/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod custom;
33
mod in_house;
44
mod macos;
55
mod text_rendering_tests;
6-
#[cfg(feature="wasm-shaper")]
6+
#[cfg(feature = "wasm-shaper")]
77
mod wasm;
88

99
use std::str::FromStr;

0 commit comments

Comments
 (0)