palm-client: small 4x6 UI font and a Font Preview screen

tools/gen_font.py builds an NFNT (app font 0x80) from X.org's public-domain
misc-fixed 4x6 BDF plus hand-drawn MeshTerm-style symbols (star, node-type
marks, ack/fail/pending, lock) in 0x80-0x9F, reusing Windows-1252's slots for
ellipsis and angle quotes. It also writes glyphs.h and a width table for host
tests. src/ui/draw.c registers the font and adds section, chip, cut and
right-align helpers. Options > Font Preview draws sample screens so the font
can be judged on the Visor's LCD before the real screens use it.
This commit is contained in:
rich committed 2026-11-01 15:12:23 -05:00
1 parent 7d1c84f35d
commit 1bae27fe9b
15 files changed
+14084 -2

No files matched your search

+3 -2
View File
@@ -10,7 +10,7 @@ APP = visormesh
NAME = VisorMesh
CREATOR = VMsh
SRCS = src/main.c src/protocol.c src/transport_srm.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/ports.c
SRCS = src/main.c src/protocol.c src/transport_srm.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/preview_form.c src/ui/draw.c src/ui/fontmetrics.c src/ports.c
OBJS = $(SRCS:src/%.c=build/%.o)
CC = m68k-palmos-gcc
@@ -37,7 +37,8 @@ else
all: build/$(APP).prc
build/%.o: src/%.c src/*.h | build
build/%.o: src/%.c src/*.h src/ui/*.h | build
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
build/$(APP): $(OBJS)
File diff suppressed because it is too large. Load diff
+12
View File
@@ -3,11 +3,15 @@
VERSION ID 1 "0.1"
APPLICATIONICONNAME ID 1000 "VisorMesh"
/* Small UI font: generated by tools/gen_font.py, registered as app font 0x80 at launch */
FONT ID SmallFontRes FONTID 128 "resources/smallfont.txt"
MENU ID MainMenuBar
BEGIN
PULLDOWN "Options"
BEGIN
MENUITEM "Serial Ports..." ID MainMenuPorts "P"
MENUITEM "Font Preview" ID MainMenuFontPreview "F"
END
END
@@ -131,3 +135,11 @@ BEGIN
MESSAGE "The radio saved the new settings, but only retunes after a restart. Reboot it now?"
BUTTONS "Reboot" "Later"
END
FORM ID FontPreviewForm AT (0 0 160 160)
NOFRAME
USABLE
BEGIN
TITLE "Font Preview"
BUTTON "Done" ID FontPreviewDoneButton AT (CENTER 147 AUTO AUTO)
END
+10
View File
@@ -7,6 +7,8 @@
#include "settings.h"
#include "contacts.h"
#include "contacts_form.h"
#include "preview_form.h"
#include "ui/draw.h"
#define VM_MIN_ROM_VERSION sysMakeROMVersion(3, 5, 0, sysROMStageRelease, 0)
#define VM_LABEL_CHARS 22 /* the info labels in the .rcp are padded to this width */
@@ -154,6 +156,10 @@ static Boolean MainFormHandleEvent(EventType *event)
FrmGotoForm(PortsForm);
return true;
}
if (event->data.menu.itemID == MainMenuFontPreview) {
FrmGotoForm(FontPreviewForm);
return true;
}
break;
default:
break;
@@ -179,6 +185,8 @@ static Boolean AppHandleEvent(EventType *event)
FrmSetEventHandler(form, SettingsFormHandleEvent);
else if (formId == ContactsForm)
FrmSetEventHandler(form, ContactsFormHandleEvent);
else if (formId == FontPreviewForm)
FrmSetEventHandler(form, FontPreviewFormHandleEvent);
return true;
}
@@ -206,10 +214,12 @@ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
if (err != errNone)
return err;
if (cmd == sysAppLaunchCmdNormalLaunch) {
UiFontInit();
FrmGotoForm(MainForm);
AppEventLoop();
SessionDisconnect();
ContactsClose();
UiFontRelease();
FrmCloseAllForms();
}
return errNone;
+79
View File
@@ -0,0 +1,79 @@
/*
* Font Preview (Options menu): sample screens in the small font, to judge how
* readable it is on the Visor's LCD before the real screens are built on it.
*/
#include <PalmOS.h>
#include "resources.h"
#include "ui/draw.h"
#include "preview_form.h"
#define TOP 16
static void Row(Coord y, Char mark, const Char *name, const Char *badge, const Char *age, const Char *preview)
{
Coord ageX = 88, previewX = 106;
WinDrawChars(&mark, 1, 1, y);
DrawCut(name, 8, y, 52);
if (badge)
DrawRight(badge, 80, y);
if (age)
DrawRight(age, previewX - 3, y);
(void)ageX;
if (preview)
DrawCut(preview, previewX, y, 160 - previewX);
}
static void DrawPreview(void)
{
Char line[48];
Coord y = TOP;
FontID old = FntSetFont(vmSmallFont);
DrawSection("Channels", y); y += VM_ROW_H;
StrPrintF(line, "%c2", GLYPH_COMPANION);
Row(y, '@', "Public", line, "5m", "Steve: spare antenna?"); y += VM_ROW_H;
Row(y, '#', "phillymesh", NULL, "1h", "ok see you there"); y += VM_ROW_H;
DrawSection("Direct", y); y += VM_ROW_H;
StrPrintF(line, "%c", GLYPH_FAILED);
Row(y, GLYPH_COMPANION, "Rich K.", line, "23h", "test from the visor"); y += VM_ROW_H;
Row(y, GLYPH_REPEATER, "Hilltop Repeater", NULL, "2d", NULL); y += VM_ROW_H;
Row(y, GLYPH_ROOM, "Rittenhouse Room", NULL, "3d", NULL); y += VM_ROW_H;
Row(y, GLYPH_SENSOR, "Weather Sensor", NULL, NULL, NULL); y += VM_ROW_H;
DrawSection("Thu Nov 1", y); y += VM_ROW_H + 1;
DrawChip("Steve K.", 1, y); y += VM_ROW_H + 1;
WinDrawChars("11:30", 5, 4, y);
WinDrawChars("I'll bring a spare antenna", 26, 26, y); y += VM_ROW_H;
WinDrawChars("for anyone who needs one +6dB", 29, 26, y); y += VM_ROW_H + 1;
StrPrintF(line, "%c VisorNeo", GLYPH_SELF);
DrawChip(line, 1, y); y += VM_ROW_H + 1;
WinDrawChars("11:33", 5, 4, y);
StrPrintF(line, "on my way, caf%c at 3 %c", (Char)0xE9, GLYPH_ACKED);
WinDrawChars(line, StrLen(line), 26, y); y += VM_ROW_H + 2;
StrPrintF(line, "%c%c%c%c%c%c%c%c%c%c%c ABCxyz 0123 %c",
GLYPH_SELF, GLYPH_COMPANION, GLYPH_REPEATER, GLYPH_ROOM, GLYPH_SENSOR, GLYPH_UNKNOWN,
GLYPH_ACKED, GLYPH_FAILED, GLYPH_PENDING, GLYPH_LOCK, GLYPH_UP, GLYPH_BACK);
WinDrawChars(line, StrLen(line), 1, y);
FntSetFont(old);
}
Boolean FontPreviewFormHandleEvent(EventType *event)
{
switch (event->eType) {
case frmOpenEvent:
FrmDrawForm(FrmGetActiveForm());
DrawPreview();
return true;
case ctlSelectEvent:
if (event->data.ctlSelect.controlID == FontPreviewDoneButton) {
FrmGotoForm(MainForm);
return true;
}
break;
default:
break;
}
return false;
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef VM_PREVIEW_FORM_H
#define VM_PREVIEW_FORM_H
#include <PalmOS.h>
Boolean FontPreviewFormHandleEvent(EventType *event);
#endif
+5
View File
@@ -14,6 +14,7 @@
#define MainContactsButton 1011
#define MainMenuBar 1000
#define MainMenuPorts 1001
#define MainMenuFontPreview 1002
#define MainLinkGroup 1
#define SettingsForm 1200
@@ -48,4 +49,8 @@
#define RomIncompatibleAlert 2000
#define SmallFontRes 1000
#define FontPreviewForm 1400
#define FontPreviewDoneButton 1401
#endif
+81
View File
@@ -0,0 +1,81 @@
#include <PalmOS.h>
#include "../resources.h"
#include "draw.h"
static MemHandle gFontH = 0;
Err UiFontInit(void)
{
if (gFontH)
return errNone;
gFontH = DmGetResource('NFNT', SmallFontRes);
if (!gFontH)
return DmGetLastErr();
return FntDefineFont(vmSmallFont, (FontPtr)MemHandleLock(gFontH));
}
void UiFontRelease(void)
{
if (gFontH) {
MemHandleUnlock(gFontH);
DmReleaseResource(gFontH);
gFontH = 0;
}
}
void DrawSection(const Char *label, Coord y)
{
Char rule = GLYPH_RULE;
FontID old = FntSetFont(vmSmallFont);
Coord ruleW = FntCharWidth(rule);
Coord labelW = FntCharsWidth(label, StrLen(label));
Coord x = 0;
UInt16 i;
for (i = 0; i < 2; i++, x += ruleW)
WinDrawChars(&rule, 1, x, y);
x += 2;
WinDrawChars(label, StrLen(label), x, y);
for (x += labelW + 2; x + ruleW <= 160; x += ruleW)
WinDrawChars(&rule, 1, x, y);
FntSetFont(old);
}
Coord DrawChip(const Char *text, Coord x, Coord y)
{
UInt16 len = StrLen(text);
Coord w = FntCharsWidth(text, len) + 2;
RectangleType r;
RctSetRectangle(&r, x, y, w, FntLineHeight());
WinDrawRectangle(&r, 0);
WinDrawInvertedChars(text, len, x + 1, y);
return w;
}
Coord DrawCut(const Char *text, Coord x, Coord y, Coord maxW)
{
Int16 w = maxW;
Int16 len = StrLen(text);
Boolean fits;
Char ell = GLYPH_ELLIPSIS;
if (FntCharsWidth(text, len) <= maxW) {
WinDrawChars(text, len, x, y);
return FntCharsWidth(text, len);
}
w = maxW - FntCharWidth(ell);
FntCharsInWidth(text, &w, &len, &fits);
WinDrawChars(text, len, x, y);
WinDrawChars(&ell, 1, x + w, y);
return w + FntCharWidth(ell);
}
Coord DrawRight(const Char *text, Coord xRight, Coord y)
{
UInt16 len = StrLen(text);
Coord x = xRight - FntCharsWidth(text, len);
WinDrawChars(text, len, x, y);
return x;
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Drawing helpers for the MeshTerm-style UI: the small font, section headers,
* inverted name chips and right-aligned lanes.
*/
#ifndef VM_DRAW_H
#define VM_DRAW_H
#include <PalmOS.h>
#include "glyphs.h"
#define vmSmallFont ((FontID)fntAppFontCustomBase)
#define VM_ROW_H (VM_SMALL_FONT_HEIGHT + 1) /* small-font line pitch */
/* Registers the small font (call once at launch / release at exit). */
Err UiFontInit(void);
void UiFontRelease(void);
/* "── Label ──" across the full width at y, in the small font. */
void DrawSection(const Char *label, Coord y);
/* A name chip: text inverted (white on black) with a 1px pad. Returns its width. */
Coord DrawChip(const Char *text, Coord x, Coord y);
/* Draws text in the current font, cut with an ellipsis to fit maxW. Returns the width drawn. */
Coord DrawCut(const Char *text, Coord x, Coord y, Coord maxW);
/* Draws text right-aligned so it ends at xRight. Returns its left edge. */
Coord DrawRight(const Char *text, Coord xRight, Coord y);
#endif
+21
View File
@@ -0,0 +1,21 @@
/* GENERATED by tools/gen_font.py: small-font character widths in pixels. */
#include "fontmetrics.h"
const UInt8 gSmallFontWidths[256] = {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 4, 5, 4, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4,
5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
};
+9
View File
@@ -0,0 +1,9 @@
#ifndef VM_FONTMETRICS_H
#define VM_FONTMETRICS_H
#include "../protocol.h" /* integer types on both Palm and host */
/* Small-font character widths in pixels, indexed by (UInt8) character. */
extern const UInt8 gSmallFontWidths[256];
#endif
+26
View File
@@ -0,0 +1,26 @@
/* GENERATED by tools/gen_font.py. UI symbols in the small font (vmSmallFont). */
#ifndef VM_GLYPHS_H
#define VM_GLYPHS_H
#define GLYPH_SELF ((Char)0x80)
#define GLYPH_COMPANION ((Char)0x81)
#define GLYPH_REPEATER ((Char)0x82)
#define GLYPH_ROOM ((Char)0x83)
#define GLYPH_SENSOR ((Char)0x84)
#define GLYPH_ELLIPSIS ((Char)0x85)
#define GLYPH_UNKNOWN ((Char)0x86)
#define GLYPH_ACKED ((Char)0x87)
#define GLYPH_FAILED ((Char)0x88)
#define GLYPH_UP ((Char)0x89)
#define GLYPH_DOWN ((Char)0x8A)
#define GLYPH_BACK ((Char)0x8B)
#define GLYPH_LOCK ((Char)0x8C)
#define GLYPH_RULE ((Char)0x8D)
#define GLYPH_LEFT ((Char)0x8E)
#define GLYPH_RIGHT ((Char)0x8F)
#define GLYPH_PENDING ((Char)0x90)
#define GLYPH_FORWARD ((Char)0x9B)
#define VM_SMALL_FONT_HEIGHT 6
#endif
File diff suppressed because it is too large. Load diff
+5
View File
@@ -0,0 +1,5 @@
# Fonts
`4x6.bdf` is X.org's `misc-fixed` 4x6 font (ISO 10646 build), from https://gitlab.freedesktop.org/xorg/font/misc-misc. It was contributed by Janne V. Kujala and is in the public domain ("Public domain font. Share and enjoy.", per its COPYRIGHT property).
`tools/gen_font.py` turns it, plus hand-drawn UI symbols, into the app's small font (`resources/smallfont.txt`, registered as app font 0x80).
+131
View File
@@ -0,0 +1,131 @@
#!/usr/bin/env python3
"""Generates VisorMesh's small font from tools/fonts/4x6.bdf (X.org misc-fixed,
public domain) plus hand-drawn UI symbols.
Outputs:
resources/smallfont.txt PilRC FONT source (compiled into an NFNT resource)
src/ui/glyphs.h code points for the UI symbols
src/ui/fontmetrics.c per-character widths, so host tests lay text out exactly
Palm fonts are 8-bit: 0x20-0x7E and 0xA0-0xFF come from the BDF (ASCII and
Latin-1); the UI symbols go in 0x80-0x9F, reusing Windows-1252's slots where it
has the same symbol (... 0x85, < 0x8B, > 0x9B).
"""
import os
HERE = os.path.dirname(os.path.abspath(__file__))
BDF = os.path.join(HERE, 'fonts', '4x6.bdf')
OUT_FONT = os.path.join(HERE, '..', 'resources', 'smallfont.txt')
OUT_GLYPHS = os.path.join(HERE, '..', 'src', 'ui', 'glyphs.h')
OUT_METRICS = os.path.join(HERE, '..', 'src', 'ui', 'fontmetrics.c')
ASCENT, DESCENT = 5, 1
HEIGHT = ASCENT + DESCENT
# UI symbols: (code point, C name, source). Source is a Unicode code point to take
# from the BDF, or a hand-drawn bitmap (one string per row, HEIGHT rows, '#' = on).
SYMBOLS = [
(0x80, 'GLYPH_SELF', ['--#--', '#####', '-###-', '-#-#-', '#---#', '-----']), # star: you
(0x81, 'GLYPH_COMPANION', ['-----', '-##-', '####', '####', '-##-', '----']), # filled circle
(0x82, 'GLYPH_REPEATER', ['-----', '--#--', '-###-', '#####', '-----', '-----']), # triangle
(0x83, 'GLYPH_ROOM', 0x25A0), # square
(0x84, 'GLYPH_SENSOR', ['-###-', '#---#', '#-#-#', '#---#', '-###-', '-----']), # fisheye
(0x85, 'GLYPH_ELLIPSIS', 0x2026),
(0x86, 'GLYPH_UNKNOWN', ['-----', '-##-', '#--#', '#--#', '-##-', '----']), # open circle
(0x87, 'GLYPH_ACKED', ['-----', '----#', '---#-', '#-#--', '-#---', '-----']), # check mark
(0x88, 'GLYPH_FAILED', ['-----', '#---#', '-#-#-', '--#--', '-#-#-', '#---#']), # ballot x
(0x89, 'GLYPH_UP', 0x2191),
(0x8A, 'GLYPH_DOWN', 0x2193),
(0x8B, 'GLYPH_BACK', 0x2039),
(0x8C, 'GLYPH_LOCK', ['-##-', '#--#', '####', '#-##', '####', '----']), # padlock: private channel
(0x8D, 'GLYPH_RULE', 0x2500),
(0x8E, 'GLYPH_LEFT', 0x2190),
(0x8F, 'GLYPH_RIGHT', 0x2192),
(0x90, 'GLYPH_PENDING', ['-----', '-###-', '#-#-#', '#-##-', '#---#', '-###-']), # clock face
(0x9B, 'GLYPH_FORWARD', 0x203A),
]
def parse_bdf(path):
"""Returns {codepoint: (width, rows)} with rows as HEIGHT strings of '#'/'-'."""
glyphs = {}
with open(path) as f:
lines = f.read().splitlines()
i = 0
while i < len(lines):
if not lines[i].startswith('STARTCHAR'):
i += 1
continue
enc = dwidth = None
bbx = None
bitmap = []
i += 1
while not lines[i].startswith('ENDCHAR'):
parts = lines[i].split()
if parts[0] == 'ENCODING':
enc = int(parts[1])
elif parts[0] == 'DWIDTH':
dwidth = int(parts[1])
elif parts[0] == 'BBX':
bbx = tuple(int(x) for x in parts[1:5])
elif parts[0] == 'BITMAP':
i += 1
while not lines[i].startswith('ENDCHAR'):
bitmap.append(int(lines[i], 16))
i += 1
break
i += 1
w, h, xoff, yoff = bbx
cell = [['-'] * dwidth for _ in range(HEIGHT)]
top = ASCENT - (yoff + h) # cell row of the bitmap's first row
nbits = ((w + 7) // 8) * 8
for r, bits in enumerate(bitmap):
for c in range(w):
if bits & (1 << (nbits - 1 - c)):
y, x = top + r, xoff + c
if 0 <= y < HEIGHT and 0 <= x < dwidth:
cell[y][x] = '#'
glyphs[enc] = (dwidth, [''.join(row) for row in cell])
i += 1
return glyphs
def main():
bdf = parse_bdf(BDF)
font = {}
for code in list(range(0x20, 0x7F)) + list(range(0xA0, 0x100)):
if code in bdf:
font[code] = bdf[code][1]
for code, _name, src in SYMBOLS:
rows = bdf[src][1] if isinstance(src, int) else src
assert len(rows) == HEIGHT, (hex(code), rows)
width = max(len(r) for r in rows)
font[code] = [r.ljust(width, '-') for r in rows]
missing = bdf[0xFFFD][1] if 0xFFFD in bdf else ['####', '#--#', '#--#', '#--#', '####', '----']
os.makedirs(os.path.dirname(OUT_GLYPHS), exist_ok=True)
with open(OUT_FONT, 'w') as f:
f.write('fontType 36864\nascent %d\ndescent %d\n\n' % (ASCENT, DESCENT))
for code in sorted(font):
f.write('GLYPH %d\n%s\n\n' % (code, '\n'.join(font[code])))
f.write('GLYPH -1\n' + '\n'.join(missing) + '\n') # PilRC wants the missing glyph last
with open(OUT_GLYPHS, 'w') as f:
f.write('/* GENERATED by tools/gen_font.py. UI symbols in the small font (vmSmallFont). */\n')
f.write('#ifndef VM_GLYPHS_H\n#define VM_GLYPHS_H\n\n')
for code, name, _src in SYMBOLS:
f.write('#define %-16s ((Char)0x%02X)\n' % (name, code))
f.write('\n#define VM_SMALL_FONT_HEIGHT %d\n\n#endif\n' % HEIGHT)
widths = [len(font[c][0]) if c in font else len(missing[0]) for c in range(256)]
with open(OUT_METRICS, 'w') as f:
f.write('/* GENERATED by tools/gen_font.py: small-font character widths in pixels. */\n')
f.write('#include "fontmetrics.h"\n\nconst UInt8 gSmallFontWidths[256] = {\n')
for r in range(0, 256, 16):
f.write('\t' + ', '.join(str(w) for w in widths[r:r + 16]) + ',\n')
f.write('};\n')
print('%d glyphs -> %s' % (len(font), os.path.relpath(OUT_FONT)))
if __name__ == '__main__':
main()