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

[fontbe] Write out glyph order when --emit-debug is set #705

Merged
merged 1 commit into from
Feb 6, 2024
Merged
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
22 changes: 15 additions & 7 deletions fontbe/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,27 @@ impl FeatureCompilationWork {
}
}

fn write_debug_glyph_order(context: &Context, glyphs: &GlyphOrder) {
let glyph_order_file = context.debug_dir().join("glyph_order.txt");
let glyph_order = glyphs.iter().map(|g| g.to_string()).collect::<Vec<_>>();
let glyph_order = glyph_order.join("\n");
if let Err(e) = fs::write(glyph_order_file, glyph_order) {
log::error!("failed to write glyph order to debug/glyph_order.txt: '{e}'");
}
}

fn write_debug_fea(context: &Context, is_error: bool, why: &str, fea_content: &str) {
if !context.flags.contains(Flags::EMIT_DEBUG) {
if is_error {
warn!("Debug fea not written for '{why}' because --emit_debug is off");
}
return;
}

let debug_file = context.debug_dir().join("features.fea");
match fs::write(&debug_file, fea_content) {
Ok(..) => {
if is_error {
warn!("{}; fea written to {:?}", why, debug_file)
} else {
debug!("fea written to {:?}", debug_file);
}
}
Ok(_) if is_error => warn!("{}; fea written to {:?}", why, debug_file),
Ok(_) => debug!("fea written to {:?}", debug_file),
Err(e) => error!("{}; failed to write fea to {:?}: {}", why, debug_file, e),
};
}
Expand All @@ -431,6 +436,9 @@ impl Work<Context, AnyWorkId, Error> for FeatureParsingWork {
let glyph_order = context.ir.glyph_order.get();
let result = self.parse(&features, &glyph_order);

if context.flags.contains(Flags::EMIT_DEBUG) {
write_debug_glyph_order(context, &glyph_order);
}
if let FeaturesSource::Memory { fea_content, .. } = features.as_ref() {
write_debug_fea(context, result.is_err(), "compile failed", fea_content);
}
Expand Down
Loading