diff --git a/apps/drawtest.c b/apps/drawtest.c index b453a99..21d5d8f 100644 --- a/apps/drawtest.c +++ b/apps/drawtest.c @@ -37,6 +37,16 @@ int main(void) { CHECK(13, dsn_bitmap(200, 10, 8, 8, large, sizeof large, 1, 32768, DSN_BITMAP_BW, DSN_BITMAP_CENTER, DSN_BLACK, 0) == -1); CHECK(14, dsn_bitmap(200, 10, 0, 0, smiley, sizeof smiley, 8, 8, DSN_BITMAP_BW, DSN_BITMAP_CENTER, DSN_BLACK, 0) == -1); + // Fixed font IDs use the same selection for measurement and drawing. + for (int font = DSN_FONT_NOTOSANS_12; font <= DSN_FONT_NOTOSANS_18; ++font) { + int height = dsn_line_height(font); + unsigned size = dsn_measure_text("fixed", 5, font, 0); + CHECK(26, height > 0 && (int)(size & 0xffff) == height); + CHECK(27, dsn_text_box(0, 200, w, height, "fixed", 5, font, 0, 1, 0) == 0); + } + CHECK(28, dsn_line_height(255) == dsn_line_height(DSN_FONT_SMALL)); + CHECK(29, dsn_text_box(0, 200, w, lh, "fallback", 8, 255, 0, 1, 0) == 0); + // Button hints: the host's band fits the drawable area, and labels it // cannot draw are refused (a fifth line, a control byte, an overlong one). CHECK(21, d.hint_height <= h); diff --git a/docs/writing-apps.md b/docs/writing-apps.md index 32f2617..109a30a 100644 --- a/docs/writing-apps.md +++ b/docs/writing-apps.md @@ -182,7 +182,12 @@ Colors: `DSN_WHITE / DSN_BLACK / DSN_LIGHT_GRAY / DSN_DARK_GRAY`, and for `dsn_fill` only `DSN_SCRIM`: light-gray ink over what is already there, for dimming behind a dialog. Whether the background shows through depends on the firmware's renderer; on one that cannot, it looks like `DSN_LIGHT_GRAY`. -Fonts: `DSN_FONT_SMALL / _BODY / _TITLE`. Text flags: `DSN_TEXT_BOLD / _INVERTED`. +Fonts: `DSN_FONT_SMALL / _BODY / _TITLE`, or optional fixed-size +`DSN_FONT_NOTOSANS_12 / _14 / _16 / _18` (slots 4–7). +Hosts bind these slots to their available fonts; always measure the actual +line height and text width rather than assuming a particular pixel size. +Slot 3 remains reserved for host label chrome. Unknown IDs use SMALL. +Text flags: `DSN_TEXT_BOLD / _INVERTED`. Calls that can fail on bad input (`text_box`, `bitmap`) return `-1`; check it during development. The host silently refuses anything out of range — it never diff --git a/freeink/DessenFreeInk.cpp b/freeink/DessenFreeInk.cpp index cdca867..83b4c3d 100644 --- a/freeink/DessenFreeInk.cpp +++ b/freeink/DessenFreeInk.cpp @@ -135,7 +135,9 @@ Paint paint(uint32_t color) { TextStyle textStyle(uint32_t font, uint32_t align, uint32_t maxLines, uint32_t flags) { TextStyle st; - st.font = static_cast(font <= DSN_FONT_TITLE ? font : DSN_FONT_SMALL); + st.font = static_cast(font <= DSN_FONT_TITLE || + (font >= DSN_FONT_NOTOSANS_12 && font <= DSN_FONT_NOTOSANS_18) + ? font : DSN_FONT_SMALL); st.align = align == DSN_ALIGN_CENTER ? TextAlign::Center : align == DSN_ALIGN_RIGHT ? TextAlign::Right : TextAlign::Left; st.maxLines = static_cast(maxLines < 1 ? 1 : maxLines > 16 ? 16 : maxLines); st.bold = flags & DSN_TEXT_BOLD; diff --git a/freeink/test_host.cpp b/freeink/test_host.cpp index f722d5e..e8ec2d2 100644 --- a/freeink/test_host.cpp +++ b/freeink/test_host.cpp @@ -422,6 +422,25 @@ int main(int argc, char** argv) { assert(host.state() == dessen::State::Exited && host.exitCode() == 0); assert(shows("fill 10,10 50x30 c4") && shows("stroke 0,0 40x40 w3") && shows("triangle")); assert(shows("text 0,100 wrapped and centred") && shows("bitmap 200,10 8x8 src 8x8") && target.lines == 1); + // Check the actual target font slots, not merely the guest return codes. + assert(host.load(mem, readApp(argv[6]), sizeof mem)); + target.ops.clear(); + target.detail = true; + while (host.step(target, screen, none) == dessen::State::Running) {} + assert(host.state() == dessen::State::Exited && host.exitCode() == 0); + for (int font = DSN_FONT_NOTOSANS_12; font <= DSN_FONT_NOTOSANS_18; ++font) { + bool found = false; + for (const auto& op : target.ops) + if (op.find(" f" + std::to_string(font) + " ") != std::string::npos && + op.find(" | fixed") != std::string::npos) found = true; + assert(found); + } + assert(shows(" f0 left c4 m1 | fallback")); + target.detail = false; + // Restore the original trace for the existing clip assertions below. + assert(host.load(mem, readApp(argv[6]), sizeof mem)); + target.ops.clear(); + while (host.step(target, screen, none) == dessen::State::Running) {} // set_clip: clipped to the safe area, the scrim dithers, a negative width // lifts the clip, an off-screen one is empty, and the firmware's clip is // back once the app stops. diff --git a/sdk/dessen_abi.h b/sdk/dessen_abi.h index 5f4ff56..e8749a8 100644 --- a/sdk/dessen_abi.h +++ b/sdk/dessen_abi.h @@ -23,6 +23,11 @@ #define DSN_FONT_SMALL 0 #define DSN_FONT_BODY 1 #define DSN_FONT_TITLE 2 +// Slot 3 is reserved for host label chrome. Fixed-size slots match FreeInkUI. +#define DSN_FONT_NOTOSANS_12 4 +#define DSN_FONT_NOTOSANS_14 5 +#define DSN_FONT_NOTOSANS_16 6 +#define DSN_FONT_NOTOSANS_18 7 #define DSN_ALIGN_LEFT 0 #define DSN_ALIGN_CENTER 1