Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/drawtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion docs/writing-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion freeink/DessenFreeInk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FontId>(font <= DSN_FONT_TITLE ? font : DSN_FONT_SMALL);
st.font = static_cast<FontId>(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<uint8_t>(maxLines < 1 ? 1 : maxLines > 16 ? 16 : maxLines);
st.bold = flags & DSN_TEXT_BOLD;
Expand Down
19 changes: 19 additions & 0 deletions freeink/test_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions sdk/dessen_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down