Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set GDEF Glyph Categories if not explicit in FEA #908

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions fontbe/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ use fontdrasil::{
orchestration::{Access, AccessBuilder, Work},
types::Axis,
};
use write_fonts::{tables::variations::VariationRegion, types::Tag, OtRound};
use write_fonts::{
tables::{layout::ClassDef, variations::VariationRegion},
types::Tag,
OtRound,
};

use crate::{
error::Error,
Expand Down Expand Up @@ -526,6 +530,7 @@ impl Work<Context, AnyWorkId, Error> for FeatureCompilationWork {

fn read_access(&self) -> Access<AnyWorkId> {
AccessBuilder::new()
.variant(FeWorkId::GlyphOrder)
.variant(WorkId::FeaturesAst)
.variant(WorkId::GatherBeKerning)
.variant(WorkId::Marks)
Expand All @@ -543,10 +548,29 @@ impl Work<Context, AnyWorkId, Error> for FeatureCompilationWork {
fn exec(&self, context: &Context) -> Result<(), Error> {
let static_metadata = context.ir.static_metadata.get();
let ast = context.fea_ast.get();
let glyph_order = context.ir.glyph_order.get();
let kerns = context.fea_rs_kerns.get();
let marks = context.fea_rs_marks.get();

let result = self.compile(&static_metadata, &ast, kerns.as_ref(), marks.as_ref())?;
let mut result = self.compile(&static_metadata, &ast, kerns.as_ref(), marks.as_ref())?;
if result.gdef_classes.is_none() {
// there were no explicit gdef categories, so let's use the ones
// that were in public.openTypeCatgories or which we computed from
// GlyphData.xml

if let Some(gdef) = result.gdef.as_mut() {
let class_def: ClassDef = static_metadata
.gdef_categories
.categories
.iter()
.filter_map(|(name, cls)| {
glyph_order.glyph_id(name).map(|id| (id, *cls as u16))
})
.collect();

gdef.glyph_class_def.set(class_def);
}
}

debug!(
"Built features, gpos? {} gsub? {} gdef? {}",
Expand Down
14 changes: 6 additions & 8 deletions glyphs2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use fontdrasil::{
use fontir::{
error::{BadGlyph, BadGlyphKind, BadSource, Error},
ir::{
self, AnchorBuilder, AnchorKind, GdefCategories, GlobalMetric, GlobalMetrics,
GlyphInstance, GlyphOrder, KernGroup, KernSide, KerningGroups, KerningInstance,
NameBuilder, NameKey, NamedInstance, StaticMetadata, DEFAULT_VENDOR_ID,
self, AnchorBuilder, GdefCategories, GlobalMetric, GlobalMetrics, GlyphInstance,
GlyphOrder, KernGroup, KernSide, KerningGroups, KerningInstance, NameBuilder, NameKey,
NamedInstance, StaticMetadata, DEFAULT_VENDOR_ID,
},
orchestration::{Context, IrWork, WorkId},
source::{Input, Source},
Expand Down Expand Up @@ -475,11 +475,9 @@ fn category_for_glyph(glyph: &glyphs_reader::Glyph) -> Option<GlyphClassDef> {
.layers
.iter()
.flat_map(|layer| layer.anchors.iter())
.any(|anchor| {
AnchorKind::new(&anchor.name)
.map(|a| a.is_attaching())
.unwrap_or(false)
});
// glyphsLib considers any anchor that does not start with '_' as an
// 'attaching anchor'; see https://github.com/googlefonts/glyphsLib/issues/1024
.any(|anchor| !anchor.name.starts_with('_'));
match (glyph.category, glyph.sub_category) {
(_, Subcategory::Ligature) if has_attaching_anchor => Some(GlyphClassDef::Ligature),
(Some(Category::Mark), Subcategory::Nonspacing | Subcategory::SpacingCombining) => {
Expand Down
Loading