metrics

    Deterministic font metrics and text measurement for MoonBit

    metrics
    font
    text
    measure
    Download zip
    Author
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    10 days ago
    Downloads
    16K

    kokic/metrics does not have a README file

    FontMetrics

    pub struct FontMetrics {
    profile : FontProfile
    style : FontStyle
    font_size : Int
    font_weight : Int
    line_height : Int
    ascent : Int
    descent : Int
    line_gap : Int
    letter_spacing : Int
    word_spacing : Int
    tab_size : Int
    kerning_scale : Int
    font_stretch : Int
    italic_width_scale : Int
    italic_overhang : Int
    width_scale : Int
    uppercase_width_scale : Int
    lowercase_width_scale : Int
    digit_width_scale : Int
    punctuation_width_scale : Int
    wide_width_scale : Int
    emoji_width_scale : Int
    bold_width_scale : Int
    space_width : Int
    narrow_width : Int
    normal_width : Int
    wide_width : Int
    uppercase_width : Int
    digit_width : Int
    cjk_width : Int
    emoji_width : Int
    } derive(Eq,
    Debug
    )

    Configurable, deterministic font metrics for SVG layout.

    Glyph advances are accumulated internally at 1/1000px precision. The public width fields are rounded pixel summaries retained for callers that inspect individual character classes.

    FontMetrics::char_width

    fn FontMetrics::char_width(self : FontMetrics, char : Char) -> Int

    FontMetrics::default

    fn FontMetrics::default() -> FontMetrics

    FontMetrics::equal

    fn FontMetrics::equal(FontMetrics, FontMetrics) -> Bool

    FontMetrics::from_defaults

    fn FontMetrics::from_defaults(profile? : FontProfile, style? : FontStyle, font_size? : Int, font_weight? : Int, line_height? : Int, ascent? : Int, descent? : Int, line_gap? : Int, width_scale? : Int, uppercase_width_scale? : Int, lowercase_width_scale? : Int, digit_width_scale? : Int, punctuation_width_scale? : Int, wide_width_scale? : Int, emoji_width_scale? : Int, font_stretch? : Int, bold_width_scale? : Int, italic_width_scale? : Int, italic_overhang? : Int, kerning_scale? : Int, letter_spacing? : Int, word_spacing? : Int, tab_size? : Int) -> FontMetrics

    Creates deterministic metrics from one of the built-in profiles. Percentage parameters use 100 as their neutral value.

    FontMetrics::measure

    fn FontMetrics::measure(self : FontMetrics, text : String) -> TextMetrics

    Measure text with this font profile.

    FontMetrics::not_equal

    fn FontMetrics::not_equal(x : FontMetrics, y : FontMetrics) -> Bool

    FontMetrics::with_face

    fn FontMetrics::with_face(self : FontMetrics, weight : Int, style : FontStyle) -> FontMetrics

    Change an inline face while retaining size, spacing, and width calibration. Verified 2026-09-16: calibrated measurement matches an equivalent configured font; restoring the original face retains every metric. Temporary tests removed.

    FontMetrics::with_profile

    fn FontMetrics::with_profile(self : FontMetrics, profile : FontProfile) -> FontMetrics

    Switch the glyph profile without changing the caller's face or calibration.

    FontMetrics::with_size

    fn FontMetrics::with_size(self : FontMetrics, size : Int) -> FontMetrics

    Resize an inline font while retaining face, spacing, and glyph calibration. Keep the configured leading relative to size and recompute glyph summaries. Zero size resets vertical metrics. Verified 2026-09-16: positive resizing matches an equivalently configured font; zero-size text has no glyph extent. Temporary property tests removed after verification.

    FontProfile

    pub(all) enum FontProfile {
    Sans
    Serif
    Monospace
    } derive(Eq,
    Debug
    )

    Coarse built-in width profiles for deterministic cross-platform layout.

    FontProfile::equal

    fn FontProfile::equal(FontProfile, FontProfile) -> Bool

    FontProfile::not_equal

    fn FontProfile::not_equal(x : FontProfile, y : FontProfile) -> Bool

    FontStyle

    pub(all) enum FontStyle {
    Normal
    Italic
    } derive(Eq,
    Debug
    )

    FontStyle::equal

    fn FontStyle::equal(FontStyle, FontStyle) -> Bool

    FontStyle::not_equal

    fn FontStyle::not_equal(x : FontStyle, y : FontStyle) -> Bool

    TextMetrics

    pub struct TextMetrics {
    width : Int
    advance_width : Int
    height : Int
    ascent : Int
    descent : Int
    baseline : Int
    ink_left : Int
    ink_right : Int
    } derive(Eq,
    Debug
    )

    Portable text measurement used by the built-in SVG renderers.

    TextMetrics::equal

    fn TextMetrics::equal(TextMetrics, TextMetrics) -> Bool

    TextMetrics::not_equal

    fn TextMetrics::not_equal(x : TextMetrics, y : TextMetrics) -> Bool

    TextMetrics::with_extra_advance

    fn TextMetrics::with_extra_advance(self : TextMetrics, extra : Int) -> TextMetrics

    A copy whose advance is widened by extra pixels, for renderers that compensate the built-in width table (e.g. the mindmap's space advance).

    MONO_DIGIT_BASE_WIDTH

    let MONO_DIGIT_BASE_WIDTH : Float

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io