Skip to content

Commit

Permalink
Merge pull request #123 from googlefonts/static_meta
Browse files Browse the repository at this point in the history
Add a phase that eliminates mixed contour+component glyphs; legal in source but not binary
  • Loading branch information
rsheeter authored Mar 2, 2023
2 parents 418cbd4 + 15f146b commit 9c961da
Show file tree
Hide file tree
Showing 16 changed files with 1,102 additions and 166 deletions.
7 changes: 4 additions & 3 deletions fontbe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ env_logger = "0.9.0"

parking_lot = "0.12.1"

read-fonts = "0.0.5"
write-fonts = "0.0.5"
fea-rs = "0.2.0"
read-fonts = "0.1.0"
write-fonts = "0.1.0"

fea-rs = "0.3.0"
smol_str = "0.1.18"

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions fontbe/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use fea_rs::{
parse::{SourceLoadError, SourceResolver},
Compiler, GlyphMap, GlyphName as FeaRsGlyphName,
};
use fontir::ir::Features;
use fontir::{ir::Features, orchestration::Flags};
use log::{debug, error, trace, warn};
use write_fonts::FontBuilder;

Expand Down Expand Up @@ -129,7 +129,7 @@ impl Work<Context, Error> for FeatureWork {
.collect();

let result = self.compile(&features, glyph_map);
if result.is_err() || context.emit_debug {
if result.is_err() || context.flags.contains(Flags::EMIT_DEBUG) {
if let Features::Memory(fea_content) = &*features {
write_debug_fea(context, result.is_err(), "compile failed", fea_content);
}
Expand Down
52 changes: 26 additions & 26 deletions fontbe/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use std::{collections::HashSet, fs, path::Path, sync::Arc};

use fontdrasil::{
orchestration::{AccessControlList, Work, MISSING_DATA},
orchestration::{access_one, AccessControlList, Work, MISSING_DATA},
types::GlyphName,
};
use fontir::orchestration::{Context as FeContext, WorkId as FeWorkIdentifier};
use fontir::orchestration::{Context as FeContext, Flags, WorkId as FeWorkIdentifier};
use parking_lot::RwLock;
use write_fonts::FontBuilder;

Expand Down Expand Up @@ -68,11 +68,7 @@ pub type BeWork = dyn Work<Context, Error> + Send;
/// access with spawned tasks. Copies with access control are created to detect bad
/// execution order / mistakes, not to block actual bad actors.
pub struct Context {
// If set artifacts prior to final binary will be emitted to disk when written into Context
pub emit_ir: bool,

// If set additional debug files will be emitted to disk
pub emit_debug: bool,
pub flags: Flags,

paths: Arc<Paths>,

Expand All @@ -87,15 +83,19 @@ pub struct Context {
}

impl Context {
pub fn new_root(
emit_ir: bool,
emit_debug: bool,
paths: Paths,
ir: &fontir::orchestration::Context,
) -> Context {
fn copy(&self, acl: AccessControlList<AnyWorkId>) -> Context {
Context {
flags: self.flags,
paths: self.paths.clone(),
ir: self.ir.clone(),
acl,
features: self.features.clone(),
}
}

pub fn new_root(flags: Flags, paths: Paths, ir: &fontir::orchestration::Context) -> Context {
Context {
emit_ir,
emit_debug,
flags,
paths: Arc::from(paths),
ir: Arc::from(ir.read_only()),
acl: AccessControlList::read_only(),
Expand All @@ -108,14 +108,14 @@ impl Context {
work_id: WorkId,
dependencies: Option<HashSet<AnyWorkId>>,
) -> Context {
Context {
emit_ir: self.emit_ir,
emit_debug: self.emit_debug,
paths: self.paths.clone(),
ir: self.ir.clone(),
acl: AccessControlList::read_write(dependencies.unwrap_or_default(), work_id.into()),
features: self.features.clone(),
}
self.copy(AccessControlList::read_write(
dependencies.unwrap_or_default(),
access_one(work_id.into()),
))
}

pub fn copy_read_only(&self) -> Context {
self.copy(AccessControlList::read_only())
}
}

Expand All @@ -126,7 +126,7 @@ impl Context {
}

fn maybe_persist(&self, file: &Path, content: &[u8]) {
if !self.emit_ir {
if !self.flags.contains(Flags::EMIT_IR) {
return;
}
fs::write(file, content)
Expand All @@ -147,7 +147,7 @@ impl Context {

pub fn get_features(&self) -> Arc<Vec<u8>> {
let id = WorkId::Features;
self.acl.check_read_access(&id.clone().into());
self.acl.assert_read_access(&id.clone().into());
{
let rl = self.features.read();
if rl.is_some() {
Expand All @@ -162,7 +162,7 @@ impl Context {

pub fn set_features(&self, mut font: FontBuilder) {
let id = WorkId::Features;
self.acl.check_write_access(&id.clone().into());
self.acl.assert_write_access(&id.clone().into());
let font = font.build();
self.maybe_persist(&self.paths.target_file(&id), &font);
self.set_cached_features(font);
Expand Down
Loading

0 comments on commit 9c961da

Please sign in to comment.