### Example of getting a layer Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Demonstrates how to retrieve a layer by its name. ```rust let layer = font.layers.get("background"); ``` -------------------------------- ### Two tabs indentation example Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Example of setting two tabs for indentation. ```rust use norad::WriteOptions; let options = WriteOptions::new() .indent(WriteOptions::TAB, 2); ``` -------------------------------- ### Two spaces indentation example Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Example of setting two spaces for indentation. ```rust use norad::WriteOptions; let options = WriteOptions::new() .indent(WriteOptions::SPACE, 2); ``` -------------------------------- ### Groups Example Source: https://github.com/linebender/norad/blob/main/_autodocs/04-kerning.md An example demonstrating how to define kerning groups in a `Font` object. ```rust use norad::Font; use maplit::btreemap; let mut font = Font::new(); font.groups = btreemap! { "public.kern1.A".into() => vec!["A".into(), "Aacute".into però], "public.kern2.V".into() => vec!["V".into(), "W".into però], }; ``` -------------------------------- ### Kerning Example Source: https://github.com/linebender/norad/blob/main/_autodocs/04-kerning.md An example demonstrating how to set kerning pairs in a `Font` object. ```rust use norad::Font; use maplit::btreemap; let mut font = Font::new(); font.kerning = btreemap! { "A".into() => btreemap! { "V".into() => -15.0, }, }; ``` -------------------------------- ### user_name_to_file_name example Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md Example usage of the user_name_to_file_name function. ```rust use norad::user_name_to_file_name; let filename = user_name_to_file_name("Copyright © 2024"); // Result suitable for use as a glyph or layer filename ``` -------------------------------- ### Single tab indentation example Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Example of setting single tab indentation. ```rust use norad::WriteOptions; let options = WriteOptions::new(); ``` -------------------------------- ### Four spaces indentation example Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Example of setting four spaces for indentation. ```rust use norad::WriteOptions; let options = WriteOptions::new() .indent(WriteOptions::SPACE, 4); ``` -------------------------------- ### Example of creating a new layer Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Demonstrates how to create a new layer named 'background'. ```rust let mut font = Font::new(); let layer = font.layers.new_layer("background")?; ``` -------------------------------- ### Kerning Resolution Example Source: https://github.com/linebender/norad/blob/main/_autodocs/04-kerning.md An example demonstrating how to use `KerningResolver::get` to retrieve kerning values, including cases involving groups. ```rust use norad::Font; use maplit::btreemap; let mut font = Font::new(); font.groups = btreemap! { "public.kern1.A".into() => vec!["A".into()], }; font.kerning = btreemap! { "public.kern1.A".into() => btreemap! { "V".into() => -15.0, }, }; let resolver = font.kerning_resolver(); assert_eq!(resolver.get("A", "V"), Some(-15.0)); ``` -------------------------------- ### Default options (single tab, double quotes) Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Example demonstrating default write options. ```rust use norad::{Font, WriteOptions}; let font = Font::load("input.ufo")?; let options = WriteOptions::default(); font.save_with_options("output.ufo", &options)?; ``` -------------------------------- ### Single quote character example Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Example of setting the quote character to single quotes. ```rust use norad::{WriteOptions, QuoteChar}; let options = WriteOptions::new() .quote_char(QuoteChar::Single); ``` -------------------------------- ### get method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns a reference to a layer, by name. ```rust pub fn get(&self, name: &str) -> Option<&Layer> ``` -------------------------------- ### Two spaces, single quotes Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Example demonstrating custom write options with two spaces and single quotes. ```rust use norad::{Font, WriteOptions, QuoteChar}; let font = Font::load("input.ufo")?; let options = WriteOptions::new() .indent(WriteOptions::SPACE, 2) .quote_char(QuoteChar::Single); font.save_with_options("output.ufo", &options)?; ``` -------------------------------- ### Four spaces, double quotes Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Example demonstrating custom write options with four spaces and double quotes. ```rust use norad::{Font, WriteOptions}; let font = Font::load("input.ufo")?; let options = WriteOptions::new() .indent(WriteOptions::SPACE, 4); font.save_with_options("output.ufo", &options)?; ``` -------------------------------- ### Iterate Glyphs Example Source: https://github.com/linebender/norad/blob/main/_autodocs/README.md Shows how to iterate over the glyphs in the default layer of a font. ```rust for (_name, glyph) in font.default_layer().iter() { println!("Width: {}", glyph.width); } ``` -------------------------------- ### Catching NamingError Example Source: https://github.com/linebender/norad/blob/main/_autodocs/08-errors.md Demonstrates how to handle NamingError when creating a new layer. ```rust use norad::{Font, error::NamingError}; let mut font = Font::load("font.ufo")?; match font.layers.new_layer("background") { Ok(layer) => { /* use layer */ }, Err(NamingError::Duplicate(_)) => { eprintln!("Layer already exists"); } Err(NamingError::Invalid(_)) => { eprintln!("Layer name is invalid"); } Err(e) => eprintln!("Error: {}", e), } ``` -------------------------------- ### Error Handling Example Source: https://github.com/linebender/norad/blob/main/_autodocs/README.md Demonstrates how to handle potential errors when loading a font using Result types. ```rust use norad::Font; use norad::error::FontLoadError; match Font::load("font.ufo") { Ok(font) => { /* use font */ } Err(FontLoadError::MissingMetaInfoFile) => { eprintln!("Not a valid UFO"); } Err(e) => eprintln!("Failed: {}", e), } ``` -------------------------------- ### How to Catch FontLoadError Source: https://github.com/linebender/norad/blob/main/_autodocs/08-errors.md Example of how to catch specific FontLoadError variants. ```rust use norad::{Font, error::FontLoadError}; match Font::load("font.ufo") { Ok(font) => { /* use font */ }, Err(FontLoadError::MissingMetaInfoFile) => { eprintln!("Not a valid UFO: missing metainfo.plist"); } Err(FontLoadError::AccessUfoDir(e)) => { eprintln!("Cannot access UFO: {}", e); } Err(e) => { eprintln!("Failed to load font: {}", e); } } ``` -------------------------------- ### Common Error Patterns Source: https://github.com/linebender/norad/blob/main/_autodocs/00-overview.md Examples of how to handle common errors when loading and manipulating UFO fonts using the Norad library. ```rust use norad::{Font, error::{FontLoadError, NamingError}}; // Handle load errors match Font::load("font.ufo") { Ok(font) => { /* ... */ }, Err(FontLoadError::MissingMetaInfoFile) => { eprintln!("Not a valid UFO"); } Err(e) => eprintln!("Load failed: {}", e), } // Handle naming errors match font.layers.new_layer("background") { Ok(layer) => { /* ... */ }, Err(NamingError::Duplicate(_)) => { eprintln!("Layer already exists"); } Err(e) => eprintln!("Error: {}", e), } ``` -------------------------------- ### get_glyph method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Get a glyph from the layer by name. ```rust pub fn get_glyph(&self, name: &str) -> Option<&Glyph> ``` -------------------------------- ### How to Catch FontWriteError Source: https://github.com/linebender/norad/blob/main/_autodocs/08-errors.md Example of how to catch specific FontWriteError variants. ```rust use norad::{Font, error::FontWriteError}; let font = Font::load("in.ufo")?; match font.save("out.ufo") { Ok(()) => println!("Saved successfully"), Err(FontWriteError::Downgrade) => { eprintln!("Cannot save: must be UFO v3"); } Err(FontWriteError::PreexistingPublicObjectLibsKey) => { eprintln!("Cannot save: public.objectLibs is managed by norad"); } Err(e) => eprintln!("Save failed: {}", e), } ``` -------------------------------- ### get Method Signature Source: https://github.com/linebender/norad/blob/main/_autodocs/04-kerning.md Signature for the `get` method of `KerningResolver`, which retrieves the kerning value between a pair of elements (glyphs or groups). ```rust pub fn get(&self, first: &str, second: &str) -> Option ``` -------------------------------- ### Exclude all data and images Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Example of creating a DataRequest to exclude both data and images, then loading a font. ```rust use norad::{Font, DataRequest}; let datareq = DataRequest::default() .data(false) .images(false); let font = Font::load_requested_data("font.ufo", datareq)?; ``` -------------------------------- ### Saving a Font Source: https://github.com/linebender/norad/blob/main/_autodocs/00-overview.md Illustrates saving a modified font to a UFO file, with an example of using custom write options for indentation and quote characters. ```rust font.save("output.ufo")?; // Or with custom formatting options use norad::{WriteOptions, QuoteChar}; let options = WriteOptions::new() .indent(WriteOptions::SPACE, 2) .quote_char(QuoteChar::Single); font.save_with_options("output.ufo", &options)?; ``` -------------------------------- ### Load only fontinfo, groups, and kerning Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Example of creating a DataRequest to load only specific components: fontinfo, groups, and kerning. ```rust use norad::{Font, DataRequest}; let datareq = DataRequest::none() .groups(true) .kerning(true); let font = Font::load_requested_data("font.ufo", datareq)?; ``` -------------------------------- ### Exclude layers and kerning Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Example of creating a DataRequest to exclude layers and kerning, then loading a font with these settings. ```rust use norad::{Font, DataRequest}; let datareq = DataRequest::default() .layers(false) .kerning(false); let font = Font::load_requested_data("font.ufo", datareq)?; ``` -------------------------------- ### Access Kerning with Group Resolution Source: https://github.com/linebender/norad/blob/main/_autodocs/00-overview.md Example of accessing kerning values, including resolution for glyphs and groups. ```rust let font = Font::load("font.ufo")?; let resolver = font.kerning_resolver(); // Works with glyphs and groups if let Some(kern_value) = resolver.get("A", "V") { println!("Kerning A V: {}", kern_value); } ``` -------------------------------- ### Filter Layers During Load Source: https://github.com/linebender/norad/blob/main/_autodocs/00-overview.md Examples of filtering layers when loading a UFO font using `DataRequest`. ```rust use norad::{Font, DataRequest}; // Only load the default layer let datareq = DataRequest::default().default_layer(true); let font = Font::load_requested_data("font.ufo", datareq)?; // Or use a custom filter let datareq = DataRequest::none() .filter_layers(|name, _| name.contains("background")); let font = Font::load_requested_data("font.ufo", datareq)?; ``` -------------------------------- ### Kerning Lookup with Group Resolution Source: https://github.com/linebender/norad/blob/main/_autodocs/README.md Illustrates how to use the KerningResolver to get kerning values, supporting both individual glyphs and groups. ```rust use norad::Font; let font = Font::load("MyFont.ufo")?; let resolver = font.kerning_resolver(); // Works with both glyphs and groups if let Some(kern) = resolver.get("A", "V") { println!("Kerning A V: {} units", kern); } ``` -------------------------------- ### new method Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Create new, default options. Returns WriteOptions with default settings (single tab indentation, double quotes) ```rust pub fn new() -> Self ``` -------------------------------- ### guidelines Method Source: https://github.com/linebender/norad/blob/main/_autodocs/09-fontinfo.md Returns a slice of global guidelines. ```rust pub fn guidelines(&self) -> &[Guideline] ``` -------------------------------- ### get_glyph_mut method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Get a mutable reference to a glyph from the layer by name. ```rust pub fn get_glyph_mut(&mut self, name: &str) -> Option<&mut Glyph> ``` -------------------------------- ### guidelines Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Return the font's global guidelines, stored in FontInfo. ```rust pub fn guidelines(&self) -> &[Guideline] ``` ```rust use norad::Font; let font = Font::load("font.ufo").expect("failed to load"); for guideline in font.guidelines() { println!("Guideline: {:?}", guideline); } ``` -------------------------------- ### Guideline::new Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Returns a new Guideline struct. ```rust pub fn new( line: Line, name: Option, color: Option, identifier: Option, ) -> Self ``` -------------------------------- ### Image::new method Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Create a new image. ```rust pub fn new( file_name: PathBuf, color: Option, transform: AffineTransform, ) -> Result ``` -------------------------------- ### Guideline::lib Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Returns a reference to the Guideline's lib. ```rust pub fn lib(&self) -> Option<&Plist> ``` -------------------------------- ### Loading a Font Source: https://github.com/linebender/norad/blob/main/_autodocs/00-overview.md Demonstrates how to load a UFO font file using the `Font::load` method. ```rust use norad::Font; let mut font = Font::load("path/to/font.ufo")?; ``` -------------------------------- ### Contour::is_closed Method Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Checks whether the contour is closed. A closed contour does not start with a Move point. ```rust pub fn is_closed(&self) -> bool ``` -------------------------------- ### Default implementation for WriteOptions Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Returns default WriteOptions with single tab indentation and double quotes. ```rust impl Default for WriteOptions ``` -------------------------------- ### new Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Returns a new, empty Font object with default settings. ```rust pub fn new() -> Self ``` ```rust use norad::Font; let font = Font::new(); assert_eq!(font.glyph_count(), 0); ``` -------------------------------- ### MetaInfo struct Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md The contents of the metainfo.plist file. ```rust pub struct MetaInfo { pub creator: Option, pub format_version: FormatVersion, pub format_version_minor: u32, } ``` -------------------------------- ### guidelines_mut Method Source: https://github.com/linebender/norad/blob/main/_autodocs/09-fontinfo.md Returns a mutable reference to the global guidelines vector. ```rust pub fn guidelines_mut(&mut self) -> &mut Vec ``` -------------------------------- ### Glyph::load Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Attempt to parse a Glyph from a .glif file at the provided path. ```rust pub fn load(path: impl AsRef) -> Result ``` ```rust use norad::Glyph; let glyph = Glyph::load("glyphs/A_.glif")?; ``` -------------------------------- ### Performance Considerations Source: https://github.com/linebender/norad/blob/main/_autodocs/00-overview.md Demonstrates how to use `DataRequest` to selectively load only necessary data from large UFO files, improving performance. ```rust use norad::{Font, DataRequest}; // Load only fontinfo and groups, skip glyphs let datareq = DataRequest::none() .groups(true) .kerning(true); let font = Font::load_requested_data("large-font.ufo", datareq)?; ``` -------------------------------- ### WriteOptions struct Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md The WriteOptions struct allows customization of how UFO files are serialized to disk. ```rust pub struct WriteOptions { // fields are private } ``` -------------------------------- ### identifier Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Returns a reference to the Guideline's identifier. ```rust pub fn identifier(&self) -> Option<&Identifier> ``` -------------------------------- ### Name::as_str Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Returns a string slice containing the name. ```rust pub fn as_str(&self) -> &str ``` -------------------------------- ### Pattern: Working with Multiple Layers Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md Shows how to iterate and process glyphs across multiple layers of a font. ```rust use norad::Font; fn process_all_layers(font: &Font) { for layer in font.iter_layers() { println!("Processing layer: {}", layer.name()); for name in layer.glyph_names() { println!(" Glyph: {}", name); } } } ``` -------------------------------- ### all Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Returns a `DataRequest` requesting all UFO data. ```rust pub fn all() -> Self ``` ```rust use norad::{Font, DataRequest}; let font = Font::load_requested_data("font.ufo", DataRequest::all())?; ``` -------------------------------- ### get_or_create_layer method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns a mutable reference to a layer by name, creating the layer if it doesn't exist. ```rust pub fn get_or_create_layer(&mut self, name: &str) -> Result<&mut Layer, NamingError> ``` -------------------------------- ### Work with Layers Source: https://github.com/linebender/norad/blob/main/_autodocs/README.md Demonstrates creating a new layer in a UFO, adding a glyph to that layer, and saving the modified font. ```rust use norad::Font; let mut font = Font::load("MyFont.ufo")?; // Create new layer let background = font.layers.new_layer("background")?; // Add glyph to it let glyph = norad::Glyph::new("A"); background.insert_glyph(glyph); font.save("MyFont-Modified.ufo")?; ``` -------------------------------- ### new_layer method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Creates and returns a new layer with the given name. Errors if the name is reserved, a duplicate, or invalid. ```rust pub fn new_layer(&mut self, name: &str) -> Result<&mut Layer, NamingError> ``` -------------------------------- ### Component::new Constructor Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns a new `Component` given a base glyph name and affine transformation definition. ```rust pub fn new( base: Name, transform: AffineTransform, identifier: Option, ) -> Self ``` -------------------------------- ### lib Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Request that returned UFO data include `` sections. ```rust pub fn lib(mut self, b: bool) -> Self ``` -------------------------------- ### Guideline::lib_mut Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Returns a mutable reference to the Guideline's lib. ```rust pub fn lib_mut(&mut self) -> Option<&mut Plist> ``` -------------------------------- ### Create a New Layer Source: https://github.com/linebender/norad/blob/main/_autodocs/00-overview.md Workflow for creating a new layer in a UFO font and adding glyphs to it. ```rust let mut font = Font::load("font.ufo")?; let layer = font.layers.new_layer("background")?; // Add glyphs to the new layer let glyph = norad::Glyph::new("A"); layer.insert_glyph(glyph); font.save("output.ufo")?; ``` -------------------------------- ### Anchor::lib Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns a reference to the anchor's lib. ```rust pub fn lib(&self) -> Option<&Plist> ``` -------------------------------- ### Selective Loading for Performance Source: https://github.com/linebender/norad/blob/main/_autodocs/README.md Shows how to load only metadata from a UFO file, skipping glyph data for performance optimization. ```rust use norad::{Font, DataRequest}; // Load only metadata, skip glyphs let request = DataRequest::default() .layers(false); let font = Font::load_requested_data("LargeFont.ufo", request)?; println!("Family: {:?}", font.font_info.family_name); ``` -------------------------------- ### Identifier::new Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Create a new Identifier from a string, if it is valid. ```rust pub fn new(string: &str) -> Result ``` -------------------------------- ### names method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns an iterator over the names of all layers. ```rust pub fn names(&self) -> impl Iterator ``` -------------------------------- ### Color::new Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Create a color with RGBA values in the range 0..=1.0. ```rust pub fn new(red: f64, green: f64, blue: f64, alpha: f64) -> Result ``` -------------------------------- ### load Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Returns a Font object with data from a UFO directory at the given path. ```rust pub fn load>(path: P) -> Result ``` ```rust use norad::Font; let font = Font::load("path/to/font.ufo") .expect("failed to load font"); assert!(font.glyph_count() > 0); ``` -------------------------------- ### Name::new Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Creates a new Name if the given value isn't empty and contains no control characters. ```rust pub fn new(name: &str) -> Result ``` -------------------------------- ### guidelines_mut Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Returns a mutable reference to the font's global guidelines. These will be created if they do not already exist. ```rust pub fn guidelines_mut(&mut self) -> &mut Vec ``` ```rust use norad::{Font, Guideline, Line}; let mut font = Font::load("font.ufo").expect("failed to load"); let guidelines = font.guidelines_mut(); // Add a new guideline let guideline = Guideline::new( Line::Vertical(50.0), None, None, None, ); guidelines.push(guideline); ``` -------------------------------- ### len method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns the number of glyphs in this layer. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### Accessing Glyphs Source: https://github.com/linebender/norad/blob/main/_autodocs/00-overview.md Shows how to access individual glyphs by name and iterate over all glyph names in a font. ```rust // Get a glyph from the default layer if let Some(glyph) = font.get_glyph("A") { println!("Glyph A has width: {}", glyph.width); } // Iterate over all glyph names for name in font.iter_names() { println!("Glyph: {}", name); } ``` -------------------------------- ### Pattern: Selective Loading for Large Fonts Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md Demonstrates how to load only metadata for large fonts by specifying a data request. ```rust use norad::{Font, DataRequest}; fn get_font_info_only(path: &str) -> Result> { let request = DataRequest::none(); // Load nothing, then we can access only metadata let font = Font::load_requested_data(path, request)?; println!("Family: {:?}", font.font_info.family_name); Ok(font) } ``` -------------------------------- ### iter method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns an iterator over all layers. ```rust pub fn iter(&self) -> impl Iterator ``` -------------------------------- ### kerning Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Request that returned UFO data include parsed `kerning.plist`. ```rust pub fn kerning(mut self, b: bool) -> Self ``` -------------------------------- ### Feature flags: object-libs Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md The `object-libs` feature is enabled by default and provides: The `Identifier::from_uuidv4()` method for generating unique identifiers, The ability to set and replace object libraries on objects, UUID v4 identifier generation using the `uuid` crate. ```toml [dependencies] norad = { version = "0.18", default-features = false } ``` -------------------------------- ### len method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns the number of layers in the set. This is always non-zero. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### Load and Modify a Font Source: https://github.com/linebender/norad/blob/main/_autodocs/README.md Demonstrates loading a UFO file, modifying the width of a specific glyph, and saving the changes. ```rust use norad::Font; // Load let mut font = Font::load("MyFont.ufo")?; // Modify if let Some(glyph) = font.get_glyph_mut("A") { glyph.width = 600.0; } // Save font.save("MyFont-Modified.ufo")?; ``` -------------------------------- ### Pattern: Read-Modify-Write Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md Demonstrates the read-modify-write pattern for modifying font data. ```rust use norad::Font; fn modify_font(path: &str) -> Result<(), Box> { // Read let mut font = Font::load(path)?; // Modify for glyph in font.default_layer_mut().iter_mut() { glyph.1.width = 600.0; } // Write font.save(path)?; Ok(()) } ``` -------------------------------- ### default_layer method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns a reference to the default layer. ```rust pub fn default_layer(&self) -> &Layer ``` -------------------------------- ### FormatVersion enum Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md A version of the UFO spec. ```rust pub enum FormatVersion { V1 = 1, V2 = 2, V3 = 3, } ``` -------------------------------- ### is_empty Method Source: https://github.com/linebender/norad/blob/main/_autodocs/09-fontinfo.md Returns true if all fields in FontInfo are None. ```rust pub fn is_empty(&self) -> bool ``` -------------------------------- ### is_empty method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns true if the layer contains no glyphs. ```rust pub fn is_empty(&self) -> bool ``` -------------------------------- ### iter method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns an iterator over glyph name-glyph pairs. ```rust pub fn iter(&self) -> impl Iterator ``` -------------------------------- ### Read-Modify-Write Pattern Source: https://github.com/linebender/norad/blob/main/_autodocs/README.md Illustrates the common pattern of loading a font, modifying it, and then saving the changes. ```rust let mut font = Font::load("in.ufo")?; // modify font font.save("out.ufo")?; ``` -------------------------------- ### save Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Serializes a Font to the given path, overwriting any existing contents. Fails if global or glyph lib contains the public.objectLibs key. ```rust pub fn save(&self, path: impl AsRef) -> Result<(), FontWriteError> ``` ```rust use norad::Font; let font = Font::load("input.ufo").expect("failed to load"); // ... modify font ... font.save("output.ufo").expect("failed to save"); ``` -------------------------------- ### Guideline struct Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md A guideline associated with a font or glyph. ```rust pub struct Guideline { pub line: Line, pub name: Option, pub color: Option, // identifier and lib fields are private } ``` -------------------------------- ### Glyph::new Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns a new, "empty" Glyph with the given name. ```rust pub fn new(name: &str) -> Self ``` ```rust use norad::Glyph; let glyph = Glyph::new("A"); assert_eq!(glyph.name().as_ref(), "A"); assert_eq!(glyph.width, 0.0); ``` -------------------------------- ### SPACE constant Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md The ASCII value of the space character (0x20). ```rust pub const SPACE: u8 = b' '; ``` -------------------------------- ### DataStore struct signature Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md The contents of the font's `data` directory. The data store is a flat or nested directory structure for arbitrary binary data associated with the font. ```rust pub struct DataStore { // private fields } ``` -------------------------------- ### Color::channels Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Returns the RGBA channel values. ```rust pub fn channels(&self) -> (f64, f64, f64, f64) ``` -------------------------------- ### kerning_resolver Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Builds a KerningResolver, which can do full kerning lookups, including group resolution. ```rust pub fn kerning_resolver(&'_ self) -> KerningResolver<'_> ``` ```rust use norad::Font; let font = Font::load("font.ufo").expect("failed to load"); let resolver = font.kerning_resolver(); if let Some(value) = resolver.get("A", "V") { println!("Kerning A V: {}", value); } ``` -------------------------------- ### Safe Saving Pattern Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md When saving to an important location, use a temporary file and then move it to avoid data loss. ```rust use norad::Font; use std::path::Path; fn safe_save(font: &Font, target: &Path) -> Result<(), Box> { let parent = target.parent().ok_or("no parent directory")?; let temp = parent.join(".temp.ufo"); // Save to temp location font.save(&temp)?; // Move temp to target only if save succeeded if target.exists() { std::fs::remove_dir_all(target)?; } std::fs::rename(&temp, target)?; Ok(()) } ``` -------------------------------- ### replace_lib Method Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Replaces the actual lib by the lib given in parameter, returning the old lib if present. Sets a new UUID v4 identifier if none is set already. ```rust #[cfg(feature = "object-libs")] pub fn replace_lib(&mut self, lib: Plist) -> Option ``` -------------------------------- ### indent method Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Customize the indent whitespace. By default, we indent with a single tab (\t). You can use this method to specify alternative indent behaviour. ```rust pub fn indent(mut self, indent_char: u8, indent_count: usize) -> Self ``` -------------------------------- ### TAB constant Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md The ASCII value of the tab character (0x09). ```rust pub const TAB: u8 = b'\t'; ``` -------------------------------- ### Plist Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md A Plist dictionary for storing arbitrary key-value data. This is an alias for `plist::Dictionary` from the plist crate. ```rust pub type Plist = plist::Dictionary; ``` -------------------------------- ### features Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Request that returned UFO data include OpenType Layout features in Adobe `.fea` format. ```rust pub fn features(mut self, b: bool) -> Self ``` -------------------------------- ### Image struct Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Image data for a glyph. ```rust pub struct Image { // fields are private, use methods to access } ``` -------------------------------- ### none Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Returns a `DataRequest` requesting no UFO data. ```rust pub fn none() -> Self ``` ```rust use norad::{Font, DataRequest}; // Load only lib and groups let datareq = DataRequest::none() .lib(true) .groups(true); let font = Font::load_requested_data("font.ufo", datareq)?; ``` -------------------------------- ### ImageStore struct signature Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md The contents of the font's `images` directory. The image store is a flat directory structure containing PNG image files. Unlike the data store, the images directory must be flat with no subdirectories. ```rust pub struct ImageStore { // private fields } ``` -------------------------------- ### insert_glyph method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Insert a glyph into the layer. Returns the previous glyph with this name, if any. ```rust pub fn insert_glyph(&mut self, glyph: Glyph) -> Option ``` -------------------------------- ### Contour::new Constructor Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns a new `Contour` given a vector of contour points. ```rust pub fn new( points: Vec, identifier: Option, ) -> Self ``` -------------------------------- ### Multiple Layers Iteration Source: https://github.com/linebender/norad/blob/main/_autodocs/README.md Demonstrates how to iterate through all layers of a font and access glyph names within each layer. ```rust for layer in font.iter_layers() { for name in layer.glyph_names() { // process glyph } } ``` -------------------------------- ### Anchor::new Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns a new `Anchor` given x and y coordinate values. ```rust pub fn new( x: f64, y: f64, name: Option, color: Option, identifier: Option, ) -> Self ``` -------------------------------- ### lib Field Pattern Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md Objects with optional lib fields follow this pattern. ```rust pub fn lib(&self) -> Option<&Plist> pub fn lib_mut(&mut self) -> Option<&mut Plist> pub fn take_lib(&mut self) -> Option #[cfg(feature = "object-libs")] pub fn replace_lib(&mut self, lib: Plist) -> Option ``` -------------------------------- ### save_with_options Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Serializes a Font to the given path with custom WriteOptions for serialization format settings, allowing customization of indentation style and XML quote characters. ```rust pub fn save_with_options( &self, path: impl AsRef, options: &WriteOptions, ) -> Result<(), FontWriteError> ``` ```rust use norad::{Font, WriteOptions, QuoteChar}; let font = Font::load("input.ufo").expect("failed to load"); let options = WriteOptions::default() .indent(WriteOptions::SPACE, 2) .quote_char(QuoteChar::Single); font.save_with_options("output.ufo", &options) .expect("failed to save"); ``` -------------------------------- ### DataRequest struct Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md A type that describes which components of a UFO should be loaded. By default, all components of the UFO file are loaded; however, if you only need a subset of them, you can pass this struct to `Font::load_requested_data()` in order to only load the fields you specify. This can improve performance in large projects. ```rust pub struct DataRequest<'a> { pub lib: bool, pub groups: bool, pub kerning: bool, pub features: bool, pub data: bool, pub images: bool, // layers are configured separately } ``` -------------------------------- ### quote_char method Source: https://github.com/linebender/norad/blob/main/_autodocs/06-write-options.md Builder-style method to customize the XML declaration attribute definition quote character. By default, we use double quotes. ```rust pub fn quote_char(mut self, quote_style: QuoteChar) -> Self ``` -------------------------------- ### ContourPoint::new Constructor Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns a new `ContourPoint` given coordinates, type, and smooth definition. ```rust pub fn new( x: f64, y: f64, typ: PointType, smooth: bool, name: Option, identifier: Option, ) -> Self ``` -------------------------------- ### Line enum Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md An infinite line, used in guidelines. ```rust pub enum Line { Vertical(f64), Horizontal(f64), Angle { x: f64, y: f64, degrees: f64 }, } ``` -------------------------------- ### glyph_names method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns an iterator over the glyph names in this layer. ```rust pub fn glyph_names(&self) -> impl Iterator ``` -------------------------------- ### Anchor::lib_mut Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns a mutable reference to the anchor's lib. ```rust pub fn lib_mut(&mut self) -> Option<&mut Plist> ``` -------------------------------- ### get_first_group Method Signature Source: https://github.com/linebender/norad/blob/main/_autodocs/04-kerning.md Signature for the `get_first_group` method of `KerningResolver`, which retrieves the group for a glyph name when it's the first in a kerning pair. ```rust pub fn get_first_group(&self, glyph_name: &str) -> Option ``` -------------------------------- ### Glyph::component_count Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns the number of components in the glyph. ```rust pub fn component_count(&self) -> usize ``` -------------------------------- ### Glyph::name Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Returns the name of the glyph. ```rust pub fn name(&self) -> &Name ``` -------------------------------- ### groups Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Request that returned UFO data include parsed `groups.plist`. ```rust pub fn groups(mut self, b: bool) -> Self ``` -------------------------------- ### get_mut method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Returns a mutable reference to a layer, by name. ```rust pub fn get_mut(&mut self, name: &str) -> Option<&mut Layer> ``` -------------------------------- ### filter_layers Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Request to load a subset of layers using a closure. Given the name and directory of a layer, the closure must return `true` or `false`. Only layers for which the closure returns `true` will be loaded. If this is set, it will override the `layers` option. ```rust pub fn filter_layers(mut self, filter: impl Fn(&str, &Path) -> bool + 'a) -> Self ``` ```rust use norad::{DataRequest, Font}; let to_load = DataRequest::none() .filter_layers(|name, _path| name.contains("background")); let font = Font::load_requested_data("font.ufo", to_load)?; ``` -------------------------------- ### Os2WidthClass Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md OpenType OS/2 width class (proportions from Ultra-condensed to Ultra-expanded). ```rust pub enum Os2WidthClass { // various width class variants } ``` -------------------------------- ### layers Source: https://github.com/linebender/norad/blob/main/_autodocs/05-data-request.md Request that returned UFO data include layers and their glyph data. ```rust pub fn layers(mut self, b: bool) -> Self ``` -------------------------------- ### Identifier::from_uuidv4 Source: https://github.com/linebender/norad/blob/main/_autodocs/07-types.md Create a new Identifier from a UUID v4 identifier. Only available with the "object-libs" feature. ```rust #[cfg(feature = "object-libs")] pub fn from_uuidv4() -> Self ``` -------------------------------- ### Codepoints struct Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md A collection of Unicode codepoints associated with a glyph. ```rust pub struct Codepoints { /* private */ } ``` -------------------------------- ### validate Method Source: https://github.com/linebender/norad/blob/main/_autodocs/09-fontinfo.md Validates the contents of the FontInfo, checking various fields for correctness according to specifications. ```rust pub fn validate(&self) -> Result<(), FontInfoErrorKind> ``` -------------------------------- ### remove method Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Removes a layer by name. The default layer cannot be removed. ```rust pub fn remove(&mut self, name: &str) -> Option ``` -------------------------------- ### LayerContents struct Source: https://github.com/linebender/norad/blob/main/_autodocs/02-layer.md Represents the ordered list of Layer objects within a UFO, including a default layer and potentially additional layers. Corresponds to `layercontents.plist` in the UFO specification. ```rust pub struct LayerContents { // fields are private } ``` -------------------------------- ### Contour::to_kurbo Method Source: https://github.com/linebender/norad/blob/main/_autodocs/03-glyph.md Converts the `Contour` to a `kurbo::BezPath`. Only available with the "kurbo" feature. ```rust #[cfg(feature = "kurbo")] pub fn to_kurbo(&self) -> Result ``` -------------------------------- ### Font struct Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Represents a complete font document with all its components. ```rust pub struct Font { pub meta: MetaInfo, pub font_info: FontInfo, pub layers: LayerContents, pub lib: Plist, pub groups: Groups, pub kerning: Kerning, pub features: String, pub data: DataStore, pub images: ImageStore, } ``` -------------------------------- ### Identifier Pattern Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md Objects with optional identifiers follow this pattern. ```rust pub fn identifier(&self) -> Option<&Identifier> pub fn replace_identifier(&mut self, id: Identifier) -> Option ``` -------------------------------- ### load_requested_data Source: https://github.com/linebender/norad/blob/main/_autodocs/01-font.md Returns a Font object with custom data inclusion/exclusion criteria from a UFO directory. ```rust pub fn load_requested_data( path: impl AsRef, request: DataRequest, ) -> Result ``` ```rust use norad::{Font, DataRequest}; let datareq = DataRequest::default() .layers(false) .kerning(false); let font = Font::load_requested_data( "path/to/font.ufo", datareq ).expect("failed to load"); ``` ```rust use norad::{Font, DataRequest}; let datareq = DataRequest::none().lib(true); let font = Font::load_requested_data( "path/to/font.ufo", datareq ).expect("failed to load"); ``` -------------------------------- ### user_name_to_file_name function signature Source: https://github.com/linebender/norad/blob/main/_autodocs/10-utilities.md Converts a user-readable name to a filename-safe name suitable for use as a .glif filename or layer directory name. This function handles the UFO specification requirements for filename conversion, making user-visible names compatible with filesystem constraints. ```rust pub fn user_name_to_file_name(name: &str) -> String ```