### Preprocessor Command Example Source: https://github.com/googlefonts/fontations/blob/main/font-codegen/README.md Example of how to run the preprocessor tool from the command line. It takes a raw table definition file and outputs formatted Rust code. ```sh $ cargo run --bin preprocessor resources/raw_tables/my_table.txt > resources/codegen_inputs/my_table.rs ``` -------------------------------- ### Install and Use cargo-release Source: https://github.com/googlefonts/fontations/blob/main/README.md Commands to install cargo-release and use its scripts for version bumping and releasing crates. ```bash cargo install cargo-release ``` ```bash ./resources/scripts/bump-version.sh ``` ```bash ./resources/scripts/bump-version.sh read-fonts write-fonts patch ``` ```bash ./resources/scripts/release.sh ``` ```bash ./resources/scripts/release.sh read-fonts write-fonts ``` -------------------------------- ### Install skera CLI Tool Source: https://github.com/googlefonts/fontations/blob/main/skera/README.md Install the skera command-line interface tool using Cargo, ensuring the 'cli' feature is enabled for full functionality. ```bash cargo install skera --features cli ``` -------------------------------- ### Codegen Tool Command Example Source: https://github.com/googlefonts/fontations/blob/main/font-codegen/README.md Example of how to run the codegen tool on a preprocessed input file. The generated Rust source code is written to standard output. ```sh # cargo run --bin=codegen resources/codegen_inputs/my_table.rs ``` -------------------------------- ### Install cargo-fuzz and nightly toolchain Source: https://github.com/googlefonts/fontations/blob/main/fuzz/README.md Ensure you have the necessary tools installed before building the fuzzer. This includes cargo-fuzz and the nightly Rust toolchain. ```shell # Make sure you have cargo-fuzz and the nightly toolchain $ cargo install cargo-fuzz $ rustup install nightly ``` -------------------------------- ### Preprocessor Input Example Source: https://github.com/googlefonts/fontations/blob/main/font-codegen/README.md Example of input format for the preprocessor, used to define font table structures. It supports comments, table/record definitions, and flags/enums with specified types. ```text /// an optional comment for each top-level item @table Gpos1_0 uint16 majorVersion Major version of the GPOS table, = 1 uint16 minorVersion Minor version of the GPOS table, = 0 Offset16 scriptListOffset Offset to ScriptList table, from beginning of GPOS table Offset16 featureListOffset Offset to FeatureList table, from beginning of GPOS table Offset16 lookupListOffset Offset to LookupList table, from beginning of GPOS table /// Part of [Name1] @record LangTagRecord uint16 lengt Language-tag string length (in bytes) Offset16 langTagOffset Language-tag string offset from start of storage area (in bytes). /// [Axis value table flags](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#flags). @flags(u16) AxisValueTableFlags 0x0001 OLDER_SIBLING_FONT_ATTRIBUTE If set, this axis value table provides axis value information 0x0002 ELIDABLE_AXIS_VALUE_NAME If set, do something else @enum(u16) GlyphClassDef 1 Base Base glyph (single character, spacing glyph) 2 Ligature Ligature glyph (multiple character, spacing glyph) 3 Mark Mark glyph (non-spacing combining glyph) 4 Component Component glyph (part of single character, spacing glyph) ``` -------------------------------- ### Example Table Definition Source: https://github.com/googlefonts/fontations/blob/main/docs/codegen-tour.md Defines a sample table structure named 'Foob' with various fields, including version, values, a count-dependent array, and a versioned field. ```rust table Foob { #[version] version: BigEndian, some_val: BigEndian, other_val: BigEndian, flags_count: BigEndian, #[count($flags_count)] flags: [BigEndian], #[since_version(1)] versioned_value: BigEndian, } ``` -------------------------------- ### Subset Font using skera CLI Source: https://github.com/googlefonts/fontations/blob/main/skera/README.md Example of how to use the skera command-line tool to subset a font. Replace placeholders with your actual file paths and desired unicodes. ```bash skera --path --unicodes --output-file ``` -------------------------------- ### Rebuild Test Font Binaries Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/README.md Rebuilds all input binaries and extracted data by installing the correct versions of fonttools and FreeType. Run from the repo root. ```shell # from the repo root somewhere/fontations $ ./font-test-data/test_data/rebuild.sh ``` -------------------------------- ### Querying GPOS Subtable in otexplorer Source: https://github.com/googlefonts/fontations/blob/main/otexplorer/README.md Use the -q flag with a query string to specify a path within a font table. This example shows how to access a specific subtable of a GPOS lookup. ```sh -q GPOS.lookup_list.lookup_offsets.1.subtable_offsets.0 ``` ```sh -q GPOS.lookupListOffset.lookupOffsets.1.subtableOffsets.0 ``` ```sh -q GPOS.look.off.1.off.0 ``` -------------------------------- ### Run Subsetter with Font File Source: https://github.com/googlefonts/fontations/blob/main/skera/test-data/README.md This command runs the subsetter tool with a specified font file, text content, and output file. Ensure you have the cargo build tool installed. ```shell cargo run -- --path=font-file --text=abc --output-file=subset.ttf ``` -------------------------------- ### MyTable Struct and Implementation Source: https://github.com/googlefonts/fontations/blob/main/docs/codegen-tour.md Illustrates a conceptual FontData table object, MyTable, which provides typed access to its fields. The example shows a method to read the table's first field, 'format', which is a u16. ```rust pub struct MyTable<'a>(FontData<'a>); impl MyTable<'_> { /// Read the table's first field pub fn format(&self) -> u16 { self.0.read_at(0) } } ``` -------------------------------- ### Run Chromium Source: https://github.com/googlefonts/fontations/blob/main/README.md Launch the compiled Chromium browser. Ensure you replace `` with your actual build directory. ```bash $ out//chrome ``` -------------------------------- ### Display skera CLI Help Source: https://github.com/googlefonts/fontations/blob/main/skera/README.md Run this command to view all available options, flags, and usage instructions for the skera command-line tool. ```bash skera --help ``` -------------------------------- ### Build and run the fuzzer Source: https://github.com/googlefonts/fontations/blob/main/fuzz/README.md Build the fuzzer with optimizations and debug assertions enabled, then execute the fuzz target. This command compiles the fuzzing harness for local execution. ```shell # Build the fuzzer $ cargo +nightly fuzz build -O --debug-assertions $ target/x86_64-unknown-linux-gnu/release/fuzz_skrifa ``` -------------------------------- ### Build Skia with Fontations Source: https://github.com/googlefonts/fontations/blob/main/README.md Command to build Skia, including Fontations, using bazelisk. Add '-c dbg' for a debug build. ```bash $ bazelisk build --sandbox_base=/dev/shm --with_fontations //tools/viewer //tests:FontationsTest ``` -------------------------------- ### Build Chromium with Fontations Source: https://github.com/googlefonts/fontations/blob/main/README.md Compile Chromium after enabling Fontations. Replace `` with your specific build directory. ```bash autoninja -C out/ chrome ``` -------------------------------- ### Enable Fontations in Chromium Build Source: https://github.com/googlefonts/fontations/blob/main/README.md Add this line to your `args.gn` file to enable the Fontations backend during Chromium compilation. This is a necessary step before building. ```bash use_typeface_fontations = true ``` -------------------------------- ### Run Font Comparison Tests Source: https://github.com/googlefonts/fontations/blob/main/fauntlet/test_fonts/README.md Execute the font comparison tests using the fauntlet tool. This command compares glyphs across different hinting engines and targets, exiting on failure. ```shell cargo run --release -p fauntlet -- compare-glyphs --hinting-engine all --hinting-target all --exit-on-fail test_fonts/*.* ``` -------------------------------- ### Build and Run Fuzzers Source: https://github.com/googlefonts/fontations/blob/main/README.md Commands to build fuzzers using cargo-fuzz and run a specific fuzzer with a test case file. ```bash cargo +nightly fuzz build -O --debug-assertions ``` ```bash target/x86_64-unknown-linux-gnu/release/fuzz_skrifa_outline ~/Downloads/clusterfuzz-testcase-minimized-fuzz_skrifa_outline-6213391169945600 ``` -------------------------------- ### Run Codegen: Rebuild All Source: https://github.com/googlefonts/fontations/blob/main/font-codegen/README.md Use this command to rebuild all generated font table code. This is the standard use case for the codegen tool. ```sh cargo run --bin=codegen resources/codegen_plan.toml ``` -------------------------------- ### Glyph Data with Relative Path Commands Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/extracted/varc-ac00-ac01-glyphs.txt Illustrates glyph data using relative 'm' (moveto) and 'l' (lineto) commands. This format is common for defining paths within glyphs. ```text glyph 10 16 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours 7 points 881,-56 881,664 881,735 72,735 72,659 872,659 793,670 793,-56 tags 1 1 1 1 1 1 1 1 m 13.765625,-0.875 l 13.765625,10.375 l 13.765625,11.484375 l 1.125,11.484375 l 1.125,10.296875 l 13.625,10.296875 l 12.390625,10.46875 l 12.390625,-0.875 l 13.765625,-0.875 ``` -------------------------------- ### Add skera Library to Rust Project Source: https://github.com/googlefonts/fontations/blob/main/skera/README.md Use this command to add the skera library as a dependency in your Rust project's Cargo.toml file. ```bash cargo add skera ``` -------------------------------- ### Run Skia Fontations Unit Tests Source: https://github.com/googlefonts/fontations/blob/main/README.md Command to run the Fontations unit tests within Skia. Can be compiled and run in one step. ```bash $ bazel-bin/tests/FontationsTest ``` ```bash $ bazelisk test --sandbox_base=/dev/shm --with_fontations //tests:FontationsTest ``` -------------------------------- ### Run Codegen: Process Single File Source: https://github.com/googlefonts/fontations/blob/main/font-codegen/README.md This command processes a single input file for parsing or compilation. The output is printed to stdout and can be redirected. ```sh cargo run --bin=codegen file $mode $input ``` ```sh cargo run --bin=codegen file parse resources/codegen_inputs/cmap.rs > read-fonts/generated/generated_cmap.rs ``` -------------------------------- ### Compare Glyphs for a Single Font Source: https://github.com/googlefonts/fontations/blob/main/fauntlet/README.md Use this command to compare glyphs for a single font file. Ensure you have the Fauntlet tool compiled and available in your PATH. ```bash cargo run --release -p fauntlet -- compare-glyphs path/to/font.ttf ``` -------------------------------- ### Configure Git Hooks Source: https://github.com/googlefonts/fontations/blob/main/README.md Set the git hooksPath to enable automatic execution of git hooks for ensuring patch quality. ```bash git config core.hooksPath "./resources/githooks" ``` -------------------------------- ### Run Skia Fontations GM Source: https://github.com/googlefonts/fontations/blob/main/README.md Command to run the Fontations Graphics Module (GM) tests in Skia. Can be compiled and run in one step. ```bash $ bazel-bin/tools/viewer/viewer --slide GM_typeface_fontations_roboto ``` ```bash $ bazelisk run --sandbox_base=/dev/shm --with_fontations //tools/viewer -- --slide GM_typeface_fontations_roboto ``` -------------------------------- ### Subset Tinos for hdmx Advances Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/README.md Subsets Tinos Regular to a few characters for testing hdmx advance widths. ```shell pyftsubset tinos-regular.ttf --text=aAbB --gids=3,5 ``` -------------------------------- ### Subset Material Icons for Scaling Test Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/README.md Subsets Google Material Icons Regular to a single glyph (GID 2) for testing empty Private DICT and scaling with upem=512, ppem=8. ```shell pyftsubset material_icons.otf --gids=2 ``` -------------------------------- ### Subset Cousine for MPPEM Instruction Test Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/README.md Subsets Cousine Regular to a single character that uses mppem for testing rounding at fractional font sizes. ```shell pyftsubset cousine-regular.ttf --gids=85 ``` -------------------------------- ### Generated Rust methods for CoverageContainer Source: https://github.com/googlefonts/fontations/blob/main/docs/codegen-tour.md Shows the methods generated by Fontations for accessing raw offsets and resolved offset types from a table structure. Includes methods for single offsets and arrays of offsets. ```rust impl<'a> ClassContainer<'a> { pub fn coverage_offset(&self) -> Offset16 { .. } pub fn coverage(&self) -> Result, ReadError> { .. } pub fn class_def_offsets(&self) -> &[BigEndian] { .. } pub fn class_defs(&self) -> impl Iterator, ReadError>> + 'a { .. } ``` -------------------------------- ### Fontations Crate Dependency Graph Source: https://github.com/googlefonts/fontations/blob/main/README.md Visual representation of the non-development dependency relationships among the font-related crates within the fontations repository. This diagram is useful for understanding how different parts of the project interact. ```mermaid %% This is a map of non-dev font-related dependencies. %% See https://mermaid.live/edit for a lightweight editing environment for %% mermaid diagrams. graph LR %% First we define the nodes and give them short descriptions. %% We group them into subgraphs by repo so that the visual layout %% maps to the source layout, as this is intended for contributors. %% https://github.com/googlefonts/fontations subgraph fontations[fontations repo] fauntlet[fauntlet\ncompares Skrifa & freetype] font-types[font-types\ndefinitions of types\nfrom OpenType and a bit more] read-fonts[read-fonts\nparses and reads OpenType fonts] skrifa[skrifa\nhigher level lib\nfor reading OpenType fonts] write-fonts[write-fonts\ncreates and edits font-files] end %% https://github.com/linebender/kurbo kurbo[kurbo\n2d curves lib] %% https://github.com/linebender/norad norad[norad\nhandles Unified Font Object files] %% https://github.com/PistonDevelopers/freetype-rs freetype-rs[freetype-rs\nbindings for the FreeType library] %% Now define the edges. %% Made by hand on March 20, 2024, probably not completely correct. %% Should be easy to automate if we want to, main thing is to %% define the crates of interest. fauntlet --> skrifa fauntlet --> freetype-rs read-fonts --> font-types skrifa --> read-fonts write-fonts --> font-types write-fonts --> read-fonts write-fonts --> kurbo norad --> kurbo ``` -------------------------------- ### Compare Glyphs with Multiple Fonts and Glob Syntax Source: https://github.com/googlefonts/fontations/blob/main/fauntlet/README.md This command allows comparison of glyphs across multiple font files, supporting glob syntax for file path specification. It processes fonts in parallel and outputs diagnostics to stderr. ```bash cargo run --release -p fauntlet -- compare-glyphs /myfonts/noto/**/hinted/**.ttf otherfonts/*.?tf ``` -------------------------------- ### Glyph Data Format Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/README.md Describes the format of extracted glyph outlines stored in text files. This format includes glyph ID, font size, hint mode, and path commands. ```text glyph points contours tags m l q c - ``` -------------------------------- ### Generated FontRead Implementation for Foob Table Source: https://github.com/googlefonts/fontations/blob/main/docs/codegen-tour.md Shows the generated Rust code for the `FontRead` trait implementation for the `Foob` table. It demonstrates how to read fields, advance cursors, and handle versioned data. ```rust impl<'a> FontRead<'a> for Foob<'a> { fn read(data: FontData<'a>) -> Result { let mut cursor = data.cursor(); let version: u16 = cursor.read()?; cursor.advance::(); // some_val cursor.advance::(); // other_val let flags_count: u16 = cursor.read()?; let flags_byte_len = flags_count as usize * u16::RAW_BYTE_LEN; cursor.advance_by(flags_byte_len); // flags let versioned_value_byte_start = version .compatible(1) .then(|| cursor.position()) .transpose()?; version.compatible(1).then(|| cursor.advance::()); cursor.finish(FoobMarker { flags_byte_len, versioned_value_byte_start, }) } } ``` -------------------------------- ### Subset Noto Serif for Ligatures and C2SC Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/README.md Subsets Noto Serif Regular to fi ligatures and c2sc support, disabling hinting, for testing autohinting shaper capture of OpenType features. ```shell pyftsubset notoserif-regular.ttf --layout-features+=c2sc --no-hinting --text=Hfix ``` -------------------------------- ### Subset Noto Sans Gurmukhi Variable Font Source: https://github.com/googlefonts/fontations/blob/main/fauntlet/test_fonts/README.md Subset the Noto Sans Gurmukhi variable font using pyftsubset to include specific glyph IDs. This font is unhinted and revealed a prior bug. ```shell pyftsubset NotoSansGurmukhi[wdth,wght].ttf --gids=0-32 ``` -------------------------------- ### Generated FontRead Implementation for Multi-Format Table Source: https://github.com/googlefonts/fontations/blob/main/docs/codegen-tour.md Shows the generated `FontRead` implementation for a multi-format table. It reads the format identifier from the input data and instantiates the appropriate enum variant. ```rust impl<'a> FontRead<'a> for MyTable<'a> { fn read(data: FontData<'a>) -> Result { let format: u16 = data.read_at(0)?; match format { MyTableFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), MyTableFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), other => Err(ReadError::InvalidFormat(other.into())), } } } ``` -------------------------------- ### Test Codegen Modifications Source: https://github.com/googlefonts/fontations/blob/main/font-codegen/README.md This command sequence is used when modifying the codegen code itself. It generates code based on a test plan and then runs tests to ensure the generated code compiles and functions correctly. ```sh cargo run --bin=codegen resources/test_plan.toml && cargo test ``` -------------------------------- ### Zerocopy Struct for Fixed-Size TableRecord Source: https://github.com/googlefonts/fontations/blob/main/docs/codegen-tour.md Defines a Rust struct with `repr(C)` and `repr(packed)` attributes to match the exact memory layout of an OpenType font's TableRecord. Implements the `FixedSize` trait to ensure all fields are also fixed-size. ```rust #[repr(C)] #[repr(packed)] pub struct TableRecord { /// Table identifier. pub tag: BigEndian, /// Checksum for the table. pub checksum: BigEndian, /// Offset from the beginning of the font data. pub offset: BigEndian, /// Length of the table. pub length: BigEndian, } impl FixedSize for TableRecord { const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN; } ``` -------------------------------- ### Implement Format Trait for Table Source: https://github.com/googlefonts/fontations/blob/main/docs/codegen-tour.md Implements the `Format` trait for a table format, associating a constant `FORMAT` value with the table type. This is automatically generated based on the `#[format]` attribute. ```rust impl Format for MyTableFormat1 { const FORMAT: u16 = 1; } ``` -------------------------------- ### Empty Glyph Data Structure Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/extracted/varc-ac00-ac01-glyphs.txt Represents a glyph with no contours or points defined. This is a placeholder or an empty glyph definition. ```text glyph 7 0 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` ```text glyph 7 16 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` ```text glyph 7 50 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` ```text glyph 8 0 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` ```text glyph 8 16 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` ```text glyph 8 50 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` ```text glyph 9 0 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` ```text glyph 9 16 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` ```text glyph 9 50 none coords 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 contours points tags ``` -------------------------------- ### Subset Noto Serif TC for CJK Routines Source: https://github.com/googlefonts/fontations/blob/main/font-test-data/test_data/README.md Subsets Noto Serif Traditional Chinese Regular to characters used for alignment zones and standard widths for testing CJK specific routines. ```shell pyftsubset NotoSerifTC-Regular.ttf --text=他你們和对就我時来能說这齊軍已既是民现理置軍配開露顾个人以你個到大對我時来要说主因想理當着者著过进過還面些你們和她將年情样理說这通即吧呢响師收斷眼间陈除随隨事學將想政新樣沒然现球經起例别动吗增明期物种调费都间田囗 ```