palm-client: mute channels and a larger text option (5x8 font) on a Preferences screen

This commit is contained in:
rich committed 2026-11-02 10:58:16 -05:00
1 parent 04dc47664b
commit b57c51feb7
27 files changed
+24025 -77

No files matched your search

+3
View File
@@ -38,6 +38,8 @@
- [x] Split the code into segments: protocol.c + ui/text.c in vmcode2 (seg 1 24.3 KB, seg 2 4.9 KB); rules in src/sections.h (to verify on the Visor)
- [ ] UI: contacts, DMs, channels
- [x] Install method confirmed: HotSync over the USB cradle from the dev Mac (`make install`)
- [x] Notification sounds per event kind, mute channels, larger text option (5x8 font)
- [ ] Flood scopes (regions): manage the list of scopes, set the default scope, and set a scope per channel. MeshCore v8+ has CMD_SET_FLOOD_SCOPE_KEY (54), CMD_SET_DEFAULT_FLOOD_SCOPE (63) / CMD_GET_DEFAULT_FLOOD_SCOPE (64)
## Open questions
- Which CF adapter is it, and does its ROM include an app installer?
@@ -82,3 +84,4 @@
- 2026-11-02: Slot with an empty slot reset the Visor (bus error at csSlot0), and since Slot was saved and Home auto-connects, every launch reset it. Slot is no longer restored at launch, and Connect now checks `HsCardAttrGet(hsCardAttrHwInstalled)` and takes the chip-select base and size from the OS before any bus access. Verified on the Neo: empty slot gives "No module in the slot." with no reset. Node-screen errors shortened to its 22-character labels.
- 2026-11-02: Notification sounds (Options > Sounds): separate tunes for direct messages, mentions, room posts, private / hashtag / Public channels and new contacts (PUSH_NEW_ADVERT), each on or off, at the alarm volume. One sound per poll, by priority; none for the conversation on screen. Verified on the Neo. Segment 3 is 13.8 KB.
- 2026-11-02: SB-LoRa receive is interrupt-driven: a slot IRQ* handler (hsCardAttrIntHandler) drains the SC16IS740 RX FIFO (IER RHR, trigger 8 or timeout) into a 1 KB ring passed as cardParam. The handler path (SbDrainRx and the bus core) is in segment 1 with no A5 references, checked in the disassembly, so it's safe in interrupt context and while the Visor sleeps. The app masks the slot interrupt around its own SPI transactions, and falls back to polling if the handler won't install. Host tests cover draining, ring wrap and overflow; untested on hardware.
- 2026-11-02: Mute Channel (Options menu; by channel key; mentions still sound; open-circle unread badge, left out of the title total) and Text size Small/Large on the new Preferences screen (5x8 misc-fixed via tools/pcf2bdf.py from XQuartz's PCF; gen_font.py builds both fonts). Verified on the Neo. Segments: 11.1 / 28.0 / 14.7 KB.
+3 -3
View File
@@ -10,7 +10,7 @@ APP = visormesh
NAME = VisorMesh
CREATOR = VMsh
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c
OBJS = $(SRCS:src/%.c=build/%.o)
CC = m68k-palmos-gcc
@@ -31,7 +31,7 @@ ifeq ($(shell command -v $(CC) 2>/dev/null),)
# so an install of an up-to-date build doesn't need the toolchain at all.
all: build/$(APP).prc
build/$(APP).prc: $(SRCS) src/*.h src/ui/*.h resources/$(APP).rcp resources/smallfont.nfnt $(APP).def
build/$(APP).prc: $(SRCS) src/*.h src/ui/*.h resources/$(APP).rcp resources/smallfont.nfnt resources/largefont.nfnt $(APP).def
$(MAKE) image
$(DOCKER_RUN) make all
@@ -60,7 +60,7 @@ build/$(APP)-sections.o: build/$(APP)-sections.s
build/$(APP): $(OBJS) build/$(APP)-sections.o build/$(APP)-sections.ld
$(CC) $(CFLAGS) -o $@ $(OBJS) build/$(APP)-sections.o build/$(APP)-sections.ld
build/res.stamp: resources/$(APP).rcp src/resources.h resources/smallfont.nfnt | build
build/res.stamp: resources/$(APP).rcp src/resources.h resources/smallfont.nfnt resources/largefont.nfnt | build
rm -rf build/res && mkdir -p build/res
$(PILRC) -q -I src $< build/res
touch $@
Binary file not shown.
File diff suppressed because it is too large. Load diff
+24 -11
View File
@@ -8,6 +8,7 @@ APPLICATIONICONNAME ID 1000 "VisorMesh"
* NFNT itself: this PilRC's FONT compiler emits a corrupt header (garbled text).
*/
DATA "NFNT" ID SmallFontRes "resources/smallfont.nfnt"
DATA "NFNT" ID LargeFontRes "resources/largefont.nfnt"
MENU ID MainMenuBar
BEGIN
@@ -19,8 +20,9 @@ BEGIN
MENUITEM "-" AUTOID
MENUITEM "Add Channel..." ID MainMenuAddChannel "A"
MENUITEM "Leave Channel" ID MainMenuLeaveChannel "L"
MENUITEM "Mute Channel" ID MainMenuMuteChannel "M"
MENUITEM "-" AUTOID
MENUITEM "Sounds..." ID MainMenuSounds "B"
MENUITEM "Preferences..." ID MainMenuSounds "R"
MENUITEM "-" AUTOID
MENUITEM "Serial Ports..." ID MainMenuPorts "P"
MENUITEM "Font Preview" ID MainMenuFontPreview "F"
@@ -267,19 +269,30 @@ FORM ID SoundsForm AT (0 0 160 160)
NOFRAME
USABLE
BEGIN
TITLE "Sounds"
CHECKBOX "Direct messages" ID 2201 AT (5 18 AUTO 12)
CHECKBOX "Mentions of me" ID 2202 AT (5 PREVBOTTOM+1 AUTO 12)
CHECKBOX "Room posts" ID 2203 AT (5 PREVBOTTOM+1 AUTO 12)
CHECKBOX "Private channels" ID 2204 AT (5 PREVBOTTOM+1 AUTO 12)
CHECKBOX "Hashtag channels" ID 2205 AT (5 PREVBOTTOM+1 AUTO 12)
CHECKBOX "Public channel" ID 2206 AT (5 PREVBOTTOM+1 AUTO 12)
CHECKBOX "New contacts" ID 2207 AT (5 PREVBOTTOM+1 AUTO 12)
LABEL "Turning a sound on plays it." AUTOID AT (5 PREVBOTTOM+6)
LABEL "Volume: Prefs, General, Alarm" AUTOID AT (5 PREVBOTTOM+1)
TITLE "Preferences"
LABEL "Text size:" AUTOID AT (5 18) FONT 1
PUSHBUTTON "Small" ID SoundsSmallPush AT (60 17 36 12) GROUP SoundsTextGroup
PUSHBUTTON "Large" ID SoundsLargePush AT (PREVRIGHT+1 PREVTOP 36 12) GROUP SoundsTextGroup
CHECKBOX "Direct messages" ID 2201 AT (5 35 AUTO 12)
CHECKBOX "Mentions of me" ID 2202 AT (5 PREVBOTTOM AUTO 12)
CHECKBOX "Room posts" ID 2203 AT (5 PREVBOTTOM AUTO 12)
CHECKBOX "Private channels" ID 2204 AT (5 PREVBOTTOM AUTO 12)
CHECKBOX "Hashtag channels" ID 2205 AT (5 PREVBOTTOM AUTO 12)
CHECKBOX "Public channel" ID 2206 AT (5 PREVBOTTOM AUTO 12)
CHECKBOX "New contacts" ID 2207 AT (5 PREVBOTTOM AUTO 12)
LABEL "Turning a sound on plays it." AUTOID AT (5 PREVBOTTOM+2)
LABEL "Volume: Prefs, General, Alarm" AUTOID AT (5 PREVBOTTOM)
BUTTON "Done" ID SoundsDoneButton AT (CENTER 145 AUTO AUTO)
END
ALERT ID MuteAlert
INFORMATION
BEGIN
TITLE "Mute Channel"
MESSAGE "^1"
BUTTONS "OK"
END
ALERT ID RomIncompatibleAlert
ERROR
BEGIN
+2
View File
@@ -4,6 +4,7 @@
#include "session.h"
#include "app.h"
#include "sounds.h"
#include "mutes.h"
VmConv gAppConv;
Boolean gAppAutoConnectTried = false;
@@ -27,6 +28,7 @@ void AppLoadPrefs(void)
Int32 west;
SoundsLoad();
MutesLoad();
if (PrefGetAppPreferences(VM_CREATOR, VM_PREFS_ID, &prefs, &size, true) != noPreferenceFound &&
size == sizeof(prefs) && prefs.version == VM_PREFS_VERSION) {
/*
+1 -1
View File
@@ -37,7 +37,7 @@ static void Tapped(UInt16 row) VM_SECT2;
#define MAX_LINES 200
#define LINE_H VM_CHIP_H /* chips need the extra 2 px */
#define TIME_X 2
#define TEXT_X 26
#define TEXT_X (gTxtLarge ? 30 : 26) /* clear of "HH:MM" in either font */
#define L_DAY 0
#define L_CHIP 1
+6 -2
View File
@@ -5,6 +5,7 @@
#include "contacts.h"
#include "messages.h"
#include "convos.h"
#include "mutes.h"
/* In the second code segment: see sections.h for the rules. */
static void HexPrefix(const UInt8 *p, Char *out) VM_SECT2;
@@ -149,7 +150,9 @@ UInt16 ConvosBuild(VmConvRow *rows, UInt16 max)
conv.type = VM_CONV_CHANNEL;
conv.channel = ch.idx;
ChannelDisplayName(&ch, name, sizeof(name));
AddConv(rows, &n, max, &conv, ChannelMarker(&ch), name);
r = AddConv(rows, &n, max, &conv, ChannelMarker(&ch), name);
if (r)
r->muted = ChannelMuted(&ch);
}
AddSection(rows, &n, max, "Direct");
@@ -206,6 +209,7 @@ UInt16 ConvosUnread(const VmConvRow *rows, UInt16 n)
UInt16 i, total = 0;
for (i = 0; i < n; i++)
total += rows[i].unread;
if (!rows[i].muted)
total += rows[i].unread;
return total;
}
+1
View File
@@ -22,6 +22,7 @@ typedef struct {
UInt16 unread;
UInt32 last; /* Unix seconds of the newest message, 0 = none */
Boolean failed; /* an outgoing message here wasn't delivered */
Boolean muted; /* a muted channel (mutes.h) */
Char preview[VM_PREVIEW_LEN];
} VmConvRow;
+2 -1
View File
@@ -50,7 +50,8 @@ static void DrawRow(UInt16 row, const RectangleType *b, void *ctx)
buf[1] = 0;
DrawRight(buf, x + BADGE_R, y);
} else if (r->unread) {
StrPrintF(buf, "%c%u", GLYPH_COMPANION, r->unread);
/* open circle: a muted channel's unread */
StrPrintF(buf, "%c%u", r->muted ? GLYPH_UNKNOWN : GLYPH_COMPANION, r->unread);
DrawRight(buf, x + BADGE_R, y);
}
if (r->last) {
+3 -1
View File
@@ -13,6 +13,7 @@
#include "remote.h"
#include "remote_form.h"
#include "sounds.h"
#include "mutes.h"
#include "node_form.h"
#include "settings.h"
#include "ports.h"
@@ -49,6 +50,7 @@ static Boolean HandleMenu(UInt16 itemID)
case MainMenuSounds: SoundsFormOpen(FrmGetActiveFormID()); return true;
case MainMenuAddChannel: FrmGotoForm(ChannelForm); return true;
case MainMenuLeaveChannel: ChannelLeaveCurrent(); return true;
case MainMenuMuteChannel: ChannelMuteToggleCurrent(); return true;
}
return false;
}
@@ -162,8 +164,8 @@ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
if (err != errNone)
return err;
if (cmd == sysAppLaunchCmdNormalLaunch) {
UiFontInit();
AppLoadPrefs();
UiFontInit(SoundsLargeText());
HeardLoad();
FrmGotoForm(HomeForm);
AppEventLoop();
+86
View File
@@ -0,0 +1,86 @@
#include <PalmOS.h>
#include "resources.h"
#include "app.h"
#include "channels.h"
#include "mutes.h"
static Int16 FindMute(const VmChannel *c) VM_SECT3;
static void SavePrefs(void) VM_SECT3;
#define VM_MUTES_PREFS_ID 2
#define VM_MUTES_PREFS_VERSION 1
#define VM_MUTES_MAX 16
#define VM_MUTE_ID_SIZE 4 /* leading bytes of the channel key */
typedef struct {
UInt16 version;
UInt16 count;
UInt8 ids[VM_MUTES_MAX][VM_MUTE_ID_SIZE];
} MutesPrefs;
static MutesPrefs gMutes;
void MutesLoad(void)
{
UInt16 size = sizeof(gMutes);
if (PrefGetAppPreferences(VM_CREATOR, VM_MUTES_PREFS_ID, &gMutes, &size, true) == noPreferenceFound ||
size != sizeof(gMutes) || gMutes.version != VM_MUTES_PREFS_VERSION || gMutes.count > VM_MUTES_MAX)
gMutes.count = 0;
gMutes.version = VM_MUTES_PREFS_VERSION;
}
static void SavePrefs(void)
{
PrefSetAppPreferences(VM_CREATOR, VM_MUTES_PREFS_ID, VM_MUTES_PREFS_VERSION, &gMutes, sizeof(gMutes), true);
}
static Int16 FindMute(const VmChannel *c)
{
UInt16 i;
for (i = 0; i < gMutes.count; i++)
if (MemCmp(gMutes.ids[i], c->secret, VM_MUTE_ID_SIZE) == 0)
return (Int16)i;
return -1;
}
Boolean ChannelMuted(const VmChannel *c)
{
return FindMute(c) >= 0;
}
Boolean ChannelSlotMuted(UInt8 slot)
{
VmChannel c;
return ChannelsFindSlot(slot, &c) && ChannelMuted(&c);
}
void ChannelMuteToggleCurrent(void)
{
VmChannel c;
Char msg[VM_NAME_SIZE + 48];
Int16 i;
if (FrmGetActiveFormID() != ConvoForm || gAppConv.type != VM_CONV_CHANNEL ||
!ChannelsFindSlot(gAppConv.channel, &c)) {
FrmCustomAlert(MuteAlert, "Open the channel you want to mute first.", "", "");
return;
}
i = FindMute(&c);
if (i >= 0) {
MemMove(gMutes.ids[i], gMutes.ids[i + 1], (gMutes.count - i - 1) * VM_MUTE_ID_SIZE);
gMutes.count--;
StrPrintF(msg, "%s is no longer muted.", c.name);
} else if (gMutes.count >= VM_MUTES_MAX) {
StrCopy(msg, "Too many muted channels: unmute one first.");
FrmCustomAlert(MuteAlert, msg, "", "");
return;
} else {
MemMove(gMutes.ids[gMutes.count++], c.secret, VM_MUTE_ID_SIZE);
StrPrintF(msg, "%s is muted: no sounds, except when you're mentioned.", c.name);
}
SavePrefs();
FrmCustomAlert(MuteAlert, msg, "", "");
}
+21
View File
@@ -0,0 +1,21 @@
/*
* Muted channels: no sound for their messages (mentions of us still sound),
* and their unread messages are left out of the Home title's total. Kept by
* channel key rather than slot, so a mute survives the cache refresh and
* follows the channel if it moves to another slot.
*/
#ifndef VM_MUTES_H
#define VM_MUTES_H
#include <PalmOS.h>
#include "sections.h"
#include "protocol.h"
void MutesLoad(void) VM_SECT3;
Boolean ChannelMuted(const VmChannel *c) VM_SECT3;
Boolean ChannelSlotMuted(UInt8 slot) VM_SECT3;
/* Options > Mute Channel: toggles the channel on screen and says which way it went. */
void ChannelMuteToggleCurrent(void) VM_SECT3;
#endif
+6
View File
@@ -23,6 +23,7 @@
#define MainMenuAddChannel 1006
#define MainMenuLeaveChannel 1007
#define MainMenuSounds 1008
#define MainMenuMuteChannel 1009
#define MainLinkGroup 1
#define SettingsForm 1200
@@ -122,8 +123,13 @@
#define SoundsForm 2200
#define SoundsFirstCheck 2201 /* + VM_SND_* (sounds.h), in that order */
#define SoundsDoneButton 2210
#define MuteAlert 2211
#define SoundsSmallPush 2212
#define SoundsLargePush 2213
#define SoundsTextGroup 5
#define SmallFontRes 1000
#define LargeFontRes 1001
#define FontPreviewForm 1400
#define FontPreviewDoneButton 1401
+8 -2
View File
@@ -9,6 +9,7 @@
#include "heard.h"
#include "remote.h"
#include "sounds.h"
#include "mutes.h"
#define VM_APP_NAME "VisorMesh"
#define VM_REPLY_TIMEOUT (2 * SysTicksPerSecond())
@@ -387,10 +388,12 @@ static UInt8 MessageSound(const VmMessage *m)
VmContact ct;
if (MentionsUs(m))
return VM_SND_MENTION;
return VM_SND_MENTION; /* even in a muted channel */
if (m->isChannel) {
if (!ChannelsFindSlot(m->channelIdx, &ch))
return VM_SND_PRIVATE;
if (ChannelMuted(&ch))
return VM_SND_NONE;
switch (ChannelKind(&ch)) {
case VM_CHAN_PUBLIC: return VM_SND_PUBLIC;
case VM_CHAN_HASHTAG: return VM_SND_HASHTAG;
@@ -443,8 +446,11 @@ Err SessionSyncMessages(void)
continue;
}
if (MessagesAddIncoming(&m, SessionNow()) == errNone) {
UInt8 kind = MessageSound(&m);
gChanged |= VM_CHANGED_MESSAGES;
NoteSound(MessageSound(&m), &m);
if (kind != VM_SND_NONE)
NoteSound(kind, &m);
}
}
gMsgWaiting = true; /* more left: carry on at the next poll */
+32
View File
@@ -3,11 +3,14 @@
#include "app.h"
#include "session.h"
#include "sounds.h"
#include "ui/draw.h"
static void SavePrefs(void) VM_SECT3;
#define VM_SOUNDS_PREFS_ID 1
#define VM_SOUNDS_PREFS_VERSION 1
#define VM_TEXT_PREFS_ID 3
#define VM_TEXT_PREFS_VERSION 1
/* Off by default: the busy channels. */
#define VM_SND_DEFAULT ((UInt16)~((1 << VM_SND_HASHTAG) | (1 << VM_SND_PUBLIC)))
@@ -17,7 +20,13 @@ typedef struct {
UInt16 enabled; /* 1 << VM_SND_* */
} SoundsPrefs;
typedef struct {
UInt16 version;
Boolean large;
} TextPrefs;
static UInt16 gEnabled = VM_SND_DEFAULT;
static Boolean gLargeText = false;
static UInt16 gReturnForm = HomeForm;
/* Up to three notes per kind as (Hz, ms) pairs; 0 ends a tune early. */
@@ -34,20 +43,34 @@ static const UInt16 kTunes[VM_SND_COUNT][6] = {
void SoundsLoad(void)
{
SoundsPrefs prefs;
TextPrefs text;
UInt16 size = sizeof(prefs);
if (PrefGetAppPreferences(VM_CREATOR, VM_SOUNDS_PREFS_ID, &prefs, &size, true) != noPreferenceFound &&
size == sizeof(prefs) && prefs.version == VM_SOUNDS_PREFS_VERSION)
gEnabled = prefs.enabled;
size = sizeof(text);
if (PrefGetAppPreferences(VM_CREATOR, VM_TEXT_PREFS_ID, &text, &size, true) != noPreferenceFound &&
size == sizeof(text) && text.version == VM_TEXT_PREFS_VERSION)
gLargeText = text.large;
}
Boolean SoundsLargeText(void)
{
return gLargeText;
}
static void SavePrefs(void)
{
SoundsPrefs prefs;
TextPrefs text;
prefs.version = VM_SOUNDS_PREFS_VERSION;
prefs.enabled = gEnabled;
PrefSetAppPreferences(VM_CREATOR, VM_SOUNDS_PREFS_ID, VM_SOUNDS_PREFS_VERSION, &prefs, sizeof(prefs), true);
text.version = VM_TEXT_PREFS_VERSION;
text.large = gLargeText;
PrefSetAppPreferences(VM_CREATOR, VM_TEXT_PREFS_ID, VM_TEXT_PREFS_VERSION, &text, sizeof(text), true);
}
void SoundsPlay(UInt8 kind)
@@ -102,6 +125,7 @@ Boolean SoundsFormHandleEvent(EventType *event)
for (kind = 0; kind < VM_SND_COUNT; kind++)
FrmSetControlValue(form, FrmGetObjectIndex(form, SoundsFirstCheck + kind),
(gEnabled & (1 << kind)) != 0);
FrmSetControlGroupSelection(form, SoundsTextGroup, gLargeText ? SoundsLargePush : SoundsSmallPush);
FrmDrawForm(form);
return true;
case ctlSelectEvent:
@@ -110,6 +134,14 @@ Boolean SoundsFormHandleEvent(EventType *event)
FrmGotoForm(gReturnForm);
return true;
}
if (id == SoundsSmallPush || id == SoundsLargePush) {
/* this screen is in the system fonts; the others lay out again as they open */
if ((id == SoundsLargePush) != gLargeText && UiFontSetLarge(id == SoundsLargePush) == errNone) {
gLargeText = id == SoundsLargePush;
SavePrefs();
}
return true;
}
if (id >= SoundsFirstCheck && id < SoundsFirstCheck + VM_SND_COUNT) {
kind = (UInt8)(id - SoundsFirstCheck);
if (event->data.ctlSelect.on) {
+7 -2
View File
@@ -1,7 +1,8 @@
/*
* Notification sounds: a short tune for each kind of event, each of which can
* be turned off on the Sounds screen. Played at the system's alarm volume
* be turned off on the Preferences screen. Played at the system's alarm volume
* (Prefs > General > Alarm Sound), so muting taps doesn't mute messages.
* The same screen has the Text size option (the larger UI font).
*/
#ifndef VM_SOUNDS_H
#define VM_SOUNDS_H
@@ -19,6 +20,7 @@
#define VM_SND_PUBLIC 5 /* the Public channel */
#define VM_SND_CONTACT 6 /* a node we haven't seen advertised itself */
#define VM_SND_COUNT 7
#define VM_SND_NONE 0xFF /* nothing to sound for (a muted channel) */
void SoundsLoad(void) VM_SECT3;
void SoundsPlay(UInt8 kind) VM_SECT3;
@@ -29,7 +31,10 @@ void SoundsPlay(UInt8 kind) VM_SECT3;
*/
void SoundsNotify(UInt16 kinds, const VmConv *onScreen) VM_SECT3;
/* The Sounds screen; Done goes back to returnForm. */
/* Text size: the larger UI font (ui/draw.h). */
Boolean SoundsLargeText(void) VM_SECT3;
/* The Preferences screen (SoundsForm); Done goes back to returnForm. */
void SoundsFormOpen(UInt16 returnForm) VM_SECT3;
Boolean SoundsFormHandleEvent(EventType *event) VM_SECT3;
+25 -2
View File
@@ -1,22 +1,45 @@
#include <PalmOS.h>
#include "../resources.h"
#include "draw.h"
#include "text.h"
/* In the second code segment: see sections.h for the rules. */
static MemHandle gFontH = 0;
UInt16 gUiFontHeight = VM_SMALL_FONT_HEIGHT;
Err UiFontInit(void)
Err UiFontInit(Boolean large)
{
if (gFontH)
return errNone;
gFontH = DmGetResource('NFNT', SmallFontRes);
gFontH = DmGetResource('NFNT', large ? LargeFontRes : SmallFontRes);
if (!gFontH)
return DmGetLastErr();
gUiFontHeight = large ? VM_LARGE_FONT_HEIGHT : VM_SMALL_FONT_HEIGHT;
gTxtLarge = large;
return FntDefineFont(vmSmallFont, (FontPtr)MemHandleLock(gFontH));
}
/* FntDefineFont replaces the font at that ID; the old resource is released after. */
Err UiFontSetLarge(Boolean large)
{
MemHandle old = gFontH;
Err err;
gFontH = 0;
err = UiFontInit(large);
if (err != errNone) {
gFontH = old;
return err;
}
if (old) {
MemHandleUnlock(old);
DmReleaseResource(old);
}
return errNone;
}
void UiFontRelease(void)
{
if (gFontH) {
+10 -5
View File
@@ -9,18 +9,23 @@
#include "../sections.h" /* this module is in the second code segment */
#include "glyphs.h"
#define vmSmallFont ((FontID)fntAppFontCustomBase)
#define VM_ROW_H (VM_SMALL_FONT_HEIGHT + 1) /* small-font line pitch */
#define vmSmallFont ((FontID)fntAppFontCustomBase) /* the UI font, small or large */
/* Registers the small font (call once at launch / release at exit). */
Err UiFontInit(void) VM_SECT2;
/* VM_SMALL_FONT_HEIGHT or VM_LARGE_FONT_HEIGHT, whichever font is in use. */
extern UInt16 gUiFontHeight;
#define VM_ROW_H (gUiFontHeight + 1) /* UI-font line pitch */
/* Registers the UI font, the larger one if large (call at launch / release at exit). */
Err UiFontInit(Boolean large) VM_SECT2;
void UiFontRelease(void) VM_SECT2;
/* Switches between the fonts; forms opened afterwards lay out for the new one. */
Err UiFontSetLarge(Boolean large) VM_SECT2;
/* "── Label ──" from x to x + width at y, in the small font. */
void DrawSection(const Char *label, Coord x, Coord y, Coord width) VM_SECT2;
/* A name chip: text inverted (white on black), VM_CHIP_H tall. Returns its width. */
#define VM_CHIP_H (VM_SMALL_FONT_HEIGHT + 2)
#define VM_CHIP_H (gUiFontHeight + 2)
Coord DrawChip(const Char *text, Coord x, Coord y) VM_SECT2;
/* Draws text in the current font, cut with an ellipsis to fit maxW. Returns the width drawn. */
+19 -1
View File
@@ -1,4 +1,4 @@
/* GENERATED by tools/gen_font.py: small-font character widths in pixels. */
/* GENERATED by tools/gen_font.py: UI font character widths in pixels. */
#include "fontmetrics.h"
/* Not const: prc-tools puts const data in the code section, but other files reach an
@@ -21,3 +21,21 @@ 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,
};
UInt8 gLargeFontWidths[256] = {
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
};
+2 -1
View File
@@ -3,8 +3,9 @@
#include "../protocol.h" /* integer types on both Palm and host */
/* Small-font character widths in pixels, indexed by (UInt8) character. */
/* UI font character widths in pixels, indexed by (UInt8) character. */
/* Not const: see the note in fontmetrics.c (prc-tools puts const data in code). */
extern UInt8 gSmallFontWidths[256];
extern UInt8 gLargeFontWidths[256];
#endif
+2 -1
View File
@@ -1,4 +1,4 @@
/* GENERATED by tools/gen_font.py. UI symbols in the small font (vmSmallFont). */
/* GENERATED by tools/gen_font.py. UI symbols in the UI fonts (vmSmallFont). */
#ifndef VM_GLYPHS_H
#define VM_GLYPHS_H
@@ -23,5 +23,6 @@
#define GLYPH_FORWARD ((Char)0x9B)
#define VM_SMALL_FONT_HEIGHT 6
#define VM_LARGE_FONT_HEIGHT 8
#endif
+3 -1
View File
@@ -5,9 +5,11 @@
/* In the second code segment: see sections.h for the rules. */
static Char MapUnicode(UInt32 cp) VM_SECT2;
Boolean gTxtLarge = 0;
Int16 TxtSmallWidth(Char c)
{
return gSmallFontWidths[(UInt8)c];
return gTxtLarge ? gLargeFontWidths[(UInt8)c] : gSmallFontWidths[(UInt8)c];
}
Int16 TxtWidth(const Char *s, UInt16 len, TxtWidthFn w)
+5 -1
View File
@@ -10,7 +10,11 @@
/* Width of one character in pixels (e.g. from gSmallFontWidths, or FntCharWidth on the device). */
typedef Int16 (*TxtWidthFn)(Char c);
/* The small font's widths from the generated table. */
/*
* The UI font's widths from the generated tables: the small font, or the
* larger one while gTxtLarge is set (draw.c keeps it in step with the font).
*/
extern Boolean gTxtLarge;
Int16 TxtSmallWidth(Char c) VM_SECT2;
Int16 TxtWidth(const Char *s, UInt16 len, TxtWidthFn w) VM_SECT2;
File diff suppressed because it is too large. Load diff
+71 -42
View File
@@ -1,14 +1,16 @@
#!/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.
"""Generates VisorMesh's UI fonts from X.org misc-fixed (public domain) plus
hand-drawn UI symbols: the small font from tools/fonts/4x6.bdf and the larger
one (the Text size option) from tools/fonts/5x8.bdf.
Outputs:
resources/smallfont.nfnt the NFNT resource, written here directly (the bundled
PilRC's FONT compiler emits a corrupt header) and
included by PilRC as a DATA resource
resources/largefont.nfnt the same for the larger font (and largefont.txt)
resources/smallfont.txt the same glyphs as text, for reading and diffs
src/ui/glyphs.h code points for the UI symbols
src/ui/fontmetrics.c per-character widths, so host tests lay text out exactly
src/ui/fontmetrics.c per-character widths of both, for text layout
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
@@ -18,17 +20,20 @@ import os
import struct
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_NFNT = os.path.join(HERE, '..', 'resources', 'smallfont.nfnt')
RES = os.path.join(HERE, '..', 'resources')
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
# (name, BDF, ascent, descent): the hand-drawn symbols below are drawn for the
# small font's 5 + 1 and are padded to the larger cell, sitting on the baseline.
FONTS = [
('small', os.path.join(HERE, 'fonts', '4x6.bdf'), 5, 1),
('large', os.path.join(HERE, 'fonts', '5x8.bdf'), 7, 1),
]
SYMBOL_ASCENT, SYMBOL_DESCENT = 5, 1
# 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).
# from the BDF, or a hand-drawn bitmap (one string per row, 6 rows, '#' = on).
SYMBOLS = [
(0x80, 'GLYPH_SELF', ['--#--', '#####', '-###-', '-#-#-', '#---#', '-----']), # star: you
(0x81, 'GLYPH_COMPANION', ['-----', '-##-', '####', '####', '-##-', '----']), # filled circle
@@ -52,8 +57,9 @@ SYMBOLS = [
]
def parse_bdf(path):
"""Returns {codepoint: (width, rows)} with rows as HEIGHT strings of '#'/'-'."""
def parse_bdf(path, ascent, descent):
"""Returns {codepoint: (width, rows)} with rows as ascent + descent strings of '#'/'-'."""
height = ascent + descent
glyphs = {}
with open(path) as f:
lines = f.read().splitlines()
@@ -82,21 +88,21 @@ def parse_bdf(path):
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
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:
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 build_nfnt(font, missing):
def build_nfnt(font, missing, ascent, descent):
"""
Palm OS FontType (Mac FONT layout, big-endian words):
fontType, firstChar, lastChar, maxWidth, kernMax, nDescent, fRectWidth,
@@ -107,6 +113,7 @@ def build_nfnt(font, missing):
where n = lastChar - firstChar + 1 and entry n is the missing-char glyph.
owTLoc is the distance in words from the owTLoc field to owTable.
"""
height = ascent + descent
first, last = min(font), max(font)
n = last - first + 1
order = [font.get(c) for c in range(first, last + 1)] + [missing]
@@ -117,7 +124,7 @@ def build_nfnt(font, missing):
locs.append(x)
strip_w = x
row_words = (strip_w + 15) // 16
bitmap = bytearray(row_words * 2 * HEIGHT)
bitmap = bytearray(row_words * 2 * height)
for rows, x0 in zip(order, locs):
if not rows:
continue
@@ -129,9 +136,9 @@ def build_nfnt(font, missing):
ow = [(0 << 8 | len(rows[0])) if rows else 0xFFFF for rows in order] + [0xFFFF]
max_w = max(len(r[0]) for r in order if r)
header_words, ow_t_loc_index = 13, 8
ow_t_loc = header_words + row_words * HEIGHT + len(locs) - ow_t_loc_index
header = struct.pack('>13h', -28672, first, last, max_w, 0, 0, max_w, HEIGHT,
ow_t_loc, ASCENT, DESCENT, 0, row_words)
ow_t_loc = header_words + row_words * height + len(locs) - ow_t_loc_index
header = struct.pack('>13h', -28672, first, last, max_w, 0, 0, max_w, height,
ow_t_loc, ascent, descent, 0, row_words)
return header + bytes(bitmap) + struct.pack('>%dH' % len(locs), *locs) + struct.pack('>%dH' % len(ow), *ow)
@@ -161,51 +168,73 @@ def decode_nfnt(data):
return out
def main():
bdf = parse_bdf(BDF)
def pad_symbol(rows, ascent, descent):
"""Fits a 5 + 1 hand-drawn symbol into a taller cell, keeping it on the baseline."""
width = len(rows[0])
blank = '-' * width
return [blank] * (ascent - SYMBOL_ASCENT) + rows + [blank] * (descent - SYMBOL_DESCENT)
def make_font(name, path, ascent, descent):
"""Builds one font, writes resources/<name>font.nfnt and .txt; returns its 256 widths."""
height = ascent + descent
bdf = parse_bdf(path, ascent, descent)
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 ['####', '#--#', '#--#', '#--#', '####', '----']
if isinstance(src, int):
rows = bdf[src][1]
else:
assert len(src) == SYMBOL_ASCENT + SYMBOL_DESCENT, (hex(code), src)
width = max(len(r) for r in src)
rows = pad_symbol([r.ljust(width, '-') for r in src], ascent, descent)
assert len(rows) == height, (name, hex(code), rows)
font[code] = rows
missing = bdf[0xFFFD][1]
os.makedirs(os.path.dirname(OUT_GLYPHS), exist_ok=True)
nfnt = build_nfnt(font, missing)
nfnt = build_nfnt(font, missing, ascent, descent)
back = decode_nfnt(nfnt)
for code, rows in font.items():
assert back.get(code) == rows, 'NFNT round trip failed for 0x%02X' % code
assert back.get(code) == rows, 'NFNT round trip failed for %s 0x%02X' % (name, code)
assert back['missing'] == missing
with open(OUT_NFNT, 'wb') as f:
out_nfnt = os.path.join(RES, name + 'font.nfnt')
with open(out_nfnt, 'wb') as f:
f.write(nfnt)
with open(OUT_FONT, 'w') as f:
f.write('fontType 36864\nascent %d\ndescent %d\n\n' % (ASCENT, DESCENT))
with open(os.path.join(RES, name + 'font.txt'), '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
print('%d glyphs -> %s (%d bytes, round trip OK)' % (len(font), os.path.relpath(out_nfnt), len(nfnt)))
return [len(font[c][0]) if c in font else len(missing[0]) for c in range(256)]
def main():
widths, heights = {}, {}
for name, path, ascent, descent in FONTS:
widths[name] = make_font(name, path, ascent, descent)
heights[name] = ascent + descent
os.makedirs(os.path.dirname(OUT_GLYPHS), exist_ok=True)
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('/* GENERATED by tools/gen_font.py. UI symbols in the UI fonts (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)
f.write('\n#define VM_SMALL_FONT_HEIGHT %d\n#define VM_LARGE_FONT_HEIGHT %d\n\n#endif\n'
% (heights['small'], heights['large']))
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('/* GENERATED by tools/gen_font.py: UI font character widths in pixels. */\n')
f.write('#include "fontmetrics.h"\n\n')
f.write('/* Not const: prc-tools puts const data in the code section, but other files reach an\n * extern table A5-relative as if it were data, so a const table reads as garbage on the Visor. */\n')
f.write('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 (%d bytes, round trip OK)' % (len(font), os.path.relpath(OUT_NFNT), len(nfnt)))
for name in ('small', 'large'):
f.write('UInt8 g%sFontWidths[256] = {\n' % name.capitalize())
for r in range(0, 256, 16):
f.write('\t' + ', '.join(str(w) for w in widths[name][r:r + 16]) + ',\n')
f.write('};\n')
if __name__ == '__main__':
+147
View File
@@ -0,0 +1,147 @@
#!/usr/bin/env python3
"""Converts an X11 PCF bitmap font (optionally .gz) to BDF, so tools/gen_font.py
can read X.org misc-fixed fonts that are installed only as PCF (XQuartz has
/opt/X11/share/fonts/misc/5x8.pcf.gz).
tools/pcf2bdf.py /opt/X11/share/fonts/misc/5x8.pcf.gz tools/fonts/5x8.bdf
Handles what bitmap fonts use: properties, accelerators, metrics (plain or
compressed), bitmaps (any padding / bit and byte order) and encodings.
"""
import gzip
import struct
import sys
PCF_PROPERTIES = 1 << 0
PCF_ACCELERATORS = 1 << 1
PCF_METRICS = 1 << 2
PCF_BITMAPS = 1 << 3
PCF_BDF_ENCODINGS = 1 << 5
PCF_BDF_ACCELERATORS = 1 << 8
PCF_BYTE_MSB = 1 << 2
PCF_BIT_MSB = 1 << 3
PCF_COMPRESSED_METRICS = 0x100
class Table:
def __init__(self, data, offset):
self.data = data
self.pos = offset
self.format = struct.unpack_from('<i', data, offset)[0]
self.pos += 4
self.endian = '>' if self.format & PCF_BYTE_MSB else '<'
def read(self, fmt):
fmt = self.endian + fmt
values = struct.unpack_from(fmt, self.data, self.pos)
self.pos += struct.calcsize(fmt)
return values if len(values) > 1 else values[0]
def read_metrics(t, compressed):
if compressed:
l, r, w, a, d = (b - 0x80 for b in t.read('5B'))
else:
l, r, w, a, d, _attr = t.read('5hH')
return l, r, w, a, d
def convert(src, dst):
raw = open(src, 'rb').read()
if raw[:2] == b'\x1f\x8b':
raw = gzip.decompress(raw)
assert raw[:4] == b'\x01fcp', 'not a PCF file'
count = struct.unpack_from('<i', raw, 4)[0]
tables = {}
for i in range(count):
ttype, _fmt, _size, offset = struct.unpack_from('<4i', raw, 8 + 16 * i)
tables[ttype] = offset
props = {}
t = Table(raw, tables[PCF_PROPERTIES])
n = t.read('i')
entries = [t.read('ibi') for _ in range(n)]
if n & 3:
t.pos += 4 - (n & 3)
t.read('i') # string pool size
pool = t.pos
def cstr(off):
end = raw.index(b'\0', pool + off)
return raw[pool + off:end].decode('latin-1')
for name_off, is_str, value in entries:
props[cstr(name_off)] = cstr(value) if is_str else value
t = Table(raw, tables.get(PCF_BDF_ACCELERATORS, tables[PCF_ACCELERATORS]))
t.pos += 8 # flag bytes
ascent, descent = t.read('ii')
t = Table(raw, tables[PCF_METRICS])
compressed = bool(t.format & PCF_COMPRESSED_METRICS)
nmetrics = t.read('h' if compressed else 'i')
metrics = [read_metrics(t, compressed) for _ in range(nmetrics)]
t = Table(raw, tables[PCF_BITMAPS])
fmt = t.format
nglyphs = t.read('i')
offsets = [t.read('i') for _ in range(nglyphs)]
sizes = [t.read('i') for _ in range(4)]
pad = 1 << (fmt & 3)
unit = 1 << ((fmt >> 4) & 3)
bits_base = t.pos
msb_bit = bool(fmt & PCF_BIT_MSB)
msb_byte = bool(fmt & PCF_BYTE_MSB)
def glyph_rows(i):
l, r, _w, a, d = metrics[i]
width, height = r - l, a + d
stride = ((width + 7) // 8 + pad - 1) // pad * pad
out = []
base = bits_base + offsets[i]
for y in range(height):
row = bytearray(raw[base + y * stride: base + (y + 1) * stride])
if msb_bit != msb_byte and unit > 1: # swap bytes within each scan unit
for k in range(0, len(row), unit):
row[k:k + unit] = row[k:k + unit][::-1]
if not msb_bit:
row = bytearray(int('{:08b}'.format(b)[::-1], 2) for b in row)
out.append(row[:(width + 7) // 8])
return out
t = Table(raw, tables[PCF_BDF_ENCODINGS])
min2, max2, min1, max1, _default = t.read('5h')
glyphs = []
for b1 in range(min1, max1 + 1):
for b2 in range(min2, max2 + 1):
idx = t.read('H')
if idx != 0xFFFF:
glyphs.append(((b1 << 8) | b2, idx))
with open(dst, 'w') as f:
f.write('STARTFONT 2.1\n')
f.write('COMMENT converted from %s by tools/pcf2bdf.py\n' % src.split('/')[-1])
f.write('FONT %s\n' % props.get('FONT', 'unknown'))
f.write('SIZE %d 75 75\n' % props.get('PIXEL_SIZE', ascent + descent))
lo = min(m[0] for m in metrics)
f.write('FONTBOUNDINGBOX %d %d %d %d\n' % (max(m[1] - m[0] for m in metrics), ascent + descent, lo, -descent))
keep = {k: v for k, v in props.items() if k != 'FONT'}
f.write('STARTPROPERTIES %d\n' % (len(keep) + 2))
for k, v in keep.items():
f.write('%s "%s"\n' % (k, v.replace('"', '""')) if isinstance(v, str) else '%s %d\n' % (k, v))
f.write('FONT_ASCENT %d\nFONT_DESCENT %d\nENDPROPERTIES\n' % (ascent, descent))
f.write('CHARS %d\n' % len(glyphs))
for enc, idx in glyphs:
l, r, w, a, d = metrics[idx]
f.write('STARTCHAR U+%04X\nENCODING %d\n' % (enc, enc))
f.write('SWIDTH %d 0\nDWIDTH %d 0\n' % (w * 1000 // max(1, ascent + descent), w))
f.write('BBX %d %d %d %d\nBITMAP\n' % (r - l, a + d, l, -d))
for row in glyph_rows(idx):
f.write(row.hex().upper() + '\n')
f.write('ENDCHAR\n')
f.write('ENDFONT\n')
print('%d glyphs, ascent %d, descent %d -> %s' % (len(glyphs), ascent, descent, dst))
if __name__ == '__main__':
convert(sys.argv[1], sys.argv[2])