diff --git a/crates/shift-backends/src/designspace/reader.rs b/crates/shift-backends/src/designspace/reader.rs index 3b9a2059..d6fe4578 100644 --- a/crates/shift-backends/src/designspace/reader.rs +++ b/crates/shift-backends/src/designspace/reader.rs @@ -5,7 +5,7 @@ use crate::ufo::UfoReader; use norad::designspace::DesignSpaceDocument; use quick_xml::events::{BytesStart, Event}; use quick_xml::Reader; -use shift_font::{Axis, Font, Layer, LayerId, Location, Source, SourceId}; +use shift_font::{Axis, Font, LayerId, Location, Source, SourceId}; use std::collections::HashMap; use std::fs; use std::path::Path; @@ -156,7 +156,6 @@ impl DesignspaceReader { }; let name = source_name(ds_source, idx); - font.add_layer(Layer::new(name.clone())); let location = location_from_dimensions(&ds_source.location, &doc); let source_id = font.add_source(Source::with_filename( name, @@ -281,7 +280,6 @@ fn load_axisless_designspace( }; let name = axisless_source_name(ds_source, idx); - font.add_layer(Layer::new(name.clone())); let source_id = font.add_source(Source::with_filename( name, Location::new(), diff --git a/crates/shift-backends/src/glyphs/reader.rs b/crates/shift-backends/src/glyphs/reader.rs index 5f7d91ca..03e2e561 100644 --- a/crates/shift-backends/src/glyphs/reader.rs +++ b/crates/shift-backends/src/glyphs/reader.rs @@ -1,7 +1,7 @@ use glyphs_reader::{FeatureSnippet, Font as GlyphsFont, NodeType, Shape}; use shift_font::{ Anchor, Axis, Component, Contour, FeatureData, Font, Glyph, GlyphLayer, KerningData, - KerningPair, KerningSide, Layer, LayerId, Location, Source, Transform, + KerningPair, KerningSide, LayerId, Location, Source, Transform, }; use std::collections::HashMap; use std::path::Path; @@ -183,10 +183,6 @@ impl FontReader for GlyphsReader { let mut source_by_master_id = HashMap::new(); for (master_idx, master) in glyphs_font.masters.iter().enumerate() { - if master_idx != glyphs_font.default_master_idx { - font.add_layer(Layer::new(master.name.clone())); - } - let mut location = Location::new(); for (axis_idx, axis) in glyphs_font.axes.iter().enumerate() { if let Some(value) = master.axes_values.get(axis_idx) { diff --git a/crates/shift-backends/src/traits.rs b/crates/shift-backends/src/traits.rs index 22a419e7..11cb4bc9 100644 --- a/crates/shift-backends/src/traits.rs +++ b/crates/shift-backends/src/traits.rs @@ -1,7 +1,7 @@ use crate::errors::FormatBackendResult; use shift_font::{ Axis, FeatureData, Font, FontMetadata, FontMetrics, Glyph, GlyphName, Guideline, KerningData, - Layer, LayerId, LibData, Source, SourceId, + LibData, Source, SourceId, }; pub trait FontView { @@ -10,14 +10,12 @@ pub trait FontView { fn axes(&self) -> &[Axis]; fn sources(&self) -> &[Source]; fn default_source_id(&self) -> Option; - fn layers(&self) -> Vec<(LayerId, &Layer)>; fn glyphs(&self) -> Vec<&Glyph>; fn glyph(&self, name: &str) -> Option<&Glyph>; fn kerning(&self) -> &KerningData; fn features(&self) -> &FeatureData; fn guidelines(&self) -> &[Guideline]; fn lib(&self) -> &LibData; - fn default_layer_id(&self) -> LayerId; } impl FontView for Font { @@ -41,13 +39,6 @@ impl FontView for Font { self.default_source_id() } - fn layers(&self) -> Vec<(LayerId, &Layer)> { - self.layers() - .iter() - .map(|(layer_id, layer)| (*layer_id, layer)) - .collect() - } - fn glyphs(&self) -> Vec<&Glyph> { self.glyphs().values().map(|glyph| glyph.as_ref()).collect() } @@ -71,10 +62,6 @@ impl FontView for Font { fn lib(&self) -> &LibData { self.lib() } - - fn default_layer_id(&self) -> LayerId { - self.default_layer_id() - } } pub trait FontReader: Send + Sync { diff --git a/crates/shift-backends/src/ufo/reader.rs b/crates/shift-backends/src/ufo/reader.rs index d5cd4983..f1101e83 100644 --- a/crates/shift-backends/src/ufo/reader.rs +++ b/crates/shift-backends/src/ufo/reader.rs @@ -3,8 +3,8 @@ use crate::traits::FontReader; use norad::{Font as NoradFont, Line}; use shift_font::{ Anchor, Component, Contour, FeatureData, Font, Glyph, GlyphLayer, Guideline, KerningData, - KerningPair, KerningSide, Layer, LayerId, LibData, LibValue, Location, PointType, Source, - SourceId, Transform, + KerningPair, KerningSide, LayerId, LibData, LibValue, Location, PointType, Source, SourceId, + Transform, }; use std::collections::HashMap; use std::path::Path; @@ -250,8 +250,6 @@ impl FontReader for UfoReader { let source_id = if layer.name() == &norad_default_layer_name { default_source_id } else { - let new_layer = Layer::new(layer.name().to_string()); - font.add_layer(new_layer); font.add_source(Source::new(layer.name().to_string(), Location::new())) }; diff --git a/crates/shift-backends/tests/loading.rs b/crates/shift-backends/tests/loading.rs index 8374d36f..3015d39c 100644 --- a/crates/shift-backends/tests/loading.rs +++ b/crates/shift-backends/tests/loading.rs @@ -99,9 +99,17 @@ fn loads_ufo_components_anchors_layers_and_kerning() { .collect(); assert!(anchor_names.contains(&"top")); - let layer_names: Vec<_> = font.layers().values().map(|layer| layer.name()).collect(); - assert!(layer_names.contains(&"public.default")); - assert!(font.layers().len() >= 2); + let source_names: Vec<_> = font.sources().iter().map(|source| source.name()).collect(); + assert!(source_names.contains(&"Regular")); + assert!(font.sources().len() >= 2); + assert!(font + .glyphs() + .values() + .flat_map(|glyph| glyph.layers().values()) + .all(|layer| font + .sources() + .iter() + .any(|source| source.id() == layer.source_id()))); assert_eq!(font.kerning().get_kerning("T", "A"), Some(-75.0)); assert_eq!(font.kerning().get_kerning("V", "A"), Some(-100.0)); diff --git a/crates/shift-backends/tests/round_trip/ufo.rs b/crates/shift-backends/tests/round_trip/ufo.rs index 96813938..8b9fe51c 100644 --- a/crates/shift-backends/tests/round_trip/ufo.rs +++ b/crates/shift-backends/tests/round_trip/ufo.rs @@ -173,19 +173,19 @@ fn preserves_components_anchors_layers_and_kerning() { && (anchor.y() - 456.0).abs() < 0.001 })); - let original_layer_names: Vec<_> = original - .layers() - .values() - .map(|layer| layer.name()) + let original_source_names: Vec<_> = original + .sources() + .iter() + .map(|source| source.name()) .collect(); - let reloaded_layer_names: Vec<_> = reloaded - .layers() - .values() - .map(|layer| layer.name()) + let reloaded_source_names: Vec<_> = reloaded + .sources() + .iter() + .map(|source| source.name()) .collect(); - assert_eq!(reloaded_layer_names.len(), original_layer_names.len()); - for name in original_layer_names { - assert!(reloaded_layer_names.contains(&name)); + assert_eq!(reloaded_source_names.len(), original_source_names.len()); + for name in original_source_names { + assert!(reloaded_source_names.contains(&name)); } assert_eq!(reloaded.kerning().get_kerning("T", "A"), Some(-75.0)); diff --git a/crates/shift-bridge/__test__/index.spec.mjs b/crates/shift-bridge/__test__/index.spec.mjs index dd47c64c..a97c8d55 100644 --- a/crates/shift-bridge/__test__/index.spec.mjs +++ b/crates/shift-bridge/__test__/index.spec.mjs @@ -28,7 +28,7 @@ describe("Bridge", () => { function defaultLayerRef(name = "A", unicode = 65) { return { glyphHandle: { name, unicode }, - layerId: bridge.getSources()[0].layerId, + sourceId: defaultSourceId(), }; } @@ -158,8 +158,8 @@ describe("Bridge", () => { it("surfaces typed bridge errors at the NAPI boundary", () => { expect(() => - bridge.addContour({ glyphHandle: { name: "A", unicode: 65 }, layerId: "not-a-layer" }), - ).toThrow(/layer ID/i); + bridge.addContour({ glyphHandle: { name: "A", unicode: 65 }, sourceId: "not-a-source" }), + ).toThrow(/source ID/i); const glyphRef = defaultLayerRef(); expect(() => diff --git a/crates/shift-bridge/src/bridge.rs b/crates/shift-bridge/src/bridge.rs index e1df3d79..dc791d79 100644 --- a/crates/shift-bridge/src/bridge.rs +++ b/crates/shift-bridge/src/bridge.rs @@ -196,15 +196,6 @@ impl FontView for FontSaveSnapshot { self.font.default_source_id() } - fn layers(&self) -> Vec<(LayerId, &shift_font::Layer)> { - self - .font - .layers() - .iter() - .map(|(layer_id, layer)| (*layer_id, layer)) - .collect() - } - fn glyphs(&self) -> Vec<&Glyph> { let override_name = self .active_glyph_override @@ -253,10 +244,6 @@ impl FontView for FontSaveSnapshot { fn lib(&self) -> &shift_font::LibData { self.font.lib() } - - fn default_layer_id(&self) -> LayerId { - self.font.default_layer_id() - } } pub struct ExportFontTask { diff --git a/crates/shift-font/src/ir/font.rs b/crates/shift-font/src/ir/font.rs index b8ca8a4d..d1db4dd8 100644 --- a/crates/shift-font/src/ir/font.rs +++ b/crates/shift-font/src/ir/font.rs @@ -1,10 +1,9 @@ use crate::axis::{Axis, Location}; -use crate::entity::{LayerId, SourceId}; +use crate::entity::SourceId; use crate::features::FeatureData; use crate::glyph::Glyph; use crate::guideline::Guideline; use crate::kerning::KerningData; -use crate::layer::Layer; use crate::lib_data::LibData; use crate::metrics::FontMetrics; use crate::source::Source; @@ -89,20 +88,15 @@ struct FontData { sources: Vec, #[serde(default)] default_source_id: Option, - layers: HashMap, glyphs: HashMap>, kerning: KerningData, features: FeatureData, guidelines: Vec, lib: LibData, - default_layer_id: LayerId, } impl Default for Font { fn default() -> Self { - let default_layer_id = LayerId::new(); - let mut layers = HashMap::new(); - layers.insert(default_layer_id, Layer::default_layer()); let default_source = Source::new("Regular".to_string(), Location::new()); let default_source_id = default_source.id(); @@ -113,13 +107,11 @@ impl Default for Font { axes: Vec::new(), sources: vec![default_source], default_source_id: Some(default_source_id), - layers, glyphs: HashMap::new(), kerning: KerningData::new(), features: FeatureData::new(), guidelines: Vec::new(), lib: LibData::new(), - default_layer_id, }), } } @@ -131,10 +123,6 @@ impl Font { } pub fn empty() -> Self { - let default_layer_id = LayerId::new(); - let mut layers = HashMap::new(); - layers.insert(default_layer_id, Layer::default_layer()); - Self { inner: Arc::new(FontData { metadata: FontMetadata::default(), @@ -142,13 +130,11 @@ impl Font { axes: Vec::new(), sources: Vec::new(), default_source_id: None, - layers, glyphs: HashMap::new(), kerning: KerningData::new(), features: FeatureData::new(), guidelines: Vec::new(), lib: LibData::new(), - default_layer_id, }), } } @@ -225,32 +211,6 @@ impl Font { !self.data().axes.is_empty() } - pub fn layers(&self) -> &HashMap { - &self.data().layers - } - - pub fn layer(&self, id: LayerId) -> Option<&Layer> { - self.data().layers.get(&id) - } - - pub fn layer_mut(&mut self, id: LayerId) -> Option<&mut Layer> { - self.data_mut().layers.get_mut(&id) - } - - pub fn default_layer_id(&self) -> LayerId { - self.data().default_layer_id - } - - pub fn default_layer(&self) -> Option<&Layer> { - self.data().layers.get(&self.data().default_layer_id) - } - - pub fn add_layer(&mut self, layer: Layer) -> LayerId { - let id = layer.id(); - self.data_mut().layers.insert(id, layer); - id - } - pub fn glyphs(&self) -> &HashMap> { &self.data().glyphs } @@ -345,7 +305,7 @@ impl Font { #[cfg(test)] mod tests { use super::*; - use crate::{Contour, GlyphLayer, PointType}; + use crate::{Contour, GlyphLayer, LayerId, PointType}; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -406,7 +366,6 @@ mod tests { fn font_creation() { let font = Font::new(); assert_eq!(font.glyph_count(), 0); - assert!(font.default_layer().is_some()); assert_eq!(font.sources().len(), 1); assert_eq!(font.default_source().map(Source::name), Some("Regular")); } diff --git a/crates/shift-font/src/ir/layer.rs b/crates/shift-font/src/ir/layer.rs deleted file mode 100644 index 4df763cb..00000000 --- a/crates/shift-font/src/ir/layer.rs +++ /dev/null @@ -1,86 +0,0 @@ -use crate::entity::LayerId; -use crate::lib_data::LibData; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Layer { - id: LayerId, - name: String, - color: Option, - lib: LibData, -} - -impl Layer { - pub fn new(name: String) -> Self { - Self { - id: LayerId::new(), - name, - color: None, - lib: LibData::new(), - } - } - - pub fn default_layer() -> Self { - Self::new("public.default".to_string()) - } - - pub fn with_id(id: LayerId, name: String) -> Self { - Self { - id, - name, - color: None, - lib: LibData::new(), - } - } - - pub fn id(&self) -> LayerId { - self.id - } - - pub fn name(&self) -> &str { - &self.name - } - - pub fn color(&self) -> Option<&str> { - self.color.as_deref() - } - - pub fn lib(&self) -> &LibData { - &self.lib - } - - pub fn lib_mut(&mut self) -> &mut LibData { - &mut self.lib - } - - pub fn set_name(&mut self, name: String) { - self.name = name; - } - - pub fn set_color(&mut self, color: Option) { - self.color = color; - } - - pub fn is_default(&self) -> bool { - self.name == "public.default" - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn layer_creation() { - let l = Layer::new("foreground".to_string()); - assert_eq!(l.name(), "foreground"); - assert_eq!(l.color(), None); - } - - #[test] - fn default_layer() { - let l = Layer::default_layer(); - assert!(l.is_default()); - assert_eq!(l.name(), "public.default"); - } -} diff --git a/crates/shift-font/src/ir/mod.rs b/crates/shift-font/src/ir/mod.rs index 0ad8503a..df7eac9c 100644 --- a/crates/shift-font/src/ir/mod.rs +++ b/crates/shift-font/src/ir/mod.rs @@ -10,7 +10,6 @@ pub mod glyph; pub mod glyph_name; pub mod guideline; pub mod kerning; -pub mod layer; pub mod lib_data; pub mod metrics; pub mod point; @@ -32,7 +31,6 @@ pub use glyph::{Glyph, GlyphLayer}; pub use glyph_name::{GlyphName, GlyphNameError}; pub use guideline::{Guideline, GuidelineOrientation}; pub use kerning::{KerningData, KerningPair, KerningSide}; -pub use layer::Layer; pub use lib_data::{LibData, LibValue}; pub use metrics::FontMetrics; pub use point::{Point, PointType}; diff --git a/crates/shift-font/src/lib.rs b/crates/shift-font/src/lib.rs index 25507258..b0758b41 100644 --- a/crates/shift-font/src/lib.rs +++ b/crates/shift-font/src/lib.rs @@ -41,7 +41,7 @@ pub use error::{CoreError, CoreResult}; pub use ir::*; pub use ir::{ anchor, axis, boolean, component, contour, entity, features, font, glyph, glyph_name, - guideline, kerning, layer, lib_data, metrics, point, segment, source, variation, + guideline, kerning, lib_data, metrics, point, segment, source, variation, }; pub use layer_edit::{ BulkNodePositionUpdates, ChangedEntities, EditableNode, PasteContour, PastePoint, PasteResult,