Skip to content

Commit

Permalink
Merge pull request #886 from googlefonts/update-fontations
Browse files Browse the repository at this point in the history
[chore] Update fontations deps
  • Loading branch information
cmyr authored Jul 26, 2024
2 parents 6f8d66e + 61be0ba commit 85795bf
Show file tree
Hide file tree
Showing 31 changed files with 290 additions and 274 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ rayon = "1.6"
icu_properties = "1.4"

# fontations etc
write-fonts = { version = "0.27.0", features = ["serde", "read"] }
skrifa = "0.19.3"
write-fonts = { version = "0.28.1", features = ["serde", "read"] }
skrifa = "0.20.0"
norad = "0.12"

# dev dependencies
Expand Down
12 changes: 6 additions & 6 deletions fea-rs/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::fmt::{Display, Formatter};

use fontdrasil::types::GlyphName;
pub use write_fonts::types::GlyphId;
pub use write_fonts::types::GlyphId16;

mod glyph_class;
mod glyph_map;
Expand All @@ -21,7 +21,7 @@ use crate::compile::Anchor;
#[derive(Debug, Clone)]
pub(crate) enum GlyphOrClass {
/// A resolved GlyphId
Glyph(GlyphId),
Glyph(GlyphId16),
/// A resolved glyph class
Class(GlyphClass),
/// An explicit `<NULL>` glyph
Expand Down Expand Up @@ -81,14 +81,14 @@ impl GlyphOrClass {
}
}

pub(crate) fn to_glyph(&self) -> Option<GlyphId> {
pub(crate) fn to_glyph(&self) -> Option<GlyphId16> {
match self {
GlyphOrClass::Glyph(gid) => Some(*gid),
_ => None,
}
}

pub(crate) fn iter(&self) -> impl Iterator<Item = GlyphId> + '_ {
pub(crate) fn iter(&self) -> impl Iterator<Item = GlyphId16> + '_ {
let mut idx = 0;
std::iter::from_fn(move || {
let next = match &self {
Expand All @@ -105,12 +105,12 @@ impl GlyphOrClass {
///
/// this is used to create the replacement targets for class -> glyph or
/// class -> null substitutions.
pub(crate) fn into_iter_for_target(self) -> impl Iterator<Item = GlyphId> {
pub(crate) fn into_iter_for_target(self) -> impl Iterator<Item = GlyphId16> {
let mut idx = 0;
std::iter::from_fn(move || {
let next = match &self {
GlyphOrClass::Glyph(id) if idx == 0 => Some(*id),
GlyphOrClass::Null if idx == 0 => Some(GlyphId::NOTDEF),
GlyphOrClass::Null if idx == 0 => Some(GlyphId16::NOTDEF),
GlyphOrClass::Class(cls) => cls.items().get(idx).copied(),
_ => None,
};
Expand Down
36 changes: 18 additions & 18 deletions fea-rs/src/common/glyph_class.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use write_fonts::types::GlyphId;
use write_fonts::types::GlyphId16;

use super::GlyphOrClass;

Expand All @@ -22,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(Vec<GlyphId>);
pub(crate) struct GlyphClass(Vec<GlyphId16>);

/// A sorted set of unique glyph ids.
///
Expand All @@ -33,13 +33,13 @@ pub(crate) struct GlyphClass(Vec<GlyphId>);
/// and stabily sort, so we ensure that these classes are sorted and deduped.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct GlyphSet(Vec<GlyphId>);
pub struct GlyphSet(Vec<GlyphId16>);

impl GlyphClass {
/// An empty glyph class
pub const EMPTY: Self = GlyphClass(Vec::new());

pub(crate) fn items(&self) -> &[GlyphId] {
pub(crate) fn items(&self) -> &[GlyphId16] {
&self.0
}

Expand All @@ -48,7 +48,7 @@ impl GlyphClass {
self.iter().collect()
}

pub(crate) fn iter(&self) -> impl Iterator<Item = GlyphId> + '_ {
pub(crate) fn iter(&self) -> impl Iterator<Item = GlyphId16> + '_ {
self.items().iter().copied()
}

Expand All @@ -62,7 +62,7 @@ impl GlyphSet {
pub const EMPTY: Self = GlyphSet(Vec::new());

/// Iterate over the glyphs in this class
pub fn iter(&self) -> impl Iterator<Item = GlyphId> + '_ {
pub fn iter(&self) -> impl Iterator<Item = GlyphId16> + '_ {
self.0.iter().copied()
}

Expand All @@ -77,24 +77,24 @@ impl GlyphSet {
}
}

impl std::iter::FromIterator<GlyphId> for GlyphClass {
fn from_iter<T: IntoIterator<Item = GlyphId>>(iter: T) -> Self {
impl std::iter::FromIterator<GlyphId16> for GlyphClass {
fn from_iter<T: IntoIterator<Item = GlyphId16>>(iter: T) -> Self {
GlyphClass(iter.into_iter().collect())
}
}

impl<'a> std::iter::IntoIterator for &'a GlyphClass {
type Item = &'a GlyphId;
type Item = &'a GlyphId16;

type IntoIter = std::slice::Iter<'a, GlyphId>;
type IntoIter = std::slice::Iter<'a, GlyphId16>;

fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}

impl From<Vec<GlyphId>> for GlyphClass {
fn from(src: Vec<GlyphId>) -> GlyphClass {
impl From<Vec<GlyphId16>> for GlyphClass {
fn from(src: Vec<GlyphId16>) -> GlyphClass {
GlyphClass(src)
}
}
Expand All @@ -106,22 +106,22 @@ impl From<GlyphClass> for GlyphSet {
}

// our base constructor; all other logic goes through here
impl From<Vec<GlyphId>> for GlyphSet {
fn from(mut value: Vec<GlyphId>) -> Self {
impl From<Vec<GlyphId16>> for GlyphSet {
fn from(mut value: Vec<GlyphId16>) -> Self {
value.sort_unstable();
value.dedup();
Self(value)
}
}

impl std::iter::FromIterator<GlyphId> for GlyphSet {
fn from_iter<T: IntoIterator<Item = GlyphId>>(iter: T) -> Self {
impl std::iter::FromIterator<GlyphId16> for GlyphSet {
fn from_iter<T: IntoIterator<Item = GlyphId16>>(iter: T) -> Self {
iter.into_iter().collect::<Vec<_>>().into()
}
}

impl From<GlyphId> for GlyphClass {
fn from(src: GlyphId) -> GlyphClass {
impl From<GlyphId16> for GlyphClass {
fn from(src: GlyphId16) -> GlyphClass {
let slice: &[_] = &[src];
GlyphClass(slice.into())
}
Expand Down
22 changes: 11 additions & 11 deletions fea-rs/src/common/glyph_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use write_fonts::tables::post::Post;

use super::{GlyphId, GlyphIdent};
use super::{GlyphId16, GlyphIdent};
use fontdrasil::types::GlyphName;
use std::{
borrow::Cow,
Expand All @@ -9,18 +9,18 @@ use std::{
iter::FromIterator,
};

/// A glyph map for mapping from raw glyph identifiers to numeral `GlyphId`s.
/// A glyph map for mapping from raw glyph identifiers to numeral `GlyphId16`s.
///
/// This is used to map from names or CIDS encountered in a FEA file to the actual
/// GlyphIds that will be used in the final font.
/// GlyphId16s that will be used in the final font.
///
/// Currently, the only way to construct this type is by calling `collect()`
/// on an iterator of cids or names.
#[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>,
names: HashMap<GlyphName, GlyphId16>,
cids: HashMap<u16, GlyphId16>,
}

impl GlyphMap {
Expand All @@ -36,7 +36,7 @@ impl GlyphMap {

/// Generates a reverse map of ids -> raw identifers (names or CIDs)
// maybe just for testing?
pub fn reverse_map(&self) -> BTreeMap<GlyphId, GlyphIdent> {
pub fn reverse_map(&self) -> BTreeMap<GlyphId16, GlyphIdent> {
self.names
.iter()
.map(|(name, id)| (*id, GlyphIdent::Name(name.clone())))
Expand Down Expand Up @@ -66,8 +66,8 @@ impl GlyphMap {
}
}

/// Return the `GlyphId` for the provided `GlyphIdent`
pub fn get<Q: ?Sized + sealed::AsGlyphIdent>(&self, key: &Q) -> Option<GlyphId> {
/// Return the `GlyphId16` for the provided `GlyphIdent`
pub fn get<Q: ?Sized + sealed::AsGlyphIdent>(&self, key: &Q) -> Option<GlyphId16> {
if let Some(name) = key.named() {
self.names.get(name).copied()
} else if let Some(cid) = key.cid() {
Expand Down Expand Up @@ -99,7 +99,7 @@ impl FromIterator<u16> for GlyphMap {
cids: iter
.into_iter()
.enumerate()
.map(|(i, cid)| (cid, GlyphId::new(i.try_into().unwrap())))
.map(|(i, cid)| (cid, GlyphId16::new(i.try_into().unwrap())))
.collect(),
}
}
Expand All @@ -111,7 +111,7 @@ impl FromIterator<GlyphName> for GlyphMap {
names: iter
.into_iter()
.enumerate()
.map(|(i, cid)| (cid, GlyphId::new(i.try_into().unwrap())))
.map(|(i, cid)| (cid, GlyphId16::new(i.try_into().unwrap())))
.collect(),
cids: HashMap::new(),
}
Expand All @@ -124,7 +124,7 @@ impl FromIterator<GlyphIdent> for GlyphMap {
let mut names = HashMap::new();
let mut cids = HashMap::new();
for (idx, item) in iter.into_iter().enumerate() {
let idx = GlyphId::new(idx.try_into().unwrap());
let idx = GlyphId16::new(idx.try_into().unwrap());
match item {
GlyphIdent::Cid(cid) => cids.insert(cid, idx),
GlyphIdent::Name(name) => names.insert(name, idx),
Expand Down
8 changes: 4 additions & 4 deletions fea-rs/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{parse::ParseTree, DiagnosticSet, GlyphMap};
use fontdrasil::types::GlyphName;
use write_fonts::types::GlyphId;
use write_fonts::types::GlyphId16;

use self::{
compile_ctx::CompilationCtx,
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn parse_glyph_order(glyphs: &str) -> Result<GlyphMap, GlyphOrderError> {
}
})
.collect::<Result<_, _>>()?;
if map.get(".notdef") != Some(GlyphId::NOTDEF) {
if map.get(".notdef") != Some(GlyphId16::NOTDEF) {
Err(GlyphOrderError::MissingNotDef)
} else {
Ok(map)
Expand All @@ -161,8 +161,8 @@ mod tests {
let raw = std::fs::read_to_string("./test-data/simple_glyph_order.txt").unwrap();
let glyph_map = parse_glyph_order(&raw).unwrap();
assert_eq!(glyph_map.len(), 215);
assert_eq!(glyph_map.get("space"), Some(GlyphId::new(1)));
assert_eq!(glyph_map.get("e.fina"), Some(GlyphId::new(214)));
assert_eq!(glyph_map.get("space"), Some(GlyphId16::new(1)));
assert_eq!(glyph_map.get("e.fina"), Some(GlyphId16::new(214)));
assert!(!glyph_map.contains("e.nada"));
}
}
Loading

0 comments on commit 85795bf

Please sign in to comment.