Skip to content

Commit

Permalink
add 'emum' prefix to class/glyph and glyph/class exceptions
Browse files Browse the repository at this point in the history
that's what ufo2ft kernFeatureWriter does -- fixes the aV kerning in Oswald and similar
  • Loading branch information
anthrotype committed Aug 20, 2023
1 parent 632db7a commit 9661684
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion fontbe/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ fn push_identifier(fea: &mut String, identifier: &KernParticipant) {
}
}

#[inline]
fn enumerated(kp1: &KernParticipant, kp2: &KernParticipant) -> bool {
// Glyph to class or class to glyph pairs are interpreted as 'class exceptions' to class pairs
// and are thus prefixed with 'enum' keyword so they will be enumerated as specific glyph-glyph pairs.
// http://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#6bii-enumerating-pairs
// https://github.com/googlefonts/ufo2ft/blob/b3895a9/Lib/ufo2ft/featureWriters/kernFeatureWriter.py#L360
kp1.is_group() ^ kp2.is_group()
}

/// Create a single variable fea describing the kerning for the entire variation space.
///
/// No merge baby! - [context](https://github.com/fonttools/fonttools/issues/3168#issuecomment-1608787520)
Expand Down Expand Up @@ -362,7 +371,11 @@ fn create_kerning_fea(axes: &HashMap<Tag, &Axis>, kerning: &Kerning) -> Result<S
let mut pos_strings = HashMap::new();
fea.push_str("feature kern {\n");
for ((participant1, participant2), values) in kerning.kerns.iter() {
fea.push_str(" pos ");
fea.push_str(" ");
if enumerated(participant1, participant2) {
fea.push_str("enum ");
}
fea.push_str("pos ");
push_identifier(&mut fea, participant1);
fea.push(' ');
push_identifier(&mut fea, participant2);
Expand Down
12 changes: 12 additions & 0 deletions fontir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ pub enum KernParticipant {
Group(GroupName),
}

impl KernParticipant {
#[inline]
pub fn is_glyph(&self) -> bool {
matches!(self, KernParticipant::Glyph(_))
}

#[inline]
pub fn is_group(&self) -> bool {
matches!(self, KernParticipant::Group(_))
}
}

impl StaticMetadata {
pub fn new(
units_per_em: u16,
Expand Down

1 comment on commit 9661684

@rsheeter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, ty.

Please sign in to comment.