2.0.0 release notes
Released
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 isadvance * 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, andhinted_outline, whose points aref32pixels whereHintedOutlineheld 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 namedbytes),TextLayout::truncated, line breaks, grapheme and word boundaries, script runs, a bidi paragraph’s levels and visual order, and the offsets aWordSegmentergives 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_positionsgivestext.len() + 1carets, every byte of a character at its leading edge.
Locations
- A variable font’s axes are resolved once,
font.location(&[(Tag, f64)]), into aLocationthat every call depending on one takes by reference, where each call tookaxes: &[(&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, sowght=400made by a font whose default it is still means 400 to one whose default is 250.normalized_axesisLocation::normalized, andLocation::coordsgives the resolved coordinates.math_constants,math_italics_correction,math_top_accent_attachment,math_kern,math_glyph_variantsandcff_hintstake aLocation, as the BASE calls do. Each read the default alone.
Errors
- One
daegun::Error, withkind()(ErrorKind:Malformed,Unsupported,Missing,InvalidArgument,LimitExceeded,NoOutline,Overflow) andmessage(), anddaegun::Result, replaceFontErrorandQuadError. - A call returns
Resultwhere it can fail for a reason to act on: opening,instance,instance_tables, subsets and closures,outline,quads,prepared_outline,color_scene,math_kernandraw::build_font, which refuses more than 65,535 tables, or a table that starts 4 GiB into the file or is that long.Optionmeans the font has none of something. Rust gets every reason C does.
Types
Tagwherever a tag goes,Tag::new(b"wght")or parsed from a string, in place of&strand[u8; 4]. A string parses as one to four printable ASCII characters, padded with spaces, as the specification has a tag; anything else is anInvalidArgumenterror.GlyphId, a transparentu32, wherever a glyph goes, for fonts past 65,535 glyphs: a run holds 4 bytes a glyph where it held 2.charis a code point, soglyph_id,has_glyph,variation_glyph_idandcoveragetake or givechars.- Enums replace bools:
Orientationforvertical,BaseDirectionforOption<bool>in bidi,Adjustmentforshrink(shape_justified’s argument andJustified::adjustment) andFontStylefor a style string.unicode::vertical_orientationgives a character’sVerticalOrientation(UAX #50’s four values) whereis_upright(c, has_vertical_form)gave a bool, andScript::directionaScriptDirectionwhereis_rtlgaveOption<bool>. - A name table ID is a
NameId, with the specification’s IDs as constants (NameId::FAMILY_NAMEand the rest), wherever one goes:name, the keys ofnames,Axis::name_id,Palette::name_idandpalette_entry_labels. - Every public type is
Debug.LocationisEqandHashby the values it was asked for, so it keys a map. Results that hold data alike areCloneandPartialEq. Results areSend + Syncin every build, andFontandLocationare withthreading. Bounds { x_min, y_min, x_max, y_max }is every box.ColrLayer, palettes and BASE’sExtentsare named structs, not tuples.ShapeOptions,LayoutOptions,JustifyOptions,OutlineOptionsandSceneOptionsare#[non_exhaustive], built fromDefaultor theirDEFAULT(JustifyOptionsfromnew) with theirwith_*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. AStrokeStyleisStrokeStyle::new(width)withwith_joinandwith_cap, aGradientisGradient::new, andJstfModListsandItemVariationStorestart fromDefault. Plain values (GlyphId,Bounds,Point,Offset,Feature,Rgba,Stop,Rect,WordSegmenter),raw::format’sEntryandRegionAxis, and sets a specification closes (Orientation,Direction,Verb,FillRuleand 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, soScript(n)and.0are gone. A script comes fromscript_runs, a constant such asScript::ARABIC,Script::from_iso15924orparse, 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’sFvarAxis),NamedInstance,FontStyle,GlyphClass,CacheandCacheStats. Every other item moved to its area’s module:metrics,shape,layout,unicode,outline,color(1.2.0’spaint, with the color glyph calls’ types),math,tables,raw(bytes,format,build_font,parse_locaandoutline_glyf_bytes) andraster. daecoreis private. What it held that a caller needs is in those modules.
One call a job
- Opening.
from_ttcisfrom_collection, which opens a font file at index 0 asfrom_bytesdoes, andttc_font_countisface_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.upmisunits_per_em,num_glyphsisglyph_countandbboxisbounds.from_vectakes a face index, 0 for a font file, asfrom_staticdoes. - Names and instances.
name_stringisname(NameId, &Location).instancegives the instance as shared bytes, anArc<[u8]>that its location’s cache hands out again without a copy.instanceandinstance_tablesreturn the instancer’s error at a location it can’t build, where they returned the font as stored;instance_tableskeys its tables byTag, andtable_tagsis an iterator. - Metrics. Every metric takes a
Location.os2_infoisos2,stat_infoisstatandflagsispdf_flags, a typedPdfFlags.line_metricstakes anOrientation, andTypoLineMetricsfolds intoLineMetrics.typographic_metricsgives each part as anOption, so a missing field is no longer 0, andSubSuperMetricsisScriptMetrics. - Glyphs.
advance_widthsisadvances(glyphs, &Location, Orientation, &mut out), filling the caller’s buffer after clearing it.vertical_advanceisadvance(glyph, &Location, Orientation).codepointsfolds intocoverage, which withglyph_idsis an iterator where they gave aVec.mark_attachment_classreturnsOption<NonZeroU32>, none for no class where it gave 0, andvertical_originreturnsf64.glyph_namereturnsOption<&str>andglyph_namesan iterator of them, each name lent from post or CFF where it was aString. - Shaping.
shape(text, &Location, &ShapeOptions)returnsArc<ShapedRun>in every build, where it was anRcwithoutthreading, and replacesshape_with_language,shape_with_featuresandshape_with_options; every run shaping gives comes as anArcalike.shape_bidi_withfolds intoshape_bidi, andmeasure_widthintoShapedRun::width. Calls that never failed return their values rather thanOptions:shape,shape_bidi,shape_justified,layout,justifyandcaret_positions. - Runs. A run’s offsets are
Offsets,xandy, and the bytes a script run, a bidi run, a laid-out run, a line and a visual run cover are acore::range::Range<usize>,bytes, where a script run’s were itsstartandend, 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 isCopy, andstart..endstill builds the oldercore::ops::Range, which.into()turns into one and back. A run’sshaperis aShaperwhere it was a&'static str;Shaper::namegives the string it was. - Features. A
Featureis a tag, a value and the bytes it holds over;Feature::new(tag, value)covers the whole text, as a pair did.ShapeOptionsnames an OpenType script as aTag, takes adirectionin place ofvertical, and gainsnot_found_glyphandnot_found_variation_selector_glyph. - Layout.
justification_extendersfolds intojustification_glyphs.shape_justifiedtakes anAdjustment, andLayoutOptionsaBaseDirection,tab_sizeandsegmenter. A LangSys tag is alanguage_system(JustifyOptions::language_system,justification_priorities(script, language_system)), aslanguagenames a BCP 47 tag.resolve_bidiisBidiParagraph::new, andline_visual_runsis itsvisual_runs, which takes the line as any range of bytes,..for the whole text. - Outlines.
outline_glyphandoutline_glyph_instancedareoutline(glyph, &Location, pen).hinted_glyphishinted_outline, which returns aResult,InvalidArgumentfor a px not finite or not above zero, andglyph_quadsisquads.draw_hintedisHintedOutline::draw.QuadraticPen::newtakes a tolerance.HintMode::SubpixelisHintMode::Font, the font’s own bytecode or CFF hints;HintMode::Classicis gone. - Points. A path’s points, contours and a hinted outline’s points are
Points, a hinted point coming with itsPointKindwhere it came with flags.Verbholds one byte,Move0 toClose4. A CFF hint mask is aCffMask, where it was a pair. AQuadis a struct of threePoints where it was[[f32; 2]; 3], laid out the same. - Strokes and limits.
stroke,stroke_simplifiedandflattenarePath’s methods and return aResultsaying why they drew nothing, and an embolden not finite isInvalidArgument, where it was ignored.MAX_RESOLVE_EDGESandMAX_CURVES_PER_GLYPHare gone:resolve_overlapsandquadstake an outline of any size (Security). - Pens.
TransformPennames its pen’s type as a parameter:TransformPen<'_, Path>over a path, andTransformPen<'_, dyn OutlinePen>over any pen, whichTransformPen<'_>was.Path::replay,PathView::replayandHintedOutline::drawtake 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_sceneandcolr_scene_witharecolor_scene(glyph, &Location, &SceneOptions).colr_v1_paintispaint_graphandcolr_v1_visitisvisit_paint_graph, and the graph typePaintisPaintGraph, named apart from a scene’sPaint.colr_layers_for_palettefolds intocolr_layers,palette_infoispalettes, andglyph_bitmapisbitmap, which lends a PNG from the font where it copied it, so aGlyphBitmapand itsBitmapImageborrow the font. A transforming paint’scenteris aCenter,xandy, andBlend::compositegives aPremultiplied,colorandalpha, where each was a pair. A scene’sPathIdandGradientIdare types of their own where both wereusize. - Caches. The four
set_*_bytescalls and their stats areset_cache_budget(Cache, bytes)andcache_stats(Cache), andclear_shape_cacheandclear_prewarmareclear_cache(Cache).set_cmap_index_allowanceisset_index_allowance, as it governs every index a font and its locations build. Underthreadinga 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_infoisbase_script(script, &Location, orientation), giving aBaseScript,base_extentsgivesExtents, andbase_is_glyph_freeishas_glyph_free_base.feature_tagsandlanguage_system_tagsname a LangSys taglanguage_system.SubsetResultisSubset, whose bytes arefontand whose map reads throughrenumbered.subsetandsubset_texttake aLocation, which the subset is pinned to. - Raster.
MAX_SUBPIXEL_TAPSandMAX_SUBPIXEL_WEIGHTSareraster::MAX_TAPSandMAX_WEIGHTS,SubpixelLayout::unfilteredtakes anOrientation, andSubpixelLayout::GRAYSCALEis private;grayscale()andDefaultremain.
Color scenes and paint graphs
- A color scene keeps its paths, clip shapes and gradient stops in one buffer each.
DisplayList::pathgives aPathView, which reads, replays and bounds as aPathdoes and copies one out withto_path.Paint::Gradientholds aGradientId, whichDisplayList::gradientreads, andOp::PushClipa range of shapes, whichDisplayList::shapesreads.push_pathtakes aPathView,Path::viewgives one, andpush_gradientandpush_shapesadd the others.OpandPaintareCopy. color::lowertakes the glyph, itsPaintGraphand a clip-box lookup givingBounds, and itsoutlinedraws a glyph into the pen it’s handed, true where it drew.resolve_stopsisStops::resolve, which takes the extend mode.Gradientborrows its stops.- A
PaintGraphholds a graph’s paints in one list and their stops in another, where it was an enum of boxed children.root()gives aPaintRef, whosenode()is the paint’s own fields as aPaintNode, withExtendandBlendin place of raw codes, andchildren()the paints below it. APaintGraphis aPaintVisitor, soPaintGraph::withbuilds one by hand.ColorStopisCopy.
Readers
raw::outline_glyf_bytestakesextendedafterglyf, true where the bytes are GLYF’s.raw::format::coverage_indexreturnsOption<u32>,coverage_glyphsgivesu32ids from Coverage formats 1 to 4, andLookup::entriesgivesGlyphValues, au32glyphand itsvalue, where it gave(u16, u16)pairs.Ankr::anchor_pointandcontrol_pointgive anAnchorPoint,xandy, where they gave a pair.raw::format::FeatureVariations::findtakes GDEF’s variation store,find(coords, store), and returns the record as au32, whichsubstitutetakes;substitutereturnsOption<Substitution>, the alternate’s offset orEmpty, where 1.2.0 gave the offset alone, andwith_axis_countis gone.Lookup::parse,StateTable::parseandAnkr::parsereturn aResultnaming what failed, where they gaveNone.- A DeltaSetIndexMap’s entries are
DeltaSetIndexes,outerandinner, where they were pairs.parse_item_variation_store,precompute_region_scalarsandcompute_ivs_delta_f64areItemVariationStore::parse,region_scalarsanddelta, andankr_versionisAnkr::version.Script::opentype_tagsis an iterator over the tags it holds in place, where it collected aVec.
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. Underthreadinga 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"fromsrc/api/c/include, an umbrella over thirteen headers indaegun/, 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_versionandDAEGUN_ABI_VERSIONgive 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 fromdaegun-2.dllwhereDAEGUN_DLLis defined, andDAEGUN_NODISCARD. Each pointer that may be NULL is markedDAEGUN_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.dylibon macOS andlibdaegun.so.2on Linux.
Statuses
DAEGUN_PARSEandDAEGUN_RANGEareDAEGUN_MALFORMEDandDAEGUN_INVALID_ARGUMENT, their values kept. Five join them, one for each kind of Rust’sError: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_locationmakes adaegun_locationfromdaegun_coords, and every call that depends on one takes it, NULL being the default instance. 1.2.0’s calls tookaxes, axes_lenand 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, isdaegun_coord, its tag adaegun_tag.daegun_axisis now fvar’s record of an axis, whichdaegun_font_axeslists where it gave two parallel lists anddaegun_font_axis_flagstwo 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_HORIZONTALorDAEGUN_VERTICAL, where 1.2.0 tookbool vertical, and a JSTF adjustmentDAEGUN_ADJUST_SHRINKorDAEGUN_ADJUST_EXTEND, where it tookbool shrink; a code that names none of its constants answersDAEGUN_INVALID_ARGUMENT.daegun_font_justifygives the run and fills adaegun_justification, where adaegun_justifiedhandle lent the run. - Glyph ids are
uint32_teverywhere, where 1.2.0’s wereuint16_t, sodaegun_colr_layergrows from 8 to 12 bytes anddaegun_glyph_valuefrom 4 to 8. Every yes or no is abool, where nine calls used anint32_t, OS/2’s info auint16_tand paint nodes and STAT values auint8_t; a list of them still comes as bytes, 1 for yes.
Calls
- One call an operation, as in Rust.
daegun_font_shapetakes text, a location anddaegun_shape_options, where 1.2.0 had_shape,_shape_with_language,_with_featuresand_with_options;daegun_font_set_cache_budget,_cache_statsand_clear_cachetake aDAEGUN_CACHE_*;daegun_font_math_constantsfills one struct;daegun_font_palettesfills the caller’s buffer;daegun_font_justification_glyphstakes in the extenders; anddaegun_shaped_run_widthstands fordaegun_font_measure_width.daegun_font_open_ownedtakes a face index, asdaegun_font_open_staticdoes. - Names follow Rust’s, as the table below lists, and the other text calls lose their
daegun_text_prefix.daegun_face_countcounts a font file as one face, wheredaegun_ttc_font_countgave 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_systemwherever it goes:daegun_justify_options’ field and the script and feature calls’ arguments. daegun_font_base_scriptand_base_extentstake the location before the orientation, as every call taking both does.daegun_script_is_rtlisdaegun_script_direction, aDAEGUN_SCRIPT_DIRECTION_*, anddaegun_char_is_uprightisdaegun_vertical_orientation, a character’sDAEGUN_VO_*(UAX #50), where it took whether the font has a vertical form and gave a flag: upright is_UPRIGHT,_TRANSFORMED_UPRIGHT, or_TRANSFORMED_ROTATEDwith a vertical form. A run’s shaper is aDAEGUN_SHAPER_*, whichdaegun_shaper_namenames, where it was a string.daegun_font_glyph_namewrites the name and a NUL into the caller’s buffer,DAEGUN_MAX_GLYPH_NAME + 1bytes always room enough, where it handed out adaegun_text, anddaegun_font_glyph_namesgives 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_classanswersDAEGUN_ABSENTwhere GDEF gives none, where it answered 0. A hinted point’s kind is aDAEGUN_POINT_*, read throughdaegun_hinted_outline_kinds, where its flags were the bitsDAEGUN_FLAG_ON_CURVEandDAEGUN_FLAG_CUBIC, anddaegun_font_hinted_outlineanswersDAEGUN_INVALID_ARGUMENTfor a px not finite or not above zero, wheredaegun_font_hinted_glyphansweredDAEGUN_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_layersanddaegun_palettesgo, with their_dataand_free.daegun_font_namesgives onedaegun_names, each ID beside its string throughdaegun_names_atin ascending order of ID, where it gave adaegun_u16_listof IDs and adaegun_str_listof strings; thedaegun_u16_listgoes 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 answersDAEGUN_UNSUPPORTED.daegun_featuregainsstartandend; an end of 0 orUINT32_MAXruns to the text’s end.
Answers that changed in C
daegun_font_open*answersDAEGUN_MALFORMEDfor 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, answerDAEGUN_INVALID_ARGUMENT. daegun_font_instanceand_instance_tablesanswer the instancer’s failure at a location it can’t build, anddaegun_font_color_scenegives a color glyph that draws nothing as a scene with no ops, where it answeredDAEGUN_ABSENT.- Every failed call leaves a number or struct out as it was and sets a handle out to NULL, so
daegun_font_tableleaves its view as it was onDAEGUN_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 answersDAEGUN_INVALID_ARGUMENTbefore anything is written (Security). daegun_aat_lookup_parse,daegun_aat_state_table_parseanddaegun_ankr_parseanswerDAEGUN_UNSUPPORTEDorDAEGUN_INVALID_ARGUMENTas Rust’s parsers fail, where each answeredDAEGUN_MALFORMED.DAEGUN_HINT_SUBPIXELisDAEGUN_HINT_FONT, still 1, and takes CFF and CFF2 hints too;DAEGUN_HINT_CLASSICis gone.DAEGUN_MAX_RESOLVE_EDGESandDAEGUN_MAX_CURVES_PER_GLYPHare gone: overlap removal, quads, strokes and embolden take outlines of any size, where they answeredDAEGUN_ABSENTorDAEGUN_RANGEpast a cap.daegun_font_prepared_outlineanswersDAEGUN_INVALID_ARGUMENTfor an embolden not finite, where it ignored it, anddaegun_table_map_buildfor 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_originanswers for every glyph id.daegun_font_layout,daegun_font_instance_tablesand the shaping calls loseDAEGUN_ABSENTpathsdaegun.hnever documented, andDAEGUN_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,coverageand shaping read one cmap subtable, the best the font has, so a code only another subtable maps is unmapped. - Metrics.
pdf_flagssets Symbolic for nearly every real font;vertical_originand 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, andstyleanswersObliquewhere 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::Autochooses 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_scenegives 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_bidicuts each bidi run where its script changes,script_runskeeps text with no strong script as one run, and each paragraph finds its own direction.layoutcuts 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_positionsplaces a cluster at its whole extent. - Subsetting.
glyph_closureand 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_allowancegoverns 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
instanceand 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
justtable 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
bitmapon 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 underHintMode::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_SIDEandMAX_DRAW_BYTES, and a flattened path withinMAX_FLATTEN_POINTSpoints. - 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_bidicopied text quadratically.
The C interface
The C interface keeps its promises across releases and to every caller.
- ABI version.
daegun.hchecked 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_boundswasn’trepr(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&mutat 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:startandendindaegun_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::directionshapes a run in any of the four directions whatever its text says, as a caller running its own bidi needs.not_found_glyphdraws a character the font lacks with a glyph of the caller’s choice, andnot_found_variation_selector_glypha 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_segmenterandline_break_opportunitiestake a word segmenter of your own (C:segmenter), and thedictionariesfeature builds in word lists for the four scripts, about 1 MB. - A layout takes features.
LayoutOptions::with_features(C:featuresindaegun_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_graphhands each paint to aPaintVisitoras 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::Rasterizerdraws 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 mostMAX_SIDEpixels across or down andMAX_DRAW_BYTES(256 MiB) in its buffers. - Drawing into your own pixels.
Rasterizer::glyph_into,color_glyph_intoandpath_intodraw into aTarget, 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
SubpixelLayoutother than grayscale draws three bytes a pixel, filtered through its taps.RasterOptions::darkenwidens thin stems by the documented CFF curve, andRasterOptions::gammaturns 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_glyphdraws 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_fielddraws a glyph’s signed distance field, one channel (Field::Sdf) or three whose median keeps corners sharp (Field::Msdf). - The raster cache.
Cache::Rasterkeeps 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 withFont::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’sFromStr, which reads a feature as shaping tools and CSS write one (kern,-liga,aalt=2,kern[3:5]=0)unicode::script, a character’s scriptFont::from_static, which reads a font where it lies in bytes that live as long as the program, copying nothingFont::palette_colors,Font::localized_names,Font::has_overlap_flagandFont::visit_namesFont::shape_into, which shapes into a run of the caller’s, reusing its vectorsPath::flatten_into,Font::quads_intoandQuadraticPen::reusing, which reuse the caller’s listsCachePool,Targetand the rasterizer’s callsrelease_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_locationhandle,daegun_bounds, the five new statuses and a counterpart for each Rust call 1.2.0’s C lacked (Compatibility, C) daegun_tag_from_stringanddaegun_feature_from_stringdaegun_font_open_staticdaegun_font_shape_intodaegun_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_rasterizerwith its calls,daegun_raster_optionsanddaegun_target daegun_cache_pooldaegun_thread_release, which also drops the freed handles the thread keeps for its nextdaegun_status_nameanddaegun_version, for a log- 13 more, each in the headers
- The
Help from the compiler
- Rust. A call whose answer is its whole point warns where the answer is dropped. A type passed as an
OutlinePenor aPaintVisitorthat 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 ofunits_per_em. - C.
DAEGUN_ABI_MAJOR,DAEGUN_ABI_MINOR,DAEGUN_ABI_PATCHandDAEGUN_ABI_COMPATIBLEcheck the library a program loaded in one line, in#iftoo. GCC and MSVC’s/analyzeknow 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/Gvand/Gzand 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,RgbaorScriptcan key aHashMap.ShapeOptions,LayoutOptions,OutlineOptionsandSceneOptionshave aDEFAULT, and every options builder is aconst fn, so options can be a constant:&ShapeOptions::DEFAULTtakes a cached run 4% sooner than&ShapeOptions::default().prepared_outlinetakes any pen generically, so a pen of yours inlines into its scaling: 12% off a glyph. AnErrorconverts into anio::Error, so a loader returningio::Resulttakes?on opening a font.Os2gives usWeightClass, usWidthClass and fsType, the embedding rights a PDF writer reads before it subsets; C’sdaegun_os2has 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 teston 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. Withoutstd, it needs a target with atomic compare-and-swap at pointer width, as its docs now say.wasm32-unknown-unknownbuilds, with the default features and without. - C.
cargo cinstallinstalls the headers, the static and shared libraries, adaegun.pcand the license notices, the libraries and the.pcversioned 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 ordaegun-2.dllexports 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 withRUSTFLAGS="--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, anddaegun::daegunlinks 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.dllneeds 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
SHA256SUMSand aBUILDINFO, 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/daegunand Apple’s privacy manifest inshare/daegun, so two archives unpacked into/usr/localdon’t clash.daegun.dllisdaegun-2.dll, so plugins built against 1.2.0’s DLL and this one don’t share one in a process, and the headerdaegun/math.hisdaegun/mathtable.h, as on-Ia 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 ownLICENSE, so software shipping daegun ships that file too, as the release archives andcargo cinstalldo.
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_collectionandface_countread 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.
coveragestopped 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_originansweredNonefor 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_flagssets 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::Autochooses 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::Fonttakes these hints, whereSubpixelleft 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-palettefalls 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_sceneansweredNone, 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
bitmapreads 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,nameandstatread 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
instanceandinstance_tablesreturned 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,
kernand 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
kerntables 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
kernand fallback mark placement. - 10 more fixes, most for edge cases.
Unicode and script runs
shape_bidicuts 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_positionsfollows 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_sizespaces 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: anywherecuts 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
kernfont shapes as its font does. Lucida Grande’s ffi stays in a subset of “ffi”, the Arabickernfonts’ 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_cosis within an ulp of std for every finite argument, where it was 5.8 million ulps off inside ±40 rad, andsin_cos_degreesis 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 anint32_tin nine calls, auint16_tin OS/2’s info and auint8_tin paint nodes and STAT values, so a call could write four bytes into a caller’s one-bytebool. - 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_ARGUMENTand the byte where it stops being UTF-8, where it answeredDAEGUN_NULLor 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_bidiandjustifytake theirs from the shape cache asshapedoes. - Drawing, hinting and color. A location builds no instance, each glyph varied when first drawn, and hinting
contexts, the autohinter and
prepared_outlinelend 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:
outlineat a location while its glyphs are first drawn, 613 ns against 405; misses of the run cache, 1.8× a font each; andinstanceat a kept location, 205 ns against 14, as every thread writes one shared count.