bobzhang/p5/font does not have a README file

    FontError

    pub suberror FontError {
    FontError(String)
    } derive(
    Debug
    )

    Errors in font files.
    impl Show for FontError

    BezierPath

    pub struct BezierPath {
    // private fields
    }

    A path of cubic segments with arc-length lookup.

    BezierPath::angle_at_length

    fn BezierPath::angle_at_length(self : BezierPath, length : Double) -> Double

    The tangent angle (radians) length along the path.

    BezierPath::from_commands

    fn BezierPath::from_commands(cmds : ArrayView[PathCmd], crds : ArrayView[Double]) -> BezierPath

    Builds a path from glyph-style commands and coordinates (createFromCommands). Quadratic curves become cubics; zero-length lines are skipped.

    BezierPath::new

    fn BezierPath::new(segments : Array[BezierSegment]) -> BezierPath

    BezierPath::point_at_length

    fn BezierPath::point_at_length(self : BezierPath, length : Double) -> Pt

    The point length along the path.

    BezierPath::tangent_at_length

    fn BezierPath::tangent_at_length(self : BezierPath, length : Double) -> Pt

    The unit tangent length along the path.

    BezierPath::total_length

    fn BezierPath::total_length(self : BezierPath) -> Double

    Total arc length (NaN for an empty path, as in JS).

    BezierSegment

    pub struct BezierSegment {
    a : Pt
    b : Pt
    c : Pt
    d : Pt
    // private fields
    }

    A cubic Bézier segment.

    BezierSegment::new

    fn BezierSegment::new(a : Pt, b : Pt, c : Pt, d : Pt) -> BezierSegment

    BezierSegment::point_at

    fn BezierSegment::point_at(self : BezierSegment, parameter : Double) -> Pt

    The point at parameter t (clamped to [0, 1]).

    BezierSegment::tangent_at

    fn BezierSegment::tangent_at(self : BezierSegment, parameter : Double) -> Pt

    Unit tangent at parameter t (clamped to [0, 1]).

    BezierSegment::total_length

    fn BezierSegment::total_length(self : BezierSegment) -> Double

    Approximate arc length.

    FontData

    pub struct FontData {
    units_per_em : Int
    ascender : Int
    descender : Int
    num_glyphs : Int
    cap_height : Int?
    // private fields
    }

    A parsed font (the parts p5.js uses for glyph outlines).

    FontData::advance_width

    fn FontData::advance_width(self : FontData, gid : Int) -> Int

    Advance width of a glyph, in font units.

    FontData::code_to_glyph

    fn FontData::code_to_glyph(self : FontData, code : Int) -> Int

    The glyph index for a Unicode code point (Typr's codeToGlyph).

    FontData::glyph_path

    fn FontData::glyph_path(self : FontData, gid : Int) -> GlyphPath

    The outline of glyph gid (cached).

    FontData::kerning

    fn FontData::kerning(self : FontData, g1 : Int, g2 : Int) -> Int

    Kerning between two glyphs from the kern table (font units).

    FontData::parse

    fn FontData::parse(input : Bytes) -> FontData raise FontError

    Parses a TrueType/OpenType font (the first font of a collection). WOFF 1.0 data is decompressed first; WOFF2 is not supported.

    FontData::shape

    fn FontData::shape(self : FontData, text : String) -> Array[ShapedGlyph]

    Maps a string to glyphs and advances (Typr's U.shape: cmap, hmtx advances and kern pairs).

    GlyphPath

    pub struct GlyphPath {
    cmds : Array[PathCmd]
    crds : Array[Double]
    } derive(
    Debug
    )

    A glyph outline in font units, y up: commands plus their flattened coordinates (Typr's {cmds, crds}).

    PathCmd

    pub(all) enum PathCmd {
    M
    L
    Q
    C
    Z
    } derive(Eq, Hash,
    Debug
    )

    A path command of a glyph outline.

    PathCmd::letter

    fn PathCmd::letter(self : PathCmd) -> String

    The SVG/Typr letter of a command: "M", "L", "Q", "C" or "Z".

    PathPoint

    pub(all) struct PathPoint {
    x : Double
    y : Double
    angle : Double
    } derive(
    Debug
    )

    A sampled outline point with its path angle in radians.
    pub(all) struct Pt {
    x : Double
    y : Double
    } derive(Eq,
    Debug
    )

    A 2D point.

    ShapedGlyph

    pub(all) struct ShapedGlyph {
    glyph : Int
    advance : Int
    } derive(
    Debug
    )

    A positioned glyph from shape.

    inflate

    fn inflate(data : Bytes, zlib? : Bool) -> Bytes raise FontError

    Decompresses zlib-wrapped (or raw, when zlib is false) DEFLATE data.

    path_to_points

    fn path_to_points(cmds : ArrayView[PathCmd], crds : ArrayView[Double], sample_factor? : Double, simplify_threshold? : Double) -> Array[PathPoint]

    Samples a contour like p5's pathToPoints: max(1, ceil(length *sample_factor)) points evenly spaced by arc length, then optionally simplified.

    woff_to_sfnt

    fn woff_to_sfnt(data : Bytes) -> Bytes raise FontError

    Converts WOFF (1.0) data to an sfnt font, like Typr's woffToOtf.