load_font_with_fallback_chain

Function load_font_with_fallback_chain 

Source
pub fn load_font_with_fallback_chain(
    primary_name: &str,
    fallback_names: &[String],
    custom_paths: &[PathBuf],
    _text: Option<&str>,
) -> Result<FontFamily<FontFallbackChain>, Error>
Expand description

Loads fonts and creates a fallback chain for handling mixed-script documents.

This function creates a FontFallbackChain by:

  1. Loading the primary font
  2. Loading all specified fallback fonts
  3. Creating a chain where fonts are tried in order

When rendering text, the chain will automatically select the appropriate font for each character based on glyph coverage.

§Arguments

  • primary_name - Name of the primary font to load
  • fallback_names - List of fallback font names to try
  • custom_paths - Custom paths to search for fonts
  • text - Optional text for validation (currently unused, kept for API compatibility)

§Returns

A FontFamily where each variant (regular, bold, etc.) is a FontFallbackChain

§Example

use markdown2pdf::fonts::load_font_with_fallback_chain;
use std::path::PathBuf;

let chain = load_font_with_fallback_chain(
    "Noto Sans",
    &["DejaVu Sans".to_string(), "Arial".to_string()],
    &[PathBuf::from("./fonts")],
    Some("Hello мир! 👋")
)?;