Skip to main content

Crate oxifont_adapter_pure

Crate oxifont_adapter_pure 

Source
Expand description

oxifont-adapter-pure — Pure Rust FontDatabase built on filesystem scanning.

Composes oxifont_discovery (directory scan) and oxifont_parser (TTF/OTF/TTC parsing) into a FontCatalog implementation that requires no native libraries.

§Features

  • cache: Enable disk-based face-metadata caching. Uses serde_json to persist FaceInfo records; requires oxifont-core/serde. When enabled, [FontDatabase::system_cached] and [FontDatabase::scan_cached] are available.
  • db: Enable the bridge to [oxifont_db]. Adds [FontDatabase::into_db] and [FontDatabase::as_db] which convert this catalog to an [oxifont_db::FontDatabase] for CSS Fonts Level 4 matching via [oxifont_db::Query].

§Integration with oxitext

FontDatabase can serve as the font backend for oxitext’s pipeline. The oxitext::Pipeline::new(font_db) constructor accepts an &oxifont::FontDatabase (which is a type alias for oxifont_adapter_pure::FontDatabase when using the pure Cargo feature).

use oxifont_adapter_pure::FontDatabase;
use oxifont::FontDatabase as OxiFont;  // requires oxifont `pure` feature

§Subsetting integration

Use FontDatabase::font_bytes to retrieve raw SFNT bytes for a face, then pass them to oxifont_subset::subset_font for glyph subsetting:

use oxifont_adapter_pure::FontDatabase;
use oxifont_core::FontCatalog as _;

let db = FontDatabase::system().unwrap();
if let Some(info) = db.faces().first() {
    let bytes = db.font_bytes(info).unwrap();
    // Pass `bytes` to `oxifont_subset::subset_font(&bytes, &codepoints)`.
}

§Example

use oxifont_adapter_pure::FontDatabase;
use oxifont_core::{FontCatalog as _, FontQuery};

let db = FontDatabase::system().unwrap();
println!("found {} faces", db.faces().len());

if let Some(face) = db.find(&FontQuery::new().family("Helvetica")) {
    println!("found: {}", face.family);
}

Structs§

FontDatabase
An in-memory catalog of font faces discovered by scanning directories.