-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add initial implementation of meta
compilation
#1136
base: main
Are you sure you want to change the base?
Changes from all commits
fa4c9ba
93cdced
726501a
4588d8f
b8b4543
c25d710
4b77968
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! Generates a [meta](https://learn.microsoft.com/en-us/typography/opentype/spec/meta) table. | ||
|
||
use fontdrasil::orchestration::{Access, AccessBuilder, Work}; | ||
use fontir::orchestration::WorkId as FeWorkId; | ||
use write_fonts::tables::meta::{DataMapRecord, Meta}; | ||
|
||
use crate::{ | ||
error::Error, | ||
orchestration::{AnyWorkId, BeWork, Context, WorkId}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
struct MetaWork {} | ||
|
||
pub fn create_meta_work() -> Box<BeWork> { | ||
Box::new(MetaWork {}) | ||
} | ||
|
||
impl Work<Context, AnyWorkId, Error> for MetaWork { | ||
fn id(&self) -> AnyWorkId { | ||
WorkId::Meta.into() | ||
} | ||
|
||
fn read_access(&self) -> Access<AnyWorkId> { | ||
AccessBuilder::new() | ||
.variant(FeWorkId::StaticMetadata) // For meta records | ||
.build() | ||
} | ||
|
||
/// Generate [meta](https://learn.microsoft.com/en-us/typography/opentype/spec/meta) | ||
fn exec(&self, context: &Context) -> Result<(), Error> { | ||
// Build from static metadata, if at least one record is provided. | ||
let meta = { | ||
let static_metadata = context.ir.static_metadata.get(); | ||
let records = &static_metadata.misc.meta; | ||
|
||
if records.is_empty() { | ||
None | ||
} else { | ||
// Instantiate DataMapRecords from tuples. | ||
Some(Meta::new( | ||
records | ||
.iter() | ||
.map(|(tag, metadata)| DataMapRecord::new(*tag, metadata.clone())) | ||
.collect(), | ||
)) | ||
} | ||
}; | ||
|
||
if let Some(meta) = meta { | ||
context.meta.set(meta); | ||
}; | ||
|
||
Ok(()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,11 @@ use glyphs_reader::{ | |
use ordered_float::OrderedFloat; | ||
use smol_str::SmolStr; | ||
use write_fonts::{ | ||
tables::{gdef::GlyphClassDef, os2::SelectionFlags}, | ||
tables::{ | ||
gdef::GlyphClassDef, | ||
meta::{Metadata, ScriptLangTag, DLNG, SLNG}, | ||
os2::SelectionFlags, | ||
}, | ||
types::{NameId, Tag}, | ||
}; | ||
|
||
|
@@ -130,6 +134,8 @@ impl GlyphsIrSource { | |
unicode_range_bits: font.unicode_range_bits.clone(), | ||
codepage_range_bits: font.codepage_range_bits.clone(), | ||
panose: font.panose.clone(), | ||
// TODO: Is this correct? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks right at a glance |
||
meta: font.meta.clone(), | ||
}; | ||
state.track_memory("/font_master".to_string(), &font)?; | ||
Ok(state) | ||
|
@@ -182,6 +188,8 @@ impl GlyphsIrSource { | |
unicode_range_bits: None, | ||
codepage_range_bits: None, | ||
panose: None, | ||
// TODO: Is this correct? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks right, I don't think meta can change global metrics |
||
meta: Default::default(), | ||
}; | ||
state.track_memory("/font_master".to_string(), &font)?; | ||
Ok(state) | ||
|
@@ -491,6 +499,36 @@ impl Work<Context, WorkId, Error> for StaticMetadataWork { | |
}) | ||
.or(static_metadata.misc.created); | ||
|
||
// TODO: Use idiomatic error handling. | ||
// TODO: This diverges from glyphsLib, which must convert a list of | ||
// records into UFO's intermediate dict representation; is this | ||
// actually an improvement, or a breaking change? What does Glyphs | ||
// do? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems like an @anthrotype question |
||
// https://github.com/googlefonts/glyphsLib/blob/74c63244fdbef1da540d646b0784ae6d2c3ca834/Lib/glyphsLib/builder/custom_params.py#L568-L584 | ||
static_metadata.misc.meta = font | ||
.meta | ||
.iter() | ||
.map(|(tag, data)| { | ||
let tag = Tag::new_checked(tag.as_bytes()) | ||
.expect("Malformed tag in meta custom parameter"); | ||
|
||
// Glyphs expects ScriptLangTag formatting for DLNG and SLNG. | ||
// https://handbook.glyphsapp.com/custom-parameter-descriptions/ | ||
let metadata = match tag { | ||
DLNG | SLNG => Metadata::ScriptLangTags( | ||
data.split(",") | ||
.map(Into::into) | ||
.map(ScriptLangTag::new) | ||
.collect::<Result<_, _>>() | ||
.expect("Invalid ScriptLangTag in meta custom parameter"), | ||
), | ||
_ => Metadata::Other(data.clone().into_bytes()), | ||
}; | ||
|
||
(tag, metadata) | ||
}) | ||
.collect(); | ||
|
||
context.static_metadata.set(static_metadata); | ||
|
||
let glyph_order = font | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it should be possible to unindent, e.g.