Skip to content

Commit

Permalink
Merge pull request #567 from googlefonts/t2
Browse files Browse the repository at this point in the history
Move construction of kerning and mark structures to feed to fea-rs into separate jobs that can run in parallel
  • Loading branch information
rsheeter authored Nov 16, 2023
2 parents 6bb65f3 + 2bdf37c commit 9d326d3
Show file tree
Hide file tree
Showing 15 changed files with 873 additions and 387 deletions.
13 changes: 6 additions & 7 deletions fea-rs/src/common/glyph_class.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::rc::Rc;

use write_fonts::types::GlyphId;

use super::GlyphOrClass;
Expand All @@ -24,7 +22,7 @@ use super::GlyphOrClass;
///
/// [spec docs]: http://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#2g-glyph-classes
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) struct GlyphClass(Rc<[GlyphId]>);
pub(crate) struct GlyphClass(Vec<GlyphId>);

/// A sorted set of unique glyph ids.
///
Expand All @@ -34,7 +32,8 @@ pub(crate) struct GlyphClass(Rc<[GlyphId]>);
/// In the former case, we want to be able to do things like compare for equality
/// and stabily sort, so we ensure that these classes are sorted and deduped.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct GlyphSet(Rc<[GlyphId]>);
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct GlyphSet(Vec<GlyphId>);

impl GlyphClass {
pub(crate) fn items(&self) -> &[GlyphId] {
Expand All @@ -43,7 +42,7 @@ impl GlyphClass {

/// Return a new, empty glyph class
pub fn empty() -> Self {
Self(Rc::new([]))
Self(Default::default())
}

/// Return a `GlyphSet` containing the unique glyphs in this class.
Expand Down Expand Up @@ -89,7 +88,7 @@ impl<'a> std::iter::IntoIterator for &'a GlyphClass {

impl From<Vec<GlyphId>> for GlyphClass {
fn from(src: Vec<GlyphId>) -> GlyphClass {
GlyphClass(src.into())
GlyphClass(src)
}
}

Expand All @@ -104,7 +103,7 @@ impl From<Vec<GlyphId>> for GlyphSet {
fn from(mut value: Vec<GlyphId>) -> Self {
value.sort_unstable();
value.dedup();
Self(value.into())
Self(value)
}
}

Expand Down
3 changes: 2 additions & 1 deletion fea-rs/src/common/glyph_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use std::{
///
/// Currently, the only way to construct this type is by calling `collect()`
/// on an iterator of cids or names.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct GlyphMap {
names: HashMap<GlyphName, GlyphId>,
cids: HashMap<u16, GlyphId>,
Expand Down
12 changes: 8 additions & 4 deletions fea-rs/src/compile/lookups/gpos_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,19 @@ fn cmp_coverage_key(coverage: &CoverageTable) -> impl Ord {
/// A builder for GPOS type 2 (PairPos) subtables
///
/// This builder can build both glyph and class-based kerning subtables.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PairPosBuilder {
pairs: GlyphPairPosBuilder,
classes: ClassPairPosBuilder,
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
struct GlyphPairPosBuilder(BTreeMap<GlyphId, BTreeMap<GlyphId, (ValueRecord, ValueRecord)>>);

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
struct ClassPairPosSubtable {
items: BTreeMap<GlyphSet, BTreeMap<GlyphSet, (ValueRecord, ValueRecord)>>,
classdef_1: ClassDefBuilder2,
Expand All @@ -137,7 +140,8 @@ impl Default for ClassPairPosSubtable {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
struct ClassPairPosBuilder(BTreeMap<(ValueFormat, ValueFormat), Vec<ClassPairPosSubtable>>);

impl VariationIndexContainingLookup for PairPosBuilder {
Expand Down
3 changes: 2 additions & 1 deletion fea-rs/src/compile/lookups/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use crate::common::{GlyphId, GlyphSet};
// - to handle optionally assigning class 0 or not
//
// TODO: use this in other lookups?
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub(crate) struct ClassDefBuilder2 {
classes: HashSet<GlyphSet>,
glyphs: HashSet<GlyphId>,
Expand Down
2 changes: 1 addition & 1 deletion fontbe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = ["text-processing", "parsing", "graphics"]
[dependencies]
fontdrasil = { version = "0.0.1", path = "../fontdrasil" }
fontir = { version = "0.0.1", path = "../fontir" }
fea-rs = { version = "0.18.0", path = "../fea-rs" }
fea-rs = { version = "0.18.0", path = "../fea-rs", features = ["serde"] }

serde.workspace = true
bincode.workspace = true
Expand Down
Loading

0 comments on commit 9d326d3

Please sign in to comment.