moon_skrifa

    MoonBit port of Fontations skrifa (font parsing, metrics, color/bitmap glyph helpers).

    font
    opentype
    truetype
    Download zip
    Author
    Version
    0.1.10
    License
    Apache-2.0
    Last updated
    1 hour ago
    Downloads
    40K

    #Milky2018/moon_skrifa

    A MoonBit library for OpenType font reading and outline drawing.

    It provides:
    • font metadata access (cmap, names, metrics, variation axes)
    • bitmap glyph access (sbix, CBDT/EBDT)
    • color glyph paint traversal (COLR)
    • outline extraction and drawing (glyf, CFF, CFF2)

    Repository: https://github.com/moonbit-community/moon_skrifa

    #Packages

    • Milky2018/moon_skrifa: facade exports for common entry points
    • Milky2018/moon_skrifa/core: font metadata, metrics, strings, bitmap/color helpers
    • Milky2018/moon_skrifa/outline: outline extraction, pens, and SVG path helpers

    #Install

    Add dependency imports in moon.pkg:

    import { "moonbitlang/core/prelude", "moonbitlang/core/bytes", "Milky2018/moon_skrifa" @moon_skrifa, "Milky2018/moon_skrifa/outline" @moon_skrifa_outline, }

    #Quick Start

    let font = @moon_skrifa.FontRef::from_bytes(font_bytes).unwrap()
    let outlines = @moon_skrifa_outline.OutlineGlyphCollection::from_font(font)

    let cmap = font.charmap().unwrap()
    let gid = cmap.glyph_id(0x41).unwrap() // 'A'

    let settings =
    @moon_skrifa_outline.DrawSettings::unhinted(
    @moon_skrifa.Size::Size(16.0),
    @moon_skrifa.LocationRef::default(),
    )

    let svg_path = outlines.svg_path(gid, settings).unwrap()

    #Core API Guide

    #Variation Axes and Locations

    Build normalized locations from user-space axis values:

    let axes = font.axes()
    let settings : Array[@moon_skrifa.VariationSetting] = Array::from_fixed_array([
    @moon_skrifa.Setting::Setting(@moon_skrifa.Tag::from_str("wght").unwrap(), 700.0),
    ])
    let loc = axes.location(settings.op_as_view()).as_ref()

    #Character Mapping

    let cmap = font.charmap().unwrap()
    let gid = cmap.glyph_id(0x4F60).unwrap() // example codepoint

    #Localized Name Strings

    let family = font.localized_strings(@moon_skrifa.STRING_ID_FAMILY_NAME)
    match family.english_or_first() {
    None => ()
    Some(s) => {
    let lang = s.language() // Option[String]
    let value = s.to_string()
    lang |> ignore
    value |> ignore
    }
    }

    #Metrics

    let fm = font.metrics(
    @moon_skrifa.Size::Size(16.0),
    @moon_skrifa.LocationRef::default(),
    )
    let gm = font.glyph_metrics(
    @moon_skrifa.Size::unscaled(),
    @moon_skrifa.LocationRef::default(),
    )

    let aw = gm.advance_width(gid)
    let lsb = gm.left_side_bearing(gid)
    let bounds = gm.bounds(gid)

    fm |> ignore
    aw |> ignore
    lsb |> ignore
    bounds |> ignore

    #Bitmap Glyphs

    let strikes = font.bitmap_strikes()
    for i in 0..<strikes.len() {
    let strike = strikes.get(i).unwrap()
    let bmp = strike.get(gid)
    bmp |> ignore
    }

    #Color Paint Traversal (COLR)

    Implement ColorPainter, then call:

    let loc = @moon_skrifa.LocationRef::default()
    try! font.paint_colr_v1_at(gid, loc, painter) |> ignore

    #Outline API Guide

    #Unhinted Draw

    let settings =
    @moon_skrifa_outline.DrawSettings::unhinted(
    @moon_skrifa.Size::Size(16.0),
    @moon_skrifa.LocationRef::default(),
    )
    let path = outlines.path(gid, settings)
    path |> ignore

    #Hinted Draw

    let hinter =
    @moon_skrifa_outline.HintingInstance::create(
    outlines,
    @moon_skrifa.Size::Size(16.0),
    @moon_skrifa.LocationRef::default(),
    @moon_skrifa_outline.HintingOptions::default(),
    ).unwrap()

    let settings = @moon_skrifa_outline.DrawSettings::hinted(hinter, false)
    let svg = outlines.svg_path(gid, settings)
    svg |> ignore

    #Path Styles

    DrawSettings supports:
    • PathStyle::FreeType
    • PathStyle::HarfBuzz

    Set with:

    let settings =
    @moon_skrifa_outline.DrawSettings::unhinted(
    @moon_skrifa.Size::Size(16.0),
    @moon_skrifa.LocationRef::default(),
    ).with_path_style(@moon_skrifa_outline.PathStyle::HarfBuzz)
    settings |> ignore

    #Development

    • moon check
    • moon test
    • moon fmt
    • moon info

    Attributes

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Axis

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    AxisCollection

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    BitmapFormat

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    BitmapGlyph

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    BitmapImageFormat

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    BitmapStrike

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    BitmapStrikes

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Brush

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Charmap

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Color

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorGlyph

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorGlyphCollection

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorGlyphFormat

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorLayer

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorPainter

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorPalette

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorPaletteType

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorPalettes

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    ColorStop

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    CompositeMode

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Decoration

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Extend

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    FontRef

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    GlyphBounds

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    GlyphId

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    GlyphMetrics

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    GlyphName

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    GlyphNameSource

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    GlyphNames

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    HmtxMetrics

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    LocalizedString

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    LocalizedStrings

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Location

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    LocationRef

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    MapVariant

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    MappingIndex

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Metrics

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    NamedInstance

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    NamedInstanceCollection

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    NormalizedCoord

    type NormalizedCoord = Int

    Instance-related types.

    Ported from fontations/skrifa (Apache-2.0 OR MIT).

    OutlineGlyph

    Re-export common outline types from Milky2018/moon_skrifa/outline.

    OutlineGlyphCollection

    Re-export common outline types from Milky2018/moon_skrifa/outline.

    PaintCachedColorGlyph

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    PaintError

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Setting

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Size

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Stretch

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    StringId

    type StringId = UInt16

    OpenType name identifier (NameID).

    This is a UInt16 in the OpenType spec.

    Style

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    TableProvider

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Tag

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    Transform

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    VariationSetting

    type VariationSetting =
    Setting
    [Double]

    Definitions for specifying variations and typographic features.

    Ported from fontations/skrifa/src/setting.rs (Apache-2.0 OR MIT).

    Weight

    Re-export the main skrifa APIs from Milky2018/moon_skrifa/core.

    MetadataProvider

    Facade for types that can provide font metadata.

    Ported from fontations/skrifa/src/provider.rs (Apache-2.0 OR MIT).

    STRING_ID_COMPATIBLE_FULL_NAME

    let STRING_ID_COMPATIBLE_FULL_NAME : UInt16

    Compatible full name (Macintosh only).
    let STRING_ID_COPYRIGHT_NOTICE : UInt16

    Copyright notice.

    STRING_ID_DARK_BACKGROUND_PALETTE

    let STRING_ID_DARK_BACKGROUND_PALETTE : UInt16

    Dark background palette label.

    STRING_ID_DESCRIPTION

    let STRING_ID_DESCRIPTION : UInt16

    Description.

    STRING_ID_DESIGNER

    let STRING_ID_DESIGNER : UInt16

    Designer name.

    STRING_ID_DESIGNER_URL

    let STRING_ID_DESIGNER_URL : UInt16

    Designer URL.

    STRING_ID_FAMILY_NAME

    let STRING_ID_FAMILY_NAME : UInt16

    STRING_ID_FULL_NAME

    let STRING_ID_FULL_NAME : UInt16

    Full font name.

    STRING_ID_LAST_ALLOWED_NAME_ID

    let STRING_ID_LAST_ALLOWED_NAME_ID : UInt16

    The last value that is available for font-specific names.

    STRING_ID_LAST_RESERVED_NAME_ID

    let STRING_ID_LAST_RESERVED_NAME_ID : UInt16

    The last value that is explicitly reserved for standard names.

    STRING_ID_LICENSE_DESCRIPTION

    let STRING_ID_LICENSE_DESCRIPTION : UInt16

    License description.

    STRING_ID_LICENSE_URL

    let STRING_ID_LICENSE_URL : UInt16

    License URL.

    STRING_ID_LIGHT_BACKGROUND_PALETTE

    let STRING_ID_LIGHT_BACKGROUND_PALETTE : UInt16

    Light background palette label.

    STRING_ID_MANUFACTURER

    let STRING_ID_MANUFACTURER : UInt16

    Manufacturer name.

    STRING_ID_POSTSCRIPT_CID_NAME

    let STRING_ID_POSTSCRIPT_CID_NAME : UInt16

    PostScript CID findfont name.

    STRING_ID_POSTSCRIPT_NAME

    let STRING_ID_POSTSCRIPT_NAME : UInt16

    PostScript name.

    STRING_ID_SAMPLE_TEXT

    let STRING_ID_SAMPLE_TEXT : UInt16

    Sample text.

    STRING_ID_SUBFAMILY_NAME

    let STRING_ID_SUBFAMILY_NAME : UInt16

    STRING_ID_TRADEMARK

    let STRING_ID_TRADEMARK : UInt16

    Trademark.

    STRING_ID_TYPOGRAPHIC_FAMILY_NAME

    let STRING_ID_TYPOGRAPHIC_FAMILY_NAME : UInt16

    Typographic family name.

    STRING_ID_TYPOGRAPHIC_SUBFAMILY_NAME

    let STRING_ID_TYPOGRAPHIC_SUBFAMILY_NAME : UInt16

    Typographic subfamily name.

    STRING_ID_UNIQUE_ID

    let STRING_ID_UNIQUE_ID : UInt16

    Unique font identifier.

    STRING_ID_VARIATIONS_POSTSCRIPT_NAME_PREFIX

    let STRING_ID_VARIATIONS_POSTSCRIPT_NAME_PREFIX : UInt16

    Variations PostScript name prefix.

    STRING_ID_VENDOR_URL

    let STRING_ID_VENDOR_URL : UInt16

    Vendor URL.

    STRING_ID_VERSION_STRING

    let STRING_ID_VERSION_STRING : UInt16

    Version string.

    STRING_ID_WWS_FAMILY_NAME

    let STRING_ID_WWS_FAMILY_NAME : UInt16

    WWS family name.

    STRING_ID_WWS_SUBFAMILY_NAME

    let STRING_ID_WWS_SUBFAMILY_NAME : UInt16

    WWS subfamily name.

    string_id_checked_add

    fn string_id_checked_add(id : UInt16, rhs : UInt16) -> UInt16?

    string_id_is_reserved

    fn string_id_is_reserved(id : UInt16) -> Bool

    string_id_predefined

    fn string_id_predefined() -> Array[UInt16]

    Returns the set of predefined name identifiers according to the OpenType spec.

    This matches fontations/font-types::NameId::predefined(): IDs 0..15 and 16..=25 (note: ID 15 is not assigned).

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io