Skip to content

Commit

Permalink
[set-digest] replace GlyphCoverage with set-digest
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Jul 2, 2024
1 parent 61070cf commit fe4d974
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 180 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(&self, glyph: GlyphId) -> bool {
self.set_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(ctx.buffer.cur(0).as_glyph()) {
for subtable in &self.subtables {
if subtable.apply(ctx).is_some() {
return Some(());
Expand Down
9 changes: 5 additions & 4 deletions src/hb/ot/layout/GSUB/subst_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::SubstLookup;
use crate::hb::ot_layout_gsubgpos::OT::hb_ot_apply_context_t;
use crate::hb::ot_layout_gsubgpos::{Apply, WouldApply, WouldApplyContext};
use crate::hb::set_digest::hb_set_digest_ext;
use ttf_parser::GlyphId;

impl LayoutLookup for SubstLookup<'_> {
Expand All @@ -13,14 +14,14 @@ impl LayoutLookup for SubstLookup<'_> {
self.reverse
}

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

impl WouldApply for SubstLookup<'_> {
fn would_apply(&self, ctx: &WouldApplyContext) -> bool {
self.covers(ctx.glyphs[0])
self.may_have(ctx.glyphs[0])
&& self
.subtables
.iter()
Expand All @@ -30,7 +31,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(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(&self, glyph: GlyphId) -> bool;
}

pub trait LayoutTableExt {
Expand Down
32 changes: 14 additions & 18 deletions src/hb/ot_layout_common.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::hb::set_digest::{hb_set_digest_ext, hb_set_digest_t};
use alloc::vec::Vec;

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 +34,19 @@ impl<'a> PositioningTable<'a> {
}

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

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

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

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

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

let mut coverage = GlyphSet::builder();
let mut set_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 set_digest);
reverse &= subtable.is_reverse();
}

Self {
subtables,
coverage: coverage.finish(),
set_digest,
reverse,
props: lookup_props(lookup),
}
Expand Down
1 change: 0 additions & 1 deletion src/hb/set_digest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::println;
use ttf_parser::GlyphId;

// To make things easier, we don't have the generic parameter mask_t,
Expand Down

0 comments on commit fe4d974

Please sign in to comment.