Sign in

    Milky2018/moon_swash/shape does not have a README file

    CharCluster

    Character cluster; output from the parser and input to the shaper.

    ClusterChar

    Character output from the cluster parser.

    ClusterInfo

    Information about a cluster including content properties and boundary analysis.

    Epoch

    type Epoch = UInt64

    Shaping caches (font metadata + feature store).

    Ported from upstream swash/src/shape/cache.rs.

    FeatureBit

    type FeatureBit = UInt16

    OpenType GSUB/GPOS shaping (AT).

    Ported from upstream swash/src/shape/at.rs.

    GlyphId

    type GlyphId = UInt16

    JoiningType

    ShapeClass

    Shaping class of a character.

    SourceRange

    Source range of a cluster in code units.

    Tag

    type Tag = UInt

    Mapping complex text to a sequence of positioned glyphs.

    This package is a strict port of upstream swash/src/shape/*.

    UserData

    type UserData = UInt

    Selector

    pub(open) trait Selector {
    fn select_font(Self, cluster :
    CharCluster
    ) -> SelectedFont?
    }

    Trait for types that can select appropriate fonts for character clusters.

    ShapeOptions

    pub(open) trait ShapeOptions {
    fn script(Self) ->
    Script

    fn language(Self) ->
    Language
    ?
    fn direction(Self) -> Direction
    fn size(Self) -> Double
    fn features(Self) -> Iter[
    Setting
    [UInt16]]
    fn variations(Self) -> Iter[
    Setting
    [Double]]
    fn insert_dotted_circles(Self) -> Bool
    }

    Trait for types that specify shaping options.

    Buffer

    pub struct Buffer {
    glyphs : Array[GlyphData]
    positions : Array[PositionData]
    infos : Array[(
    ClusterInfo
    , Bool, UInt)]
    ranges : Array[
    SourceRange
    ]
    shaped_glyphs : Array[Glyph]
    is_rtl : Bool
    dotted_circle : UInt16?
    has_cursive : Bool
    has_marks : Bool
    reversed : Bool
    next_cluster : UInt
    skip_state : SkipState
    sub_args : Array[UInt16]
    pos_args : Array[UInt16]
    }

    Buffer::Buffer

    fn Buffer::Buffer() -> Buffer

    Buffer::_push_hangul

    Buffer::clear

    fn Buffer::clear(self : Buffer) -> Unit

    Buffer::clear_flags

    fn Buffer::clear_flags(self : Buffer, flags : UInt16, range : IndexRange?) -> Unit

    Buffer::default

    fn Buffer::default() -> Buffer

    Buffer::ensure_order

    fn Buffer::ensure_order(self : Buffer, reversed : Bool) -> Unit

    Buffer::glyphs

    fn Buffer::glyphs(self : Buffer) -> ArrayView[GlyphData]

    Buffer::len

    fn Buffer::len(self : Buffer) -> Int

    Buffer::multiply

    fn Buffer::multiply(self : Buffer, index : Int, count : Int) -> Unit

    Buffer::position

    fn Buffer::position(self : Buffer, index : Int, x : Double, y : Double, xadvance : Double, _yadvance : Double) -> Unit

    Buffer::position_cursive

    fn Buffer::position_cursive(self : Buffer, index : Int, next : Int, _x : Double, y : Double) -> Unit

    Buffer::position_mark

    fn Buffer::position_mark(self : Buffer, index : Int, base : Int, dx : Double, dy : Double) -> Unit

    Buffer::positions

    fn Buffer::positions(self : Buffer) -> ArrayView[PositionData]

    Buffer::push_order

    fn Buffer::push_order(self : Buffer, cluster :
    CharCluster
    , order : ArrayView[Int]) -> IndexRange

    Buffer::set_join_masks

    fn Buffer::set_join_masks(self : Buffer) -> Unit

    Buffer::setup_positions

    fn Buffer::setup_positions(self : Buffer, was_morx : Bool) -> Unit

    Buffer::substitute

    fn Buffer::substitute(self : Buffer, index : Int, id : UInt16) -> Unit

    Buffer::substitute_ligature

    fn Buffer::substitute_ligature(self : Buffer, index : Int, id : UInt16, components : ArrayView[Int]) -> Unit

    Buffer::substitute_multiple

    fn Buffer::substitute_multiple(self : Buffer, index : Int, ids : ArrayView[UInt16]) -> Unit

    ContextState

    type ContextState

    CoverageBuilder

    type CoverageBuilder

    Builds a compact coverage cache used to cheaply skip lookups.

    Format matches upstream swash/src/shape/at.rs: [min, max, bitset words (u16)], keyed by base index into FeatureStore.coverage.

    Direction

    pub(all) enum Direction {
    LeftToRight
    RightToLeft
    }

    Text direction.
    impl Eq for Direction

    Direction::equal

    fn Direction::equal(self : Direction, other : Direction) -> Bool

    Direction::not_equal

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

    Engine

    pub struct Engine {
    data : Bytes
    gdef :
    Gdef

    gsub : StageOffsets
    gpos : StageOffsets
    morx : UInt
    kerx : UInt
    ankr : UInt
    kern : UInt
    storage : Storage
    coords : ArrayView[Int]
    script :
    Script

    tags : (UInt, UInt, UInt, UInt)
    sub_mode : SubMode
    pos_mode : PosMode
    use_ot : Bool
    mode : EngineMode
    }

    Engine::Engine

    fn Engine::Engine(metadata : EngineMetadata, font_data : Bytes, coords : ArrayView[Int], script :
    Script
    , language :
    Language
    ?) -> Engine

    Engine::collect_features

    fn Engine::collect_features(self : Engine, builder : FeatureStoreBuilder, store :
    Ref
    [FeatureStore]) -> Unit

    Builds a feature store for the current engine configuration.

    Engine::collect_selectors

    fn Engine::collect_selectors(self : Engine, features : ArrayView[
    Setting
    [UInt16]], selectors : Array[(UInt16, UInt16)]) -> Unit

    Converts feature settings into a sorted collection of AAT selectors.

    Engine::gpos

    fn Engine::gpos(self : Engine, store : FeatureStore, feature_mask : FeatureMask, buffer : Buffer, buffer_range : IndexRange?) -> Bool

    Applies the GPOS features to the specified range of the buffer.

    Engine::gsub

    fn Engine::gsub(self : Engine, store : FeatureStore, feature_mask : FeatureMask, buffer : Buffer, buffer_range : IndexRange?) -> Bool

    Applies the GSUB features to the specified range of the buffer.

    Engine::has_feature_vars

    fn Engine::has_feature_vars(self : Engine) -> Bool

    Returns true if feature variations are supported.

    Engine::kern

    fn Engine::kern(self : Engine, buffer : Buffer) -> Unit

    Applies the kerning table.

    Engine::kerx

    fn Engine::kerx(self : Engine, buffer : Buffer, disable_kern : Bool) -> Unit

    Applies the extended kerning table.

    Engine::morx

    fn Engine::morx(self : Engine, buffer : Buffer, selectors : ArrayView[(UInt16, UInt16)]) -> Unit

    Applies the extended metamorphosis table.

    Engine::set_classes

    fn Engine::set_classes(self : Engine, buffer : Buffer, range : IndexRange?) -> Unit

    Sets glyph and mark classes for the specified range of the buffer.

    Engine::tags

    fn Engine::tags(self : Engine) -> (UInt, UInt, UInt, UInt)

    OpenType shaping.

    EngineMetadata

    pub struct EngineMetadata {
    gdef : UInt
    gsub : UInt
    gpos : UInt
    morx : UInt
    kerx : UInt
    ankr : UInt
    kern : UInt
    sub_mode : SubMode
    pos_mode : PosMode
    }

    Metadata for creating a shaping engine.

    EngineMetadata::from_font

    EngineMode

    pub(all) enum EngineMode {
    Simple
    Myanmar
    Complex
    }

    impl Eq for EngineMode

    EngineMode::equal

    fn EngineMode::equal(self : EngineMode, other : EngineMode) -> Bool

    EngineMode::not_equal

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

    FeatureGroups

    pub struct FeatureGroups {
    default : FeatureMask
    reph : UInt16?
    pref : UInt16?
    stage1 : FeatureMask
    stage2 : FeatureMask
    basic : FeatureMask
    position : FeatureMask
    vert : FeatureMask
    rtl : FeatureMask
    }

    Masks or bits for specific feature groups.

    FeatureGroups::default

    fn FeatureGroups::default() -> FeatureGroups

    FeatureMask

    pub struct FeatureMask {
    b0 : UInt64
    b1 : UInt64
    b2 : UInt64
    b3 : UInt64
    }

    Feature mask: up to 256 feature bits packed into 4x u64 words.

    FeatureMask::clear

    fn FeatureMask::clear(self : FeatureMask, bit : UInt16) -> Unit

    FeatureMask::default

    fn FeatureMask::default() -> FeatureMask

    FeatureMask::has

    fn FeatureMask::has(self : FeatureMask, bit : UInt16) -> Bool

    FeatureMask::is_empty

    fn FeatureMask::is_empty(self : FeatureMask) -> Bool

    FeatureMask::or

    fn FeatureMask::or(self : FeatureMask, other : FeatureMask) -> FeatureMask

    Returns the union of two masks.

    FeatureMask::or_assign

    fn FeatureMask::or_assign(self : FeatureMask, other : FeatureMask) -> Unit

    Mutating OR assignment.

    FeatureMask::set

    fn FeatureMask::set(self : FeatureMask, bit : UInt16) -> Unit

    FeatureStore

    pub struct FeatureStore {
    sub_features : Array[(UInt, UInt16)]
    pos_features : Array[(UInt, UInt16)]
    lookups : Array[
    LookupData
    ]
    subtables : Array[
    SubtableData
    ]
    coverage : Array[UInt16]
    pos_start : Int
    sub_count : Int
    truncated : Bool
    groups : FeatureGroups
    }

    Cache of features, lookups and subtables for a particular script/language pair.

    Only the feature-group plumbing is ported in this step; lookup application is implemented as part of the AT shaper task.

    FeatureStore::clear

    fn FeatureStore::clear(self : FeatureStore) -> Unit

    FeatureStore::custom_masks

    fn FeatureStore::custom_masks(self : FeatureStore, features : ArrayView[
    Setting
    [UInt16]], sub_args : Array[UInt16], pos_args : Array[UInt16], dir : Direction) -> (FeatureMask, FeatureMask)

    Returns new basic and position masks based on the specified custom features.

    FeatureStore::default

    fn FeatureStore::default() -> FeatureStore

    FeatureStore::groups

    Computes feature groups for a script based on available features.

    FeatureStore::pos_bit

    fn FeatureStore::pos_bit(self : FeatureStore, feature : UInt) -> UInt16?

    FeatureStore::sub_bit

    fn FeatureStore::sub_bit(self : FeatureStore, feature : UInt) -> UInt16?

    FeatureStoreBuilder

    pub struct FeatureStoreBuilder {
    indices : Array[(UInt16, UInt16, Byte)]
    coverage : CoverageBuilder
    next_bit : UInt16
    }

    Builder for a feature cache.

    FeatureStoreBuilder::build

    FeatureStoreBuilder::default

    FontEntry

    pub struct FontEntry {
    metrics :
    MetricsProxy

    charmap :
    CharmapProxy

    coord_count : UInt16
    metadata : EngineMetadata
    }

    FontEntry::FontEntry

    Glyph

    pub struct Glyph {
    id : UInt16
    info : GlyphInfo
    x : Double
    y : Double
    advance : Double
    data : UInt
    }

    Glyph identifier and positioning information as a result of shaping.

    Glyph::advance

    fn Glyph::advance(self : Glyph) -> Double

    Glyph::data

    fn Glyph::data(self : Glyph) -> UInt

    Glyph::default

    fn Glyph::default() -> Glyph

    Glyph::id

    fn Glyph::id(self : Glyph) -> UInt16

    Glyph::info

    fn Glyph::info(self : Glyph) -> GlyphInfo

    Glyph::x

    fn Glyph::x(self : Glyph) -> Double

    Glyph::y

    fn Glyph::y(self : Glyph) -> Double

    GlyphCluster

    Collection of glyphs and associated metadata corresponding to one or more source clusters.

    GlyphCluster::advance

    fn GlyphCluster::advance(self : GlyphCluster) -> Double

    Computes the full advance width or height of the cluster.

    GlyphCluster::data

    fn GlyphCluster::data(self : GlyphCluster) -> UInt

    GlyphCluster::glyphs

    fn GlyphCluster::glyphs(self : GlyphCluster) -> ArrayView[Glyph]

    GlyphCluster::is_complex

    fn GlyphCluster::is_complex(self : GlyphCluster) -> Bool

    Returns true if the cluster is complex-- that is if it contains more than one glyph. This will be true for clusters containing marks and is also commonly true for syllabic languages such as those in the Indic family.

    GlyphCluster::is_empty

    fn GlyphCluster::is_empty(self : GlyphCluster) -> Bool

    Returns true if the cluster is empty. Empty clusters still represent characters in the source text, but contain no glyphs. This will be true, for example, with newline sequences (\n or \r\n) as well as other control characters.

    GlyphCluster::is_ligature

    fn GlyphCluster::is_ligature(self : GlyphCluster) -> Bool

    Returns true if the cluster corresponds to multiple source clusters. Note that a ligature cluster can also be complex.

    GlyphCluster::is_simple

    fn GlyphCluster::is_simple(self : GlyphCluster) -> Bool

    Returns true if the cluster contains a single glyph. Note that a simple cluster can also be a ligature.

    GlyphData

    pub struct GlyphData {
    id : UInt16
    flags : UInt16
    class : Byte
    char_class :
    ShapeClass

    mark_type : Byte
    joining_type : Byte
    mask : Byte
    skip : Bool
    component : Byte
    cluster : UInt
    data : UInt
    }

    Per glyph shaping data.

    GlyphData::cluster

    fn GlyphData::cluster(self : GlyphData) -> UInt

    GlyphData::default

    fn GlyphData::default() -> GlyphData

    GlyphData::flags

    fn GlyphData::flags(self : GlyphData) -> UInt16

    GlyphData::id

    fn GlyphData::id(self : GlyphData) -> UInt16

    GlyphData::is_component

    fn GlyphData::is_component(self : GlyphData) -> Bool

    GlyphInfo

    pub struct GlyphInfo {
    bits : UInt16
    }

    Information for a glyph.

    GlyphInfo::GlyphInfo

    fn GlyphInfo::GlyphInfo(bits : UInt16) -> GlyphInfo

    GlyphInfo::default

    fn GlyphInfo::default() -> GlyphInfo

    GlyphInfo::is_mark

    fn GlyphInfo::is_mark(self : GlyphInfo) -> Bool

    Returns true if the glyph is an attached mark.

    IndexRange

    pub struct IndexRange {
    start : Int
    end : Int
    }

    IndexRange::IndexRange

    fn IndexRange::IndexRange(start : Int, end : Int) -> IndexRange

    IndexRange::end

    fn IndexRange::end(self : IndexRange) -> Int

    IndexRange::start

    fn IndexRange::start(self : IndexRange) -> Int

    LookupState

    type LookupState

    Lookup cursor state for nested lookups.

    PosMode

    pub(all) enum PosMode {
    None
    Gpos
    Kerx
    Kern
    }

    impl Eq for PosMode

    PosMode::equal

    fn PosMode::equal(self : PosMode, other : PosMode) -> Bool

    PosMode::not_equal

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

    PositionData

    pub struct PositionData {
    base : Byte
    flags : UInt16
    x : Double
    y : Double
    advance : Double
    }

    Per glyph shaping position data.

    PositionData::default

    fn PositionData::default() -> PositionData

    SelectedFont

    pub struct SelectedFont {
    font :
    FontRef

    id_override : (UInt64, UInt64)?
    synthesis :
    Synthesis
    ?
    }

    Font selected for a cluster.

    Note: upstream uses a trait with an associated type returned by the selector. MoonBit traits do not support associated types, so we use a concrete carrier struct for the selected font.

    SelectedFont::SelectedFont

    Creates a selected font wrapper.

    SelectedFont::font

    Returns the underlying font.

    SelectedFont::id_override

    fn SelectedFont::id_override(self : SelectedFont) -> (UInt64, UInt64)?

    Returns an optional override for cache identifier (id0, id1).

    SelectedFont::synthesis

    Returns an optional synthesis state for the font.

    SelectedFont::with_id_override

    fn SelectedFont::with_id_override(self : SelectedFont, id : (UInt64, UInt64)) -> SelectedFont

    Returns a copy with an explicit cache id override.

    SelectedFont::with_synthesis

    Returns a copy with a synthesis state attached.

    ShapeContext

    pub struct ShapeContext {
    inner :
    Ref
    [ContextState]
    }

    Context that manages transient buffers for shaping.

    This is intentionally minimal for ro7.1: caches and engines are introduced in later shaping tasks.

    ShapeContext::ShapeContext

    fn ShapeContext::ShapeContext() -> ShapeContext

    Creates a new shaping context.

    ShapeContext::builder

    Creates a new builder for constructing a shaper with this context.

    ShapeContext::builder_with_id

    fn ShapeContext::builder_with_id(self : ShapeContext, font :
    FontRef
    , id : (UInt64, UInt64)) -> ShaperBuilder

    Creates a new builder for constructing a shaper with this context.

    ShapeContext::with_max_entries

    fn ShapeContext::with_max_entries(max_entries : Int) -> ShapeContext

    Creates a new shaping context with the specified maximum number of cache entries.

    Shaper

    pub struct Shaper {
    cx :
    Ref
    [ContextState]
    font :
    FontRef

    id0 : UInt64
    id1 : UInt64
    font_entry :
    Ref
    [FontEntry]
    charmap :
    Charmap

    size : Double
    script :
    Script

    language :
    Language
    ?
    direction : Direction
    retain_ignorables : Bool
    joined : Bool
    engine : Engine
    store :
    Ref
    [FeatureStore]?
    sub_mask : FeatureMask
    pos_mask : FeatureMask
    }

    Maps character clusters to (eventually) positioned glyph clusters.

    In ro7.1 this shaper only collects clusters into the underlying Buffer.

    Shaper::add_cluster

    fn Shaper::add_cluster(self : Shaper, cluster :
    CharCluster
    ) -> Unit

    Adds a character cluster to the shaper.

    Shaper::add_str

    fn Shaper::add_str(self : Shaper, s : String) -> Unit

    Adds a string to the shaper.

    Shaper::metrics

    Returns the current font metrics in use by the shaper.

    Shaper::normalized_coords

    fn Shaper::normalized_coords(self : Shaper) -> ArrayView[Int]

    Returns the current normalized variation coordinates in use by the shaper.

    Shaper::shape_with

    fn Shaper::shape_with(self : Shaper, f : (GlyphCluster) -> Unit) -> Unit

    Shapes the text and invokes the specified closure with each resulting glyph cluster.

    ShaperBuilder

    pub struct ShaperBuilder {
    cx :
    Ref
    [ContextState]
    font :
    FontRef

    id0 : UInt64
    id1 : UInt64
    size : Double
    script :
    Script

    language :
    Language
    ?
    direction : Direction
    font_entry :
    Ref
    [FontEntry]
    charmap :
    Charmap

    dotted_circle : UInt16?
    retain_ignorables : Bool
    }

    Builder for configuring a shaper.

    ShaperBuilder::build

    fn ShaperBuilder::build(self : ShaperBuilder) -> Shaper

    Builds a shaper for the current configuration.

    ShaperBuilder::direction

    fn ShaperBuilder::direction(self : ShaperBuilder, direction : Direction) -> ShaperBuilder

    Specifies the text direction. The default value is Direction::LeftToRight.

    ShaperBuilder::features

    Adds feature settings to the shaper.

    ShaperBuilder::insert_dotted_circles

    fn ShaperBuilder::insert_dotted_circles(self : ShaperBuilder, yes : Bool) -> ShaperBuilder

    Specifies whether to insert dotted circles for broken clusters. The default value is false.

    ShaperBuilder::language

    Specifies the language. The default value is None.

    ShaperBuilder::retain_ignorables

    fn ShaperBuilder::retain_ignorables(self : ShaperBuilder, yes : Bool) -> ShaperBuilder

    Specifies whether characters defined as default ignorable should be retained by the shaper. The default is false.

    ShaperBuilder::script

    Specifies the script. The default value is Script::Latin.

    ShaperBuilder::size

    fn ShaperBuilder::size(self : ShaperBuilder, ppem : Double) -> ShaperBuilder

    Specifies the font size in pixels per em. The default value is 0 which will produce glyphs with offsets and advances in font units.

    ShaperBuilder::variations

    Adds variation settings to the shaper.

    SimpleShapeOptions

    pub struct SimpleShapeOptions {
    script :
    Script

    language :
    Language
    ?
    direction : Direction
    size : Double
    features : Array[
    Setting
    [UInt16]]
    variations : Array[
    Setting
    [Double]]
    insert_dotted_circles : Bool
    }

    Simple implementation of the shape options trait.

    SimpleShapeOptions::default

    SimpleShapeOptions::direction

    SimpleShapeOptions::features

    SimpleShapeOptions::insert_dotted_circles

    fn SimpleShapeOptions::insert_dotted_circles(self : SimpleShapeOptions) -> Bool

    SimpleShapeOptions::language

    SimpleShapeOptions::script

    SimpleShapeOptions::size

    fn SimpleShapeOptions::size(self : SimpleShapeOptions) -> Double

    SimpleShapeOptions::variations

    SkipState

    pub struct SkipState {
    flags : Byte
    mask : Byte
    mark_check : Byte
    mark_class : Byte
    mark_set : UInt
    }

    SkipState::default

    fn SkipState::default() -> SkipState

    StageOffsets

    pub struct StageOffsets {
    base : UInt
    lang : UInt
    vars : UInt
    }

    Offsets for a particular layout stage.

    StageOffsets::default

    fn StageOffsets::default() -> StageOffsets

    StageOffsets::from_layout

    fn StageOffsets::from_layout(data : Bytes, base : UInt, script : UInt, language : UInt?) -> (StageOffsets, (UInt, UInt))?

    Storage

    pub struct Storage {
    stack : Array[LookupState]
    ids : Array[UInt16]
    indices : Array[Int]
    }

    Scratch storage used by the OT lookup application engine.

    Storage::default

    fn Storage::default() -> Storage

    SubMode

    pub(all) enum SubMode {
    None
    Gsub
    Morx
    }

    impl Eq for SubMode

    SubMode::equal

    fn SubMode::equal(self : SubMode, other : SubMode) -> Bool

    SubMode::not_equal

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

    COMPONENT

    let COMPONENT : UInt16

    CURSIVE_ATTACH

    let CURSIVE_ATTACH : UInt16

    IGNORABLE

    let IGNORABLE : UInt16

    LIGATED

    let LIGATED : UInt16

    MARK_ATTACH

    let MARK_ATTACH : UInt16

    MAX_CLUSTER_SIZE

    let MAX_CLUSTER_SIZE : Int

    SUBSTITUTED

    let SUBSTITUTED : UInt16

    Glyph flags.

    apply

    fn apply(stage : Byte, data : Bytes, base : UInt, coords : ArrayView[Int], gdef :
    Gdef
    , storage : Storage, store : FeatureStore, feature_mask : FeatureMask, buffer : Buffer, buffer_range : IndexRange?) -> Bool?

    Applies lookups for either substitutions (stage=0) or positioning (stage=1).

    This is ported from upstream swash/src/shape/at.rs (apply) and is completed as part of ro7.2.3.

    apply_kern

    fn apply_kern(data : Bytes, kern : UInt, buffer : Buffer) -> Unit

    apply_kerx

    fn apply_kerx(data : Bytes, kerx : UInt, ankr : UInt, buffer : Buffer, disable_kern : Bool) -> Unit

    apply_morx

    fn apply_morx(data : Bytes, morx : UInt, buffer : Buffer, selectors : ArrayView[(UInt16, UInt16)]) -> Unit

    feature_bit_to_mask

    fn feature_bit_to_mask(bit : UInt16?) -> FeatureMask

    reorder_complex

    fn reorder_complex(glyphs : Array[GlyphData], buf : Array[GlyphData], order : Array[Int]) -> Unit

    reorder_myanmar

    fn reorder_myanmar(chars : ArrayView[
    ClusterChar
    ], order : Array[Int]) -> Unit

    shape

    fn[S : Selector, O : ShapeOptions] shape(context : ShapeContext, selector : S, options : O, tokens : Iter[
    Token
    ], f : (SelectedFont, Shaper) -> Unit) -> Unit

    Shapes a run of text (provided as a Token iterator) using the specified selector to assign per-cluster fonts.