docxcraft 0.1.0

Generate editable DOCX documents with rich text, tables, charts and SVG drawings
Documentation
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 ALGFORCE INC.

#![doc = include_str!("../README.md")]

pub mod chart;
pub mod document;
pub mod editable_svg;
pub mod html_paragraph;
pub mod image;
pub mod markdown;
pub mod paragraph;
pub mod table;

/// 根据 locale 获取推荐的默认字体
///
/// # 参数
/// - locale: 语言代码(如 "zh", "en", "ja" 等)
///
/// # 返回
/// 对应语言的推荐字体名称
pub(crate) fn get_font_for_locale(locale: &str) -> String {
    match locale.to_lowercase().as_str() {
        // 中文(简体)
        "zh" | "zh-cn" | "zh-hans" | "zh-sg" => "Microsoft YaHei UI".to_string(),

        // 中文(繁体)
        "zh-tw" | "zh-hk" | "zh-mo" | "zh-hant" => "Microsoft YaHei UI".to_string(),

        // 日文
        "ja" | "jp" | "ja-jp" => "MS 明朝".to_string(),

        // 韩文
        "ko" | "ko-kr" => "맑은 고딕".to_string(),

        // 阿拉伯文
        "ar" | "ar-sa" | "ar-ae" | "ar-eg" => "Arial".to_string(),

        // 英文
        "en" | "en-us" | "en-gb" | "en-au" | "en-ca" => "Verdana".to_string(),

        // 西班牙文
        "es" | "es-es" | "es-mx" | "es-ar" => "Verdana".to_string(),

        // 其他语言默认使用 Verdana(通用字体)
        _ => "Verdana".to_string(),
    }
}

/// 图表轴、图例及数据标签字号(hundredths of a point)。
/// 统一为 9pt,对应前端 12px 的可读性基准。
pub(crate) fn get_chart_label_font_size(_locale: &str) -> u32 {
    900
}

/// 根据 locale 获取图表推荐字体(使用 Light 变体)
pub(crate) fn get_chart_font_for_locale(locale: &str) -> String {
    match locale.to_lowercase().as_str() {
        // 中文(简体/繁体)
        "zh" | "zh-cn" | "zh-hans" | "zh-sg" | "zh-tw" | "zh-hk" | "zh-mo" | "zh-hant" => {
            "Microsoft YaHei UI Light".to_string()
        }
        // 其他语言使用通用字体
        _ => get_font_for_locale(locale),
    }
}