Repository navigation
onedraw v3.8.4 — Release Notes
Highlights
- Inline markdown text — new
od_draw_md_string()draws one line of UTF-8 text with inline styling:*italic*,**bold**,~~strikethrough~~,`monospace`and\escapes. The markup picks the font family per run (unmarked text uses the regular face; baselines stay aligned on it), so there's no[font]parameter. - Sharper text — two quality fixes: glyphs now snap to the device pixel grid, and the coverage curve is gamma-corrected in the rasterizer.
- Hardened memory allocator — the vendored
vmem.h(used by the pre-build font-atlas builder) was rewritten over the release window: guard pages, immediate page release, ASan poisoning, and loud corruption detection, finishing at v0.0.2.
New API
od_draw_md_string(r, x, y, text, size_in_byte, size, color)— draws a single line with inline markdown styling. Parser rules of note:- a run opens a style only if its next character isn't whitespace or end-of-string, and closes only if the previous isn't whitespace or start-of-string — so
"2 * 3"and"a ~~ b"stay literal; - an unclosed opener styles the rest of the line; bold wins over italic; nothing is parsed inside a code span (content is literal up to the next backtick);
\*\~\`\\escape the literal character; a backslash before any other character is drawn as-is.
- a run opens a style only if its next character isn't whitespace or end-of-string, and closes only if the previous isn't whitespace or start-of-string — so
od_md_string_width(r, text, size_in_byte, size)— width of the string as drawn, markup excluded, in canvas units.od_draw_string_view()/od_string_view_width()were refactored internally to share the glyph-run walker with the markdown renderer; their public signatures and behavior are unchanged.
Text rendering fixes
- Pixel-grid glyph snapping — each glyph's top-left is rounded to the device pixel grid (the pen stays fractional, so rounding never accumulates). At scale 1 the pixel centers then land exactly on the atlas texel centers, so the bilinear filter copies the baked coverage instead of blending two texels — noticeably crisper text at 1× displays.
- Gamma-corrected coverage — text coverage is blended in linear light (both backbuffer modes), where a 50%-edge pixel of dark text on a light background displays as ~73% grey and looks washed out. The rasterizer now reshapes the sampled coverage with a gamma that runs from 1/1.6 for black text to 1.0 for white text (already bolded by linear blending), pushing edge pixels toward opaque. Regression references regenerated.
- Doc fix — the
od_set_canvascomment no longer claims text sizes/advances are unscaled screen pixels; they are canvas units like every other coordinate (the face is picked fromsize × canvas scale). The behavior itself dates from v3.7.1; the comment was stale.
Memory allocator & build tooling
The pre-build font-atlas builder (which bakes lib/default_font_atlas.h) went through a full allocator overhaul over this window:
- arena.h → vmem.h — the 454-line vendored
arena.h(Linux-mmap backend) was replaced by a small reserve-onlyvmem.hpool: it reserves address space and the OS commits pages on first touch, so the builder's 32 MiB worst-case reservation costs no RAM until touched. - Stack allocator — the builder allocates through vmem's canary-protected stack allocator; the sizing-search scratch buffer is popped after the search, which doubles as an out-of-bounds-write detector.
- vmem.h 0.0.2 (final hardening):
- every arena is fenced with
PROT_NONEguard pages at both ends — running off either end faults immediately; vmem_release()remaps the range as fresh anonymous pages instead ofmadvise(MADV_FREE)— pages are returned to the OS immediately (footprint drops right away) and read back as zeros;- under AddressSanitizer, unallocated arena space, per-allocation padding, stack trailers and freed ranges are poisoned, so OOB and use-after-free are reported at the faulting instruction;
stack_pop()now takes the pointer that was allocated — an out-of-order free fails loudly; newstack_mark()/stack_rewind()/stack_check();- corruption (bad canary or invalid trailer) invokes the
VMEM_ON_CORRUPT(s)hook — default: message + trap — instead of the old silent degrade-to-NULL.
- every arena is fenced with
- Builder bug fix —
gather_face_rects()passed a 1×1 dummy size with 1-px padding to the packer, which divides by(width − padding)→ divide by zero; the dummy is now 16×16.
The generated font atlas is unchanged by any of this — the runtime library's baked assets are byte-identical.
Testing
- The test scene now renders eight markdown lines exercising every syntax rule (styles, nesting with bold winning, literal fallbacks, unclosed openers), plus a width check: a line drawn on a box of its
od_md_string_width()size reaches the box's right edge exactly. - Regression references (
primitives.png,primitives_highdpi.png) regenerated to match the text quality fixes.