load_unicode_system_font

Function load_unicode_system_font 

Source
pub fn load_unicode_system_font(
    text: Option<&str>,
) -> Result<FontFamily<FontData>, Error>
Expand description

Loads a Unicode-capable system font with good international character support.

This function attempts to find and load a font from the system that supports a wide range of Unicode characters, making it suitable for documents with international text (Romanian, Cyrillic, Greek, etc.).

§Priority Order

  1. Noto Sans - Google’s comprehensive Unicode font
  2. DejaVu Sans - Popular open-source Unicode font
  3. Liberation Sans - Red Hat’s Unicode font
  4. Arial Unicode MS - Microsoft’s Unicode font (if available)
  5. Fallback to Helvetica (PDF built-in, limited to Windows-1252)

§Arguments

  • text - Optional text to check coverage for. If provided, will verify the selected font supports all characters.

§Returns

  • Ok(FontFamily<FontData>) - A font family with good Unicode support
  • Err(Error) - If no suitable font could be loaded

§Example

use markdown2pdf::fonts::load_unicode_system_font;

// Load best available Unicode font
let font = load_unicode_system_font(None)?;

// Load and verify coverage for Romanian text
let romanian_text = "ăâîșț ĂÂÎȘȚ";
let font = load_unicode_system_font(Some(romanian_text))?;