Skip to content

Commit

Permalink
Merge pull request #489 from daltonmaag/postscript-names
Browse files Browse the repository at this point in the history
Postscript names for UFO sources
  • Loading branch information
anthrotype authored Oct 23, 2023
2 parents bcc834e + 82ad1bd commit 4f35733
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 26 deletions.
1 change: 1 addition & 0 deletions fontbe/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ mod tests {
],
Default::default(),
HashSet::from([min_wght, def_wght, max_wght]),
Default::default(),
)
.unwrap()
}
Expand Down
1 change: 1 addition & 0 deletions fontbe/src/fvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ mod tests {
axes.to_vec(),
Default::default(),
Default::default(),
Default::default(),
)
.unwrap()
}
Expand Down
7 changes: 6 additions & 1 deletion fontbe/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ impl Work<Context, AnyWorkId, Error> for PostWork {
// TODO optionally drop glyph names with format 3.0.
// TODO a more serious post
let static_metadata = context.ir.static_metadata.get();
let postscript_names = &static_metadata.postscript_names;
let glyph_order = context.ir.glyph_order.get();
let mut post = Post::new_v2(glyph_order.iter().map(|g| g.as_str()));
let mut post = Post::new_v2(
glyph_order
.iter()
.map(|g| postscript_names.get(g).unwrap_or(g).as_str()),
);
post.underline_position = FWord::new(static_metadata.misc.underline_position.0 as i16);
post.underline_thickness = FWord::new(static_metadata.misc.underline_thickness.0 as i16);
context.post.set_unconditionally(post.into());
Expand Down
16 changes: 15 additions & 1 deletion fontc/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ pub struct Args {
// https://github.com/googlefonts/fontmake/blob/6a8b2907/Lib/fontmake/__main__.py#L443
#[arg(long, default_value = "false")]
pub keep_direction: bool,

/// Don't rename glyphs with production names
// Named to match fontmake's homonymous flag:
// https://github.com/googlefonts/fontmake/blob/6a8b2907/Lib/fontmake/__main__.py#L602
#[arg(long, default_value = "false")]
pub no_production_names: bool,
}

impl Args {
Expand All @@ -80,6 +86,7 @@ impl Args {
);
flags.set(Flags::EMIT_TIMING, self.emit_timing);
flags.set(Flags::KEEP_DIRECTION, self.keep_direction);
flags.set(Flags::PRODUCTION_NAMES, !self.no_production_names);

flags
}
Expand All @@ -104,6 +111,7 @@ impl Args {
.contains(Flags::DECOMPOSE_TRANSFORMED_COMPONENTS),
skip_features: false,
keep_direction: false,
no_production_names: false,
}
}
}
Expand All @@ -120,6 +128,12 @@ mod tests {
fn arg_default_matches_flags_default() {
let arg_default = Args::parse_from(vec!["program", "--source", "dont.care"]).flags();
let flags_default = Flags::default();
assert_eq!(flags_default.bits(), arg_default.bits());
assert_eq!(
flags_default.bits(),
arg_default.bits(),
"mismatch in defaults. flags_default: {:#032b}. args_default: {:#032b}",
flags_default.bits(),
arg_default.bits(),
);
}
}
9 changes: 9 additions & 0 deletions fontir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub struct StaticMetadata {
/// See <https://learn.microsoft.com/en-us/typography/opentype/spec/name>.
pub names: HashMap<NameKey, String>,

/// See <https://learn.microsoft.com/en-us/typography/opentype/spec/post> and
/// <https://github.com/adobe-type-tools/agl-specification>
pub postscript_names: PostscriptNames,

/// Miscellaneous font-wide data that didn't seem worthy of top billing
pub misc: MiscMetadata,
}
Expand Down Expand Up @@ -178,6 +182,9 @@ impl IntoIterator for GlyphOrder {
}
}

/// Glyph names mapped to postscript names
pub type PostscriptNames = HashMap<GlyphName, GlyphName>;

/// In logical (reading) order
type KernPair = (KernParticipant, KernParticipant);
type KernValues = BTreeMap<NormalizedLocation, OrderedFloat<f32>>;
Expand Down Expand Up @@ -235,6 +242,7 @@ impl StaticMetadata {
axes: Vec<Axis>,
named_instances: Vec<NamedInstance>,
glyph_locations: HashSet<NormalizedLocation>,
postscript_names: PostscriptNames,
) -> Result<StaticMetadata, VariationModelError> {
// Point axes are less exciting than ranged ones
let variable_axes: Vec<_> = axes.iter().filter(|a| !a.is_point()).cloned().collect();
Expand Down Expand Up @@ -275,6 +283,7 @@ impl StaticMetadata {
variation_model,
axes_default,
variable_axes_default,
postscript_names,
misc: MiscMetadata {
selection_flags: Default::default(),
vendor_id: DEFAULT_VENDOR_ID_TAG,
Expand Down
4 changes: 3 additions & 1 deletion fontir/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ bitflags! {
const EMIT_TIMING = 0b00100000;
// If set, the direction of contours will NOT be reversed
const KEEP_DIRECTION = 0b01000000;
// If set, production names are read & used
const PRODUCTION_NAMES = 0b10000000;
}
}

impl Default for Flags {
fn default() -> Self {
Flags::EMIT_IR | Flags::PREFER_SIMPLE_GLYPHS
Flags::EMIT_IR | Flags::PREFER_SIMPLE_GLYPHS | Flags::PRODUCTION_NAMES
}
}

Expand Down
6 changes: 5 additions & 1 deletion fontir/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use crate::{
coords::{CoordConverter, DesignCoord, NormalizedLocation, UserCoord},
ir::{
Axis, GlobalMetric, GlobalMetrics, Glyph, GlyphBuilder, GlyphInstance, GlyphOrder,
KernParticipant, Kerning, MiscMetadata, NameKey, NamedInstance, StaticMetadata,
KernParticipant, Kerning, MiscMetadata, NameKey, NamedInstance, PostscriptNames,
StaticMetadata,
},
stateset::{FileState, MemoryState, State, StateIdentifier, StateSet},
};
Expand Down Expand Up @@ -59,6 +60,7 @@ pub(crate) struct StaticMetadataSerdeRepr {
pub named_instances: Vec<NamedInstance>,
pub glyph_locations: Vec<NormalizedLocation>,
pub names: HashMap<NameKey, String>,
pub postscript_names: PostscriptNames,
pub misc: MiscSerdeRepr,
}

Expand All @@ -70,6 +72,7 @@ impl From<StaticMetadataSerdeRepr> for StaticMetadata {
from.axes,
from.named_instances,
from.glyph_locations.into_iter().collect(),
from.postscript_names,
)
.unwrap()
}
Expand All @@ -84,6 +87,7 @@ impl From<StaticMetadata> for StaticMetadataSerdeRepr {
named_instances: from.named_instances,
glyph_locations,
names: from.names,
postscript_names: from.postscript_names,
misc: from.misc.into(),
}
}
Expand Down
1 change: 1 addition & 0 deletions glyphs2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ impl Work<Context, WorkId, WorkError> for StaticMetadataWork {
axes,
named_instances,
glyph_locations,
Default::default(), // TODO: impl reading PS names from Glyphs
)
.map_err(WorkError::VariationModelError)?;
static_metadata.misc.selection_flags = selection_flags;
Expand Down
Loading

0 comments on commit 4f35733

Please sign in to comment.