Skip to content

Commit

Permalink
[set-digest] Use set digest instead of GlyphCoverage
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Jul 2, 2024
1 parent cef1719 commit 32f2ae6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 177 deletions.
152 changes: 0 additions & 152 deletions src/hb/glyph_set.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/hb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ mod aat_layout_trak_table;
mod aat_map;
pub mod common;
pub mod face;
mod glyph_set;
mod kerning;
mod machine_cursor;
mod ot;
Expand Down
7 changes: 4 additions & 3 deletions src/hb/ot/layout/GPOS/pos_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::hb::ot_layout::LayoutLookup;
use crate::hb::ot_layout_common::PositioningLookup;
use crate::hb::ot_layout_gsubgpos::Apply;
use crate::hb::ot_layout_gsubgpos::OT::hb_ot_apply_context_t;
use crate::hb::set_digest::hb_set_digest_ext;
use ttf_parser::GlyphId;

impl LayoutLookup for PositioningLookup<'_> {
Expand All @@ -13,14 +14,14 @@ impl LayoutLookup for PositioningLookup<'_> {
false
}

fn covers(&self, glyph: GlyphId) -> bool {
self.coverage.contains(glyph)
fn may_have_glyph(&self, glyph: GlyphId) -> bool {
self.digest.may_have_glyph(glyph)
}
}

impl Apply for PositioningLookup<'_> {
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
if self.covers(ctx.buffer.cur(0).as_glyph()) {
if self.may_have_glyph(ctx.buffer.cur(0).as_glyph()) {
for subtable in &self.subtables {
if subtable.apply(ctx).is_some() {
return Some(());
Expand Down
2 changes: 1 addition & 1 deletion src/hb/ot_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub trait LayoutLookup: Apply {
fn is_reverse(&self) -> bool;

/// Whether any subtable of the lookup could apply at a specific glyph.
fn covers(&self, glyph: GlyphId) -> bool;
fn may_have_glyph(&self, glyph: GlyphId) -> bool;
}

pub trait LayoutTableExt {
Expand Down
29 changes: 13 additions & 16 deletions src/hb/ot_layout_common.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use alloc::vec::Vec;

use crate::hb::set_digest::{hb_set_digest_ext, hb_set_digest_t};
use ttf_parser::gpos::PositioningSubtable;
use ttf_parser::gsub::SubstitutionSubtable;
use ttf_parser::opentype_layout::{Coverage, Lookup};

use super::glyph_set::{GlyphSet, GlyphSetBuilder};

#[allow(dead_code)]
pub mod lookup_flags {
pub const RIGHT_TO_LEFT: u16 = 0x0001;
Expand Down Expand Up @@ -36,21 +35,19 @@ impl<'a> PositioningTable<'a> {
}

pub trait CoverageExt {
fn collect(&self, set: &mut GlyphSetBuilder);
fn collect(&self, digest: &mut hb_set_digest_t);
}

impl CoverageExt for Coverage<'_> {
/// Collect this coverage table into a glyph set.
fn collect(&self, set: &mut GlyphSetBuilder) {
fn collect(&self, digest: &mut hb_set_digest_t) {
match *self {
Self::Format1 { glyphs } => {
for glyph in glyphs {
set.insert(glyph);
}
digest.add_array(glyphs);
}
Self::Format2 { records } => {
for record in records {
set.insert_range(record.start..=record.end);
digest.add_range(record.start, record.end);
}
}
}
Expand All @@ -60,7 +57,7 @@ impl CoverageExt for Coverage<'_> {
#[derive(Clone)]
pub struct PositioningLookup<'a> {
pub subtables: Vec<PositioningSubtable<'a>>,
pub coverage: GlyphSet,
pub digest: hb_set_digest_t,
pub props: u32,
}

Expand All @@ -71,14 +68,14 @@ impl<'a> PositioningLookup<'a> {
.into_iter::<PositioningSubtable>()
.collect();

let mut coverage = GlyphSet::builder();
let mut digest = hb_set_digest_t::new();
for subtable in &subtables {
subtable.coverage().collect(&mut coverage);
subtable.coverage().collect(&mut digest);
}

Self {
subtables,
coverage: coverage.finish(),
digest,
props: lookup_props(lookup),
}
}
Expand All @@ -101,7 +98,7 @@ impl<'a> SubstitutionTable<'a> {
#[derive(Clone)]
pub struct SubstLookup<'a> {
pub subtables: Vec<SubstitutionSubtable<'a>>,
pub coverage: GlyphSet,
pub digest: hb_set_digest_t,
pub reverse: bool,
pub props: u32,
}
Expand All @@ -113,17 +110,17 @@ impl<'a> SubstLookup<'a> {
.into_iter::<SubstitutionSubtable>()
.collect();

let mut coverage = GlyphSet::builder();
let mut digest = hb_set_digest_t::new();
let mut reverse = !subtables.is_empty();

for subtable in &subtables {
subtable.coverage().collect(&mut coverage);
subtable.coverage().collect(&mut digest);
reverse &= subtable.is_reverse();
}

Self {
subtables,
coverage: coverage.finish(),
digest,
reverse,
props: lookup_props(lookup),
}
Expand Down
9 changes: 5 additions & 4 deletions src/hb/ot_layout_gsub_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::ot_layout::*;
use super::ot_layout_common::{SubstLookup, SubstitutionTable};
use super::ot_layout_gsubgpos::*;
use super::ot_shape_plan::hb_ot_shape_plan_t;
use crate::hb::set_digest::hb_set_digest_ext;
use OT::hb_ot_apply_context_t;

pub fn substitute(plan: &hb_ot_shape_plan_t, face: &hb_font_t, buffer: &mut hb_buffer_t) {
Expand All @@ -34,14 +35,14 @@ impl LayoutLookup for SubstLookup<'_> {
self.reverse
}

fn covers(&self, glyph: GlyphId) -> bool {
self.coverage.contains(glyph)
fn may_have_glyph(&self, glyph: GlyphId) -> bool {
self.digest.may_have_glyph(glyph)
}
}

impl WouldApply for SubstLookup<'_> {
fn would_apply(&self, ctx: &WouldApplyContext) -> bool {
self.covers(ctx.glyphs[0])
self.may_have_glyph(ctx.glyphs[0])
&& self
.subtables
.iter()
Expand All @@ -51,7 +52,7 @@ impl WouldApply for SubstLookup<'_> {

impl Apply for SubstLookup<'_> {
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
if self.covers(ctx.buffer.cur(0).as_glyph()) {
if self.may_have_glyph(ctx.buffer.cur(0).as_glyph()) {
for subtable in &self.subtables {
if subtable.apply(ctx).is_some() {
return Some(());
Expand Down

0 comments on commit 32f2ae6

Please sign in to comment.