Measure rendered text without drawing it
akbasic needs the advance width of one character cell to build a terminal-style
text surface, and the wrapped size to know where a string crosses the right
margin. akgl_text_measure and akgl_text_measure_wrapped report both over
TTF_GetStringSize and TTF_GetStringSizeWrapped; neither needs a renderer, so
this half of the text subsystem is testable without the offscreen harness.
A negative wrap length is refused with AKERR_OUTOFBOUNDS: SDL_ttf reads it as a
very large unsigned width and quietly stops wrapping, which would return a
measurement that is wrong rather than an error the caller can see.
Also fixes akgl_text_loadfont, which checked name twice and passed an unchecked
filepath to TTF_OpenFont (TODO item 39).
The fixture font is a 10 KB monospaced ASCII subset of Liberation Mono, renamed
because "Liberation" is a Reserved Font Name; see
tests/assets/akgl_test_mono.LICENSE.txt. Monospaced so the suite can assert
width("AAAA") == 4 * width("A") rather than hardcode glyph metrics.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
15
TODO.md
15
TODO.md
@@ -352,6 +352,9 @@ overlap the existing **Defects** list are cross-referenced rather than repeated.
|
||||
`name` a second time; `filepath` is never checked and is passed straight to
|
||||
`TTF_OpenFont`. Copy-paste of line 18.
|
||||
|
||||
**Resolved** alongside the text measurement work; `tests/text.c` asserts a
|
||||
NULL filepath reports `AKERR_NULLPOINTER`.
|
||||
|
||||
40. **`akgl_path_relative` and `akgl_path_relative_from` disagree on the output
|
||||
parameter.** `akgl_path_relative` and `akgl_path_relative_root` take
|
||||
`akgl_String *dst`; `akgl_path_relative_from` takes `akgl_String **dst`
|
||||
@@ -654,6 +657,18 @@ a consumer is the wanted outcome. Each entry says what the BASIC verb needs, wha
|
||||
This is the only one of the four that blocks work already designed and waiting. **`akbasic`
|
||||
cannot render any output through `libakgl` until it lands.**
|
||||
|
||||
**Resolved.** `akgl_text_measure(font, text, w, h)` and
|
||||
`akgl_text_measure_wrapped(font, text, wraplength, w, h)` are in
|
||||
`include/akgl/text.h`, over `TTF_GetStringSize` and `TTF_GetStringSizeWrapped`.
|
||||
Neither needs a renderer. A negative `wraplength` is refused with
|
||||
`AKERR_OUTOFBOUNDS` rather than passed through, because SDL_ttf reads it as a
|
||||
very large unsigned width and silently stops wrapping. `tests/text.c` covers
|
||||
both against `tests/assets/akgl_test_mono.ttf`, a 10 KB monospaced ASCII
|
||||
subset added for the purpose — being monospaced, it lets the suite assert
|
||||
`width("AAAA") == 4 * width("A")` instead of hardcoding glyph metrics that
|
||||
FreeType is free to round differently. Same change fixed item 39 below:
|
||||
`akgl_text_loadfont` checked `name` twice and never checked `filepath`.
|
||||
|
||||
2. **No immediate-mode drawing.** `include/akgl/draw.h` declares exactly one function,
|
||||
`akgl_draw_background(int w, int h)`, and `src/draw.c` is at 0% coverage. BASIC 7.0's
|
||||
graphics verbs are all immediate-mode plotting against the current screen: `DRAW` (line and
|
||||
|
||||
Reference in New Issue
Block a user