From 6dd623f778d9872db5ef8bab750310cb93aa6b02 Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Mon, 2 Nov 2026 13:07:01 -0500 Subject: [PATCH] palm-client: glyphs for 12 common emoji, tap an emoji to see it enlarged --- docs/progress.md | 1 + palm-client/Makefile | 6 +- palm-client/resources/emoji.bin | Bin 0 -> 729 bytes palm-client/resources/largefont.nfnt | Bin 1986 -> 2066 bytes palm-client/resources/largefont.txt | 120 +++++++++++++++ palm-client/resources/smallfont.nfnt | Bin 1578 -> 1626 bytes palm-client/resources/smallfont.txt | 96 ++++++++++++ palm-client/resources/visormesh.rcp | 1 + palm-client/src/convo_form.c | 112 +++++++++++--- palm-client/src/resources.h | 1 + palm-client/src/ui/draw.c | 5 + palm-client/src/ui/draw.h | 2 + palm-client/src/ui/emoji.c | 94 ++++++++++++ palm-client/src/ui/emoji.h | 16 ++ palm-client/src/ui/fontmetrics.c | 4 +- palm-client/src/ui/glyphs.h | 12 ++ palm-client/src/ui/text.c | 21 ++- palm-client/tests/test_text.c | 18 ++- palm-client/tools/gen_font.py | 222 +++++++++++++++++++++++++++ 19 files changed, 699 insertions(+), 32 deletions(-) create mode 100644 palm-client/resources/emoji.bin create mode 100644 palm-client/src/ui/emoji.c create mode 100644 palm-client/src/ui/emoji.h diff --git a/docs/progress.md b/docs/progress.md index 0423f0a..4e37e4a 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -89,3 +89,4 @@ - 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. - 2026-11-02: Flood scopes: a list of scope names (Options > Flood Scopes), the radio's default (Set Default / No Default), a per-channel choice (Options > Channel Scope: radio default, none, or a named scope), and Discover, which asks neighbouring repeaters for their regions (SEND_ANON_REQ type 0x01). The session sets the scope override before each flood send and resets it on disconnect. Keys and frames are host-tested (tests/test_scopes.c; the key for "test" matches the radio's #test channel key). Verified on the Neo. Discover only reaches 0-hop repeaters for now. - 2026-11-02: Map screen (Options > Map): an OpenStreetMap basemap of the Philadelphia metro in 4 greys with the contacts that advertise a position plotted on it (no position, not shown). `tools/make_map.py` downloads OSM roads, rail, water and parks (Overpass, cached in tools/map-cache), draws zooms 10-12 for the metro and 13 with residential streets for ~16 km around Center City, and writes build/VisorMeshMap.pdb (290 PackBits tiles, 1,045 KB); `make map`, `make install-map`. Zoom with -/+ or the hard buttons, drag to pan, tap a node for its info, tap again to open it. Fixed on the device: a long node name overflowed the info bar (reset), and the attribution overlapped the buttons. Verified on the Neo. Segment 3 is 24.9 KB. +- 2026-11-02: Emoji: 12 common ones have their own glyph in both fonts (thumbs up, tears of joy, heart, crying, folded hands, waving hand, fire, party popper, thinking, eyes, antenna, 100), with close variants mapped onto them and skin tones dropped; the rest stay the generic smiley. Tap an emoji in a message for a 32x32 picture and its name (resources/emoji.bin from gen_font.py). Verified on the Neo. Segments: 12.2 / 28.8 / 25.7 KB; vmcode2 is nearly full. diff --git a/palm-client/Makefile b/palm-client/Makefile index 77180d0..4c20b98 100644 --- a/palm-client/Makefile +++ b/palm-client/Makefile @@ -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 src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.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 src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.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 resources/largefont.nfnt $(APP).def +build/$(APP).prc: $(SRCS) src/*.h src/ui/*.h resources/$(APP).rcp resources/smallfont.nfnt resources/largefont.nfnt resources/emoji.bin $(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 resources/largefont.nfnt | build +build/res.stamp: resources/$(APP).rcp src/resources.h resources/smallfont.nfnt resources/largefont.nfnt resources/emoji.bin | build rm -rf build/res && mkdir -p build/res $(PILRC) -q -I src $< build/res touch $@ diff --git a/palm-client/resources/emoji.bin b/palm-client/resources/emoji.bin new file mode 100644 index 0000000000000000000000000000000000000000..d386807ea309cdae56cb001704c67e237458e1e8 GIT binary patch literal 729 zcmd;`>6c%kkeR1Yl98$qmRX!%q+YC0oLa)b{y;)PfyIHzfvH8YMX`agfw4o-MalV) z0*izM`vV4si6I%Kxk<$er3DOVfUyCn$$AnGFO zAsQrqML7 z4gl573dzXK%f<{DXt)$1;=O^<`H%yXZG#ho6N3%I9M{TJ;;0x zMkgm58-(m!$Gno%yu3t&2#lr3;i(cR5TA#|NeY^U0>7#V4i&IihNla)`RsuTuFnSaCCt zU9K4&2RSUebE8uEj7r>!?7a_~n+t}H&9C@c3d_*B2vRiKXqyC{-LMYx3}wy0fuTBysq6j5?XWQ)yy36uuXIHt#b028c6lnL)!&}v99w4qmAT)!zD z_Qpum=5mxh85>|EplTsLaJ)iV8~m_wy_6Vo30IITKNnFvb2vbYo{7J33CNSX+K=fL z`n-o^>r3(9j~dR`Usxp36F;df*pN(5rq*!Pr{Qmp*Bq~47D!XZ)yM-esXV|(#(;~f$ls$^qF|G z;2%pAUSrMrGEmAHUodY9R#B#+l3L(@frwx$R8Y5|nDK8fH#Yq*dhN@gHPO#I50WNw zgvcaJPLddjlP=OnPLs3b0=cA}GS50_74^~mw2n5=L-Z&O(stTGJ87JD(cUcoOnYka W>;?;%{~iPVe{H&+<%<-|y8Z_t1j?BJ delta 657 zcmZ8fUuaTM82`@ks#gp0T7i>@n{$?XC>ByG;p(RDu0P|>T?j@GmSYb!qG1uV9^CN3 ziOAf&K@SSjyk&0-dQD7LVGklBdK|`B_89D8FM)kmT2a5l_wk+IJ@A@RK*J^-X(fJ0d#Fv4t|g+=e5_DNQA zrNggy$fyO&oN|stLmgmbd4j$G(mu6xo3zn_7e;c4f$@c{-D1~sE#at7$JDhZx^rM4 zBn*l{Kvp(LWV9qhe!FHd@Df?)Hf%#}NNK*tm6)oDf^Cr%9%03!#?#?ID_Pn`amR-P znCe0N(0ri8Xf$L8RmhAPPOp{PkdM1JNo&d&Uf9}u`#o9w$_k!MRU5h!Q*Zd@flGEOL$cR#L-; z{xn3Lc$2vOK6t$O-(U(OhdI4(e=%V4D_Lge{2BW1@KGNP{23v7nTqr}jnNzQCcQ;x l>0NrCKBSM8tg)&{=9+TQ>^|Q64`A%!liMe8S)I|RzW^`(&~*R+ diff --git a/palm-client/resources/largefont.txt b/palm-client/resources/largefont.txt index e5ca5f5..432aa5b 100644 --- a/palm-client/resources/largefont.txt +++ b/palm-client/resources/largefont.txt @@ -1122,6 +1122,86 @@ GLYPH 144 #---# -###- +GLYPH 145 +------ +------ +--#--- +-##--- +#####- +#####- +####-- +------ + +GLYPH 146 +----- +----- +-###- +##-## +##### +##-## +-###- +#---# + +GLYPH 147 +----- +----- +##-## +##### +##### +-###- +--#-- +----- + +GLYPH 148 +----- +----- +-###- +##-## +#---# +#-#-# +-###- +-#--- + +GLYPH 149 +----- +----- +--#-- +-#-#- +-#-#- +#-#-# +##-## +----- + +GLYPH 150 +------ +------ +-#-#-- +#-#-#- +#####- +#####- +-###-- +------ + +GLYPH 151 +----- +----- +--#-- +-##-# +-#### +##-## +-###- +----- + +GLYPH 152 +------ +------ +--#-#- +#--#-- +-##-#- +-###-- +####-- +------ + GLYPH 153 ----- ----- @@ -1132,6 +1212,16 @@ GLYPH 153 -###- ----- +GLYPH 154 +------ +------ +-###-- +##-##- +#---#- +#-###- +-##--# +---##- + GLYPH 155 ----- ----- @@ -1142,6 +1232,36 @@ GLYPH 155 ----- ----- +GLYPH 156 +------ +------ +------ +##-##- +#####- +##-##- +------ +------ + +GLYPH 157 +----- +----- +-#-#- +#-#-# +--#-- +-###- +#-#-# +----- + +GLYPH 158 +---------- +---------- +#-###-###- +#-#-#-#-#- +#-#-#-#-#- +#-###-###- +---------- +#########- + GLYPH 160 ----- ----- diff --git a/palm-client/resources/smallfont.nfnt b/palm-client/resources/smallfont.nfnt index 8f5ae8b831e39886c48ce7f2310294f7157d7497..3cccb6502fb2522bf7726f3af1952c9e37269ceb 100644 GIT binary patch delta 695 zcmXX^Ur5tY6u$R6n{I2-#EE~&iI##7J_yR%g9{O7Mk4ydz|6ov!b(HT2cb>0yi3jG z=MN_)4SProi72RuOsGh6R$!9pMpj5hMVJo-M(a-f4(EIy_nhxsxZH8`k~!%rV>T9M zCKiE-MWK-C8JGG%f0EsiwtUW-cBF|ZK|`mt_wW=8dVS6nLwk%@-|PCSThM83HlWpZ7FE$bBYVA-(?-W zBd=CsEJ8@XM2RL#d1RmDgNjm9v!cF~{`F_)gRNIivN2}RvN~g@7)!Av_}iye&&at` za!2T`5bYzOnUp{v@I5dW3JwV2?Fl@;=vVV#cfjV951GKC|3=6x3u6|U`)xZy(iS3z zh8-;_F>ys5#j5)ipXZA_#6R&h{)2DuKl~p619l@`Mlw>7j!a}D2f4_H0|h8VF-lQ} z3RIyQwWvcq8qkPlw4x1ebf62}=!1$u4C6X(;3jV2Htym+9^na|;ss{$8uNIE~E)J5IYM=A}{u-c@5pn7ysYKA^zFN=~NZ#yDtJ9S%Z3Ws+_O$dko1Lb_& A0RR91 delta 648 zcmZ8dO=uHA7@c{uvl3~+26||rvYEI^iUgakY28Y})l_Yv(8P{GrD9tWqaemW+z5(4 zAlQS_5IlGg^x(mwpofAUJVYqyAz%YNw9rEjIaDavLk~TaI9sZq?_=J4yzhJSU{+e@ zS~_P5F-Vhe;(-$#hZR%R_mw+sD~|vVp6em~B75K%jKq{Pof>fBj#;P%e;oBEPddGI z;$$2%RSl;!e{!fq%Fk?Tjub{hTKz#OEzF!Q6NU&0>AG$qD#B*UAQ{2QfDoZEQxMW? z;KW%{0ky3eoa*QLyqgmVejQ@rtCaF?HY>zUDN{u$&s&x?A*BfQ2@zJaOpa7;E8hwV zy+QraY!8{@5kHT-Q&}>R5aNhhQr3*3aqk^B9^d> zRji?bb!=c0TiC`9ql_~jYh`V$oprD-7GNgpW>FSnab~kY=CC0)%tl#~$;vDKsq#V7 XE93mo!RCJ;yxAn$A8~JWKbp 0 && n < sizeof(name)) + break; } - for (end = i + 2; end < len && text[end] != ']'; end++) - ; - n = end - (i + 2); - if (end >= len || n == 0 || n >= sizeof(name)) { - i++; - continue; + if (i + 2 >= len) + i = len; + /* the plain text before it */ + if (hitX < 0) { + WinDrawChars(text + start, i - start, x, y); + x += FntCharsWidth(text + start, i - start); + } else { + for (k = start; k < i; k++, x += w) { + w = FntCharWidth(text[k]); + if (hitX < x + w) + return hitX >= x ? (Int16)k : -1; + } } - WinDrawChars(text + start, i - start, x, y); - x += FntCharsWidth(text + start, i - start); + if (i >= len) + return -1; MemMove(name, text + i + 2, n); name[n] = 0; - x += DrawChip(name, x, y - 1); + w = hitX < 0 ? DrawChip(name, x, y - 1) : ChipWidth(name); + if (hitX >= 0 && hitX < x + w) + return -1; + x += w; i = start = end + 1; } - WinDrawChars(text + start, len - start, x, y); } static void DrawLine(UInt16 row, const RectangleType *b, void *ctx) @@ -253,7 +276,7 @@ static void DrawLine(UInt16 row, const RectangleType *b, void *ctx) StrPrintF(buf, "%02u:%02u", dt.hour, dt.minute); WinDrawChars(buf, StrLen(buf), x + TIME_X, y); } - DrawTextWithMentions(text, l->len, x + TEXT_X, y); + TextWithMentions(text, l->len, x + TEXT_X, y, -1); if (l->last) { SuffixOf(h, buf); if (buf[0]) @@ -371,13 +394,56 @@ static void InsertMention(const Char *sender) DrawCounter(); } -/* Tap a failed message of ours to retry it, or someone's channel message to reply to them. */ -static void Tapped(UInt16 row) +/* An emoji (or its neighbour, they're narrow) under the pen: show it enlarged. */ +static Boolean TappedEmoji(UInt16 row, Coord penX) { - const VmMsgHeader *h = MessagesLock(gLines[row].msg); + FormType *form = FrmGetActiveForm(); + const Line *l = &gLines[row]; + const VmMsgHeader *h; + const Char *text; + RectangleType b; + FontID old; + Int16 k; + Char c[3]; + UInt16 n = 0, i; + + if (l->kind != L_TEXT) + return false; + h = MessagesLock(l->msg); + if (!h) + return false; + FrmGetObjectBounds(form, FrmGetObjectIndex(form, ConvoGadget), &b); + text = (const Char *)(h + 1) + l->off; + old = FntSetFont(vmSmallFont); + k = TextWithMentions(text, l->len, b.topLeft.x + TEXT_X, 0, penX); + FntSetFont(old); + if (k >= 0) { + c[n++] = text[k]; + if (k > 0) + c[n++] = text[k - 1]; + if (k + 1 < (Int16)l->len) + c[n++] = text[k + 1]; + } + MessagesRelease(l->msg); + for (i = 0; i < n; i++) + if (EmojiShow(c[i])) + return true; + return false; +} + +/* + * Tap an emoji to see it enlarged, a failed message of ours to retry it, or + * someone's channel message to reply to them. + */ +static void Tapped(UInt16 row, Coord penX) +{ + const VmMsgHeader *h; Boolean failed, reply; Char sender[VM_NAME_SIZE]; + if (TappedEmoji(row, penX)) + return; + h = MessagesLock(gLines[row].msg); if (!h) return; failed = h->dir == VM_DIR_OUT && h->status == VM_ST_FAILED; @@ -466,7 +532,7 @@ Boolean ConvoFormHandleEvent(EventType *event) if (gLines && RowListHandleEvent(&gList, event, &tapped)) { if (tapped >= 0) - Tapped((UInt16)tapped); + Tapped((UInt16)tapped, event->screenX); return true; } return false; diff --git a/palm-client/src/resources.h b/palm-client/src/resources.h index e14a646..b94854b 100644 --- a/palm-client/src/resources.h +++ b/palm-client/src/resources.h @@ -157,6 +157,7 @@ #define SmallFontRes 1000 #define LargeFontRes 1001 +#define EmojiArtRes 1002 #define FontPreviewForm 1400 #define FontPreviewDoneButton 1401 diff --git a/palm-client/src/ui/draw.c b/palm-client/src/ui/draw.c index fc3f075..7a63df0 100644 --- a/palm-client/src/ui/draw.c +++ b/palm-client/src/ui/draw.c @@ -71,6 +71,11 @@ void DrawSection(const Char *label, Coord x0, Coord y, Coord width) #define CHIP_PAD_X 2 #define CHIP_PAD_Y 1 +Coord ChipWidth(const Char *text) +{ + return FntCharsWidth(text, StrLen(text)) + 2 * CHIP_PAD_X; +} + Coord DrawChip(const Char *text, Coord x, Coord y) { UInt16 len = StrLen(text); diff --git a/palm-client/src/ui/draw.h b/palm-client/src/ui/draw.h index ace2186..4818d6c 100644 --- a/palm-client/src/ui/draw.h +++ b/palm-client/src/ui/draw.h @@ -27,6 +27,8 @@ 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 (gUiFontHeight + 2) Coord DrawChip(const Char *text, Coord x, Coord y) VM_SECT2; +/* The width DrawChip would take, without drawing. */ +Coord ChipWidth(const Char *text) VM_SECT2; /* 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) VM_SECT2; diff --git a/palm-client/src/ui/emoji.c b/palm-client/src/ui/emoji.c new file mode 100644 index 0000000..9cdaa6e --- /dev/null +++ b/palm-client/src/ui/emoji.c @@ -0,0 +1,94 @@ +#include +#include "../resources.h" +#include "draw.h" +#include "emoji.h" + +static void WaitForTap(void) VM_SECT3; + +#define ENTRY 56 /* code, name[23], 16 rows of 2 bytes */ +#define NAME_SIZE 23 +#define SCALE 2 +#define BOX_W 104 +#define BOX_H 70 + +/* Until a tap (down and up) or a key; the tap that opened the box is still queued. */ +static void WaitForTap(void) +{ + EventType e; + Boolean down = false; + + for (;;) { + EvtGetEvent(&e, evtWaitForever); + if (e.eType == appStopEvent) { + EvtAddEventToQueue(&e); + return; + } + if (e.eType == keyDownEvent) + return; + if (e.eType == penDownEvent) + down = true; + else if (e.eType == penUpEvent && down) + return; + } +} + +Boolean EmojiShow(Char c) +{ + MemHandle h = DmGetResource('EMJI', EmojiArtRes); + const UInt8 *p, *e = NULL; + UInt8 bits[32]; + Char name[NAME_SIZE + 1]; + RectangleType box, save, px; + WinHandle under; + UInt16 i, err, row, col, rowBits; + Coord x0, y0; + FontID old; + + if (!h) + return false; + p = (const UInt8 *)MemHandleLock(h); + for (i = 0; i < p[0]; i++) + if (p[1 + i * ENTRY] == (UInt8)c) + e = p + 1 + i * ENTRY; + if (e) { + MemMove(name, e + 1, NAME_SIZE); + name[NAME_SIZE] = 0; + MemMove(bits, e + 1 + NAME_SIZE, sizeof(bits)); + } + MemHandleUnlock(h); + DmReleaseResource(h); + if (!e) + return false; + + RctSetRectangle(&box, (160 - BOX_W) / 2, 40, BOX_W, BOX_H); + RctSetRectangle(&save, box.topLeft.x - 3, box.topLeft.y - 3, BOX_W + 6, BOX_H + 6); + under = WinSaveBits(&save, &err); + WinEraseRectangle(&box, 0); + WinDrawRectangleFrame(dialogFrame, &box); + + x0 = box.topLeft.x + (BOX_W - 16 * SCALE) / 2; + y0 = box.topLeft.y + 4; + for (row = 0; row < 16; row++) { + rowBits = (UInt16)((bits[2 * row] << 8) | bits[2 * row + 1]); + for (col = 0; col < 16; col++) { + if (!(rowBits & (0x8000 >> col))) + continue; + RctSetRectangle(&px, x0 + col * SCALE, y0 + row * SCALE, SCALE, SCALE); + WinDrawRectangle(&px, 0); + } + } + old = FntSetFont(stdFont); + WinDrawChars(name, StrLen(name), box.topLeft.x + (BOX_W - FntCharsWidth(name, StrLen(name))) / 2, + y0 + 16 * SCALE + 3); + FntSetFont(vmSmallFont); + WinDrawChars("tap to close", 12, box.topLeft.x + (BOX_W - FntCharsWidth("tap to close", 12)) / 2, + box.topLeft.y + BOX_H - gUiFontHeight - 3); + FntSetFont(old); + + WaitForTap(); + if (under) + WinRestoreBits(under, save.topLeft.x, save.topLeft.y); + else + FrmUpdateForm(FrmGetActiveFormID(), frmRedrawUpdateCode); + return true; +} diff --git a/palm-client/src/ui/emoji.h b/palm-client/src/ui/emoji.h new file mode 100644 index 0000000..044d3ae --- /dev/null +++ b/palm-client/src/ui/emoji.h @@ -0,0 +1,16 @@ +/* + * The enlarged view of an emoji: its 16x16 picture at double size and its + * name, in a box over the screen until the next tap. The pictures come from + * resources/emoji.bin (tools/gen_font.py), a resource rather than a table in + * the code (see sections.h). + */ +#ifndef VM_EMOJI_H +#define VM_EMOJI_H + +#include +#include "../sections.h" + +/* Shows c if it's one of the font's emoji (or GLYPH_EMOJI); false if it isn't one. */ +Boolean EmojiShow(Char c) VM_SECT3; + +#endif diff --git a/palm-client/src/ui/fontmetrics.c b/palm-client/src/ui/fontmetrics.c index c037860..ca6eb14 100644 --- a/palm-client/src/ui/fontmetrics.c +++ b/palm-client/src/ui/fontmetrics.c @@ -13,7 +13,7 @@ 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, 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, 5, 4, 4, 4, 4, 4, 4, + 5, 6, 5, 5, 5, 5, 6, 5, 6, 5, 6, 4, 6, 5, 10, 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, @@ -31,7 +31,7 @@ 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, 4, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 6, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 10, 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, diff --git a/palm-client/src/ui/glyphs.h b/palm-client/src/ui/glyphs.h index 03d2ac9..42b448c 100644 --- a/palm-client/src/ui/glyphs.h +++ b/palm-client/src/ui/glyphs.h @@ -21,6 +21,18 @@ #define GLYPH_PENDING ((Char)0x90) #define GLYPH_EMOJI ((Char)0x99) #define GLYPH_FORWARD ((Char)0x9B) +#define GLYPH_THUMBS ((Char)0x91) +#define GLYPH_LAUGH ((Char)0x92) +#define GLYPH_HEART ((Char)0x93) +#define GLYPH_CRY ((Char)0x94) +#define GLYPH_PRAY ((Char)0x95) +#define GLYPH_WAVE ((Char)0x96) +#define GLYPH_FIRE ((Char)0x97) +#define GLYPH_PARTY ((Char)0x98) +#define GLYPH_THINK ((Char)0x9A) +#define GLYPH_EYES ((Char)0x9C) +#define GLYPH_DISH ((Char)0x9D) +#define GLYPH_HUNDRED ((Char)0x9E) #define VM_SMALL_FONT_HEIGHT 6 #define VM_LARGE_FONT_HEIGHT 8 diff --git a/palm-client/src/ui/text.c b/palm-client/src/ui/text.c index 0cfbe84..3debe4f 100644 --- a/palm-client/src/ui/text.c +++ b/palm-client/src/ui/text.c @@ -137,8 +137,25 @@ UInt16 TxtSplitSender(const Char *text, UInt16 len) */ static Char MapUnicode(UInt32 cp) { - if (cp == 0xFE0F || cp == 0xFE0E || (cp >= 0x200B && cp <= 0x200F) || cp == 0x2060) - return 0; /* invisible */ + if (cp == 0xFE0F || cp == 0xFE0E || (cp >= 0x200B && cp <= 0x200F) || cp == 0x2060 || + (cp >= 0x1F3FB && cp <= 0x1F3FF)) + return 0; /* invisible; skin tones: the plain emoji */ + /* the emoji with their own glyph (tools/gen_font.py EMOJI); the rest get GLYPH_EMOJI */ + switch (cp) { + case 0x1F44D: return GLYPH_THUMBS; + case 0x1F602: case 0x1F923: return GLYPH_LAUGH; + case 0x2764: case 0x2665: case 0x1F499: case 0x1F49A: case 0x1F49B: case 0x1F49C: + case 0x1F5A4: case 0x1F90D: case 0x1F90E: case 0x1F9E1: return GLYPH_HEART; + case 0x1F622: case 0x1F62D: return GLYPH_CRY; + case 0x1F64F: return GLYPH_PRAY; + case 0x1F44B: return GLYPH_WAVE; + case 0x1F525: return GLYPH_FIRE; + case 0x1F389: case 0x1F973: return GLYPH_PARTY; + case 0x1F914: return GLYPH_THINK; + case 0x1F440: return GLYPH_EYES; + case 0x1F4E1: return GLYPH_DISH; + case 0x1F4AF: return GLYPH_HUNDRED; + } if ((cp >= 0x1F000 && cp <= 0x1FAFF) || (cp >= 0x2600 && cp <= 0x27BF && cp != 0x2605 && cp != 0x2713 && cp != 0x2714 && cp != 0x2717 && cp != 0x2718 && cp != 0x2705 && cp != 0x274C)) return GLYPH_EMOJI; diff --git a/palm-client/tests/test_text.c b/palm-client/tests/test_text.c index a60e09f..5053d2b 100644 --- a/palm-client/tests/test_text.c +++ b/palm-client/tests/test_text.c @@ -80,6 +80,20 @@ static void test_age_and_snr(void) { char buf[16]; + { + /* thumbs up with a skin tone, tears of joy, rolling (same glyph), a heart with VS16, 100, a rocket */ + static const UInt8 em[] = { + 0xF0, 0x9F, 0x91, 0x8D, 0xF0, 0x9F, 0x8F, 0xBD, + 0xF0, 0x9F, 0x98, 0x82, 0xF0, 0x9F, 0xA4, 0xA3, + 0xE2, 0x9D, 0xA4, 0xEF, 0xB8, 0x8F, + 0xF0, 0x9F, 0x92, 0xAF, 0xF0, 0x9F, 0x9A, 0x80 + }; + Char o[16]; + + CHECK(TxtUtf8ToPalm(em, sizeof(em), o, sizeof(o)) == 6); + CHECK(o[0] == GLYPH_THUMBS && o[1] == GLYPH_LAUGH && o[2] == GLYPH_LAUGH); + CHECK(o[3] == GLYPH_HEART && o[4] == GLYPH_HUNDRED && o[5] == GLYPH_EMOJI); + } { static const UInt8 key[] = { 0x00, 0x9c, 0xd8, 0xff, 0x0a }; Char hex[11]; @@ -120,7 +134,7 @@ static void test_utf8(void) CHECK(TxtUtf8ToPalm(cafe, sizeof(cafe), out, sizeof(out)) == 4 && (unsigned char)out[3] == 0xE9); CHECK(TxtUtf8ToPalm(dots, sizeof(dots), out, sizeof(out)) == 2 && out[1] == GLYPH_ELLIPSIS); - CHECK(TxtUtf8ToPalm(emoji, sizeof(emoji), out, sizeof(out)) == 4 && out[3] == GLYPH_EMOJI); + CHECK(TxtUtf8ToPalm(emoji, sizeof(emoji), out, sizeof(out)) == 4 && out[3] == GLYPH_WAVE); { /* "a→b" (arrow), "“hi”" (curly quotes), "x—y" (em dash), "❤️" (heart + VS16) */ static const UInt8 arrow[] = { 'a', 0xE2, 0x86, 0x92, 'b' }; @@ -132,7 +146,7 @@ static void test_utf8(void) CHECK(TxtUtf8ToPalm(arrow, sizeof(arrow), out, sizeof(out)) == 3 && out[1] == GLYPH_RIGHT); CHECK(TxtUtf8ToPalm(quotes, sizeof(quotes), out, sizeof(out)) == 4 && strcmp(out, "\"hi\"") == 0); CHECK(TxtUtf8ToPalm(dash, sizeof(dash), out, sizeof(out)) == 3 && strcmp(out, "x-y") == 0); - CHECK(TxtUtf8ToPalm(heart, sizeof(heart), out, sizeof(out)) == 1 && out[0] == GLYPH_EMOJI); + CHECK(TxtUtf8ToPalm(heart, sizeof(heart), out, sizeof(out)) == 1 && out[0] == GLYPH_HEART); CHECK(TxtUtf8ToPalm(check, sizeof(check), out, sizeof(out)) == 1 && out[0] == GLYPH_ACKED); } CHECK(TxtUtf8ToPalm(broken, sizeof(broken), out, sizeof(out)) == 2 && strcmp(out, "x?") == 0); diff --git a/palm-client/tools/gen_font.py b/palm-client/tools/gen_font.py index b728253..d18dea9 100644 --- a/palm-client/tools/gen_font.py +++ b/palm-client/tools/gen_font.py @@ -11,6 +11,8 @@ Outputs: 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 of both, for text layout + resources/emoji.bin 16x16 pictures and names of the emoji in the font, + for the tap-to-enlarge view (ui/emoji.c) 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 @@ -23,6 +25,7 @@ HERE = os.path.dirname(os.path.abspath(__file__)) 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') +OUT_EMOJI = os.path.join(HERE, '..', 'resources', 'emoji.bin') # (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. @@ -56,6 +59,214 @@ SYMBOLS = [ (0x9B, 'GLYPH_FORWARD', 0x203A), ] +# The emoji with their own glyph (src/ui/text.c MapUnicode says which code points +# land on each): (code point in the font, C name, 6-row glyph, 16x16 picture for +# the enlarged view, name shown there). GLYPH_EMOJI, the stand-in for the rest, +# comes first in emoji.bin. +FACE = [ + '.....######.....', + '...##......##...', + '..#..........#..', + '.#............#.', + '.#............#.', + '#..............#', + '#..............#', + '#..............#', + '#..............#', + '#..............#', + '.#............#.', + '.#............#.', + '..#..........#..', + '...##......##...', + '.....######.....', + '................', +] + + +def face(features): + """FACE with (row, col) pixels added.""" + rows = [list(r) for r in FACE] + for r, c in features: + rows[r][c] = '#' + return [''.join(r) for r in rows] + + +def pts(row, cols): + return [(row, c) for c in cols] + + +EMOJI = [ + (0x99, 'GLYPH_EMOJI', None, + face(pts(5, [5, 10]) + pts(6, [5, 10]) + pts(9, [4, 11]) + pts(10, [5, 10]) + pts(11, [6, 7, 8, 9])), + "Not in the Visor's set"), + (0x91, 'GLYPH_THUMBS', ['--#---', '-##---', '#####-', '#####-', '####--', '------'], [ + '................', + '.......##.......', + '......#..#......', + '......#..#......', + '.....#...#......', + '.....#...#......', + '....#....######.', + '###.#.........#.', + '#.#.#........##.', + '#.#.#.........#.', + '#.#.#........##.', + '#.#.#.........#.', + '#.#.#........##.', + '###..########...', + '................', + '................'], 'Thumbs up'), + (0x92, 'GLYPH_LAUGH', ['-###-', '##-##', '#####', '##-##', '-###-', '#---#'], + face(pts(4, [5, 10]) + pts(5, [4, 6, 9, 11]) + pts(6, [3, 12]) + pts(7, [3, 12]) + + pts(8, range(3, 13)) + pts(9, [3, 12]) + pts(10, [4, 11]) + pts(11, range(5, 11))), 'Tears of joy'), + (0x93, 'GLYPH_HEART', ['##-##', '#####', '#####', '-###-', '--#--', '-----'], [ + '................', + '..####....####..', + '.######..######.', + '################', + '################', + '################', + '################', + '.##############.', + '..############..', + '...##########...', + '....########....', + '.....######.....', + '......####......', + '.......##.......', + '................', + '................'], 'Red heart'), + (0x94, 'GLYPH_CRY', ['-###-', '##-##', '#---#', '#-#-#', '-###-', '-#---'], + face(pts(5, [4, 5, 10, 11]) + pts(6, [4, 5, 10, 11]) + pts(8, [4]) + pts(9, [4]) + + pts(10, range(5, 11)) + pts(11, [4, 11])), 'Crying face'), + (0x95, 'GLYPH_PRAY', ['--#--', '-#-#-', '-#-#-', '#-#-#', '##-##', '-----'], [ + '......####......', + '.....#.##.#.....', + '.....#.##.#.....', + '.....#.##.#.....', + '....#..##..#....', + '....#..##..#....', + '...#...##...#...', + '...#...##...#...', + '..#....##....#..', + '..#....##....#..', + '..#....##....#..', + '..#...#..#...#..', + '..#..#....#..#..', + '.####......####.', + '.####......####.', + '................'], 'Folded hands'), + (0x96, 'GLYPH_WAVE', ['-#-#--', '#-#-#-', '#####-', '#####-', '-###--', '------'], [ + '...#.#.#........', + '...#.#.#.#......', + '...#.#.#.#...#..', + '...#.#.#.#..#...', + '...#.#.#.#.#..#.', + '...#######.#.#..', + '...#.......#.#..', + '...#......#.....', + '...#.....#..#...', + '...#....#..#....', + '....#..#........', + '.....##.........', + '................', + '................', + '................', + '................'], 'Waving hand'), + (0x97, 'GLYPH_FIRE', ['--#--', '-##-#', '-####', '##-##', '-###-', '-----'], [ + '.......#........', + '.......##.......', + '......###.......', + '......####......', + '.....#####...#..', + '....#######.##..', + '....##########..', + '...###########..', + '..#####.######..', + '..####...#####..', + '..###.....####..', + '..###..#..###...', + '..###.###.###...', + '...##.###.##....', + '....#######.....', + '................'], 'Fire'), + (0x98, 'GLYPH_PARTY', ['--#-#-', '#--#--', '-##-#-', '-###--', '####--', '------'], [ + '.......#....#...', + '...#.........#..', + '.....#..##......', + '#......#..#..#..', + '......#...#.....', + '.....#....#..#..', + '....#.....#.....', + '...#.....#...#..', + '..#.....#.......', + '..#....#....#...', + '.#....#.........', + '.#...#....#.....', + '#...#...........', + '#.##............', + '##..............', + '................'], 'Party popper'), + (0x9A, 'GLYPH_THINK', ['-###--', '##-##-', '#---#-', '#-###-', '-##--#', '---##-'], + face(pts(3, [9, 10, 11]) + pts(5, [5, 10]) + pts(6, [5, 10]) + pts(10, range(6, 10))) [:12] + [ + '..####.##.......', + '.#....#.........', + '.#....#.........', + '..####..........'], 'Thinking face'), + (0x9C, 'GLYPH_EYES', ['------', '##-##-', '#####-', '##-##-', '------', '------'], [ + '................', + '................', + '................', + '..####....####..', + '.#....#..#....#.', + '#......##......#', + '#...##.##...##.#', + '#...##.##...##.#', + '#......##......#', + '.#....#..#....#.', + '..####....####..', + '................', + '................', + '................', + '................', + '................'], 'Eyes'), + (0x9D, 'GLYPH_DISH', ['-#-#-', '#-#-#', '--#--', '-###-', '#-#-#', '-----'], [ + '................', + '..#....#....#...', + '.#..#..#..#..#..', + '.#.#...#...#.#..', + '.#.#..###..#.#..', + '.#..#.###.#..#..', + '..#...#.#...#...', + '......#.#.......', + '.....#...#......', + '.....#...#......', + '....#.###.#.....', + '....#.....#.....', + '...#.......#....', + '...#.......#....', + '..###.....###...', + '................'], 'Antenna'), + (0x9E, 'GLYPH_HUNDRED', ['#-###-###-', '#-#-#-#-#-', '#-#-#-#-#-', '#-###-###-', '----------', '#########-'], [ + '................', + '................', + '.##..###...###..', + '###.#...#.#...#.', + '.##.#...#.#...#.', + '.##.#...#.#...#.', + '.##.#...#.#...#.', + '.##.#...#.#...#.', + '.##.#...#.#...#.', + '####.###...###..', + '................', + '###############.', + '................', + '###############.', + '................', + '................'], 'Hundred points'), +] +SYMBOLS += [(code, name, small) for code, name, small, _big, _title in EMOJI if small] + def parse_bdf(path, ascent, descent): """Returns {codepoint: (width, rows)} with rows as ascent + descent strings of '#'/'-'.""" @@ -226,6 +437,17 @@ def main(): f.write('\n#define VM_SMALL_FONT_HEIGHT %d\n#define VM_LARGE_FONT_HEIGHT %d\n\n#endif\n' % (heights['small'], heights['large'])) + # emoji.bin: count, then per emoji: code, name[23], 16 rows of 2 bytes (MSB = left) + out = bytearray([len(EMOJI)]) + for code, _cname, _small, big, title in EMOJI: + assert len(big) == 16 and all(len(r) == 16 for r in big), (hex(code), [len(r) for r in big]) + out.append(code) + out += title.encode('latin-1')[:22].ljust(23, b'\0') + for r in big: + out += int(r.replace('.', '0').replace('#', '1'), 2).to_bytes(2, 'big') + with open(OUT_EMOJI, 'wb') as f: + f.write(out) + with open(OUT_METRICS, 'w') as f: f.write('/* GENERATED by tools/gen_font.py: UI font character widths in pixels. */\n') f.write('#include "fontmetrics.h"\n\n')