Skip to content

daegun 2.0.0

Latest

Choose a tag to compare

@zztaeha zztaeha released this 16 Nov 12:16

The daegun crate is the public API, over daecore, which holds daetype, daegun's font engine, the shaper
daeshaper and daemachine's math. daetype was audited end to end for this release, then the rest of the core and
the public API, the shaper and the C interface. Fonts that could hang it, crash it or make it hold gigabytes no longer
can, and a caller's axes or text can no longer grow a cache past its budget or take quadratic time. Where the engine
read one table two or more ways, it now reads it one way, so a font, its subset and its instance give the same answers.

Alongside the audits, 2.0.0 came to read fonts past 65,535 glyphs, which keep their glyphs and metrics in tables of
their own and name glyphs in 24 bits, and brought its shaping, subsetting, instancing and hinting up to date: its
shaper, TrueType interpreter and CFF hinter are written anew from the specifications, with no mode kept for older
screens.

Contents

Each area names the changes most readers will meet and, where there are others, counts the rest at its end.

  • Compatibility: what code built against 1.2.0 must change, and the answers that moved
  • Security: what an untrusted font or caller could do
  • Added: what's new
  • Fixed: what was wrong, from loading a font to the C interface
  • Performance: what got faster

Compatibility

2.0.0 changes the public API, in Rust and in C, wherever a wrong answer could only be fixed that way. Code built against
1.2.0 needs the changes below. DAEGUN_ABI_VERSION and daegun_abi_version read 2.0.0, the C ABI's own version
(Compatibility, C). The minimum Rust version is 1.99, from 1.97.1.

Rust

The Rust API was rebuilt for 2.0.0 on the rules below, so nearly every call changed shape. The renames follow them.

Units
  • Every metric, advance, offset, box and outline is in the font's own units, f64, y up and unrounded, where 1.2.0 put
    shaped advances and layout on a 1000-unit em and rounded metrics on it. A pen position is
    advance * px / units_per_em. Layout and justification take their sizes in font units too.
  • Only the calls that take a pixel size answer in pixels: prepared_outline, and hinted_outline, whose points are
    f32 pixels where HintedOutline held 26.6 fields.
Text positions
  • Every position in text is a UTF-8 byte offset, where 1.2.0 counted characters: a run's clusters, a Feature's range,
    the ranges a bidi run, a laid-out run, a line and a visual run cover (each field named bytes),
    TextLayout::truncated, line breaks, grapheme and word boundaries, script runs, a bidi paragraph's levels and visual
    order, and the offsets a WordSegmenter gives back. Each falls on a character boundary, so &text[range] slices it.
    A bidi paragraph has a level for every byte, and its visual order lists each character's first byte. caret_positions
    gives text.len() + 1 carets, every byte of a character at its leading edge.
Locations
  • A variable font's axes are resolved once, font.location(&[(Tag, f64)]), into a Location that every call depending
    on one takes by reference, where each call took axes: &[(&str, f64)] and rebuilt it. A tag the font lacks is
    ignored, a value is clamped to its axis, and the last of a tag named twice wins.
  • Location::default() is the default instance of any font. A location keeps the values it was asked for, and another
    font resolves it again from them, so wght=400 made by a font whose default it is still means 400 to one whose
    default is 250. normalized_axes is Location::normalized, and Location::coords gives the resolved coordinates.
  • math_constants, math_italics_correction, math_top_accent_attachment, math_kern, math_glyph_variants and
    cff_hints take a Location, as the BASE calls do. Each read the default alone.
Errors
  • One daegun::Error, with kind() (ErrorKind: Malformed, Unsupported, Missing, InvalidArgument,
    LimitExceeded, NoOutline, Overflow) and message(), and daegun::Result, replace FontError and QuadError.
  • A call returns Result where it can fail for a reason to act on: opening, instance, instance_tables, subsets and
    closures, outline, quads, prepared_outline, color_scene, math_kern and raw::build_font, which refuses more
    than 65,535 tables, or a table that starts 4 GiB into the file or is that long. Option means the font has none of
    something. Rust gets every reason C does.
Types
  • Tag wherever a tag goes, Tag::new(b"wght") or parsed from a string, in place of &str and [u8; 4]. A string
    parses as one to four printable ASCII characters, padded with spaces, as the specification has a tag; anything else is
    an InvalidArgument error.
  • GlyphId, a transparent u32, wherever a glyph goes, for fonts past 65,535 glyphs: a run holds 4 bytes a glyph where
    it held 2. char is a code point, so glyph_id, has_glyph, variation_glyph_id and coverage take or give
    chars.
  • Enums replace bools: Orientation for vertical, BaseDirection for Option<bool> in bidi, Adjustment for
    shrink (shape_justified's argument and Justified::adjustment) and FontStyle for a style string.
    unicode::vertical_orientation gives a character's VerticalOrientation (UAX #50's four values) where
    is_upright(c, has_vertical_form) gave a bool, and Script::direction a ScriptDirection where is_rtl gave
    Option<bool>.
  • A name table ID is a NameId, with the specification's IDs as constants (NameId::FAMILY_NAME and the rest),
    wherever one goes: name, the keys of names, Axis::name_id, Palette::name_id and palette_entry_labels.
  • Every public type is Debug. Location is Eq and Hash by the values it was asked for, so it keys a map. Results
    that hold data alike are Clone and PartialEq. Results are Send + Sync in every build, and Font and Location
    are with threading.
  • Bounds { x_min, y_min, x_max, y_max } is every box. ColrLayer, palettes and BASE's Extents are named structs,
    not tuples.
  • ShapeOptions, LayoutOptions, JustifyOptions, OutlineOptions and SceneOptions are #[non_exhaustive], built
    from Default or their DEFAULT (JustifyOptions from new) with their with_* methods. So is every struct a call
    returns and every enum that may gain a variant, so a later field or variant comes in a minor release: match them with
    a _ arm. A StrokeStyle is StrokeStyle::new(width) with with_join and with_cap, a Gradient is
    Gradient::new, and JstfModLists and ItemVariationStore start from Default. Plain values (GlyphId, Bounds,
    Point, Offset, Feature, Rgba, Stop, Rect, WordSegmenter), raw::format's Entry and RegionAxis, and
    sets a specification closes (Orientation, Direction, Verb, FillRule and the like) stay exhaustive, as the
    crate docs list.
  • unicode::Script's id is private, as a release renumbers the ids when Unicode adds scripts, so Script(n) and .0
    are gone. A script comes from script_runs, a constant such as Script::ARABIC, Script::from_iso15924 or parse,
    given its Unicode name or its ISO 15924 code.
Modules
  • The root holds Font, Location, Tag, GlyphId, NameId, Error, ErrorKind, Result, Bounds,
    Orientation, Axis (1.2.0's FvarAxis), NamedInstance, FontStyle, GlyphClass, Cache and CacheStats.
    Every other item moved to its area's module: metrics, shape, layout, unicode, outline, color (1.2.0's
    paint, with the color glyph calls' types), math, tables, raw (bytes, format, build_font, parse_loca
    and outline_glyf_bytes) and raster.
  • daecore is private. What it held that a caller needs is in those modules.
One call a job
  • Opening. from_ttc is from_collection, which opens a font file at index 0 as from_bytes does, and
    ttc_font_count is face_count, which counts a font file as one face where it gave 0. Opening refuses a font whose
    head (or Apple's bhed) gives no unitsPerEm, or whose maxp gives no glyph count. upm is units_per_em, num_glyphs
    is glyph_count and bbox is bounds. from_vec takes a face index, 0 for a font file, as from_static does.
  • Names and instances. name_string is name(NameId, &Location). instance gives the instance as shared bytes, an
    Arc<[u8]> that its location's cache hands out again without a copy. instance and instance_tables return the
    instancer's error at a location it can't build, where they returned the font as stored; instance_tables keys its
    tables by Tag, and table_tags is an iterator.
  • Metrics. Every metric takes a Location. os2_info is os2, stat_info is stat and flags is pdf_flags, a
    typed PdfFlags. line_metrics takes an Orientation, and TypoLineMetrics folds into LineMetrics.
    typographic_metrics gives each part as an Option, so a missing field is no longer 0, and SubSuperMetrics is
    ScriptMetrics.
  • Glyphs. advance_widths is advances(glyphs, &Location, Orientation, &mut out), filling the caller's buffer
    after clearing it. vertical_advance is advance(glyph, &Location, Orientation). codepoints folds into coverage,
    which with glyph_ids is an iterator where they gave a Vec. mark_attachment_class returns Option<NonZeroU32>,
    none for no class where it gave 0, and vertical_origin returns f64. glyph_name returns Option<&str> and
    glyph_names an iterator of them, each name lent from post or CFF where it was a String.
  • Shaping. shape(text, &Location, &ShapeOptions) returns Arc<ShapedRun> in every build, where it was an Rc
    without threading, and replaces shape_with_language, shape_with_features and shape_with_options; every run
    shaping gives comes as an Arc alike. shape_bidi_with folds into shape_bidi, and measure_width into
    ShapedRun::width. Calls that never failed return their values rather than Options: shape, shape_bidi,
    shape_justified, layout, justify and caret_positions.
  • Runs. A run's offsets are Offsets, x and y, and the bytes a script run, a bidi run, a laid-out run, a line
    and a visual run cover are a core::range::Range<usize>, bytes, where a script run's were its start and end,
    and a visual run's and a bidi run's were each character listed: an odd level draws its range last to first. The range
    is Copy, and start..end still builds the older core::ops::Range, which .into() turns into one and back. A
    run's shaper is a Shaper where it was a &'static str; Shaper::name gives the string it was.
  • Features. A Feature is a tag, a value and the bytes it holds over; Feature::new(tag, value) covers the whole
    text, as a pair did. ShapeOptions names an OpenType script as a Tag, takes a direction in place of vertical,
    and gains not_found_glyph and not_found_variation_selector_glyph.
  • Layout. justification_extenders folds into justification_glyphs. shape_justified takes an Adjustment, and
    LayoutOptions a BaseDirection, tab_size and segmenter. A LangSys tag is a language_system
    (JustifyOptions::language_system, justification_priorities(script, language_system)), as language names a BCP 47
    tag. resolve_bidi is BidiParagraph::new, and line_visual_runs is its visual_runs, which takes the line as any
    range of bytes, .. for the whole text.
  • Outlines. outline_glyph and outline_glyph_instanced are outline(glyph, &Location, pen). hinted_glyph is
    hinted_outline, which returns a Result, InvalidArgument for a px not finite or not above zero, and glyph_quads
    is quads. draw_hinted is HintedOutline::draw. QuadraticPen::new takes a tolerance. HintMode::Subpixel is
    HintMode::Font, the font's own bytecode or CFF hints; HintMode::Classic is gone.
  • Points. A path's points, contours and a hinted outline's points are Points, a hinted point coming with its
    PointKind where it came with flags. Verb holds one byte, Move 0 to Close 4. A CFF hint mask is a CffMask,
    where it was a pair. A Quad is a struct of three Points where it was [[f32; 2]; 3], laid out the same.
  • Strokes and limits. stroke, stroke_simplified and flatten are Path's methods and return a Result saying
    why they drew nothing, and an embolden not finite is InvalidArgument, where it was ignored. MAX_RESOLVE_EDGES and
    MAX_CURVES_PER_GLYPH are gone: resolve_overlaps and quads take an outline of any size (Security).
  • Pens. TransformPen names its pen's type as a parameter: TransformPen<'_, Path> over a path, and
    TransformPen<'_, dyn OutlinePen> over any pen, which TransformPen<'_> was. Path::replay, PathView::replay and
    HintedOutline::draw take any pen, &mut (impl OutlinePen + ?Sized), where they took &mut dyn OutlinePen: the same
    calls compile, but one taken as a function pointer names its pen's type.
  • Color. colr_scene and colr_scene_with are color_scene(glyph, &Location, &SceneOptions). colr_v1_paint is
    paint_graph and colr_v1_visit is visit_paint_graph, and the graph type Paint is PaintGraph, named apart from
    a scene's Paint. colr_layers_for_palette folds into colr_layers, palette_info is palettes, and
    glyph_bitmap is bitmap, which lends a PNG from the font where it copied it, so a GlyphBitmap and its
    BitmapImage borrow the font. A transforming paint's center is a Center, x and y, and Blend::composite
    gives a Premultiplied, color and alpha, where each was a pair. A scene's PathId and GradientId are types of
    their own where both were usize.
  • Caches. The four set_*_bytes calls and their stats are set_cache_budget(Cache, bytes) and
    cache_stats(Cache), and clear_shape_cache and clear_prewarm are clear_cache(Cache). set_cmap_index_allowance
    is set_index_allowance, as it governs every index a font and its locations build. Under threading a shape budget
    of 4 MB or more is split over lists, so a run leaves by its own list's use rather than the whole cache's.
  • Tables and subsets. base_info is base_script(script, &Location, orientation), giving a BaseScript,
    base_extents gives Extents, and base_is_glyph_free is has_glyph_free_base. feature_tags and
    language_system_tags name a LangSys tag language_system. SubsetResult is Subset, whose bytes are font and
    whose map reads through renumbered. subset and subset_text take a Location, which the subset is pinned to.
  • Raster. MAX_SUBPIXEL_TAPS and MAX_SUBPIXEL_WEIGHTS are raster::MAX_TAPS and MAX_WEIGHTS,
    SubpixelLayout::unfiltered takes an Orientation, and SubpixelLayout::GRAYSCALE is private; grayscale() and
    Default remain.
Color scenes and paint graphs
  • A color scene keeps its paths, clip shapes and gradient stops in one buffer each. DisplayList::path gives a
    PathView, which reads, replays and bounds as a Path does and copies one out with to_path. Paint::Gradient
    holds a GradientId, which DisplayList::gradient reads, and Op::PushClip a range of shapes, which
    DisplayList::shapes reads. push_path takes a PathView, Path::view gives one, and push_gradient and
    push_shapes add the others. Op and Paint are Copy.
  • color::lower takes the glyph, its PaintGraph and a clip-box lookup giving Bounds, and its outline draws a
    glyph into the pen it's handed, true where it drew. resolve_stops is Stops::resolve, which takes the extend mode.
    Gradient borrows its stops.
  • A PaintGraph holds a graph's paints in one list and their stops in another, where it was an enum of boxed children.
    root() gives a PaintRef, whose node() is the paint's own fields as a PaintNode, with Extend and Blend in
    place of raw codes, and children() the paints below it. A PaintGraph is a PaintVisitor, so PaintGraph::with
    builds one by hand. ColorStop is Copy.
Readers
  • raw::outline_glyf_bytes takes extended after glyf, true where the bytes are GLYF's.
    raw::format::coverage_index returns Option<u32>, coverage_glyphs gives u32 ids from Coverage formats 1 to 4,
    and Lookup::entries gives GlyphValues, a u32 glyph and its value, where it gave (u16, u16) pairs.
    Ankr::anchor_point and control_point give an AnchorPoint, x and y, where they gave a pair.
  • raw::format::FeatureVariations::find takes GDEF's variation store, find(coords, store), and returns the record as
    a u32, which substitute takes; substitute returns Option<Substitution>, the alternate's offset or Empty,
    where 1.2.0 gave the offset alone, and with_axis_count is gone. Lookup::parse, StateTable::parse and
    Ankr::parse return a Result naming what failed, where they gave None.
  • A DeltaSetIndexMap's entries are DeltaSetIndexes, outer and inner, where they were pairs.
    parse_item_variation_store, precompute_region_scalars and compute_ivs_delta_f64 are ItemVariationStore::parse,
    region_scalars and delta, and ankr_version is Ankr::version. Script::opentype_tags is an iterator over the
    tags it holds in place, where it collected a Vec.
Memory a thread keeps
  • A thread keeps what its last call grew, up to 64 KB of each, for its next: a hint context's buffers, a glyph's decoded
    points, a paint graph's lists, a prepared outline's path, a stroke's lists and the like. They go when the thread ends,
    or when it calls release_thread (C: daegun_thread_release), which a pool's worker calls as it goes idle. Under
    threading a thread also keeps its last four hinting contexts, the autohinters of its last four locations, its eight
    most recently resolved locations and its 32 most recent runs; a context holds its font's bytes, so a dropped font's
    bytes may stay until the thread hints other fonts, releases or ends.

C

The C ABI is rebuilt to mirror the Rust API, so a program built against 1.2.0 is ported, not just recompiled. Every
1.2.0 call has a counterpart under Rust's name, folds into the call that does its work, or goes with the list or handle
it read, as such results now come in a struct or the caller's buffer.

Headers and version
  • #include "daegun.h" from src/api/c/include, an umbrella over thirteen headers in daegun/, one an area, each
    compiling alone. 1.2.0's was one file, src/c-wrapper/daegun.h. The headers need C11 or C++11, where 1.2.0's read as
    C99, and compile clean through C23 and C++23 under clang and GCC.
  • daegun_abi_version and DAEGUN_ABI_VERSION give the C ABI's own version, 2.0.0, where they gave the crate's. Its
    major moves whenever a struct or an existing call changes shape, its minor when calls or constants are added or an
    options struct grows at its end: refuse a library whose major differs or whose minor is lower (Security). A major also
    freezes each set of codes a call answers, but where the call says a newer library may answer more (DAEGUN_SHAPER_*,
    DAEGUN_VO_*).
  • Each call is declared with DAEGUN_API, which imports it from daegun-2.dll where DAEGUN_DLL is defined, and
    DAEGUN_NODISCARD. Each pointer that may be NULL is marked DAEGUN_NULLABLE, so to clang every other pointer is
    required and NULL passed to one warns.
  • A shared library is loaded by a name that carries the ABI's major: libdaegun.2.dylib on macOS and libdaegun.so.2
    on Linux.
Statuses
  • DAEGUN_PARSE and DAEGUN_RANGE are DAEGUN_MALFORMED and DAEGUN_INVALID_ARGUMENT, their values kept. Five join
    them, one for each kind of Rust's Error: DAEGUN_UNSUPPORTED (-6), _MISSING (-7), _LIMIT_EXCEEDED (-8),
    _NO_OUTLINE (-9) and _OVERFLOW (-10), for failures 1.2.0 answered with one of the first two, so a caller testing
    for -2 or -3 alone misses them. -5, 1.x's unsupported, is never reused.
Locations, units and types
  • A location is resolved once: daegun_font_location makes a daegun_location from daegun_coords, and every call
    that depends on one takes it, NULL being the default instance. 1.2.0's calls took axes, axes_len and resolved them
    on every call, and its metrics, names, flags, MATH values and CFF hints answered at the default alone.
  • 1.2.0's daegun_axis, a tag string and a value, is daegun_coord, its tag a daegun_tag. daegun_axis is now
    fvar's record of an axis, which daegun_font_axes lists where it gave two parallel lists and daegun_font_axis_flags
    two more.
  • Every metric, advance, offset, bound and outline is in font units, a double, y up and unrounded, where 1.2.0 put
    advances and metrics on a 1000-unit em, quads on an em of 1 and hinted points in 26.6. A call that hints or prepares a
    glyph takes a pixel size and answers in pixels.
  • A tag is a daegun_tag, four bytes packed big-endian (DAEGUN_TAG('w','g','h','t')), where 1.2.0 took and gave
    strings; where a call may go without one, 0 is none. A script is its ISO 15924 code as a tag, where 1.2.0 gave a
    numeric id.
  • Text comes as a pointer and a count of bytes, so a slice of a larger buffer goes in without a copy and U+0000 is a
    character like any other; 1.2.0 read NUL-terminated strings. A short identifier, such as a language, stays
    NUL-terminated. Every position in text is a byte offset where a character starts, as in Rust, where 1.2.0 counted
    characters.
  • An orientation is DAEGUN_HORIZONTAL or DAEGUN_VERTICAL, where 1.2.0 took bool vertical, and a JSTF adjustment
    DAEGUN_ADJUST_SHRINK or DAEGUN_ADJUST_EXTEND, where it took bool shrink; a code that names none of its constants
    answers DAEGUN_INVALID_ARGUMENT. daegun_font_justify gives the run and fills a daegun_justification, where a
    daegun_justified handle lent the run.
  • Glyph ids are uint32_t everywhere, where 1.2.0's were uint16_t, so daegun_colr_layer grows from 8 to 12 bytes
    and daegun_glyph_value from 4 to 8. Every yes or no is a bool, where nine calls used an int32_t, OS/2's info a
    uint16_t and paint nodes and STAT values a uint8_t; a list of them still comes as bytes, 1 for yes.
Calls
  • One call an operation, as in Rust. daegun_font_shape takes text, a location and daegun_shape_options, where 1.2.0
    had _shape, _shape_with_language, _with_features and _with_options; daegun_font_set_cache_budget,
    _cache_stats and _clear_cache take a DAEGUN_CACHE_*; daegun_font_math_constants fills one struct;
    daegun_font_palettes fills the caller's buffer; daegun_font_justification_glyphs takes in the extenders; and
    daegun_shaped_run_width stands for daegun_font_measure_width. daegun_font_open_owned takes a face index, as
    daegun_font_open_static does.
  • Names follow Rust's, as the table below lists, and the other text calls lose their daegun_text_ prefix.
    daegun_face_count counts a font file as one face, where daegun_ttc_font_count gave 0.
1.2.0 2.0.0
daegun_run daegun_shaped_run
daegun_font_upm daegun_font_units_per_em
daegun_font_num_glyphs daegun_font_glyph_count
daegun_font_bbox daegun_font_bounds
daegun_font_flags daegun_font_pdf_flags
daegun_font_os2_info daegun_font_os2
daegun_font_stat_info daegun_font_stat
daegun_font_name_string daegun_font_name
daegun_font_base_info daegun_font_base_script
daegun_font_glyph_bitmap daegun_font_bitmap
daegun_font_colr_scene daegun_font_color_scene
daegun_font_colr_v1_paint daegun_font_paint_graph
daegun_font_hinted_glyph daegun_font_hinted_outline
daegun_font_glyph_quads daegun_font_quads
daegun_font_outline_glyph, daegun_font_outline_glyph_instanced daegun_font_outline
daegun_font_advance_widths daegun_font_advances
daegun_font_vertical_advance daegun_font_advance
daegun_ttc_font_count daegun_face_count
daegun_font_base_is_glyph_free daegun_font_has_glyph_free_base
daegun_font_language_tags daegun_font_language_system_tags
daegun_subset_new_gid daegun_subset_renumbered
daegun_text_resolve_bidi, daegun_text_bidi_paragraph daegun_bidi_paragraph_new
daegun_text_line_visual_runs daegun_bidi_paragraph_visual_runs
  • A LangSys tag is a language_system wherever it goes: daegun_justify_options' field and the script and feature
    calls' arguments.
  • daegun_font_base_script and _base_extents take the location before the orientation, as every call taking both
    does.
  • daegun_script_is_rtl is daegun_script_direction, a DAEGUN_SCRIPT_DIRECTION_*, and daegun_char_is_upright is
    daegun_vertical_orientation, a character's DAEGUN_VO_* (UAX #50), where it took whether the font has a vertical
    form and gave a flag: upright is _UPRIGHT, _TRANSFORMED_UPRIGHT, or _TRANSFORMED_ROTATED with a vertical form. A
    run's shaper is a DAEGUN_SHAPER_*, which daegun_shaper_name names, where it was a string.
  • daegun_font_glyph_name writes the name and a NUL into the caller's buffer, DAEGUN_MAX_GLYPH_NAME + 1 bytes always
    room enough, where it handed out a daegun_text, and daegun_font_glyph_names gives one list, an empty string for a
    glyph without a name, where a second list, out_present, said which had one; a name holding a NUL is none through
    both. daegun_font_mark_attachment_class answers DAEGUN_ABSENT where GDEF gives none, where it answered 0. A hinted
    point's kind is a DAEGUN_POINT_*, read through daegun_hinted_outline_kinds, where its flags were the bits
    DAEGUN_FLAG_ON_CURVE and DAEGUN_FLAG_CUBIC, and daegun_font_hinted_outline answers DAEGUN_INVALID_ARGUMENT for
    a px not finite or not above zero, where daegun_font_hinted_glyph answered DAEGUN_ABSENT.
  • Every list of fixed-size items goes into the caller's buffer, which a caller keeping it between calls makes free of
    allocation: glyph ids, advances, carets, boundaries, runs, tags, coverage, ligature carets, COLR layers, palettes, a
    glyph closure and the rest, each of which came in a list handle. A NULL buffer with a length of 0 asks for the count
    alone; a buffer too small answers DAEGUN_INVALID_ARGUMENT, writes nothing and still sets the count it needs.
    daegun_u32_list, daegun_f64_list, daegun_usize_list, daegun_glyph_value_list, daegun_colr_layers and
    daegun_palettes go, with their _data and _free. daegun_font_names gives one daegun_names, each ID beside its
    string through daegun_names_at in ascending order of ID, where it gave a daegun_u16_list of IDs and a
    daegun_str_list of strings; the daegun_u16_list goes with it.
  • Each options struct opens with size_t size, which its _default(&opts, sizeof opts) sets, so a struct from an older
    header works with a newer library, and one larger than the library knows answers DAEGUN_UNSUPPORTED.
    daegun_feature gains start and end; an end of 0 or UINT32_MAX runs to the text's end.
Answers that changed in C
  • daegun_font_open* answers DAEGUN_MALFORMED for a font whose head (or Apple's bhed) gives no unitsPerEm, or whose
    maxp gives no glyph count.
  • Text that isn't UTF-8 answers DAEGUN_INVALID_ARGUMENT; NULL with a count of 0 is empty in every call; a miter limit
    not above 0 means 4; and a table tag that isn't four printable characters, and an offset24 past 24 bits, answer
    DAEGUN_INVALID_ARGUMENT.
  • daegun_font_instance and _instance_tables answer the instancer's failure at a location it can't build, and
    daegun_font_color_scene gives a color glyph that draws nothing as a scene with no ops, where it answered
    DAEGUN_ABSENT.
  • Every failed call leaves a number or struct out as it was and sets a handle out to NULL, so daegun_font_table leaves
    its view as it was on DAEGUN_ABSENT, where it cleared it. A buffer a call writes may not share bytes with one it
    reads or writes, base.h's BUFFERS rule, and overlap answers DAEGUN_INVALID_ARGUMENT before anything is written
    (Security).
  • daegun_aat_lookup_parse, daegun_aat_state_table_parse and daegun_ankr_parse answer DAEGUN_UNSUPPORTED or
    DAEGUN_INVALID_ARGUMENT as Rust's parsers fail, where each answered DAEGUN_MALFORMED.
  • DAEGUN_HINT_SUBPIXEL is DAEGUN_HINT_FONT, still 1, and takes CFF and CFF2 hints too; DAEGUN_HINT_CLASSIC is
    gone. DAEGUN_MAX_RESOLVE_EDGES and DAEGUN_MAX_CURVES_PER_GLYPH are gone: overlap removal, quads, strokes and
    embolden take outlines of any size, where they answered DAEGUN_ABSENT or DAEGUN_RANGE past a cap.
  • daegun_font_prepared_outline answers DAEGUN_INVALID_ARGUMENT for an embolden not finite, where it ignored it, and
    daegun_table_map_build for more than 65,535 tables or a table that starts 4 GiB into the file or is that long, where
    it built a file whose header disagreed with its directory. daegun_font_vertical_origin answers for every glyph id.
  • daegun_font_layout, daegun_font_instance_tables and the shaping calls lose DAEGUN_ABSENT paths daegun.h never
    documented, and DAEGUN_SCRIPT_DIRECTION_EITHER, which no script answered, is gone.

Answers that changed

Most of the fixes change answers only for fonts that break the spec. These change them for fonts that keep to it, or for
a caller; each is under Fixed, Added or Security.

  • Loading. A collection's header at major 1 or 2 with a minor of 1 or more names its faces in its second list.
  • Character maps. glyph_id, has_glyph, coverage and shaping read one cmap subtable, the best the font has, so
    a code only another subtable maps is unmapped.
  • Metrics. pdf_flags sets Symbolic for nearly every real font; vertical_origin and vertical shaping take one
    rule, so glyf fonts without vmtx, CFF fonts without VORG and color and bitmap glyphs move; without vmtx a glyph
    advances the font extents' height; OS/2's USE_TYPO_METRICS and OBLIQUE count in any version, and style answers
    Oblique where fsSelection says so.
  • Outlines and hinting. A composite is drawn from its USE_MY_METRICS component's origin, and a CFF glyph is placed
    by its FontMatrix. HintMode::Auto chooses one hinter a font. TrueType bytecode fits y alone, x staying as drawn
    unless a font declares native ClearType; CFF glyphs are hinted by their blue zones. So hinted outlines move.
  • Color. A solid color or gradient stop at a partial alpha over a translucent palette entry can come out one level
    of 255 different, and color_scene gives a color glyph that draws nothing as a scene with no ops.
  • Variations and instances. Metrics, names and styles read their location's tables; a call's axes keep only the
    font's own, clamped; a design value normalizes in float, so about one setting in 1,700 moves a 2.14 step; a CFF2
    font's instance and its subsets hold static CFF2, not CFF.
  • Layout and shaping. Every call that takes a tag pads a short one with spaces. A font whose morx has data shapes a
    script with its own shaper through "dumber", the shaper that adds no features, masks or reordering; trak tracks only a
    font with a STAT; a language tag takes up to three language systems; Dae1, DAE1, Dae2 and DAE2 lookups run by default.
    A run grows and edits within 256 glyphs and 4,096 edits a character, 65,536 at least.
  • Scripts. Garay and Sidetic run right to left. Indic, Myanmar, Khmer, Hangul, Arabic and the Universal Shaping
    Engine's scripts reorder or position differently in places, and Indic, Khmer and Myanmar find their syllables as
    Microsoft's specifications draw them, so a sequence those don't allow takes a dotted circle.
  • Text and carets. shape_bidi cuts each bidi run where its script changes, script_runs keeps text with no strong
    script as one run, and each paragraph finds its own direction. layout cuts a word no line can hold, draws a line as
    it measures it, sets tabs and soft hyphens, and lays upright text left to right; caret_positions places a cluster at
    its whole extent.
  • Subsetting. glyph_closure and every subset close over only the lookups each feature reaches from the request, so
    they keep fewer; a subset's GSUB, GPOS and GDEF come out smaller; a subset measures the glyphs it keeps.
  • Trigonometry. The sine and cosine daegun computes with are within an ulp of std for every finite argument, so the
    last bit of a value made from them can change anywhere.

Caches

Caches hold less under the same budget:

  • Every byte budget evicts the least recently used, and lowering a budget keeps what still fits.
  • One budget bounds a font's locations and counts everything a location builds, so the same budget holds fewer; each
    shaped run is charged for what it holds, and a budget of 0 keeps none.
  • set_index_allowance governs every index a font and its locations build, by default 4 MiB and 8 bytes for each
    distinct byte of the font's tables, where every font had 25 MB.
  • A variable font draws, measures and shapes from its own tables, so only instance and subsetting build an instance. A
    CFF2 font keeps each glyph's outline as first drawn, up to 16 MB at its default and at each location, and a variable
    glyf font each simple glyph's points, up to 16 MB.
  • Cache::Raster (C: DAEGUN_CACHE_RASTER) keeps the images a rasterizer draws, off at a budget of 0 until set.
  • 3 more, on how plans and locations are kept.

Bytes written

Some tables daegun writes changed byte for byte while reading back the same. Tests that compare a written font with a
stored copy will see these:

  • An instance writes loca in the short format wherever every offset fits, and its name table stores each distinct string
    once.
  • A subset's just table writes each distinct action list once.
  • A subset's morx ligature subtables write components only for the glyphs an action can pop.
  • A subset's cmap writes its wide subtable as format 13 where that takes fewer groups.

Security

2.0.0 fixes more than 110 security issues that an untrusted font, or a caller's input, could reach through public
calls, from Rust and from C. The most serious are below, the rest counted after them.

Untrusted fonts

Untrusted fonts can no longer hang daegun, crash it or exhaust its memory.

  • Endless loops. Shaping never returned on a GPOS cursive chain that loops back on itself, and bitmap on an EBDT
    or CBDT composite that names itself (16^16 visits). The attachment walk visits each glyph once, and a bitmap's
    components spend 64 units of work a byte of its tables.
  • Crashes. A panic aborts a program built with panic = "abort", as the C library is. Hinting a CFF glyph whose
    charstring computes a NaN under HintMode::Auto, drawing at a location from a gvar of no axes with shared tuples, and
    morx states that don't advance over 524,288 characters each panicked; on a 32-bit target, GSUB sets sharing one set of
    65,535 wrapped the size of the index reserved for them. Each is checked now, and every offset and count near 2^32 is
    checked on 32-bit targets.
  • Gigabytes. Subsetting a 147 KB GSUB held 3.16 GB, copying a PairSet many pairs share headed for 31 GB from 96 KB
    of GPOS, and walking nested lookups again for each lookup naming them headed for about 450 GB from 54 KB. Instancing
    grew a Unique ID to about 3.2 GB and decoded every glyph below the one asked for; reading names reserved 4.29 GB from
    an 850 KB table; and a 64 KB GSUB's lookup index held 1.17 GB. Each is now charged to a budget, held once or refused.
  • Minutes to hours. Subsetting read Script and LangSys tables many records share, and coverage ranges laid over one
    another, for an hour or more a call. Reading a glyf glyph's overlap flag took 502 s, a glyph's points at a location
    320.8 s from 29 KB of gvar, a bitmap-only font's first advance over 300 s, and a hinted composite 41.3 s; an Indic
    syllable's probes made about a billion reads. Each is now charged to the call's budget or done once.
  • No fixed ceilings on work. No glyph, scene or text is refused or cut for the work it asks for alone. Each bound
    that stays grows with the input asking for the work and is priced so a hostile font finishes within seconds, while no
    real font comes near one: bytecode hinting spends 2^26 units and 2,048 a point, a CFF glyph 64 steps a byte of its
    charstrings, a glyph's draw 2^30 units, overlap removal 2^25 instructions and 80,000 a curve, a color scene 2^29
    passes and 1,024 a pixel of its frame. The values kept fixed are the formats' own or what fonts are built to expect,
    and what a call hands back whole keeps a size: an image a rasterizer lends stays within MAX_SIDE and
    MAX_DRAW_BYTES, and a flattened path within MAX_FLATTEN_POINTS points.
  • Over 70 more fixes, most where a crafted font took seconds or hundreds of megabytes in subsetting, shaping,
    instancing, hinting, outlines or color, the rest sums that overflowed: each is charged to a budget, done once, refused
    or checked.

A caller's axes and text

A caller's axes and text can no longer grow a cache past its budget or make a call take quadratic time.

  • Caches. Every axis location got a whole cache of its own, charged only its tables' length (400 weights of a
    260-byte font held 253 MB); a tag the font lacks or a weight past its range made a new entry each time; and empty text
    grew the shape cache without a ceiling. A font keeps one cache per location under one budget, keyed by its own axes,
    clamped, and each shaped run pays for what it holds.
  • Quadratic time. Bidi isolates searched ahead for their closing PDI (320,000 U+2068 took about 42 s, now 15 ms),
    Myanmar syllables reordered with the square of their length (240,000 characters, 31.8 s), and grapheme and word
    breaking recounted regional indicators (80,000 flags, 7.1 s and 9.6 s). Each grows linearly now.
  • 2 more fixes: a long run's shaping buffer outlived it, and shape_bidi copied text quadratically.

The C interface

The C interface keeps its promises across releases and to every caller.

  • ABI version. daegun.h checked the crate's major, which stayed at 1 through 2.0.0's development while structs
    changed in place, so a program built against 1.2.0's header took a development build as compatible, and the library
    wrote 96 bytes of shape options into its 88. The C ABI has a version of its own now, held to it by a check in the
    release tooling.
  • Undefined behavior. Options structs' flags were read with Rust's bool, so any byte but 0 or 1 was undefined
    behavior; they're read as bytes. daegun_bounds wasn't repr(C); it is, and a check holds every struct in the
    headers to its Rust twin. Twelve calls held an input and an output buffer sharing bytes as Rust's & and &mut at
    once; base.h's BUFFERS rule now forbids the overlap.
  • Contracts and testing. The headers state that callbacks must return normally and which pointers may be NULL, each
    checked against the translation. The ABI is fuzzed through C under ASan, and one font shared by eight threads runs
    under TSan.

Added

Fonts past 65,535 glyphs

A font past 65,535 glyphs counts them in MAXP, keeps its outlines in GLYF and LOCA, its metrics in HHEA and HMTX (VHEA
and VMTX) and its variations in GVAR, and names those glyphs in 24 bits. None of these was read; each is now read, so
such a font draws, hints, measures, shapes, subsets and instances.

  • Characters and metrics. DMAP answers a character before cmap does, cmap's format 15 maps in 24 bits, and formats
    12 and 13 map glyphs past 65,535. HHEA and HMTX give the metrics where HHEA's count gives a glyph a record, VHEA and
    VMTX alike, and VORG 2 gives origins in 24 bits.
  • Outlines. GLYF and LOCA are the glyph tables where both hold bytes, a composite naming its component in 24 bits,
    and GVAR varies them. In GLYF a control whose flag sets 0x80 is a cubic one.
  • Layout, color, BASE and JSTF. GSUB and GPOS 1.2 and GDEF 1.4 are read through their 32-bit offsets, with Coverage
    and ClassDef formats 3 and 4 and the 24-bit twin of every lookup format; COLR's PaintGlyph format 33, BASE coordinate
    format 4 and JSTF 1.1 name their glyphs in 24 bits.
  • Subsets and instances. Each table keeps its source's tag. Subsets and instances keep every glyph's outline and
    metrics on fonts of 68,473 and 199,545 glyphs built from Inter, and every layout subset shapes as its font does.

Shaping

  • A feature can hold over part of the text. A Feature (C: start and end in daegun_feature) names the
    characters it holds over, in GSUB, GPOS and morx fonts alike. Turning small caps or ligatures off for one span meant
    shaping that span as a run of its own, which loses the kerning and contextual forms across its edges.
  • A run can be shaped in a stated direction, with glyphs for what the font lacks. ShapeOptions::direction shapes a
    run in any of the four directions whatever its text says, as a caller running its own bidi needs. not_found_glyph
    draws a character the font lacks with a glyph of the caller's choice, and not_found_variation_selector_glyph a
    variation selector the font can't apply.
  • Fonts can run lookups at two fixed stages. Lookups under Dae1 and DAE1 run before a script's own features and
    those under Dae2 and DAE2 after them, always on.
  • Text follows Unicode 18.0.0. Character properties, script runs, grapheme and word boundaries, line breaks and bidi
    follow it, where they followed 17.0.0: 13,007 more code points have their properties, Jurchen, Proto-Cuneiform and
    Seal among them.

Text layout

  • Thai, Lao, Khmer and Myanmar break between words. Text written without spaces between words broke only at spaces.
    LayoutOptions::with_segmenter and line_break_opportunities take a word segmenter of your own (C: segmenter), and
    the dictionaries feature builds in word lists for the four scripts, about 1 MB.
  • A layout takes features. LayoutOptions::with_features (C: features in daegun_layout_options) turns on small
    capitals or tabular figures over a paragraph or a range of its bytes.

Color and composite glyphs

  • A COLR version 1 paint graph can be walked without building it. Font::visit_paint_graph hands each paint to a
    PaintVisitor as it is read, a gradient's stops lent rather than copied: 92.3 ns a glyph over Noto COLRv1's.
  • VARC's variable composite glyphs are drawn, measured, subset and instanced. A glyph VARC covers is built from
    components, each another glyph at its own axis values and transform, then drawn and measured as any glyph is.

Drawing pixels

  • A rasterizer of its own. daegun draws glyphs again: raster::Rasterizer draws a glyph or any path into an image
    it lends, keeping its buffers between calls. Coverage is the exact area under the outline, and stays exact where
    contours overlap: a glyph's overlaps are found once, in font units, and a path's are resolved exactly in the rows
    where its contours meet. Every CPU gets the same bytes. A lent image is at most MAX_SIDE pixels across or down and
    MAX_DRAW_BYTES (256 MiB) in its buffers.
  • Drawing into your own pixels. Rasterizer::glyph_into, color_glyph_into and path_into draw into a Target,
    the caller's pixels and the rectangle of the drawing they cover, of any size, a band of rows at a time, so a glyph
    30,000 pixels tall draws without an image of its own.
  • Subpixel layouts, darkening and gamma. A SubpixelLayout other than grayscale draws three bytes a pixel, filtered
    through its taps. RasterOptions::darken widens thin stems by the documented CFF curve, and RasterOptions::gamma
    turns coverage into alpha for a compositor that blends in sRGB. Both are off by default: exact coverage is right for a
    compositor that blends in linear light.
  • Color glyphs and distance fields. Rasterizer::color_glyph draws a color glyph's scene into premultiplied sRGB,
    composited in linear light through its clips, layers, blend modes and gradients, then rounded once.
    Rasterizer::distance_field draws a glyph's signed distance field, one channel (Field::Sdf) or three whose median
    keeps corners sharp (Field::Msdf).
  • The raster cache. Cache::Raster keeps the images a rasterizer draws, each under its glyph, location and every
    option that changes its pixels, and lends them again in place of drawing. It's off until set; once warm, a rasterizer
    allocates nothing.

Caches shared across fonts

  • A group of fonts can share one cache budget. A CachePool (C: daegun_cache_pool) is a byte budget that fonts
    join for a cache kind with Font::set_cache_pool. Past it, the least recently used entry across every font in the
    pool goes; each font keeps its own budget too, and a hit stays lock-free.

New calls

  • Rust.
    • The types the API was rebuilt on (Compatibility, Rust)
    • Feature's FromStr, which reads a feature as shaping tools and CSS write one (kern, -liga, aalt=2,
      kern[3:5]=0)
    • unicode::script, a character's script
    • Font::from_static, which reads a font where it lies in bytes that live as long as the program, copying nothing
    • Font::palette_colors, Font::localized_names, Font::has_overlap_flag and Font::visit_names
    • Font::shape_into, which shapes into a run of the caller's, reusing its vectors
    • Path::flatten_into, Font::quads_into and QuadraticPen::reusing, which reuse the caller's lists
    • CachePool, Target and the rasterizer's calls
    • release_thread, which lets go of what the calling thread keeps between calls, the fonts' bytes its hinters hold
      among them
    • 20 more, each in the crate docs
  • C.
    • The daegun_location handle, daegun_bounds, the five new statuses and a counterpart for each Rust call 1.2.0's C
      lacked (Compatibility, C)
    • daegun_tag_from_string and daegun_feature_from_string
    • daegun_font_open_static
    • daegun_font_shape_into
    • daegun_shaped_run_copy, which keeps a run a bidi set or a layout lends past the set's free or the layout's
    • The rasterizer, daegun_rasterizer with its calls, daegun_raster_options and daegun_target
    • daegun_cache_pool
    • daegun_thread_release, which also drops the freed handles the thread keeps for its next
    • daegun_status_name and daegun_version, for a log
    • 13 more, each in the headers

Help from the compiler

  • Rust. A call whose answer is its whole point warns where the answer is dropped. A type passed as an OutlinePen
    or a PaintVisitor that isn't one gets an error naming what to do instead. The main calls carry examples, each run as
    a test. Each call, type and constant renamed since 1.2.0 answers to its old name in the docs' search, and a call by
    the old name gets the compiler's help naming the new one: font.upm() is told of units_per_em.
  • C. DAEGUN_ABI_MAJOR, DAEGUN_ABI_MINOR, DAEGUN_ABI_PATCH and DAEGUN_ABI_COMPATIBLE check the library a
    program loaded in one line, in #if too. GCC and MSVC's /analyze know the length of each of 79 arrays a call reads
    or writes, so one shorter than the length passed warns, and clang's bounds safety, which Swift's C interop reads,
    refuses one. Calls whose answer is their only result warn where it's dropped, no call throws to C++, and each call and
    callback keeps C's calling convention under MSVC's /Gv and /Gz and GCC's -mrtd. Each comment documenting a call,
    a type or a field is a doc comment, so Xcode's Quick Help and Swift's generated interface show it. The headers note
    the rest.

Values and options

  • Rust. Every public type that compares equal hashes too, so a Feature, Direction, Rgba or Script can key a
    HashMap. ShapeOptions, LayoutOptions, OutlineOptions and SceneOptions have a DEFAULT, and every options
    builder is a const fn, so options can be a constant: &ShapeOptions::DEFAULT takes a cached run 4% sooner than
    &ShapeOptions::default(). prepared_outline takes any pen generically, so a pen of yours inlines into its scaling:
    12% off a glyph. An Error converts into an io::Error, so a loader returning io::Result takes ? on opening a
    font. Os2 gives usWeightClass, usWidthClass and fsType, the embedding rights a PDF writer reads before it subsets;
    C's daegun_os2 has the same three. The crate docs list the rest: conversions, const fns and iterators.

Installing and linking

  • Rust. The crate ships without its tests: 326 files, where it held 561, so cargo test on the published crate
    stops at the tests it excludes, and its own tests are its doc tests, cargo test --doc, which pass from the package.
    Without std, it needs a target with atomic compare-and-swap at pointer width, as its docs now say.
    wasm32-unknown-unknown builds, with the default features and without.
  • C. cargo cinstall installs the headers, the static and shared libraries, a daegun.pc and the license notices,
    the libraries and the .pc versioned by the C ABI, so pkg-config, CMake and Meson find daegun as the README shows,
    its ranges taking any 2.x and no 3. A shared library or daegun-2.dll exports daegun's calls alone, and the README
    merges daegun's static library into one object that exports its calls alone, so it doesn't clash with another Rust
    static library. The README says how to hide daegun's calls inside a shared library of yours, hold a handle in C++ and
    build for MemorySanitizer, and a library built with RUSTFLAGS="--cfg daegun_no_spares" frees each handle at once, so
    ASan or Valgrind sees one used after its free.
  • Release archives. The archives for macOS, iOS, Mac Catalyst, tvOS, visionOS, Linux with glibc or musl, Android and
    Windows hold the headers, the libraries, a .pc, CMake package files and the license notices.
    • find_package(daegun 2.0) finds them, and daegun::daegun links on every platform.
    • Linux's glibc libraries need glibc 2.17 at most; Android's cover aarch64, x86_64 and 32-bit Arm from Android 5.0,
      the 64-bit ones on the 16 KB pages Google Play asks for; daegun-2.dll needs only the UCRT Windows 10 and later
      have.
    • Beside them come a universal macOS archive and an XCFramework for Xcode and SwiftPM, each Apple archive with the
      privacy manifest Apple asks of an SDK.
    • The set comes with SHA256SUMS and a BUILDINFO, builds the same byte for byte twice, and each archive builds the
      round trip as its users would before it ships.
  • Paths and names. The notices are in share/doc/daegun and Apple's privacy manifest in share/daegun, so two
    archives unpacked into /usr/local don't clash. daegun.dll is daegun-2.dll, so plugins built against 1.2.0's DLL
    and this one don't share one in a process, and the header daegun/math.h is daegun/mathtable.h, as on -I a
    framework's flat headers hid the C library's <math.h>.
  • The license. It reads MIT AND Unicode-3.0 AND ICU AND BSD-2-Clause AND BSD-3-Clause, where it read MIT alone:
    the Unicode tables and CLDR's likely subtags come under the Unicode License v3, the word lists under Unicode's
    licenses, ICU's older one among them, and BSD licenses, and the Universal Shaping Engine data comes from Microsoft's
    under MIT. Their notices are in one file, CREDITS.txt, beside daegun's own LICENSE, so software shipping daegun
    ships that file too, as the release archives and cargo cinstall do.

Fixed

Each area lists the fixes a well-formed font or a caller will see and, where there are others, ends with a count of
them.

Loading

  • A font is checked once, at load. One whose head gives no unitsPerEm, or whose maxp gives no glyph count, is
    refused there, where a missing em was guessed as 2,048 and four copies of the glyph-count rule disagreed. A font whose
    header is Apple's bhed loads on the em it declares.
  • An extended TTC header names its faces in its second list, at major 1 or 2 with a minor of 1 or more, where
    from_collection and face_count read the first, which such a collection keeps for older readers.
  • 3 more fixes, most for fonts that break the spec.

Character maps

  • A cmap is read through one subtable, the best it has. Each code fell through every subtable in turn, so Symbol and
    ZapfDingbats drew Latin text as Greek letters and dingbats, and Webdings and the Wingdings drew Latin and math from
    their Mac subtables. One subtable now answers glyph_id, has_glyph, coverage, shaping and subsetting. On 827 of
    828 faces tested, every code from 0 to U+10FFFF maps as expected.
  • A cmap over all of Unicode is listed and kept whole. coverage stopped at 200,000 codes, so Last Resort, one
    format 13 group over all of Unicode, covered nothing and its subset mapped nothing. Its subset now carries all
    1,114,112 codes in 84 bytes.
  • 7 more fixes, most for fonts that break the spec.

Metrics

  • Every glyph has one vertical origin: VORG, then glyf's top phantom point, then the glyph's box centered on the
    line. vertical_origin answered None for every glyph of a glyf font without vmtx and of a CFF font without VORG,
    and the shaper had a rule of its own.
  • Vertical advances read as fonts state them. A stated zero stays 0, where Source Han Sans's vertical Hangul tone
    marks advanced 1,448 down the line, and without vertical metrics a glyph advances the font extents' height, where
    TestShapeLana advanced 4,311 units a line rather than 3,156.
  • pdf_flags sets Symbolic past the standard Latin set, as PDF reads the flag, where Wingdings and Noto Color Emoji
    came out Nonsymbolic like every other font.
  • A font can read as oblique. FontStyle::Oblique (C: DAEGUN_STYLE_OBLIQUE) answers for fsSelection's oblique
    bit, ahead of italic, and OS/2's USE_TYPO_METRICS and OBLIQUE count in any version.
  • 7 more fixes, most for fonts that break the spec.

Outlines

  • A composite whose metrics come from a component is drawn from that component's origin: its phantom point 1 is its
    USE_MY_METRICS component's. Over the corpus 867 composites in 27 faces move across, Arial's and Times New Roman's
    among them.
  • A CFF or CFF2 glyph is placed by its FontMatrix, in a CID-keyed font each FD's composed with the Top DICT's.
  • 23 more fixes, most for fonts that break the spec.

Hinting

  • HintMode::Auto chooses its hinter once per font: the autohinter for a TrueType font with no font program and a
    CVT program of at most 7 bytes, the font's own bytecode or CFF hints for any other, where it chose glyph by glyph.
  • CFF and CFF2 glyphs are hinted in full by Type 1's hint model: blue zones and overshoot, hint replacement and
    counter masks. Small lowercase keeps its x-height (Source Serif's at 9 px is 5 px, not 4), and an ideographic font's
    glyphs sit in the em box its BASE table gives. HintMode::Font takes these hints, where Subpixel left CFF glyphs
    unhinted.
  • TrueType bytecode runs one way, for today's screens: y fits the pixel grid and x stays as drawn, so advances and
    subpixel positions match the unhinted outline, unless a font declares native ClearType. Its arithmetic rounds each
    value once and never wraps.
  • 10 more fixes, most for fonts that break the spec.

Color

  • A palette index at or past the palette count reads palette 0, the default, as CSS's base-palette falls back to
    it, where a version 0 glyph lost its layers and a version 1 glyph its fills.
  • A color glyph that draws nothing is a scene with no ops. color_scene answered None, so a caller fell back to
    the plain outline the font says not to draw.
  • A solid color and a gradient stop naming one palette entry at one alpha get the same color, where they came out a
    level apart in 516,559 of 4,194,560 pairs.
  • Gradients' edge cases draw as COLR defines them: a hard edge takes the later color on its own offset, and stops at
    one offset or a sweep with no span draw as the spec says.
  • 22 more fixes, most for fonts that break the spec.

Bitmap fonts

  • bitmap reads Apple's bloc and bdat, so the bitmaps of Geneva, Monaco, AppleMyungjo, the four Cochins and
    NISC18030 read.
  • A font with only bitmaps is measured from its strikes, where NISC18030's glyphs advanced half an em and its
    ascender read 0.

Variations and instances

  • Metrics, names and styles answer at the location they're asked for. ascender, descender, cap_height,
    line_metrics, os2, italic_angle, pdf_flags, style, family_name, names, name and stat read the
    default instance; each now reads the tables of its location.
  • A design value normalizes in 32-bit float, rounded once. Rounding it to 16.16 first put 1,322 of 2,212,335
    settings over 71 variable faces a 2.14 step from where fonts expect them, Skia's width at 0.7 among them.
  • avar reads the maps fonts ship. A map of one pair shifts every value by it, and a value outside a map's pairs
    shifts by the nearest.
  • A variable font draws and hints at a location a glyph at a time, in 16.16 with no 2.14 step, where every glyph was
    instanced at once first, so Inter at wght 777.7 opsz 17.3 drew 429 glyphs a unit off. An instance's advances and boxes
    now match the live glyphs at all 1.57 million glyph locations checked.
  • A location the instancer can't build reports why, where instance and instance_tables returned the font as
    stored.
  • A CFF2 font's instance is static CFF2, desubroutinized, where it was CFF, and keeps BlueScale and the other
    fractional Private DICT values, where Source Serif's 0.0375 was written 0.
  • 27 more fixes, most for fonts that break the spec.

Layout tables

  • A short tag is padded with spaces, as fonts store it. feature_tags(Some("latn"), Some("DEU")) gave nothing and a
    short feature or script in shaping was dropped.
  • Lookups match as fonts expect. A mark filtering set the font lacks filters nothing, where every mark was skipped,
    and a ligature counts each glyph's components within its own ligation.
  • A failed match marks what it read unsafe to concat, so text split there shapes the same when joined: in Noto Sans
    Devanagari, 1,191 of 6,000 random strings lacked a flag they needed.
  • 7 more fixes, most for fonts that break the spec.

Shaping

  • A shape spends a budget of operations, 4,096 a character and at least 65,536, which stops morx and kerx machines
    as it stops GSUB and GPOS.
  • A run that grows keeps every glyph, where a substitution that grew a run early cut its output short: San Francisco
    shaped a sentence of 65 glyphs as 35, and Arial its 70-character Yoruba sentence as 49.
  • Safe-to-break holds its promise. Text broken where a run says it may, and shaped in two pieces, now gives the
    glyphs the whole run did. Spans past 255 glyphs, edits joining glyphs at levels that keep them apart, kern and kerx
    shifts across the line and pushes past the stack, AAT actions reaching back past a break, ranged features stopping a
    morx machine, Arabic joining at a run's edges, a character normalized by what stood beside it, and a side of a break
    reading as a number each called a break safe that wasn't.
  • A font with morx leaves shaping to it. A script's own shaper gives way to "dumber", which adds no features, masks
    or reordering: Skia's lone U+0300 down a line sat at y −279 and now sits at −2,327.
  • A morx ligature builds on the ligature before it. Lucida Grande, Athelas and Zapfino shaped "ffi" as ff and i.
  • Apple kern tables kern. Format 1 state machines and format 3 class tables kerned nothing; Geeza Pro, Waseem,
    Farisi, Mishafi and Diwan Thuluth's Arabic and Skia's Latin kern now. kerx format 2 reads its classes as the byte
    offsets Apple's spec stores, so Malayalam MN no longer kerns by 0 a pair that holds −60.
  • AAT fonts take requested features and the text's language, through the font's feat table and Apple's mapping of
    OpenType features: Baskerville takes its Serbian forms in Serbian text.
  • trak tracks only a font with a STAT, so Skia, Hoefler Text, Apple Color Emoji, Apple Chancery, AppleMyungjo and
    Hiragino are no longer tracked.
  • Language tags reach the systems fonts hold. A tag reaches up to three, most specific first: Inuktitut its Nunavik
    forms in Euphemia, Iranian Persian its Persian digits in Noto Nastaliq. Chinese reaches its systems by script, then
    region, as CLDR's likely subtags give them, a tag with a script, region or variant falls back on its language, and a
    language's own systems come before its macrolanguage's.
  • 28 more fixes, most for fonts that break the spec.

Scripts

  • Every script takes its shaper and direction. Garay and Sidetic run right to left, and the scripts Unicode 18.0.0
    adds take the Universal Shaping Engine. The Hangul fillers and Duployan's format controls, which fonts draw, are no
    longer hidden.
  • Fullwidth punctuation turns in vertical text. vertical_form (C: daegun_vertical_form) gives the twelve
    fullwidth punctuation marks' vertical forms.
  • A font with no Arabic forms in its layout tables shapes Arabic by fallback, through the presentation forms its
    cmap maps: each letter's contextual form and the lam-alef ligatures Unicode makes obligatory.
  • Arabic matches across a ZWNJ and stretches as fonts expect. 31 of 784 letter pairs around a ZWNJ shaped otherwise
    in Noto Nastaliq Urdu, and a font with rclt takes calt in rclt's stage. stch repeats only the tiles that repeat, where
    Noto Sans Syriac stretched to 497 glyphs for 375.
  • Indic and Myanmar reordering reads each sign as fonts expect. After a conjunct, Gurmukhi Yakash made the wrong
    consonant the base, so 100 of 150 Yakash sequences in Arial Unicode shaped differently.
  • Indic, Khmer and Myanmar syllables follow Microsoft's specifications. Khmer has a grammar of its own, so a fourth
    coeng opens a broken cluster; Myanmar puts Pwo tones before visargas; Indic sequences the Devanagari specification
    doesn't allow take a dotted circle. The Universal Shaping Engine reorders, decomposes and classes as its data says:
    Newa and Modi put a repha before their post-base vowel signs.
  • Hebrew composes only to its presentation forms. In a font without GPOS marks, yod and patah composed to U+FB1F;
    they stay apart now.
  • Hangul is positioned and flagged as other text is, taking kern and fallback mark placement.
  • 10 more fixes, most for edge cases.

Unicode and script runs

  • shape_bidi cuts each bidi run where its script changes, so the Arabic of "עולם, مرحبا" no longer shapes with the
    Hebrew shaper and keeps its joining forms.
  • Text with no strong script stays one run, so a variation selector, ZWJ or combining mark after a symbol, emoji or
    digit shapes with it: the emoji family, ❤️ and keycaps.
  • Brackets, marks and Script_Extensions decide script runs, as UAX #24 asks: a closing bracket takes the script its
    opening bracket took, and a combining mark stays in its base's run.
  • 2 more fixes, for edge cases.

Carets and text layout

  • caret_positions follows clusters, bidi runs and scripts. A cluster of several glyphs spans them all, split at a
    ligature's carets or evenly, where its inner characters sat at 0, and digits in right-to-left text no longer come out
    reversed.
  • Tabs reach their stops, LayoutOptions::tab_size spaces apart, where a tab drew as the font's .notdef.
  • A line broken at a soft hyphen shows a hyphen, U+2010, else U+002D, and is measured with it.
  • Each paragraph finds its own direction, as UAX #9's P1 asks, and under an infinite measure, the default, lines
    align against the widest one.
  • A word no line can hold is cut between graphemes, as CSS's overflow-wrap: anywhere cuts it, where Thai laid out
    to 3,000 units made one line 21,394 wide.
  • A line is measured as it's drawn, so lines no longer draw past the measure.
  • 5 more fixes, for edge cases.

Subsetting

  • A subset closes over GSUB through each feature's lookups over the request, so it keeps fewer glyphs: Noto Sans
    Devanagari's "किसी भी" kept 149 and keeps 13.
  • A layout subset writes each shared part once. GSUB, GPOS and GDEF are written as one graph, where Inter's GSUB
    came out at 39,290 bytes from 24,406, and every text subset shapes as its font does.
  • A text subset keeps every character and sequence shaping its text can reach: decompositions, compositions,
    vertical forms, mirrors, the space and the dotted circle. Hiragino's Greek ά, Gill Sans's ≠ and Tahoma's Thai came out
    as .notdef in their subsets.
  • A subset of a morx or kern font shapes as its font does. Lucida Grande's ffi stays in a subset of "ffi", the
    Arabic kern fonts' subsets kern, and Times's subset of five accented letters holds 60 glyphs, where it held 879 and
    dropped morx.
  • A subset keeps exactly the bitmaps its font draws, where every subset dropped Geneva's and AppleMyungjo's 24 ppem
    strikes, and NISC18030, bitmap-only, subsets now.
  • 34 more fixes, most for fonts that break the spec.

Everything else

  • MATH's values and a CFF2 glyph's stems answer at a location, where they read the default alone, and an instance
    bakes MATH's variation deltas into its values.
  • A full cache drops its least recently used entries and keeps the rest, where overflow emptied a whole cache.
  • sin_cos is within an ulp of std for every finite argument, where it was 5.8 million ulps off inside ±40 rad, and
    sin_cos_degrees is exact on every quarter turn.
  • 5 more fixes, most for fonts that break the spec.

The C interface

  • A yes or no has one type, bool, where it was an int32_t in nine calls, a uint16_t in OS/2's info and a
    uint8_t in paint nodes and STAT values, so a call could write four bytes into a caller's one-byte bool.
  • The headers are plain ASCII, so MSVC at a Chinese, Japanese or Korean code page reads them under /WX.
  • The C ABI builds for 32-bit targets, the headers checking their layouts under C and C++.
  • A script is named by its ISO 15924 code, which no release renumbers, where 1.2.0's numeric id held for one build.
  • Text that isn't UTF-8 is refused, with DAEGUN_INVALID_ARGUMENT and the byte where it stops being UTF-8, where it
    answered DAEGUN_NULL or was dropped.
  • Every failure gives its reason in daegun_last_error, where 31 calls left an earlier failure's, and a failed call
    leaves its outs as they were.
  • 12 more fixes, to the headers' wording and for edge cases.

Performance

Figures come from one machine, most the median or the best of three or more rounds. Before
is the code before the change that moved the figure, or before the first of several. The headline rows are below.

Area Operation Before Now
Opening Font::from_vec, Inter 3.4 µs 318 ns
Metrics ascender, descender and cap_height 3.4 ns 0.5 to 0.8 ns
Lookups glyph_id, a code asked again, Inter 25.2 ns 0.7 ns
Lookups advance, one glyph, Inter 18.5 ns 1.2 ns
Lookups advances down the page, ten glyphs at a location, Inter 207.4 ns 49.6 ns
Lookups Naming every glyph one at a time, DecoTypeNastaleeqUrdu 2.25 s 2.1 ms
Shaping Inter's sentence 6.83 µs 6.00 µs
Shaping A fresh font's first shape, Inter 312 µs 180 µs
Shaping First shape at a location, ThonburiUI and Skia – 0.21× and 0.24× the time
Shaping Inter down the page 8,875 ns 4,008 ns
Shaping shape_bidi again, Scheherazade New's Arabic 7.92 µs 1.52 µs
Shaping daegun_font_shape from the shape cache, Inter's sentence 38.5 ns 22.7 ns
Hinting Bytecode, a glyph hinted by a kept context at 16 px 1.29 µs 875 ns
Hinting Autohinting all of Inter 6.48 ms 3.83 ms
Drawing prepared_outline, Inter's g at 16 px 767 ns 326 ns
Drawing glyph_bounds, Inter 777 ns 340 ns
Drawing Path::stroke_simplified, Inter's g in font units 6.03 ms 363 µs
Drawing resolve_overlaps, Inter's g flattened for 16 px 17.0 µs 4.0 µs
Drawing A VARC glyph, an ideograph 6.26 µs 3.14 µs
Color paint_graph, Noto COLRv1, a glyph 244.6 ns 109.4 ns
Color Paint graphs of test_glyphs_variable at a location 460.9 µs 27.0 µs
Color bitmap, Noto Color Emoji's 😀 at 64 ppem 107 ns 27.7 ns
Names daegun_font_names, every name, Inter 6.04 µs 3.81 µs
Variations A weight never seen, Inter's sentence shaped there and each glyph drawn 98.44 µs 26.58 µs
Text Thai line breaking with the word lists 1.82 ms 183 µs
Subsetting Hoefler Text's text subset 729 µs 543 µs
Instancing A CFF2 instance, Source Han Sans at wght 250 60.9 ms 70.6 ms
Instancing instance again at one location, Inter 7.17 µs 25.1 ns
Threads A shape on one shared font at 8 threads, Source Han Sans 2,747 ns 1,165 ns
Threads A shape cache hit at 8 threads, Inter 1,176 ns 28 ns
Threads outline at 8 threads on one font, Inter 7,975 ns 350 ns
Threads A new location each call at 8 threads, Inter 10,944 ns 219 ns
  • Opening and lookups. The directory is read into one sorted list and a font reads its tables where they lie rather
    than copying them: over 828 faces the fonts hold 54.5 MB less. A font keeps the glyphs of its 256 most recent codes in
    front of its cmap, and C writes every list of fixed-size items into the caller's buffer, so one kept between calls
    means none allocates.
  • Shaping. Lookups are gated by 256-bit glyph digests, indexes are built once a font straight from its coverages,
    and an OpenType shape allocates nothing once its buffer is made. A run is shared rather than copied, so shape_bidi
    and justify take theirs from the shape cache as shape does.
  • Drawing, hinting and color. A location builds no instance, each glyph varied when first drawn, and hinting
    contexts, the autohinter and prepared_outline lend their buffers from one glyph to the next, so a warm sweep
    allocates nothing. A COLR version 1 glyph's paints are read where they lie and a paint graph is one arena. A CFF2
    instance takes longer, as it's written as static CFF2, desubroutinized.
  • Threads. One font serves many threads at nearly the cost of a font each: what a font builds when first read is
    read with one atomic load rather than a lock, each thread keeps its own shaping buffer, hinting contexts and recent
    runs, and a font's runs are split over 16 lists no shape waits on. Three things still cost more on one font: outline
    at a location while its glyphs are first drawn, 613 ns against 405; misses of the run cache, 1.8× a font each; and
    instance at a kept location, 205 ns against 14, as every thread writes one shared count.