aura-gui 0.3.0

UI nativa acelerada por GPU para escritorio, Android e iOS, en un solo crate: estilo tipo Tailwind, componentes, sombras, animaciones y agentes de IA. Reposo a cero. Licencia AGPL-3.0 o comercial.
//! Carga mínima de fuentes: solo las necesarias, en lugar de todo el sistema.
//!
//! `FontSystem::new()` indexa cientos de familias; cargar unas pocas reduce
//! varias decenas de MB del presupuesto de memoria.

use cosmic_text::{FontSystem, fontdb};
use std::path::PathBuf;

#[cfg(target_os = "macos")]
const FONT_FILES: &[&str] = &[
    "/System/Library/Fonts/Menlo.ttc",
    "/System/Library/Fonts/HelveticaNeue.ttc",
    "/System/Library/Fonts/Apple Color Emoji.ttc",
    "/System/Library/Fonts/Apple Symbols.ttf",
    "/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
];

/// Relativas a `%WINDIR%\Fonts`. Con las cuatro variantes de Consolas y Segoe UI, negrita y cursiva usan los
/// diseños reales del sistema en lugar de un trazo engrosado o inclinado por software.
#[cfg(target_os = "windows")]
const FONT_FILES: &[&str] = &[
    "consola.ttf",
    "consolab.ttf",
    "consolai.ttf",
    "consolaz.ttf",
    "segoeui.ttf",
    "segoeuib.ttf",
    "segoeuii.ttf",
    "segoeuiz.ttf",
    "seguiemj.ttf",
    "seguisym.ttf",
];

#[cfg(target_os = "ios")]
const FONT_FILES: &[&str] = &[
    "/System/Library/Fonts/Core/HelveticaNeue.ttc",
    "/System/Library/Fonts/CoreUI/Menlo.ttc",
    "/System/Library/Fonts/CoreAddition/AppleColorEmoji-160px.ttc",
    "/System/Library/Fonts/Core/AppleSymbols.ttf",
];

#[cfg(target_os = "android")]
const FONT_FILES: &[&str] =
    &["/system/fonts/Roboto-Regular.ttf", "/system/fonts/DroidSansMono.ttf", "/system/fonts/NotoColorEmoji.ttf"];

#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios", target_os = "android")))]
const FONT_FILES: &[&str] = &[];

#[cfg(any(target_os = "macos", target_os = "ios"))]
const FAMILIES: (&str, &str) = ("Helvetica Neue", "Menlo");
#[cfg(target_os = "windows")]
const FAMILIES: (&str, &str) = ("Segoe UI", "Consolas");
#[cfg(target_os = "android")]
const FAMILIES: (&str, &str) = ("Roboto", "Droid Sans Mono");
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios", target_os = "android")))]
const FAMILIES: (&str, &str) = ("DejaVu Sans", "DejaVu Sans Mono");

/// Ruta de un archivo del sistema. En el simulador de iOS las fuentes están dentro del runtime simulado
/// (`IPHONE_SIMULATOR_ROOT`), no en la raíz del Mac; en un iPhone real la ruta es la de siempre.
pub(crate) fn system_path(path: &str) -> PathBuf {
    #[cfg(windows)]
    {
        let windir = std::env::var_os("WINDIR").map_or_else(|| PathBuf::from("C:\\Windows"), PathBuf::from);
        return windir.join("Fonts").join(path);
    }
    #[cfg(not(windows))]
    match std::env::var_os("IPHONE_SIMULATOR_ROOT") {
        Some(root) if cfg!(target_os = "ios") => std::path::Path::new(&root).join(path.trim_start_matches('/')),
        _ => PathBuf::from(path),
    }
}

pub fn build_font_system() -> FontSystem {
    let mut database = fontdb::Database::new();
    for path in FONT_FILES {
        if let Err(error) = database.load_font_file(system_path(path)) {
            eprintln!("no se pudo cargar la fuente {path}: {error}");
        }
    }
    if database.is_empty() {
        database.load_system_fonts();
    }
    database.set_sans_serif_family(FAMILIES.0);
    database.set_monospace_family(FAMILIES.1);
    FontSystem::new_with_locale_and_db("en-US".to_owned(), database)
}