Skip to content

Commit

Permalink
use new set digest in fontations
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrg committed Jul 15, 2024
1 parent 2ef33d7 commit bd0ddd9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
5 changes: 1 addition & 4 deletions src/hb/fonta/ot/gpos/pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ fn find_second_glyph<'a>(
hi = mid;
} else {
let set = pair_pos.pair_sets().get(set_index).ok()?;
return Some((
set.pair_value_records().get(mid).ok()?,
set.offset_data(),
));
return Some((set.pair_value_records().get(mid).ok()?, set.offset_data()));
}
}
None
Expand Down
34 changes: 28 additions & 6 deletions src/hb/fonta/ot/lookup_cache.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::hb::set_digest::{hb_set_digest_ext, hb_set_digest_t};

use super::super::SetDigest;
use alloc::vec::Vec;
use core::ops::Range;
Expand Down Expand Up @@ -206,8 +208,10 @@ impl LookupCache {
}
let subtable = subtable_info.materialize(data.table_data.as_bytes())?;
let (coverage, coverage_offset) = subtable.coverage_and_offset()?;
subtable_info.digest.insert_coverage(&coverage);
entry.digest.insert_coverage(&coverage);
add_coverage_to_digest(&coverage, &mut subtable_info.digest);
add_coverage_to_digest(&coverage, &mut entry.digest);
// subtable_info.digest.insert_coverage(&coverage);
// entry.digest.insert_coverage(&coverage);
subtable_info.coverage_offset = coverage_offset;
self.subtables.push(subtable_info);
entry.subtables_count += 1;
Expand Down Expand Up @@ -241,6 +245,24 @@ fn is_reversed(table_data: FontData, lookup: &Lookup<()>, lookup_offset: usize)
}
}

fn add_coverage_to_digest(coverage: &CoverageTable, digest: &mut hb_set_digest_t) {
match coverage {
CoverageTable::Format1(table) => {
for glyph in table.glyph_array() {
digest.add(ttf_parser::GlyphId(glyph.get().to_u32() as _));
}
}
CoverageTable::Format2(table) => {
for range in table.range_records() {
let first = range.start_glyph_id().to_u32();
let last = range.end_glyph_id().to_u32();
let [first, last] = [first, last].map(|gid| ttf_parser::GlyphId(gid as _));
digest.add_range(first, last);
}
}
}
}

/// Current state of a lookup cache entry.
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
#[repr(u8)]
Expand All @@ -256,7 +278,7 @@ pub enum LookupState {
}

/// Cached information about a lookup.
#[derive(Copy, Clone, Default, Debug)]
#[derive(Clone, Default, Debug)]
pub struct LookupInfo {
/// Current state of this lookup info entry.
pub state: LookupState,
Expand All @@ -272,7 +294,7 @@ pub struct LookupInfo {
pub subtables_count: u16,
/// Bloom filter representing the set of glyphs from the primary
/// coverage of all subtables in the lookup.
pub digest: SetDigest,
pub digest: hb_set_digest_t,
}

impl LookupInfo {
Expand All @@ -283,7 +305,7 @@ impl LookupInfo {
}

/// Cached information about a subtable.
#[derive(Copy, Clone, Debug)]
#[derive(Clone, Debug)]
pub struct SubtableInfo {
/// Byte offset to the subtable from the base of the GSUB or GPOS
/// table.
Expand All @@ -296,7 +318,7 @@ pub struct SubtableInfo {
pub is_subst: bool,
/// Original lookup type.
pub lookup_type: u8,
pub digest: SetDigest,
pub digest: hb_set_digest_t,
}

impl SubtableInfo {
Expand Down
13 changes: 7 additions & 6 deletions src/hb/fonta/ot/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::hb::{
ot_layout::LayoutLookup,
ot_layout_gsubgpos::{Apply, OT::hb_ot_apply_context_t},
set_digest::hb_set_digest_ext,
};
use skrifa::raw::{
tables::{gdef::Gdef, variations::ItemVariationStore},
Expand Down Expand Up @@ -44,19 +45,19 @@ impl LayoutLookup for LookupInfo {
self.props
}

fn covers(&self, glyph: ttf_parser::GlyphId) -> bool {
self.digest.may_contain(glyph.0)
}

fn is_reverse(&self) -> bool {
self.is_reversed
}

fn digest(&self) -> &crate::hb::set_digest::hb_set_digest_t {
&self.digest
}
}

impl Apply for LookupInfo {
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
let glyph = ctx.buffer.cur(0).as_glyph();
if !self.covers(glyph) {
if !self.digest.may_have_glyph(glyph) {
return None;
}
let (table_data, lookups) = if self.is_subst {
Expand All @@ -68,7 +69,7 @@ impl Apply for LookupInfo {
};
let subtables = lookups.subtables(self)?;
for subtable_info in subtables {
if !subtable_info.digest.may_contain(glyph.0) {
if !subtable_info.digest.may_have_glyph(glyph) {
continue;
}
// if subtable_info
Expand Down
6 changes: 3 additions & 3 deletions src/hb/set_digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ttf_parser::GlyphId;
// harfbuzz.
type mask_t = u64;

pub trait hb_set_digest_ext: Clone {
pub trait hb_set_digest_ext: Clone + Default {
type A;
// Instead of `init()`
fn new() -> Self;
Expand All @@ -17,7 +17,7 @@ pub trait hb_set_digest_ext: Clone {
fn may_have_glyph(&self, g: GlyphId) -> bool;
}

#[derive(Clone)]
#[derive(Clone, Default, Debug)]
pub struct hb_set_digest_bits_pattern_t<const shift: u8> {
mask: mask_t,
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<const shift: u8> hb_set_digest_ext for hb_set_digest_bits_pattern_t<shift>
}
}

#[derive(Clone)]
#[derive(Clone, Default, Debug)]
pub struct hb_set_digest_combiner_t<head_t, tail_t>
where
head_t: hb_set_digest_ext,
Expand Down
2 changes: 1 addition & 1 deletion tests/shaping/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod custom;
mod in_house;
mod macos;
mod text_rendering_tests;
#[cfg(feature="wasm-shaper")]
#[cfg(feature = "wasm-shaper")]
mod wasm;

use std::str::FromStr;
Expand Down

0 comments on commit bd0ddd9

Please sign in to comment.