diff --git a/apps/watch-replies/CHANGES.md b/apps/watch-replies/CHANGES.md new file mode 100644 index 0000000..0c34733 --- /dev/null +++ b/apps/watch-replies/CHANGES.md @@ -0,0 +1,127 @@ +## Next +- A long message now comes whole (up to 400 bytes) and shows folded to 4 lines with an underlined "Show more"; tapping it opens all of it, with "Show less" at the end. The phone sends the rest in `r1M` pieces. +- The pin sign on a pinned chat is smaller (19 x 26). +- Hindi glyphs are back. To make room the small name font is gone (names use the normal font) and the test page is not in this version. +- Hindi: a Hindi keyboard (consonants / more letters and vowel signs / vowels, Shift steps through them) with Devanagari text drawn in messages; the short i sign is put before its letter. Conjuncts show the halant sign instead of joining. Dictation uses hi-IN. +- Two keyboards: the phone's Watch Replies settings pick Keyboard 1 (English, Arabic or Hindi) and Keyboard 2 (none, or one of the other two). Holding Space switches between them; with none, it does nothing. +- Memory: the separate 32 px UI font is gone (all text uses the 27 px font), which pays for the Hindi glyphs. + +## 1.2.27 +- Conversation focus: Watch Replies sends a small heartbeat with the selected chat; the phone expires stale focus automatically. New messages for the open chat update it in place, while other chats continue to enter the inbox normally. +- Phone discovery: the companion reads installed WP2 app identifiers and shows only registered Watch Menu apps on Home. +- Home tiles: slightly shorter 5:4 cards. + +## 1.2.26 +- Conversation focus: Watch Replies sends a small heartbeat with the selected chat; the phone expires stale focus automatically. New messages for the open chat update it in place, while other chats continue to enter the inbox normally. +- Phone discovery: the companion reads installed WP2 app identifiers and shows only registered Watch Menu apps on Home. +- Home tiles: slightly shorter 5:4 cards. + +## 1.2.25 +- Scrolling: cache conversation layout height outside animation frames, use finger travel for swipe distance and make the glide settle faster without removing its easing. +- Dictation: microphone icon redrawn as a solid microphone with a cleaner cradle; the red listening state remains. +- Dictation: the watch's keyboard language now selects English (en-US) or Egyptian Arabic (ar-EG) explicitly. + +## 1.2.24 +- Keyboard: the empty send slot is now a phone-microphone dictation button; speech appears in the editable draft, and typing switches the same slot back to the blue send button. + +## 1.2.23 +- Conversation: the black rim round the app sign is smooth now. It was drawn in whole pixels, so its edge looked stepped, and Messenger's came out lumpy because dark corner pixels of its picture were counted as part of the sign. The rim now follows the real shape evenly (tail included) and its edge blends into the bubble colour under it. The round sign of other apps got the same soft edge. + +## 1.2.22 +- Conversation: the app sign at the top has no black circle behind it any more. It has a black outline that follows its own shape (the tail included), so the bubbles scrolling under it show right up to its edge. + +## 1.2.21 +- The app sign and the Message box now float over the bubbles (each with a black rim); the bubbles scroll under them all the way to the screen edge instead of being cut off above and below. +- Less lag: the small WhatsApp sign is pre-drawn (it was filtered again on every frame), and the glide takes the same time however long a frame needs. + +## 1.2.20 +- WhatsApp icon redrawn: smooth round edges, a clean tail and a black rim around it like the others (it was a jagged bitmap that touched the edge). + +## 1.2.19 +- Bubbles stick to the round wall: theirs to the left side, mine to the right side, and they follow the curve of the wall as you scroll (no more middle lane). +- Smoother glide: smaller steps, more frames. + +## 1.2.18 +- Curved list: in the messages screen the bubbles follow the round screen (all of them now, also the middle ones), and the gliding is quicker. +- Drawing is faster: the round-screen edge is looked up from a table instead of being worked out for every row. +- The list of chats (WhatsApp, Messenger...) is unchanged: no curve, no slide. + +## 1.2.17 +- Conversation: bigger bubbles. Plain English messages use the big font (32 px, was 27), with more room round the text and a wider bubble; messages with Arabic letters keep the Arabic-capable font, a little more spaced. +- Conversation: your own reply no longer comes back as a message from them. The chat app puts your reply in its notification and the phone sent it on as a new message, so your "hi" showed up on the left as theirs. For 8 seconds after you send, a message from that chat with the same text (or "You: text") is taken for your own reply and left out. It counts once, and a message with other words, or from another chat, is shown as usual. + +## 1.2.16 +- Font: the T font (fixed English UI text and single key letters) no longer carries its own Arabic table — it was an exact duplicate of the one in B, which is what Arabic text actually uses. Frees about 18.7KB. +- Word/suggestion lists trimmed further. + +## 1.2.15 +- Shrank the word lists (suggestions) so the app fits in the image size again — it was overflowing by about 30KB after Arabic was added. + +## 1.2.14 +- Conversation: every bubble has a pointed tail at its bottom corner, on the left for theirs and on the right for yours. + +## 1.2.13 +- Message cards: shorter, so the bottom gap matches the top; the app sign gets a black cut-out that follows its outline (the WhatsApp and Messenger tails included), half on the card and half off. + +## 1.2.12 +- Conversation: the app sign at the top is smaller (44 px) and the bubbles start higher, so more messages fit. + +## 1.2.11 +- Conversation: the sender's name is smaller than the text, the bubble corners are rounder, your replies are a normal grey with white text, and bubbles from other apps (SMS and so on) are light grey. + +## 1.2.10 +- The conversation screen is now a chat: their messages are bubbles on the left with the name (green WhatsApp, blue Messenger, light blue Telegram, dark grey for other apps), your replies are light grey bubbles on the right, and the reply button is a "Message" box (tap it for the keyboard). Replies you send from the watch stay in the conversation. + +## 1.2.9 +- WhatsApp icon: it had empty margin around it, so it looked smaller than Messenger and Telegram. Trimmed and scaled to the same full size. + +## 1.2.8 +- Keyboard: the text line and the suggestion row moved up about 28 px, and the keys use the room: taller keys, and the top row a little narrower so it stays on the round screen. + +## 1.2.7 +- Reply button: taller, with a larger "reply". +- Keyboard: bigger letters; a smaller space bar; bigger send and delete buttons. (The unused arrow tile next to the suggested words was already removed in 1.2.6.) + +## 1.2.6 +- Chats are told apart by the phone's id only. Before, chats whose names were replaced by dots (Arabic names) were taken for one chat, so only one WhatsApp chat showed. +- Suggested words: while you type a word, the row above the keys offers words that continue it (ho -> home); tap one to finish the word and add a space. + +## 1.2.5 +- Keyboard: wider keys, using the room the round screen has at each row. Quick replies: wider fit, and "Ok / On my way / Thanks!" show even before the phone sends its own. + +## 1.2.4 +- Messages from the same chat now pile up: the first screen still shows the newest message, but opening it shows every message you missed from that chat (oldest at the top, newest at the bottom, scrolls). Kept: the last ~400 letters per chat. + +## 1.2.3 +- WhatsApp icon: removed the white outline and grey fringe, clean green bubble like the others. + +## 1.2.2 +- Keyboard bottom row like the Wear OS picture: ?123, a tall rounded space bar and delete side by side, with the space bar reaching down along the round edge. The full stop takes the place of the second delete key at the end of the third row (the comma is on the ?123 page). + +## 1.2.1 +- Keyboard: one delete key (at the end of the third row), outlined shift and delete signs like the Wear OS picture, and a wide, darker space bar next to ?123 on the bottom row. The unused big key font is removed (smaller app). + +## 1.2.0 +- Tapping a message opens it in full: the app's sign, the name, the whole text and a reply button. Turn the crown or swipe up and down to scroll a long text; reply opens the keyboard. Back (swipe right) goes keyboard -> message -> messages. + +## 1.1.5 +- The keyboard now matches the Wear OS picture: capital letters on dark rounded keys, three rows of letters with shift and delete, a bottom row with ?123, a wide space bar and delete, the ">" tile and suggestion chips above, a light-blue capsule send button, and the word being typed in light blue. +- The comma and full stop are on the ?123 page. + + +## 1.1.3 +- Messages from the same chat (same app and name) are one page, showing the latest message; with 8 chats, a new one drops the oldest. + +## 1.1.2 +- The WhatsApp, Messenger and Telegram signs now look like the real icons (64 px pictures, gradient included) on the empty screen and on every message page. + +## 1.1.0 +- One message per page, like a phone notification: the app's sign in the middle at the top, then the sender, the time and the message in bigger letters. Swipe up/down or turn the crown to move between messages; tap to reply. +- A full-screen keyboard: big bare letters over the whole screen, quick replies above and a send button. +- Times are shown as 12:05 a.m. + +## 1.0.1 +- A reply counts as sent when the chat disappears on the phone as well as when the phone says so; waits 15 s. + +## 1.0.0 +- First version. diff --git a/apps/watch-replies/Cargo.toml b/apps/watch-replies/Cargo.toml new file mode 100644 index 0000000..67202ea --- /dev/null +++ b/apps/watch-replies/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "watch-replies" +edition.workspace = true +license.workspace = true +version.workspace = true + +[dependencies] +cmf-wp2-app.workspace = true +cmf-wp2-ui.workspace = true + +[[bin]] +name = "watch-replies" +bench = false diff --git a/apps/watch-replies/NOTICE.md b/apps/watch-replies/NOTICE.md new file mode 100644 index 0000000..fbe790e --- /dev/null +++ b/apps/watch-replies/NOTICE.md @@ -0,0 +1,6 @@ +# Notice + +- **Watch Replies** is an original app by Abdalrahman for the CMF Watch Pro 2. It reuses the text and shape drawing + code of V-maps (also his), which began as Vela Nav by arunk140 in the CMF Tech Community apps repository (MIT). +- The text is drawn from tables made from **Noto Sans** (SIL Open Font License 1.1, `fonts/OFL.txt`). +- The WhatsApp, Messenger and Telegram signs are simple drawings made for this app; the names belong to their owners. diff --git a/apps/watch-replies/fonts/NOTO-FONT-COPYRIGHT.txt b/apps/watch-replies/fonts/NOTO-FONT-COPYRIGHT.txt new file mode 100644 index 0000000..e9dbd01 --- /dev/null +++ b/apps/watch-replies/fonts/NOTO-FONT-COPYRIGHT.txt @@ -0,0 +1,155 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: Noto +Upstream-Contact: https://github.com/googlei18n/noto-fonts/issues + http://groups.google.com/group/noto-font +Source: https://github.com/googlei18n/noto-fonts + +Files: * +Copyright: + 2010,2012-2020, Google Inc. + 2015-2020, Google LLC. +License-Grant: + This Font Software is licensed under the SIL Open Font License, + Version 1.1. +License: OFL-1.1 + +Files: + debian/* +Copyright: + 2013-2020, Jonas Smedegaard + 2020, Purism, SPC + 2013, Vasudev Kamath +License-Grant: + This program is free software; + you can redistribute it and/or modify it + under the terms of the GNU General Public License + as published by the Free Software Foundation; + either version 3, or (at your option) any later version. +License: GPL-3+ + +Files: + debian/NotoMono/NotoMono-Regular.ttf +Copyright: + 2007, Google Inc. +License-Grant: + This Font Software is licensed under the SIL Open Font License, + Version 1.1. +License: OFL-1.1 + +License: OFL-1.1 + PREAMBLE + . + The goals of the Open Font License (OFL) are to stimulate + worldwide development of collaborative font projects, + to support the font creation efforts + of academic and linguistic communities, + and to provide a free and open framework + in which fonts may be shared and improved + in partnership with others. + . + The OFL allows the licensed fonts to be used, studied, + modified and redistributed freely + as long as they are not sold by themselves. + The fonts, including any derivative works, + can be bundled, embedded, + redistributed and/or sold with any software + provided that any reserved names are not used + by derivative works. + The fonts and derivatives, however, + cannot be released under any other type of license. + The requirement for fonts to remain under this license + does not apply to any document + created using the fonts or their derivatives. + . + DEFINITIONS + . + "Font Software" refers to the set of files + released by the Copyright Holder(s) under this license + and clearly marked as such. + This may include source files, build scripts and documentation. + . + "Reserved Font Name" refers to any names specified as such + after the copyright statement(s). + . + "Original Version" refers to the collection + of Font Software components + as distributed by the Copyright Holder(s). + . + "Modified Version" refers to any derivative + made by adding to, deleting, or substituting -- + in part or in whole -- + any of the components of the Original Version, + by changing formats + or by porting the Font Software to a new environment. + . + "Author" refers to any designer, engineer, programmer, + technical writer or other person + who contributed to the Font Software. + . + PERMISSION & CONDITIONS + . + Permission is hereby granted, free of charge, + to any person obtaining a copy of the Font Software, + to use, study, copy, merge, embed, modify, redistribute, + and sell modified and unmodified copies of the Font Software, + subject to the following conditions: + . + 1) Neither the Font Software nor any of its individual components, + in Original or Modified Versions, + may be sold by itself. + . + 2) Original or Modified Versions of the Font Software + may be bundled, redistributed and/or sold with any software, + provided that each copy contains the above copyright notice + and this license. + These can be included either as stand-alone text files, + human-readable headers or in the appropriate + machine-readable metadata fields within text or binary files + as long as those fields can be easily viewed by the user. + . + 3) No Modified Version of the Font Software may use + the Reserved Font Name(s) + unless explicit written permission is granted + by the corresponding Copyright Holder. + This restriction only applies to the primary font name + as presented to the users. + . + 4) The name(s) of the Copyright Holder(s) + or the Author(s) of the Font Software + shall not be used to promote, + endorse or advertise any Modified Version, + except to acknowledge the contribution(s) + of the Copyright Holder(s) and the Author(s) + or with their explicit written permission. + . + 5) The Font Software, + modified or unmodified, in part or in whole, + must be distributed entirely under this license, + and must not be distributed under any other license. + The requirement for fonts to remain under this license + does not apply to any document + created using the Font Software. + . + TERMINATION + . + This license becomes null and void + if any of the above conditions are not met. + . + DISCLAIMER + . + THE FONT SOFTWARE IS PROVIDED "AS IS", + WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO + ANY WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. + IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE + FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + INCLUDING ANY GENERAL, SPECIAL, INDIRECT, + INCIDENTAL, OR CONSEQUENTIAL DAMAGES, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF THE USE OR INABILITY TO USE + THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. + +License: GPL-3+ +License-Reference: /usr/share/common-licenses/GPL-3 diff --git a/apps/watch-replies/fonts/OFL.txt b/apps/watch-replies/fonts/OFL.txt new file mode 100644 index 0000000..c9af0d2 --- /dev/null +++ b/apps/watch-replies/fonts/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2022 The Noto Project Authors (https://github.com/notofonts/latin-greek-cyrillic) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/apps/watch-replies/fonts/mkemoji.py b/apps/watch-replies/fonts/mkemoji.py new file mode 100644 index 0000000..7ee8684 --- /dev/null +++ b/apps/watch-replies/fonts/mkemoji.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Draws the 5 emoji (20x20, 3 colours + clear, 2 bits a pixel) and prints the Rust tables for font.rs. +Run: python3 mkemoji.py > emoji.rs.txt (also writes emoji_preview.png)""" +import math, sys +N=24; SS=6; K=1.2 # 24 x 24 dots; the shapes below are drawn on a 20 grid and scaled by K +def seg(px,py,a,b,c,d): + vx,vy=c-a,d-b; L=vx*vx+vy*vy + t=max(0,min(1,((px-a)*vx+(py-b)*vy)/L)) if L else 0 + return math.hypot(px-(a+t*vx),py-(b+t*vy)) +def disc(px,py,cx,cy,r): return math.hypot(px-cx,py-cy)<=r +def arc(px,py,cx,cy,r,a0,a1,w): + d=math.hypot(px-cx,py-cy) + if abs(d-r)>w/2: return False + a=math.degrees(math.atan2(py-cy,px-cx))%360 + return (a0%360)<=a<=(a1%360) if (a0%360)<=(a1%360) else (a>=(a0%360) or a<=(a1%360)) +# each emoji: mask(px,py)->bool body, paint(px,py)->0 body colour(1) | 2 dark | 3 accent +def laugh(): + mask=lambda x,y: disc(x,y,10,10,9.4) + def paint(x,y): + if disc(x,y,3.3,11.8,1.7) or disc(x,y,16.7,11.8,1.7) or disc(x,y,3.9,14.6,1.1) or disc(x,y,16.1,14.6,1.1): return 3 + if seg(x,y,3.9,4.6,7.0,3.6)<.45 or seg(x,y,16.1,4.6,13.0,3.6)<.45: return 2 + if seg(x,y,4.6,6.4,7.6,7.9)<.8 or seg(x,y,7.6,7.9,4.6,9.4)<.8: return 2 + if seg(x,y,15.4,6.4,12.4,7.9)<.8 or seg(x,y,12.4,7.9,15.4,9.4)<.8: return 2 + if ((x-10)/5.6)**2+((y-11.4)/4.6)**2<=1 and y>10.6: return 2 + return 1 + return mask,paint +def smile(): + mask=lambda x,y: disc(x,y,10,10,9.4) + def paint(x,y): + if disc(x,y,4.4,12.2,1.6) or disc(x,y,15.6,12.2,1.6): return 3 + if arc(x,y,6.6,6.4,2.4,215,325,.55) or arc(x,y,13.4,6.4,2.4,215,325,.55): return 2 + if arc(x,y,7,9,2,180,360,1.0) or arc(x,y,13,9,2,180,360,1.0): return 2 + if arc(x,y,10,8.2,5.6,25,155,1.1): return 2 + return 1 + return mask,paint +def heart(): + def mask(px,py): + x=(px-10)/7.5; y=(10.6-py)/7.5 + return (x*x+y*y-1)**3-x*x*y**3<=0 + def paint(x,y): + if ((x-6.2)/1.9)**2+((y-6.0)/1.3)**2<=1 or disc(x,y,8.6,5.2,.55): return 3 + return 1 + return mask,paint +def thumb(): + def mask(x,y): + body = 6<=x<=17 and 9.5<=y<=18 and not (x>15.5 and y<10.5) + cap = seg(x,y,9.2,9.8,10.6,3.6)<=1.9 + cuff = 1.5<=x<=6.6 and 9.5<=y<=18.5 + return body or cap or cuff + def paint(x,y): + if arc(x,y,10.1,4.9,1.1,200,340,.55): return 2 + if x<5.0: return 3 + if 5.0<=x<=5.9 and y>9.2: return 2 + if x>9 and any(abs(y-v)<.45 for v in (12.4,14.7,17.0)) and x<15.8: return 2 + return 1 + return mask,paint +def pray(): + def un(x,y): return x-(19.5-y)*0.13-0.8 # lean the tips a little to the right; u = 10 is the middle line + def mask(x,y): + u=un(x,y) + if y<1.5 or y>19.6: return False + w=5.5*math.sin(math.pi*(y-1.5)/15.8)**.6 if y<=17.3 else 0 + return abs(u-10)<=w or (15.6<=y<=19.6 and abs(u-10)<=5.4) + def paint(x,y): + u=un(x,y) + if y>16.2: return 3 + if 15.6>3)<<11|(g>>2)<<5|b>>3 +E=[("1F602",laugh,("#FFCC33","#5A3300","#3AA0FF")), + ("2764",heart,("#E8283C","#6A0F1C","#FF9AA8")), + ("1F44D",thumb,("#FFCC33","#5A3300","#3A6FD8")), + ("1F60A",smile,("#FFCC33","#5A3300","#FF8FA0")), + ("1F64F",pray,("#FFCC33","#5A3300","#3A6FD8"))] +bits=bytearray(); pals=[]; imgs=[] +for cp,fn,pal in E: + g=build(*fn()); imgs.append((g,pal)) + flat=[v for row in g for v in row] + for i in range(0,len(flat),4): + a,b,c,d=flat[i:i+4]; bits.append(a<<6|b<<4|c<<2|d) + pals.append([rgb565(h) for h in pal]) +sys.stdout.write("const EMOJI: [char; 5] = [%s];\n"%", ".join("'\\u{%s}'"%e[0] for e in E)) +sys.stdout.write("const EMOJI_PAL: [[u16; 3]; 5] = [%s];\n"%", ".join("[%s]"%", ".join("0x%04X"%c for c in p) for p in pals)) +sys.stdout.write("const EMOJI_BITS: [u8; %d] = [\n"%len(bits)) +for i in range(0,len(bits),20): sys.stdout.write(" "+", ".join(str(b) for b in bits[i:i+20])+",\n") +sys.stdout.write("];\n") +from PIL import Image +S=10; im=Image.new("RGB",(N*S*5+60,N*S+20),(40,40,40)) +for k,(g,pal) in enumerate(imgs): + cols=[(40,40,40)]+[tuple(int(h[i:i+2],16) for i in (1,3,5)) for h in pal] + for r in range(N): + for c in range(N): + im.paste(cols[g[r][c]],(10+k*(N*S+10)+c*S,10+r*S,10+k*(N*S+10)+c*S+S,10+r*S+S)) +im.save("emoji_preview.png") diff --git a/apps/watch-replies/fonts/mkhindi.py b/apps/watch-replies/fonts/mkhindi.py new file mode 100644 index 0000000..7470ae2 --- /dev/null +++ b/apps/watch-replies/fonts/mkhindi.py @@ -0,0 +1,32 @@ +import re,sys +from PIL import Image,ImageDraw,ImageFont +PX=22 +font=ImageFont.truetype('NotoSansDevanagari-Medium.ttf',PX,layout_engine=ImageFont.Layout.BASIC) +chars=[chr(c) for c in range(0x915,0x93A) if c not in (0x929,0x931,0x934)] +chars+=list("अआइईउऊऋऍऑएऐओऔ")+list("ािीुूृॅेैॉोौ")+list("़्ँंः।॥")+[chr(c) for c in range(0x966,0x970)] +chars=sorted(set(chars),key=ord);print(len(chars)) +rows=[];data=bytearray() +for ch in chars: + adv=max(0,round(font.getlength(ch))) + big=Image.new('L',(PX*3,PX*3),0);ImageDraw.Draw(big).text((PX,PX*2),ch,font=font,fill=255,anchor='ls') + q=big.point(lambda v:(v*15+127)//255*17);box=q.getbbox() + x0=y0=w=h=0;off=len(data) + if box: + x0,y0=box[0]-PX,box[1]-PX*2;w,h=box[2]-box[0],box[3]-box[1] + px2=[min(3,((v//17)+2)//5) for v in q.crop(box).get_flattened_data()] + px2.extend([0]*((-len(px2))%4)) + data.extend((px2[i]<<6)|(px2[i+1]<<4)|(px2[i+2]<<2)|px2[i+3] for i in range(0,len(px2),4)) + rows.append((ch,min(255,adv),x0,y0,w,h,off)) +assert len(data)<65536 and all(-128<=r[2]<=127 and -128<=r[3]<=127 for r in rows) +print('bytes',len(data),'max h',max(r[5] for r in rows),'min y',min(r[3] for r in rows),'max y+h',max(r[3]+r[5] for r in rows)) +gl="\n".join(f" Glyph {{ c: '\\u{{{ord(ch):04X}}}', adv: {a}, x: {x}, y: {y}, w: {w}, h: {h}, off: {o} }}," for ch,a,x,y,w,h,o in rows) +bits="\n".join(" "+" ".join(f"{b}," for b in data[i:i+24]) for i in range(0,len(data),24)) +hind=f" hindi_glyphs: &[\n{gl}\n ],\n hindi_bits: &[\n{bits}\n ],\n" +src=sys.argv[1];t=open(src).read() +# 1. drop T +a=t.index("/// NotoSans-SemiBold");b=t.index("/// NotoSans-Medium") +t=t[:a]+t[b:] +# 2. hindi tables at the end of B +end=t.rindex("};") +t=t[:end]+hind+t[end:] +open(sys.argv[2],'w').write(t) diff --git a/apps/watch-replies/fonts/mkscale.py b/apps/watch-replies/fonts/mkscale.py new file mode 100644 index 0000000..a97d510 --- /dev/null +++ b/apps/watch-replies/fonts/mkscale.py @@ -0,0 +1,52 @@ +"""Makes the small name font N (Latin only) by scaling the 27 px Noto Sans Medium glyphs of src/fonts.rs by 7/9 (21 px). +Usage: python3 fonts/mkscale.py (writes src/fonts_small.rs; Noto Sans is SIL OFL 1.1)""" +import re +from pathlib import Path +from PIL import Image + +ROOT = Path(__file__).resolve().parent.parent +src = (ROOT / "src" / "fonts.rs").read_text(encoding="utf-8") +b = src[src.index("pub static B: Font"):] +head = re.search(r"ascent: (\d+), descent: (\d+), cap: (\d+)", b) +asc, desc, cap = map(int, head.groups()) +glyph_part = b[b.index("glyphs: &["):b.index(" ],\n bits:")] +bits_part = b[b.index(" bits: &["):b.index(" ],\n arabic_ascent")] +bits = [int(x) for x in re.findall(r"\d+", bits_part[bits_part.index("["):])] +rows = re.findall(r"Glyph \{ c: '(.*?)', adv: (\d+), x: (-?\d+), y: (-?\d+), w: (\d+), h: (\d+), off: (\d+) \}", glyph_part) +N, D, PAD, UP, DOWN = 7, 9, 9, 36, 18 +out_rows, data = [], bytearray() +for ch, adv, x, y, w, h, off in rows: + adv, x, y, w, h, off = map(int, (adv, x, y, w, h, off)) + cw = -(-(adv + 2 * PAD + w) // D) * D + ch_ = UP + DOWN + canvas = Image.new("L", (cw, ch_), 0) + if w and h: + for i in range(w * h): + v = (bits[off + i // 4] >> (6 - 2 * (i % 4))) & 3 + if v: + canvas.putpixel((PAD + x + i % w, UP + y + i // w), v * 85) + small = canvas.resize((cw * N // D, ch_ * N // D), Image.BOX) + q = small.point(lambda v: (v * 15 + 127) // 255 * 17) + box = q.getbbox() + x0 = y0 = ww = hh = 0 + o = len(data) + if box: + x0, y0 = box[0] - PAD * N // D, box[1] - UP * N // D + ww, hh = box[2] - box[0], box[3] - box[1] + px = [min(3, ((v // 17) + 2) // 5) for v in q.crop(box).get_flattened_data()] + px.extend([0] * ((-len(px)) % 4)) + data.extend((px[i] << 6) | (px[i + 1] << 4) | (px[i + 2] << 2) | px[i + 3] for i in range(0, len(px), 4)) + out_rows.append((ch, round(adv * N / D), x0, y0, ww, hh, o)) +lines = ["//! Generated by fonts/mkscale.py from the 27 px Noto Sans Medium glyphs (SIL OFL 1.1). Do not edit.", "", + "use crate::font::{Font, Glyph};", "", + "/// Noto Sans Medium at 21 px, Latin only: the sender's name in a bubble.", + "pub static N: Font = Font {", + f" ascent: {round(asc*N/D)}, descent: {round(desc*N/D)}, cap: {round(cap*N/D)},", " glyphs: &["] +for ch, adv, x, y, w, h, o in out_rows: + lines.append(f" Glyph {{ c: '{ch}', adv: {adv}, x: {x}, y: {y}, w: {w}, h: {h}, off: {o} }},") +lines += [" ],", " bits: &["] +for i in range(0, len(data), 24): + lines.append(" " + " ".join(f"{v}," for v in data[i:i + 24])) +lines += [" ],", " arabic_ascent: 0, arabic_descent: 0, arabic_cap: 0,", " arabic_glyphs: &[],", " arabic_bits: &[],", "};", ""] +(ROOT / "src" / "fonts_small.rs").write_text("\n".join(lines), encoding="utf-8") +print(len(out_rows), "glyphs", len(data), "bytes") diff --git a/apps/watch-replies/fonts/mkwords.py b/apps/watch-replies/fonts/mkwords.py new file mode 100644 index 0000000..4052f84 --- /dev/null +++ b/apps/watch-replies/fonts/mkwords.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +"""Builds the English suggestion list for words.rs: sorted, front-coded, 8 popularity tiers. +Entry = one header byte (0x80 | tier<<4 | letters shared with the previous word) + the new ending (ASCII). +Run: python3 mkwords.py > en_words.txt (the output is pasted into words.rs as `const EN`)""" +import sys +T0 = """the be to of and a in that have i it for not on with you do at this but by from they we say her she or an will my +one all would there what so up out if about who get go me when make can like time no just him know take people into your +good some could them see other than then now look only come its over think also back after use two how our work first well +way even new want because any these give day most us is are was were been has had am did does going got let yes ok okay hi +hello thanks thank please sorry where why while home here there's i'm i'll don't can't it's that's what's let's you're +where's how's we're they're i've he's she's didn't doesn't isn't wasn't won't""".split() +T1 = """tomorrow today tonight morning night evening afternoon yesterday soon later again always never maybe sure right wrong +fine great nice cool love miss need call text message send sent answer reply wait coming arrive arrived leave leaving left +late early busy free ready done sleep eat food lunch dinner breakfast hungry tired water phone battery charge car drive +driving bus train taxi road street house room door office work school class study exam test meeting meet met talk talking +told tell ask asked said thing things everything something nothing anything someone everyone anyone friend friends family +mother father brother sister mom dad man woman boy girl baby kid kids husband wife son daughter happy sad angry worried +hope wish believe understand remember forget forgot feel feeling felt hear heard seen saw show look looking find found +help helped hello goodbye bye welcome congratulations birthday wedding week weekend month year years hour hours minute +minutes second monday tuesday wednesday thursday friday saturday sunday january""".split() +T2 = """about above across actually almost along already although amazing another anyway around away bad bag beautiful because +before behind believe below best better between big bit black blue book bring brought buy bought came change check +children city clean close clothes coffee color come comes could country course cut dear different difficult doing door +down during each easy else enough every example excuse expensive face fast fell few find first five flight four free from +front full game gave gift girl glad gone hand happen happened hard hate having head hello high hold hot however hundred +idea important inside instead interesting its job keep kind knew large last learn least less life light little long lost +lot made many market may mean might mind money month much must myself near next nobody number often old once open +order own pain paper part pay people perfect picture place plan play point pretty probably problem question quick quiet +quite rain read real really reason rest ride room run safe same school search seem set several share shop short should +since small snow some soon sound start stay still stop store story strong such sun super sure take team tell ten thank +than their theirs them themselves though thought three through together told took top town travel tried true try turn +under until upon used usually very visit walk want warm watch way wear weather where whether white whole whose will +window wonderful word world worry would write written yeah young youth""".split() +T3 = """accept account address afraid agree airport alone alright angry apartment appointment around attention available +awesome bathroom beach beautiful bedroom believe bill birthday blessed bored bottom brother camera careful cause chance +chat cheap choose clear coming complete confirm continue conversation cousin crazy customer dangerous deal decide +delivery doctor dollar drink drop dude election email enjoy entire excellent excited exactly explain fight finally finish +forgive forward funny future garden glass god grocery guess guys hospital hotel however hurry image important invite +issue join journey kitchen laptop laugh lesson letter listen location luck manager married matter medicine message mistake +moment movie music neighbor news noise normal notice online parents party passport patient perhaps person pharmacy photo +pick pizza pleasure police popular position possible prayer prepare present price promise proud public quickly rather +receive recently remind repeat reply request result return review rich ring salary save secret serious service shirt +shopping simple single sister situation smile someone sometimes song sorry special sport station stuff success sudden +suggest suppose surprise sweet system tablet taste teacher telephone thanks ticket tired total touch trip trouble trust +truth unless upset useful vacation video voice wallet warning wash website welcome whatever whenever wherever whoever +wish without wonder worry yourself""".split() +import os +N=int(os.environ.get('N','330')) # how many words to keep (the lists above are in order of importance) +order=[] +for ws in (T0,T1,T2,T3): + for w in ws: + if all(c.isalpha() and c.islower() and c.isascii() or c=="'" for c in w) and len(w)<=23 and w not in order: + order.append(w) +order=order[:N] +BANDS=(5,12,24,42,75,130,220) # rank -> tier 0..7, the most common words in the lowest tiers +seen={w:sum(i>=c for c in BANDS) for i,w in enumerate(order)} +words=sorted(seen) +out=bytearray(); prev='' +for w in words: + p=0 + while p=0x80 or c in (34,92) else chr(c) + return 'const EN: &[u8] = b"%s";'%s +print(lit(out)) +sys.stderr.write('%d words, %d bytes \n'%(len(words),len(out))) diff --git a/apps/watch-replies/icon.svg b/apps/watch-replies/icon.svg new file mode 100644 index 0000000..438bca9 --- /dev/null +++ b/apps/watch-replies/icon.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/apps/watch-replies/shots/empty.png b/apps/watch-replies/shots/empty.png new file mode 100644 index 0000000..016cd94 Binary files /dev/null and b/apps/watch-replies/shots/empty.png differ diff --git a/apps/watch-replies/shots/inbox.png b/apps/watch-replies/shots/inbox.png new file mode 100644 index 0000000..b4fca5f Binary files /dev/null and b/apps/watch-replies/shots/inbox.png differ diff --git a/apps/watch-replies/shots/keyboard-recording.png b/apps/watch-replies/shots/keyboard-recording.png new file mode 100644 index 0000000..1ee5f5f Binary files /dev/null and b/apps/watch-replies/shots/keyboard-recording.png differ diff --git a/apps/watch-replies/shots/keyboard.png b/apps/watch-replies/shots/keyboard.png new file mode 100644 index 0000000..b6e9d33 Binary files /dev/null and b/apps/watch-replies/shots/keyboard.png differ diff --git a/apps/watch-replies/src/arabic.rs b/apps/watch-replies/src/arabic.rs new file mode 100644 index 0000000..b3d9cfd --- /dev/null +++ b/apps/watch-replies/src/arabic.rs @@ -0,0 +1,278 @@ +//! Small no-allocation Arabic shaper and bidirectional run reordering for the watch UI. +//! The watch font contains the Unicode Arabic Presentation Forms glyphs generated by mkfont.py. + +pub const MAX_TEXT: usize = 128; + +#[derive(Clone, Copy)] +struct Shape { + base: char, + isolated: char, + final_form: char, + initial: char, + medial: char, +} + +const SHAPES: &[Shape] = &[ + Shape { base: '\u{0621}', isolated: '\u{FE80}', final_form: '\0', initial: '\0', medial: '\0' }, + Shape { base: '\u{0622}', isolated: '\u{FE81}', final_form: '\u{FE82}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0623}', isolated: '\u{FE83}', final_form: '\u{FE84}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0624}', isolated: '\u{FE85}', final_form: '\u{FE86}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0625}', isolated: '\u{FE87}', final_form: '\u{FE88}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0626}', isolated: '\u{FE89}', final_form: '\u{FE8A}', initial: '\u{FE8B}', medial: '\u{FE8C}' }, + Shape { base: '\u{0627}', isolated: '\u{FE8D}', final_form: '\u{FE8E}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0628}', isolated: '\u{FE8F}', final_form: '\u{FE90}', initial: '\u{FE91}', medial: '\u{FE92}' }, + Shape { base: '\u{0629}', isolated: '\u{FE93}', final_form: '\u{FE94}', initial: '\0', medial: '\0' }, + Shape { base: '\u{062A}', isolated: '\u{FE95}', final_form: '\u{FE96}', initial: '\u{FE97}', medial: '\u{FE98}' }, + Shape { base: '\u{062B}', isolated: '\u{FE99}', final_form: '\u{FE9A}', initial: '\u{FE9B}', medial: '\u{FE9C}' }, + Shape { base: '\u{062C}', isolated: '\u{FE9D}', final_form: '\u{FE9E}', initial: '\u{FE9F}', medial: '\u{FEA0}' }, + Shape { base: '\u{062D}', isolated: '\u{FEA1}', final_form: '\u{FEA2}', initial: '\u{FEA3}', medial: '\u{FEA4}' }, + Shape { base: '\u{062E}', isolated: '\u{FEA5}', final_form: '\u{FEA6}', initial: '\u{FEA7}', medial: '\u{FEA8}' }, + Shape { base: '\u{062F}', isolated: '\u{FEA9}', final_form: '\u{FEAA}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0630}', isolated: '\u{FEAB}', final_form: '\u{FEAC}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0631}', isolated: '\u{FEAD}', final_form: '\u{FEAE}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0632}', isolated: '\u{FEAF}', final_form: '\u{FEB0}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0633}', isolated: '\u{FEB1}', final_form: '\u{FEB2}', initial: '\u{FEB3}', medial: '\u{FEB4}' }, + Shape { base: '\u{0634}', isolated: '\u{FEB5}', final_form: '\u{FEB6}', initial: '\u{FEB7}', medial: '\u{FEB8}' }, + Shape { base: '\u{0635}', isolated: '\u{FEB9}', final_form: '\u{FEBA}', initial: '\u{FEBB}', medial: '\u{FEBC}' }, + Shape { base: '\u{0636}', isolated: '\u{FEBD}', final_form: '\u{FEBE}', initial: '\u{FEBF}', medial: '\u{FEC0}' }, + Shape { base: '\u{0637}', isolated: '\u{FEC1}', final_form: '\u{FEC2}', initial: '\u{FEC3}', medial: '\u{FEC4}' }, + Shape { base: '\u{0638}', isolated: '\u{FEC5}', final_form: '\u{FEC6}', initial: '\u{FEC7}', medial: '\u{FEC8}' }, + Shape { base: '\u{0639}', isolated: '\u{FEC9}', final_form: '\u{FECA}', initial: '\u{FECB}', medial: '\u{FECC}' }, + Shape { base: '\u{063A}', isolated: '\u{FECD}', final_form: '\u{FECE}', initial: '\u{FECF}', medial: '\u{FED0}' }, + Shape { base: '\u{0640}', isolated: '\0', final_form: '\0', initial: '\0', medial: '\u{FE7F}' }, + Shape { base: '\u{0641}', isolated: '\u{FED1}', final_form: '\u{FED2}', initial: '\u{FED3}', medial: '\u{FED4}' }, + Shape { base: '\u{0642}', isolated: '\u{FED5}', final_form: '\u{FED6}', initial: '\u{FED7}', medial: '\u{FED8}' }, + Shape { base: '\u{0643}', isolated: '\u{FED9}', final_form: '\u{FEDA}', initial: '\u{FEDB}', medial: '\u{FEDC}' }, + Shape { base: '\u{0644}', isolated: '\u{FEDD}', final_form: '\u{FEDE}', initial: '\u{FEDF}', medial: '\u{FEE0}' }, + Shape { base: '\u{0645}', isolated: '\u{FEE1}', final_form: '\u{FEE2}', initial: '\u{FEE3}', medial: '\u{FEE4}' }, + Shape { base: '\u{0646}', isolated: '\u{FEE5}', final_form: '\u{FEE6}', initial: '\u{FEE7}', medial: '\u{FEE8}' }, + Shape { base: '\u{0647}', isolated: '\u{FEE9}', final_form: '\u{FEEA}', initial: '\u{FEEB}', medial: '\u{FEEC}' }, + Shape { base: '\u{0648}', isolated: '\u{FEED}', final_form: '\u{FEEE}', initial: '\0', medial: '\0' }, + Shape { base: '\u{0649}', isolated: '\u{FEEF}', final_form: '\u{FEF0}', initial: '\0', medial: '\0' }, + Shape { base: '\u{064A}', isolated: '\u{FEF1}', final_form: '\u{FEF2}', initial: '\u{FEF3}', medial: '\u{FEF4}' }, +]; + +fn shape_for(c: char) -> Option<&'static Shape> { + SHAPES.iter().find(|s| s.base == c) +} + +fn is_mark(c: char) -> bool { + matches!(c as u32, 0x064B..=0x065F | 0x0670 | 0x08D3..=0x08FF) +} + +fn joins_previous(c: char) -> bool { + if c == '\u{0640}' { return true; } + shape_for(c).is_some_and(|s| s.final_form != '\0' || s.medial != '\0') +} + +fn joins_next(c: char) -> bool { + if c == '\u{0640}' { return true; } + shape_for(c).is_some_and(|s| s.initial != '\0' || s.medial != '\0') +} + +fn previous_base(chars: &[char], mut i: usize) -> Option { + while i > 0 { + i -= 1; + let c = chars[i]; + if is_mark(c) { continue; } + return Some(c); + } + None +} + +fn next_base(chars: &[char], mut i: usize) -> Option { + while i < chars.len() { + let c = chars[i]; + i += 1; + if is_mark(c) { continue; } + return Some(c); + } + None +} + +fn shape_logical(input: &str, out: &mut [char; MAX_TEXT]) -> usize { + let mut n = 0; + for c in input.chars().take(MAX_TEXT) { + // This compact bitmap renderer has no mark-positioning engine. Drop optional tashkeel + // rather than drawing the font's dotted-circle fallback glyph beside the letter. + if is_mark(c) { continue; } + out[n] = c; + n += 1; + } + let original = *out; + for i in 0..n { + let c = original[i]; + // Tatweel already has the correct joining appearance and must not be converted to a form. + if c == '\u{0640}' { continue; } + let Some(form) = shape_for(c) else { continue; }; + let prev = previous_base(&original[..n], i).is_some_and(|p| joins_next(p) && joins_previous(c)); + let next = next_base(&original[..n], i + 1).is_some_and(|q| joins_next(c) && joins_previous(q)); + out[i] = if prev && next && form.medial != '\0' { + form.medial + } else if prev && form.final_form != '\0' { + form.final_form + } else if next && form.initial != '\0' { + form.initial + } else { + form.isolated + }; + } + n +} + +/// Hindi: the short i sign (ि) is written after its letter but drawn before it (and before a conjunct's letters). +pub fn devanagari(t: &mut [char]) { + let cons = |c: char| ('\u{915}'..='\u{939}').contains(&c) || ('\u{958}'..='\u{95F}').contains(&c); + for i in 1..t.len() { + if t[i] != '\u{93F}' { continue; } + let mut s = i - 1; + while s > 0 && t[s] == '\u{93C}' { s -= 1; } + if !cons(t[s]) { continue; } + // back over "letter + halant" pairs: क्ष is one unit + while s >= 2 && t[s - 1] == '\u{94D}' { + let mut k = s - 2; + if t[k] == '\u{93C}' && k > 0 { k -= 1; } + if !cons(t[k]) { break; } + s = k; + } + t[s..=i].rotate_right(1); + } +} + +pub fn contains_rtl(input: &str) -> bool { + input.chars().any(is_rtl) +} + +fn is_rtl(c: char) -> bool { + matches!(c as u32, 0x0600..=0x08FF | 0xFE70..=0xFEFF) +} + +fn is_ltr(c: char) -> bool { + c.is_ascii_alphanumeric() || matches!(c as u32, 0x0660..=0x0669 | 0x06F0..=0x06F9) +} + +fn direction(c: char) -> u8 { + // Digits live in the Arabic Unicode block too, but remain left-to-right sequences. + if is_ltr(c) { 2 } else if is_rtl(c) { 1 } else { 0 } +} + +fn mirror(c: char) -> char { + match c { + '(' => ')', ')' => '(', '[' => ']', ']' => '[', '{' => '}', '}' => '{', + '<' => '>', '>' => '<', + _ => c, + } +} + +/// Produces glyphs in left-to-right paint order after contextual Arabic shaping and a compact bidi pass. +/// It supports common Arabic / Latin / digit / punctuation combinations; optional vowel marks are omitted. +pub fn visual(input: &str, out: &mut [char; MAX_TEXT]) -> usize { + let mut shaped = ['\0'; MAX_TEXT]; + let n = shape_logical(input, &mut shaped); + if n == 0 { return 0; } + + // Each remaining codepoint is one display unit; optional vowel marks were removed above. + let mut starts = [0u8; MAX_TEXT]; + let lens = [1u8; MAX_TEXT]; + let mut dirs = [0u8; MAX_TEXT]; + let count = n; + for i in 0..n { + starts[i] = i as u8; + dirs[i] = direction(shaped[i]); + } + + let base_dir = (0..count).find_map(|i| if dirs[i] != 0 { Some(dirs[i]) } else { None }).unwrap_or(2); + let mut prior = 0u8; + for i in 0..count { + if dirs[i] == 0 { + dirs[i] = if prior != 0 { prior } else { base_dir }; + } else { + prior = dirs[i]; + } + } + + let mut run_start = [0u8; MAX_TEXT]; + let mut run_end = [0u8; MAX_TEXT]; + let mut run_dir = [0u8; MAX_TEXT]; + let mut runs = 0usize; + let mut at = 0usize; + while at < count { + let d = dirs[at]; + let start = at; + at += 1; + while at < count && dirs[at] == d { at += 1; } + run_start[runs] = start as u8; + run_end[runs] = at as u8; + run_dir[runs] = d; + runs += 1; + } + + let mut written = 0usize; + let mut emit_cluster = |cluster: usize, rtl: bool, out: &mut [char; MAX_TEXT], written: &mut usize| { + let start = starts[cluster] as usize; + for j in 0..lens[cluster] as usize { + if *written >= MAX_TEXT { return; } + let mut c = shaped[start + j]; + if rtl { c = mirror(c); } + out[*written] = c; + *written += 1; + } + }; + + if base_dir == 1 { + for r in (0..runs).rev() { + let start = run_start[r] as usize; + let end = run_end[r] as usize; + if run_dir[r] == 1 { + for c in (start..end).rev() { emit_cluster(c, true, out, &mut written); } + } else { + for c in start..end { emit_cluster(c, false, out, &mut written); } + } + } + } else { + for r in 0..runs { + let start = run_start[r] as usize; + let end = run_end[r] as usize; + if run_dir[r] == 1 { + for c in (start..end).rev() { emit_cluster(c, true, out, &mut written); } + } else { + for c in start..end { emit_cluster(c, false, out, &mut written); } + } + } + } + written +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn arabic_letters_get_contextual_presentation_forms() { + let mut out = ['\0'; MAX_TEXT]; + let n = visual("سلام", &mut out); + let rendered: String = out[..n].iter().collect(); + assert!(rendered.chars().all(|c| (0xFE70..=0xFEFF).contains(&(c as u32))), "{rendered}"); + assert_eq!(n, 4); + } + + #[test] + fn latin_runs_and_digits_stay_in_order_inside_rtl_text() { + let mut out = ['\0'; MAX_TEXT]; + let n = visual("مرحبا ABC 123", &mut out); + let rendered: String = out[..n].iter().collect(); + assert!(rendered.contains("ABC"), "{rendered}"); + assert!(rendered.contains("123"), "{rendered}"); + let n = visual("مرحبا ١٢٣", &mut out); + let rendered: String = out[..n].iter().collect(); + assert!(rendered.contains("١٢٣"), "Arabic digits reversed: {rendered}"); + } + + #[test] + fn empty_and_english_text_are_unchanged() { + let mut out = ['\0'; MAX_TEXT]; + assert_eq!(visual("", &mut out), 0); + let n = visual("Hello 123", &mut out); + assert_eq!(out[..n].iter().collect::(), "Hello 123"); + } +} diff --git a/apps/watch-replies/src/font.rs b/apps/watch-replies/src/font.rs new file mode 100644 index 0000000..d4991d2 --- /dev/null +++ b/apps/watch-replies/src/font.rs @@ -0,0 +1,312 @@ +//! Small anti-aliased Noto font renderer. Latin and Arabic glyph tables are generated in `fonts.rs`. +// Bitmap coverage is stored at 2 bits per pixel (four alpha levels) to fit the watch app partition. + +use cmf_wp2_ui::color::blend565; +use cmf_wp2_ui::{ONE, Surface}; + +pub struct Glyph { + pub c: char, + pub adv: u8, + pub x: i8, + pub y: i8, + pub w: u8, + pub h: u8, + pub off: u16, +} + +#[allow(dead_code)] +pub struct Font { + pub ascent: i32, + pub descent: i32, + pub cap: i32, + pub glyphs: &'static [Glyph], + pub bits: &'static [u8], + pub arabic_ascent: i32, + pub arabic_descent: i32, + pub arabic_cap: i32, + pub arabic_glyphs: &'static [Glyph], + pub arabic_bits: &'static [u8], + /// Devanagari (Hindi): sorted by character; marks have no advance and sit over the letter before them. + pub hindi_glyphs: &'static [Glyph], + pub hindi_bits: &'static [u8], +} + +/// The few emoji the watch can show in a message (😂 ❤ 👍 😊 🙏), drawn by `draw_scaled`; the heart's variation sign is skipped. +const EMOJI_ADV: i32 = 26; +const EMOJI: [char; 5] = ['\u{1F602}', '\u{2764}', '\u{1F44D}', '\u{1F60A}', '\u{1F64F}']; +const EMOJI_PAL: [[u16; 3]; 5] = [[0xFE66, 0x5980, 0x3D1F], [0xE947, 0x6863, 0xFCD5], [0xFE66, 0x5980, 0x3B7B], [0xFE66, 0x5980, 0xFC74], [0xFE66, 0x5980, 0x3B7B]]; +const EMOJI_BITS: [u8; 720] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 170, 170, 0, 0, 0, 10, 149, 86, 160, 0, 0, 41, + 85, 85, 104, 0, 0, 170, 149, 86, 170, 0, 2, 165, 85, 85, 90, 128, 10, 85, 85, 85, + 85, 160, 9, 105, 85, 85, 105, 96, 41, 106, 149, 86, 169, 104, 37, 86, 165, 90, 149, 88, + 37, 106, 149, 86, 169, 88, 37, 105, 85, 85, 105, 88, 39, 213, 85, 85, 87, 216, 47, 250, + 170, 170, 175, 248, 47, 250, 170, 170, 175, 248, 43, 250, 170, 170, 175, 232, 9, 218, 170, 170, + 167, 96, 10, 246, 170, 170, 159, 160, 2, 213, 106, 169, 87, 128, 0, 149, 85, 85, 86, 0, + 0, 41, 85, 85, 104, 0, 0, 10, 149, 86, 160, 0, 0, 0, 170, 170, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 170, 168, 42, + 170, 0, 2, 149, 90, 165, 86, 128, 10, 85, 85, 85, 85, 160, 9, 85, 85, 85, 85, 96, + 9, 127, 253, 85, 85, 96, 9, 127, 245, 85, 85, 96, 9, 95, 213, 85, 85, 96, 9, 85, + 85, 85, 85, 96, 9, 85, 85, 85, 85, 96, 10, 85, 85, 85, 85, 160, 2, 85, 85, 85, + 85, 128, 2, 149, 85, 85, 86, 128, 0, 165, 85, 85, 90, 0, 0, 37, 85, 85, 88, 0, + 0, 9, 85, 85, 96, 0, 0, 2, 149, 86, 128, 0, 0, 0, 165, 90, 0, 0, 0, 0, + 41, 104, 0, 0, 0, 0, 2, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 2, 160, 0, 0, 0, 0, 10, 104, 0, 0, 0, 0, 10, 168, 0, 0, 0, 0, + 9, 88, 0, 0, 0, 0, 41, 104, 0, 0, 0, 0, 37, 96, 0, 0, 0, 0, 37, 96, + 0, 0, 0, 0, 37, 96, 0, 0, 0, 0, 37, 160, 0, 0, 10, 170, 149, 106, 170, 0, + 10, 170, 85, 90, 170, 128, 11, 249, 85, 85, 85, 128, 11, 249, 90, 170, 170, 128, 11, 249, + 85, 85, 86, 128, 11, 249, 85, 85, 86, 128, 11, 249, 90, 170, 170, 0, 11, 249, 85, 85, + 86, 0, 11, 249, 85, 85, 90, 0, 11, 249, 90, 170, 168, 0, 10, 170, 170, 170, 168, 0, + 10, 170, 170, 170, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 170, 170, 0, 0, 0, 10, 149, 86, 160, 0, 0, 41, 85, 85, 104, 0, 0, 149, 85, 85, + 86, 0, 2, 89, 101, 89, 101, 128, 10, 85, 85, 85, 85, 160, 9, 85, 85, 85, 85, 96, + 41, 90, 165, 90, 165, 104, 37, 89, 89, 101, 101, 88, 37, 89, 89, 101, 101, 88, 37, 85, + 85, 85, 85, 88, 37, 85, 85, 85, 85, 88, 37, 253, 85, 85, 127, 88, 39, 254, 85, 85, + 191, 216, 41, 254, 165, 90, 191, 104, 9, 85, 106, 169, 85, 96, 10, 85, 85, 85, 85, 160, + 2, 85, 85, 85, 85, 128, 0, 149, 85, 85, 86, 0, 0, 41, 85, 85, 104, 0, 0, 10, + 149, 86, 160, 0, 0, 0, 170, 170, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 170, 128, 0, 0, 0, 41, 85, 160, + 0, 0, 0, 149, 85, 104, 0, 0, 2, 85, 86, 88, 0, 0, 10, 85, 105, 88, 0, 0, + 9, 85, 85, 88, 0, 0, 41, 85, 90, 90, 0, 0, 37, 85, 165, 88, 0, 0, 37, 85, + 85, 88, 0, 0, 37, 85, 105, 88, 0, 0, 165, 150, 149, 88, 0, 0, 169, 86, 85, 104, + 0, 0, 165, 86, 85, 96, 0, 0, 165, 86, 85, 160, 0, 0, 37, 86, 85, 128, 0, 0, + 37, 90, 86, 0, 0, 0, 41, 89, 88, 0, 0, 2, 170, 170, 170, 128, 0, 2, 191, 255, + 254, 128, 0, 2, 255, 255, 254, 128, 0, 2, 170, 170, 170, 0, 0, 2, 170, 170, 170, 0, +]; + +impl Font { + fn glyph_data(&self, c: char) -> Option<(&Glyph, &[u8])> { + // The common ASCII range is contiguous in the generated table; avoid a linear search per letter. + if (' '..='~').contains(&c) { + return self.glyphs.get(c as usize - 32).map(|g| (g, self.bits)); + } + if let Some(g) = self.glyphs.iter().find(|g| g.c == c) { + return Some((g, self.bits)); + } + if let Ok(i) = self.arabic_glyphs.binary_search_by_key(&c, |g| g.c) { + return Some((&self.arabic_glyphs[i], self.arabic_bits)); + } + self.hindi_glyphs.binary_search_by_key(&c, |g| g.c).ok().map(|i| (&self.hindi_glyphs[i], self.hindi_bits)) + } + + fn visual_text(t: &str, out: &mut [char; crate::arabic::MAX_TEXT]) -> usize { + let n = crate::arabic::visual(t, out); + crate::arabic::devanagari(&mut out[..n]); + n + } + + /// A character's advance and where its ink is (x, y from the baseline, w, h); None if the font has no such glyph. + pub fn ink(&self, c: char) -> Option<(i32, i32, i32, i32, i32)> { + self.glyph_data(c).map(|(g, _)| (g.adv as i32, g.x as i32, g.y as i32, g.w as i32, g.h as i32)) + } + + /// Every character of `t` is in either the Latin or Arabic glyph table. + #[cfg(test)] + pub fn covers(&self, t: &str) -> bool { + let mut visual = ['\0'; crate::arabic::MAX_TEXT]; + let n = Self::visual_text(t, &mut visual); + visual[..n].iter().all(|&c| self.glyph_data(c).is_some()) + } + + /// Width after contextual Arabic shaping and visual-order conversion. + pub fn width(&self, t: &str) -> i32 { + self.width_scaled(t, 1, 1) + } + + #[inline] + fn scaled(v: i32, numerator: i32, denominator: i32) -> i32 { + if v >= 0 { (v * numerator + denominator / 2) / denominator } + else { (v * numerator - denominator / 2) / denominator } + } + + /// Width after shaping, with glyph metrics scaled by a rational factor. + pub fn width_scaled(&self, t: &str, numerator: i32, denominator: i32) -> i32 { + let denominator = denominator.max(1); + let mut visual = ['\0'; crate::arabic::MAX_TEXT]; + let n = Self::visual_text(t, &mut visual); + visual[..n].iter().map(|&c| if EMOJI.contains(&c) { Self::scaled(EMOJI_ADV, numerator, denominator) } else { self.glyph_data(c).map_or(0, |(g, _)| Self::scaled(g.adv as i32, numerator, denominator)) }).sum() + } + + /// Draws shaped glyphs at a rational scale without storing a second, larger bitmap table. + pub fn draw_scaled(&self, s: &mut impl Surface, x: i32, y: i32, t: &str, fg: u16, bg: u16, numerator: i32, denominator: i32) -> i32 { + let denominator = denominator.max(1); + let mut shade = [0u16; 16]; + for (a, c) in shade.iter_mut().enumerate() { + *c = blend565(bg, fg, a as i32 * ONE / 15); + } + let mut visual = ['\0'; crate::arabic::MAX_TEXT]; + let n = Self::visual_text(t, &mut visual); + let mut pen = x; + for &ch in &visual[..n] { + if let Some(k) = EMOJI.iter().position(|&e| e == ch) { + // a small picture of 24 x 24 dots in 3 colours (see `fonts/mkemoji.py`), sitting on the baseline + let (gx, gy) = (pen + Self::scaled(1, numerator, denominator), y + Self::scaled(-21, numerator, denominator)); + let at = |i: usize| (EMOJI_BITS[k * 144 + i / 4] >> (6 - 2 * (i % 4))) & 3; + for row in 0..24usize { + let y0 = Self::scaled(row as i32, numerator, denominator); + let y1 = Self::scaled(row as i32 + 1, numerator, denominator).max(y0 + 1); + let mut col = 0; + while col < 24 { + let a = at(row * 24 + col); + let start = col; + while col < 24 && at(row * 24 + col) == a { col += 1; } + if a != 0 { + let x0 = Self::scaled(start as i32, numerator, denominator); + let x1 = Self::scaled(col as i32, numerator, denominator).max(x0 + 1); + s.rect(gx + x0, gy + y0, x1 - x0, y1 - y0, EMOJI_PAL[k][a as usize - 1]); + } + } + } + pen += Self::scaled(EMOJI_ADV, numerator, denominator); + continue; + } + let Some((g, bits)) = self.glyph_data(ch) else { continue }; + let (gx, gy, w) = (pen + Self::scaled(g.x as i32, numerator, denominator), y + Self::scaled(g.y as i32, numerator, denominator), g.w as usize); + let at = |i: usize| { + let b = bits[g.off as usize + i / 4]; + (b >> (6 - 2 * (i % 4))) & 3 + }; + for row in 0..g.h as usize { + let y0 = Self::scaled(row as i32, numerator, denominator); + let y1 = Self::scaled(row as i32 + 1, numerator, denominator).max(y0 + 1); + let base = row * w; + let mut col = 0; + while col < w { + let a = at(base + col); + let start = col; + while col < w && at(base + col) == a { col += 1; } + if a != 0 { + let x0 = Self::scaled(start as i32, numerator, denominator); + let x1 = Self::scaled(col as i32, numerator, denominator).max(x0 + 1); + s.rect(gx + x0, gy + y0, x1 - x0, y1 - y0, shade[(a * 5) as usize]); + } + } + } + pen += Self::scaled(g.adv as i32, numerator, denominator); + } + pen + } + + /// Draws left-to-right visual-order glyphs; Arabic is shaped and reordered before rasterisation. + pub fn draw(&self, s: &mut impl Surface, x: i32, y: i32, t: &str, fg: u16, bg: u16) -> i32 { + self.draw_scaled(s, x, y, t, fg, bg, 1, 1) + } + + /// The longest logical prefix of `t` that fits `max` pixels, and whether it was cut. + pub fn fit<'a>(&self, t: &'a str, max: i32) -> (&'a str, bool) { + if self.width(t) <= max { return (t, false); } + let room = max - self.width("…"); + let mut end = 0; + for (i, c) in t.char_indices() { + let next = i + c.len_utf8(); + if self.width(&t[..next]) > room { + return (t[..end].trim_end(), true); + } + end = next; + } + (t, false) + } + + #[allow(clippy::too_many_arguments)] + pub fn centre(&self, s: &mut impl Surface, cx: i32, y: i32, t: &str, max: i32, fg: u16, bg: u16) { + let (t, cut) = self.fit(t, max); + let w = self.width(t) + if cut { self.width("…") } else { 0 }; + let end = self.draw(s, cx - w / 2, y, t, fg, bg); + if cut { self.draw(s, end, y, "…", fg, bg); } + } +} + +/// A filled polygon (any shape, even-odd), antialiased: exact horizontal coverage on 4 sub-rows a pixel. +pub fn poly(s: &mut impl Surface, pts: &[(i32, i32)], bg: u16, paint: impl Fn(i32) -> u16) { + if pts.len() > 8 { return; } + let mut h = [(0, 0); 8]; + for (d, p) in h.iter_mut().zip(pts) { *d = (p.0 * 2, p.1 * 2); } + poly_half(s, &h[..pts.len()], bg, paint) +} + +pub fn poly_half(s: &mut impl Surface, pts: &[(i32, i32)], bg: u16, paint: impl Fn(i32) -> u16) { + const SUB: i32 = 4; + const FX: i32 = 16; + let y0 = pts.iter().map(|p| p.1).min().unwrap_or(0).div_euclid(2); + let y1 = (pts.iter().map(|p| p.1).max().unwrap_or(0) + 1).div_euclid(2); + let x0 = pts.iter().map(|p| p.0).min().unwrap_or(0).div_euclid(2); + let x1 = (pts.iter().map(|p| p.0).max().unwrap_or(0) + 1).div_euclid(2); + let wide = (x1 - x0 + 2) as usize; + if wide > 128 || pts.len() > 8 { return; } + for y in y0..y1 { + let mut cov = [0i32; 128]; + for k in 0..SUB { + let sy2 = y * 2 * SUB + 2 * k + 1; + let mut xs = [0i32; 8]; + let mut n = 0; + for i in 0..pts.len() { + let (a, b) = (pts[i], pts[(i + 1) % pts.len()]); + let (ay, by) = (a.1 * SUB, b.1 * SUB); + if (ay <= sy2) != (by <= sy2) { + xs[n] = a.0 * (FX / 2) + (b.0 - a.0) * (FX / 2) * (sy2 - ay) / (by - ay); + n += 1; + } + } + xs[..n].sort_unstable(); + for span in xs[..n].chunks(2) { + let [l, r] = span else { continue }; + for px in l.div_euclid(FX)..=r.div_euclid(FX) { + let lo = (px * FX).max(*l); + let hi = ((px + 1) * FX).min(*r); + let i = px - x0 + 1; + if hi > lo && i >= 0 && (i as usize) < wide { cov[i as usize] += hi - lo; } + } + } + } + let full = FX * SUB; + let mut i = 0; + while i < wide { + let c = cov[i]; + let x = x0 - 1 + i as i32; + let col = if c == 0 { None } else { Some(blend565(bg, paint(x), c * ONE / full)) }; + let start = i; + while i < wide && cov[i] == c && paint(x0 - 1 + i as i32) == paint(x) { i += 1; } + if let Some(col) = col { s.rect(x, y, (i - start) as i32, 1, col); } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::fonts::{B, B as T}; + use cmf_wp2_ui::{Fb, SIZE}; + use std::vec; + + #[test] + fn text_is_antialiased_and_fits() { + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + let end = T.draw(&mut fb, 100, 200, "Jane", 0xFFFF, 0); + assert_eq!(end, 100 + T.width("Jane")); + let mut shades = std::collections::BTreeSet::new(); + for y in 170..215 { for x in 90..end + 10 { shades.insert(fb.at(x, y)); } } + assert!(shades.len() > 2, "{}", shades.len()); + let (t, cut) = B.fit("Bannerghatta Main Road", 120); + assert!(cut && B.width(t) + B.width("…") <= 120, "{t}"); + assert_eq!(B.fit("Road", 120), ("Road", false)); + } + + #[test] + fn both_fonts_cover_common_arabic_and_mixed_text() { + // T carries no Arabic (view.rs falls back to B for non-ASCII names, saving the duplicate table); + // B, used for message text and keys, has the full Arabic set. + assert!(B.covers("أهلاً، كيف حالك؟ 123 ABC")); + } + + #[test] + fn a_polygon_has_soft_edges_and_a_solid_middle() { + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + poly(&mut fb, &[(100, 100), (140, 160), (60, 160)], 0, |_| 0xFFFF); + assert_eq!(fb.at(100, 150), 0xFFFF); + assert_eq!(fb.at(100, 90), 0); + let edge = fb.at(79, 130); + assert!(edge != 0 && edge != 0xFFFF, "{edge:x}"); + } +} diff --git a/apps/watch-replies/src/fonts.rs b/apps/watch-replies/src/fonts.rs new file mode 100644 index 0000000..04cd851 --- /dev/null +++ b/apps/watch-replies/src/fonts.rs @@ -0,0 +1,1180 @@ +//! Generated by fonts/mkfont.py from Noto Sans and Noto Sans Arabic (SIL OFL 1.1). Do not edit. + +use crate::font::{Font, Glyph}; + +/// NotoSans-Medium at 27px plus NotoSansArabic-Medium at 27px. +pub static B: Font = Font { + ascent: 29, descent: 8, cap: 20, + glyphs: &[ + Glyph { c: ' ', adv: 7, x: 0, y: 0, w: 0, h: 0, off: 0 }, + Glyph { c: '!', adv: 7, x: 1, y: -20, w: 5, h: 20, off: 0 }, + Glyph { c: '"', adv: 12, x: 1, y: -20, w: 9, h: 7, off: 25 }, + Glyph { c: '#', adv: 17, x: 0, y: -20, w: 17, h: 20, off: 41 }, + Glyph { c: '$', adv: 15, x: 1, y: -21, w: 13, h: 22, off: 126 }, + Glyph { c: '%', adv: 23, x: 1, y: -20, w: 21, h: 20, off: 198 }, + Glyph { c: '&', adv: 20, x: 1, y: -20, w: 19, h: 20, off: 303 }, + Glyph { c: '\'', adv: 6, x: 1, y: -20, w: 4, h: 7, off: 398 }, + Glyph { c: '(', adv: 8, x: 1, y: -20, w: 7, h: 24, off: 405 }, + Glyph { c: ')', adv: 8, x: 1, y: -20, w: 7, h: 24, off: 447 }, + Glyph { c: '*', adv: 15, x: 1, y: -21, w: 13, h: 13, off: 489 }, + Glyph { c: '+', adv: 15, x: 1, y: -16, w: 14, h: 13, off: 532 }, + Glyph { c: ',', adv: 7, x: 1, y: -4, w: 5, h: 7, off: 578 }, + Glyph { c: '-', adv: 9, x: 1, y: -9, w: 7, h: 3, off: 587 }, + Glyph { c: '.', adv: 7, x: 1, y: -4, w: 5, h: 4, off: 593 }, + Glyph { c: '/', adv: 10, x: 0, y: -20, w: 10, h: 20, off: 598 }, + Glyph { c: '0', adv: 15, x: 1, y: -20, w: 14, h: 20, off: 648 }, + Glyph { c: '1', adv: 15, x: 2, y: -20, w: 9, h: 20, off: 718 }, + Glyph { c: '2', adv: 15, x: 1, y: -20, w: 14, h: 20, off: 763 }, + Glyph { c: '3', adv: 15, x: 1, y: -20, w: 13, h: 20, off: 833 }, + Glyph { c: '4', adv: 15, x: 0, y: -20, w: 15, h: 20, off: 898 }, + Glyph { c: '5', adv: 15, x: 1, y: -20, w: 13, h: 20, off: 973 }, + Glyph { c: '6', adv: 15, x: 1, y: -20, w: 14, h: 20, off: 1038 }, + Glyph { c: '7', adv: 15, x: 1, y: -20, w: 14, h: 20, off: 1108 }, + Glyph { c: '8', adv: 15, x: 1, y: -20, w: 14, h: 20, off: 1178 }, + Glyph { c: '9', adv: 15, x: 1, y: -20, w: 14, h: 20, off: 1248 }, + Glyph { c: ':', adv: 7, x: 1, y: -15, w: 5, h: 15, off: 1318 }, + Glyph { c: ';', adv: 7, x: 0, y: -15, w: 6, h: 19, off: 1337 }, + Glyph { c: '<', adv: 15, x: 1, y: -17, w: 14, h: 14, off: 1366 }, + Glyph { c: '=', adv: 15, x: 1, y: -14, w: 13, h: 8, off: 1415 }, + Glyph { c: '>', adv: 15, x: 1, y: -17, w: 14, h: 14, off: 1441 }, + Glyph { c: '?', adv: 12, x: 0, y: -20, w: 12, h: 20, off: 1490 }, + Glyph { c: '@', adv: 24, x: 1, y: -20, w: 22, h: 23, off: 1550 }, + Glyph { c: 'A', adv: 18, x: 0, y: -20, w: 18, h: 20, off: 1677 }, + Glyph { c: 'B', adv: 18, x: 2, y: -20, w: 15, h: 20, off: 1767 }, + Glyph { c: 'C', adv: 17, x: 1, y: -20, w: 16, h: 20, off: 1842 }, + Glyph { c: 'D', adv: 20, x: 2, y: -20, w: 17, h: 20, off: 1922 }, + Glyph { c: 'E', adv: 15, x: 2, y: -20, w: 12, h: 20, off: 2007 }, + Glyph { c: 'F', adv: 14, x: 2, y: -20, w: 12, h: 20, off: 2067 }, + Glyph { c: 'G', adv: 20, x: 1, y: -20, w: 17, h: 20, off: 2127 }, + Glyph { c: 'H', adv: 20, x: 2, y: -20, w: 16, h: 20, off: 2212 }, + Glyph { c: 'I', adv: 10, x: 1, y: -20, w: 8, h: 20, off: 2292 }, + Glyph { c: 'J', adv: 8, x: -3, y: -20, w: 9, h: 25, off: 2332 }, + Glyph { c: 'K', adv: 17, x: 2, y: -20, w: 15, h: 20, off: 2389 }, + Glyph { c: 'L', adv: 14, x: 2, y: -20, w: 12, h: 20, off: 2464 }, + Glyph { c: 'M', adv: 25, x: 2, y: -20, w: 21, h: 20, off: 2524 }, + Glyph { c: 'N', adv: 21, x: 2, y: -20, w: 17, h: 20, off: 2629 }, + Glyph { c: 'O', adv: 21, x: 1, y: -20, w: 19, h: 20, off: 2714 }, + Glyph { c: 'P', adv: 16, x: 2, y: -20, w: 14, h: 20, off: 2809 }, + Glyph { c: 'Q', adv: 21, x: 1, y: -20, w: 19, h: 25, off: 2879 }, + Glyph { c: 'R', adv: 17, x: 2, y: -20, w: 15, h: 20, off: 2998 }, + Glyph { c: 'S', adv: 15, x: 1, y: -20, w: 13, h: 20, off: 3073 }, + Glyph { c: 'T', adv: 15, x: 0, y: -20, w: 15, h: 20, off: 3138 }, + Glyph { c: 'U', adv: 20, x: 2, y: -20, w: 16, h: 20, off: 3213 }, + Glyph { c: 'V', adv: 17, x: 0, y: -20, w: 17, h: 20, off: 3293 }, + Glyph { c: 'W', adv: 25, x: 0, y: -20, w: 26, h: 20, off: 3378 }, + Glyph { c: 'X', adv: 16, x: 0, y: -20, w: 17, h: 20, off: 3508 }, + Glyph { c: 'Y', adv: 16, x: 0, y: -20, w: 16, h: 20, off: 3593 }, + Glyph { c: 'Z', adv: 16, x: 0, y: -20, w: 15, h: 20, off: 3673 }, + Glyph { c: '[', adv: 9, x: 2, y: -20, w: 7, h: 24, off: 3748 }, + Glyph { c: '\\', adv: 10, x: 0, y: -20, w: 11, h: 20, off: 3790 }, + Glyph { c: ']', adv: 9, x: 0, y: -20, w: 7, h: 24, off: 3845 }, + Glyph { c: '^', adv: 15, x: 1, y: -20, w: 14, h: 13, off: 3887 }, + Glyph { c: '_', adv: 12, x: -1, y: 1, w: 13, h: 3, off: 3933 }, + Glyph { c: '`', adv: 8, x: 1, y: -22, w: 7, h: 5, off: 3943 }, + Glyph { c: 'a', adv: 15, x: 1, y: -15, w: 13, h: 15, off: 3952 }, + Glyph { c: 'b', adv: 17, x: 2, y: -21, w: 14, h: 21, off: 4001 }, + Glyph { c: 'c', adv: 13, x: 1, y: -15, w: 12, h: 15, off: 4075 }, + Glyph { c: 'd', adv: 17, x: 1, y: -21, w: 14, h: 21, off: 4120 }, + Glyph { c: 'e', adv: 16, x: 1, y: -15, w: 14, h: 15, off: 4194 }, + Glyph { c: 'f', adv: 10, x: 0, y: -21, w: 11, h: 21, off: 4247 }, + Glyph { c: 'g', adv: 17, x: 1, y: -15, w: 14, h: 22, off: 4305 }, + Glyph { c: 'h', adv: 17, x: 2, y: -21, w: 13, h: 21, off: 4382 }, + Glyph { c: 'i', adv: 7, x: 2, y: -21, w: 4, h: 21, off: 4451 }, + Glyph { c: 'j', adv: 7, x: -2, y: -21, w: 8, h: 28, off: 4472 }, + Glyph { c: 'k', adv: 15, x: 2, y: -21, w: 13, h: 21, off: 4528 }, + Glyph { c: 'l', adv: 7, x: 2, y: -21, w: 4, h: 21, off: 4597 }, + Glyph { c: 'm', adv: 26, x: 2, y: -15, w: 22, h: 15, off: 4618 }, + Glyph { c: 'n', adv: 17, x: 2, y: -15, w: 13, h: 15, off: 4701 }, + Glyph { c: 'o', adv: 16, x: 1, y: -15, w: 15, h: 15, off: 4750 }, + Glyph { c: 'p', adv: 17, x: 2, y: -15, w: 14, h: 22, off: 4807 }, + Glyph { c: 'q', adv: 17, x: 1, y: -15, w: 14, h: 22, off: 4884 }, + Glyph { c: 'r', adv: 11, x: 2, y: -15, w: 9, h: 15, off: 4961 }, + Glyph { c: 's', adv: 13, x: 1, y: -15, w: 11, h: 15, off: 4995 }, + Glyph { c: 't', adv: 10, x: 0, y: -19, w: 10, h: 19, off: 5037 }, + Glyph { c: 'u', adv: 17, x: 2, y: -15, w: 13, h: 15, off: 5085 }, + Glyph { c: 'v', adv: 14, x: 0, y: -15, w: 15, h: 15, off: 5134 }, + Glyph { c: 'w', adv: 22, x: 0, y: -15, w: 22, h: 15, off: 5191 }, + Glyph { c: 'x', adv: 15, x: 0, y: -15, w: 15, h: 15, off: 5274 }, + Glyph { c: 'y', adv: 14, x: 0, y: -15, w: 15, h: 22, off: 5331 }, + Glyph { c: 'z', adv: 13, x: 1, y: -15, w: 11, h: 15, off: 5414 }, + Glyph { c: '{', adv: 10, x: 0, y: -20, w: 10, h: 24, off: 5456 }, + Glyph { c: '|', adv: 15, x: 6, y: -21, w: 3, h: 28, off: 5516 }, + Glyph { c: '}', adv: 10, x: 0, y: -20, w: 10, h: 24, off: 5537 }, + Glyph { c: '~', adv: 15, x: 1, y: -12, w: 14, h: 4, off: 5597 }, + Glyph { c: '\u{2026}', adv: 22, x: 1, y: -4, w: 19, h: 4, off: 5611 }, + Glyph { c: '\u{00B7}', adv: 7, x: 1, y: -12, w: 5, h: 4, off: 5630 }, + ], + bits: &[ + 63, 79, 211, 244, 253, 47, 11, 194, 240, 188, 47, 11, 193, 240, 120, 30, 7, 128, 0, 0, 46, 15, 211, 244, + 184, 126, 15, 143, 131, 227, 208, 248, 244, 46, 61, 11, 143, 66, 210, 192, 180, 0, 7, 128, 180, 0, 2, 224, + 61, 0, 0, 244, 15, 0, 0, 61, 7, 192, 0, 31, 1, 224, 0, 7, 192, 184, 1, 255, 255, 255, 248, 127, + 255, 255, 254, 5, 125, 87, 213, 64, 15, 1, 224, 0, 7, 192, 184, 0, 2, 224, 61, 0, 127, 255, 255, 255, + 31, 255, 255, 255, 193, 95, 86, 245, 80, 7, 192, 184, 0, 1, 224, 45, 0, 0, 184, 15, 64, 0, 45, 3, + 192, 0, 15, 65, 240, 0, 0, 30, 0, 0, 7, 128, 0, 26, 250, 64, 63, 255, 253, 63, 239, 191, 31, 135, + 129, 71, 209, 224, 1, 248, 120, 0, 63, 158, 0, 7, 255, 144, 0, 111, 254, 64, 0, 191, 248, 0, 30, 191, + 128, 7, 131, 240, 1, 224, 189, 64, 120, 127, 126, 174, 191, 95, 255, 255, 129, 175, 250, 0, 0, 120, 0, 0, + 30, 0, 0, 7, 128, 0, 11, 228, 0, 11, 128, 11, 255, 64, 7, 208, 7, 231, 240, 2, 224, 2, 240, 125, + 1, 244, 0, 184, 15, 64, 184, 0, 46, 3, 208, 124, 0, 11, 128, 244, 46, 0, 2, 224, 61, 31, 1, 64, + 184, 15, 79, 75, 248, 31, 75, 199, 203, 255, 131, 255, 227, 211, 225, 244, 47, 226, 241, 240, 46, 1, 64, 244, + 124, 11, 128, 0, 184, 31, 2, 224, 0, 61, 7, 192, 184, 0, 46, 1, 240, 46, 0, 31, 64, 125, 15, 128, + 11, 128, 15, 155, 208, 7, 192, 1, 255, 224, 2, 224, 0, 27, 224, 0, 111, 224, 0, 0, 11, 255, 244, 0, + 0, 127, 91, 224, 0, 2, 240, 15, 192, 0, 15, 192, 47, 0, 0, 47, 0, 252, 0, 0, 125, 11, 224, 0, + 0, 253, 190, 0, 0, 1, 255, 224, 0, 0, 7, 254, 0, 0, 0, 191, 253, 0, 126, 11, 245, 253, 2, 244, + 127, 65, 253, 15, 194, 248, 1, 253, 190, 11, 208, 1, 255, 240, 47, 64, 1, 255, 64, 127, 0, 7, 253, 0, + 255, 150, 255, 253, 1, 255, 255, 245, 253, 0, 111, 249, 1, 253, 126, 62, 61, 61, 61, 61, 44, 1, 244, 15, + 128, 188, 3, 224, 47, 64, 252, 7, 224, 31, 64, 188, 2, 240, 11, 192, 63, 0, 252, 2, 240, 11, 192, 47, + 0, 125, 1, 248, 3, 224, 11, 208, 31, 128, 47, 0, 62, 0, 125, 248, 1, 244, 2, 240, 7, 224, 15, 192, + 31, 64, 126, 0, 248, 2, 240, 11, 192, 47, 64, 125, 1, 244, 11, 208, 47, 0, 188, 3, 240, 15, 128, 125, + 2, 240, 31, 128, 188, 7, 208, 62, 0, 0, 62, 0, 0, 15, 128, 0, 2, 224, 0, 0, 180, 0, 185, 45, + 91, 111, 255, 255, 230, 175, 250, 164, 2, 253, 0, 1, 247, 208, 1, 248, 252, 0, 252, 31, 128, 30, 3, 208, + 0, 0, 64, 0, 0, 30, 0, 0, 1, 224, 0, 0, 30, 0, 0, 1, 224, 0, 0, 30, 0, 11, 255, 255, + 252, 191, 255, 255, 197, 86, 245, 84, 0, 30, 0, 0, 1, 224, 0, 0, 30, 0, 0, 1, 224, 0, 0, 30, + 0, 0, 47, 79, 195, 225, 244, 124, 46, 15, 64, 85, 87, 255, 239, 255, 128, 46, 15, 211, 244, 184, 0, 2, + 240, 0, 62, 0, 7, 208, 0, 252, 0, 31, 128, 2, 244, 0, 62, 0, 7, 208, 0, 188, 0, 15, 128, 1, + 244, 0, 47, 0, 3, 224, 0, 125, 0, 11, 192, 0, 248, 0, 31, 64, 3, 240, 0, 126, 0, 11, 192, 0, + 1, 191, 144, 0, 127, 255, 128, 31, 229, 253, 2, 244, 3, 240, 62, 0, 31, 71, 224, 0, 248, 189, 0, 15, + 203, 208, 0, 188, 188, 0, 11, 203, 192, 0, 189, 188, 0, 11, 219, 192, 0, 188, 189, 0, 11, 199, 208, 0, + 252, 126, 0, 15, 131, 224, 1, 248, 47, 64, 63, 0, 254, 95, 224, 7, 255, 248, 0, 11, 249, 0, 0, 47, + 0, 127, 192, 127, 240, 127, 252, 191, 47, 30, 11, 193, 2, 240, 0, 188, 0, 47, 0, 11, 192, 2, 240, 0, + 188, 0, 47, 0, 11, 192, 2, 240, 0, 188, 0, 47, 0, 11, 192, 2, 240, 0, 188, 1, 191, 144, 1, 255, + 255, 128, 127, 149, 254, 2, 208, 3, 240, 0, 0, 47, 64, 0, 1, 244, 0, 0, 47, 64, 0, 2, 240, 0, + 0, 126, 0, 0, 15, 208, 0, 2, 248, 0, 0, 190, 0, 0, 47, 128, 0, 11, 240, 0, 1, 252, 0, 0, + 127, 0, 0, 31, 192, 0, 7, 245, 85, 84, 191, 255, 255, 219, 255, 255, 253, 6, 255, 144, 31, 255, 255, 7, + 249, 111, 224, 160, 0, 253, 0, 0, 47, 64, 0, 7, 208, 0, 2, 244, 0, 1, 248, 1, 86, 248, 0, 255, + 244, 0, 63, 255, 128, 0, 6, 252, 0, 0, 31, 128, 0, 3, 240, 0, 0, 252, 0, 0, 127, 64, 0, 47, + 190, 85, 191, 207, 255, 255, 144, 111, 254, 64, 0, 0, 63, 64, 0, 2, 253, 0, 0, 31, 244, 0, 0, 255, + 208, 0, 11, 223, 64, 0, 125, 125, 0, 3, 225, 244, 0, 47, 11, 208, 1, 244, 47, 64, 15, 128, 189, 0, + 188, 2, 244, 7, 208, 11, 208, 62, 0, 47, 65, 255, 255, 255, 247, 255, 255, 255, 197, 85, 91, 213, 0, 0, + 47, 64, 0, 0, 189, 0, 0, 2, 244, 0, 0, 11, 208, 31, 255, 254, 7, 255, 255, 129, 245, 85, 80, 188, + 0, 0, 47, 0, 0, 11, 192, 0, 2, 240, 0, 0, 188, 84, 0, 63, 255, 228, 15, 255, 255, 128, 80, 27, + 244, 0, 0, 190, 0, 0, 15, 192, 0, 3, 240, 0, 0, 252, 0, 0, 126, 80, 0, 63, 94, 149, 191, 135, + 255, 255, 128, 107, 254, 64, 0, 27, 254, 0, 11, 255, 240, 3, 254, 86, 0, 190, 0, 0, 31, 128, 0, 2, + 240, 0, 0, 62, 0, 0, 7, 208, 84, 0, 125, 127, 248, 11, 223, 255, 240, 191, 208, 127, 139, 240, 0, 252, + 189, 0, 11, 219, 208, 0, 189, 125, 0, 11, 211, 224, 0, 188, 47, 64, 31, 128, 254, 91, 244, 7, 255, 253, + 0, 6, 254, 0, 255, 255, 255, 223, 255, 255, 253, 85, 85, 95, 192, 0, 1, 248, 0, 0, 47, 0, 0, 7, + 224, 0, 0, 189, 0, 0, 15, 192, 0, 2, 244, 0, 0, 63, 0, 0, 7, 224, 0, 0, 189, 0, 0, 31, + 128, 0, 2, 244, 0, 0, 63, 0, 0, 11, 208, 0, 0, 252, 0, 0, 31, 128, 0, 3, 244, 0, 0, 126, + 0, 0, 1, 191, 160, 0, 191, 255, 208, 47, 229, 191, 3, 240, 2, 244, 62, 0, 31, 131, 224, 1, 244, 47, + 64, 47, 65, 253, 11, 224, 7, 255, 244, 0, 31, 253, 0, 7, 255, 248, 2, 249, 27, 224, 126, 0, 47, 139, + 208, 0, 188, 188, 0, 11, 203, 192, 0, 188, 190, 0, 31, 195, 249, 91, 244, 31, 255, 253, 0, 27, 250, 0, + 1, 191, 144, 0, 191, 255, 128, 47, 213, 253, 7, 224, 3, 240, 189, 0, 31, 139, 192, 0, 252, 188, 0, 11, + 203, 208, 0, 252, 190, 0, 31, 195, 248, 11, 252, 31, 255, 235, 192, 127, 248, 188, 0, 84, 15, 128, 0, 1, + 248, 0, 0, 47, 64, 0, 3, 240, 0, 1, 253, 1, 85, 191, 128, 31, 255, 208, 1, 255, 144, 0, 46, 15, + 211, 244, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 184, 63, 79, 210, 224, 11, 128, 253, 15, 208, 184, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 208, 252, 31, 129, 244, 47, 2, 224, 60, 0, 0, 0, + 0, 64, 0, 0, 108, 0, 0, 111, 192, 0, 111, 224, 0, 111, 224, 0, 111, 224, 0, 111, 208, 0, 11, 224, + 0, 0, 127, 224, 0, 0, 111, 228, 0, 0, 111, 244, 0, 0, 47, 248, 0, 0, 31, 192, 0, 0, 24, 85, + 85, 85, 111, 255, 255, 251, 255, 255, 252, 0, 0, 0, 0, 0, 0, 21, 85, 85, 91, 255, 255, 254, 255, 255, + 255, 64, 0, 0, 11, 64, 0, 0, 191, 64, 0, 1, 255, 64, 0, 1, 255, 64, 0, 1, 191, 64, 0, 1, + 191, 64, 0, 1, 252, 0, 1, 191, 128, 2, 255, 128, 6, 254, 64, 7, 254, 64, 0, 190, 0, 0, 9, 0, + 0, 0, 6, 254, 128, 127, 255, 244, 126, 86, 252, 16, 0, 189, 0, 0, 125, 0, 0, 125, 0, 0, 188, 0, + 2, 248, 0, 11, 224, 0, 63, 128, 0, 189, 0, 0, 248, 0, 0, 244, 0, 0, 160, 0, 0, 0, 0, 0, + 0, 0, 1, 244, 0, 2, 252, 0, 2, 248, 0, 1, 244, 0, 0, 1, 111, 249, 0, 0, 1, 191, 255, 253, + 0, 0, 127, 229, 91, 248, 0, 31, 144, 0, 11, 224, 7, 224, 0, 0, 31, 64, 248, 2, 254, 144, 188, 31, + 1, 255, 255, 3, 210, 224, 63, 150, 240, 46, 61, 11, 208, 31, 2, 231, 192, 248, 2, 224, 30, 120, 15, 64, + 46, 1, 231, 128, 244, 2, 224, 46, 120, 15, 64, 62, 2, 215, 128, 248, 7, 224, 125, 124, 11, 229, 255, 159, + 131, 208, 63, 253, 127, 240, 46, 0, 190, 65, 248, 1, 244, 0, 0, 0, 0, 11, 224, 0, 0, 0, 0, 47, + 212, 1, 104, 0, 0, 191, 255, 255, 128, 0, 1, 191, 255, 160, 0, 0, 0, 21, 64, 0, 0, 0, 3, 248, + 0, 0, 0, 127, 192, 0, 0, 11, 253, 0, 0, 0, 251, 224, 0, 0, 31, 111, 0, 0, 2, 241, 244, 0, + 0, 63, 15, 128, 0, 7, 224, 188, 0, 0, 188, 7, 208, 0, 15, 128, 62, 0, 2, 244, 2, 244, 0, 63, + 0, 31, 128, 7, 255, 255, 252, 0, 191, 255, 255, 208, 15, 234, 170, 190, 1, 248, 0, 3, 240, 47, 64, 0, + 47, 67, 240, 0, 1, 248, 126, 0, 0, 15, 203, 208, 0, 0, 189, 127, 255, 228, 1, 255, 255, 253, 7, 229, + 91, 252, 31, 64, 3, 244, 125, 0, 11, 225, 244, 0, 31, 135, 208, 0, 189, 31, 64, 3, 240, 126, 85, 191, + 65, 255, 255, 224, 7, 255, 255, 228, 31, 64, 7, 244, 125, 0, 7, 241, 244, 0, 15, 199, 208, 0, 63, 95, + 64, 0, 252, 125, 0, 11, 241, 249, 85, 191, 71, 255, 255, 244, 31, 255, 250, 0, 0, 6, 255, 148, 0, 127, + 255, 252, 2, 254, 86, 184, 7, 244, 0, 20, 15, 208, 0, 0, 47, 128, 0, 0, 63, 64, 0, 0, 127, 0, + 0, 0, 126, 0, 0, 0, 126, 0, 0, 0, 126, 0, 0, 0, 126, 0, 0, 0, 127, 0, 0, 0, 63, 0, + 0, 0, 47, 128, 0, 0, 31, 208, 0, 0, 11, 244, 0, 0, 3, 254, 85, 184, 0, 191, 255, 248, 0, 26, + 255, 164, 127, 255, 228, 0, 31, 255, 255, 208, 7, 229, 91, 254, 1, 244, 0, 47, 208, 125, 0, 1, 252, 31, + 64, 0, 47, 71, 208, 0, 7, 225, 244, 0, 1, 252, 125, 0, 0, 63, 31, 64, 0, 15, 199, 208, 0, 3, + 241, 244, 0, 0, 252, 125, 0, 0, 127, 31, 64, 0, 31, 135, 208, 0, 15, 209, 244, 0, 11, 240, 125, 0, + 11, 244, 31, 149, 111, 244, 7, 255, 255, 228, 1, 255, 254, 144, 0, 127, 255, 253, 127, 255, 253, 126, 85, 84, + 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 126, 85, 84, 127, 255, 252, 127, 255, 252, + 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 126, 85, 84, 127, 255, 253, + 127, 255, 253, 127, 255, 253, 127, 255, 253, 126, 85, 84, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, + 125, 0, 0, 125, 0, 0, 126, 85, 84, 127, 255, 252, 127, 255, 252, 125, 0, 0, 125, 0, 0, 125, 0, 0, + 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 0, 6, 191, 229, 0, 31, 255, 255, 208, + 47, 249, 90, 224, 31, 224, 0, 20, 15, 208, 0, 0, 11, 224, 0, 0, 3, 244, 0, 0, 0, 252, 0, 0, + 0, 126, 0, 0, 0, 31, 128, 1, 85, 87, 224, 1, 255, 249, 248, 0, 127, 254, 63, 0, 0, 31, 143, 208, + 0, 7, 226, 248, 0, 1, 248, 127, 64, 0, 126, 11, 244, 0, 31, 128, 191, 165, 91, 224, 11, 255, 255, 248, + 0, 43, 255, 164, 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, + 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, 126, 85, 85, 190, 127, 255, 255, 254, 127, 255, 255, 254, + 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, + 125, 0, 0, 126, 125, 0, 0, 126, 125, 0, 0, 126, 255, 254, 255, 253, 31, 228, 11, 208, 11, 208, 11, 208, + 11, 208, 11, 208, 11, 208, 11, 208, 11, 208, 11, 208, 11, 208, 11, 208, 11, 208, 11, 208, 11, 208, 11, 208, + 255, 253, 255, 254, 0, 47, 64, 11, 208, 2, 244, 0, 189, 0, 47, 64, 11, 208, 2, 244, 0, 189, 0, 47, + 64, 11, 208, 2, 244, 0, 189, 0, 47, 64, 11, 208, 2, 244, 0, 189, 0, 47, 64, 11, 208, 2, 244, 0, + 189, 0, 47, 64, 15, 193, 91, 224, 255, 240, 63, 144, 0, 125, 0, 3, 245, 244, 0, 47, 135, 208, 2, 248, + 31, 64, 31, 192, 125, 1, 252, 1, 244, 15, 208, 7, 208, 189, 0, 31, 75, 224, 0, 125, 126, 0, 1, 251, + 252, 0, 7, 255, 248, 0, 31, 231, 244, 0, 126, 11, 240, 1, 244, 11, 224, 7, 208, 15, 208, 31, 64, 31, + 192, 125, 0, 47, 129, 244, 0, 63, 71, 208, 0, 127, 31, 64, 0, 190, 125, 0, 0, 125, 0, 0, 125, 0, + 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, + 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 125, 0, 0, 126, 170, 169, 127, 255, + 254, 127, 255, 254, 127, 192, 0, 0, 255, 95, 244, 0, 0, 127, 215, 254, 0, 0, 47, 245, 255, 192, 0, 31, + 189, 126, 244, 0, 11, 239, 95, 126, 0, 3, 235, 215, 207, 192, 1, 246, 245, 245, 244, 0, 188, 189, 125, 62, + 0, 62, 47, 95, 75, 192, 31, 75, 215, 209, 244, 11, 194, 245, 244, 62, 3, 224, 189, 125, 11, 193, 240, 47, + 95, 65, 244, 184, 11, 215, 208, 62, 61, 2, 245, 244, 11, 239, 0, 189, 125, 1, 255, 128, 47, 95, 64, 63, + 208, 11, 215, 208, 11, 240, 2, 245, 244, 1, 248, 0, 189, 127, 64, 0, 31, 95, 240, 0, 7, 215, 254, 0, + 1, 245, 255, 208, 0, 125, 126, 252, 0, 31, 95, 63, 128, 7, 215, 199, 244, 1, 245, 240, 190, 0, 125, 125, + 31, 208, 31, 95, 66, 252, 7, 215, 208, 63, 129, 245, 244, 7, 244, 125, 125, 0, 191, 31, 95, 64, 15, 231, + 215, 208, 2, 253, 245, 244, 0, 63, 253, 125, 0, 7, 255, 95, 64, 0, 191, 215, 208, 0, 15, 245, 244, 0, + 1, 253, 0, 26, 255, 144, 0, 2, 255, 255, 224, 0, 63, 229, 111, 240, 2, 248, 0, 11, 240, 31, 192, 0, + 15, 208, 190, 0, 0, 31, 195, 240, 0, 0, 63, 31, 192, 0, 0, 189, 126, 0, 0, 2, 245, 248, 0, 0, + 11, 231, 224, 0, 0, 47, 159, 128, 0, 0, 189, 127, 0, 0, 2, 244, 252, 0, 0, 15, 194, 248, 0, 0, + 127, 7, 240, 0, 3, 244, 11, 224, 0, 47, 128, 11, 249, 91, 252, 0, 11, 255, 255, 128, 0, 6, 191, 228, + 0, 127, 255, 144, 7, 255, 255, 208, 126, 86, 255, 71, 208, 2, 248, 125, 0, 15, 199, 208, 0, 252, 125, 0, + 15, 199, 208, 0, 252, 125, 0, 47, 135, 208, 27, 240, 127, 255, 253, 7, 255, 254, 0, 126, 85, 0, 7, 208, + 0, 0, 125, 0, 0, 7, 208, 0, 0, 125, 0, 0, 7, 208, 0, 0, 125, 0, 0, 7, 208, 0, 0, 0, + 26, 255, 144, 0, 2, 255, 255, 224, 0, 63, 229, 111, 240, 2, 248, 0, 11, 224, 31, 192, 0, 15, 208, 190, + 0, 0, 31, 195, 240, 0, 0, 63, 31, 192, 0, 0, 189, 126, 0, 0, 2, 245, 248, 0, 0, 11, 231, 224, + 0, 0, 47, 159, 128, 0, 0, 189, 127, 0, 0, 2, 244, 252, 0, 0, 15, 194, 248, 0, 0, 127, 7, 240, + 0, 3, 244, 11, 224, 0, 47, 192, 11, 249, 91, 253, 0, 11, 255, 255, 128, 0, 6, 191, 248, 0, 0, 0, + 7, 244, 0, 0, 0, 11, 240, 0, 0, 0, 11, 240, 0, 0, 0, 15, 240, 0, 0, 0, 21, 80, 127, 255, + 160, 1, 255, 255, 244, 7, 229, 91, 244, 31, 64, 11, 224, 125, 0, 15, 193, 244, 0, 63, 71, 208, 0, 252, + 31, 64, 3, 240, 125, 0, 47, 129, 249, 86, 248, 7, 255, 255, 128, 31, 255, 248, 0, 125, 3, 244, 1, 244, + 7, 224, 7, 208, 11, 208, 31, 64, 31, 192, 125, 0, 47, 129, 244, 0, 63, 71, 208, 0, 127, 31, 64, 0, + 253, 1, 191, 229, 2, 255, 255, 194, 253, 90, 224, 252, 0, 20, 126, 0, 0, 31, 128, 0, 7, 240, 0, 0, + 255, 64, 0, 31, 249, 0, 1, 255, 244, 0, 11, 255, 128, 0, 31, 248, 0, 0, 191, 64, 0, 11, 224, 0, + 1, 248, 0, 0, 126, 64, 0, 63, 110, 149, 191, 139, 255, 255, 128, 107, 254, 64, 191, 255, 255, 250, 255, 255, + 255, 229, 85, 253, 85, 64, 3, 240, 0, 0, 15, 192, 0, 0, 63, 0, 0, 0, 252, 0, 0, 3, 240, 0, + 0, 15, 192, 0, 0, 63, 0, 0, 0, 252, 0, 0, 3, 240, 0, 0, 15, 192, 0, 0, 63, 0, 0, 0, + 252, 0, 0, 3, 240, 0, 0, 15, 192, 0, 0, 63, 0, 0, 0, 252, 0, 0, 3, 240, 0, 189, 0, 0, + 126, 189, 0, 0, 126, 189, 0, 0, 126, 189, 0, 0, 126, 189, 0, 0, 126, 189, 0, 0, 126, 189, 0, 0, + 126, 189, 0, 0, 126, 189, 0, 0, 126, 189, 0, 0, 126, 189, 0, 0, 126, 189, 0, 0, 126, 189, 0, 0, + 126, 189, 0, 0, 125, 126, 0, 0, 189, 63, 0, 0, 252, 47, 128, 2, 248, 15, 245, 95, 240, 7, 255, 255, + 128, 0, 111, 249, 0, 252, 0, 0, 47, 95, 64, 0, 15, 195, 224, 0, 7, 224, 188, 0, 2, 244, 31, 64, + 0, 252, 3, 224, 0, 126, 0, 188, 0, 47, 64, 31, 64, 15, 192, 3, 224, 7, 224, 0, 188, 2, 244, 0, + 31, 64, 252, 0, 3, 224, 126, 0, 0, 188, 47, 64, 0, 31, 79, 192, 0, 3, 227, 224, 0, 0, 189, 244, + 0, 0, 31, 188, 0, 0, 3, 254, 0, 0, 0, 191, 64, 0, 0, 31, 192, 0, 189, 0, 3, 244, 0, 15, + 199, 224, 0, 127, 128, 1, 248, 62, 0, 11, 248, 0, 31, 131, 240, 0, 191, 192, 2, 244, 47, 64, 15, 189, + 0, 63, 1, 248, 1, 247, 224, 3, 224, 15, 128, 47, 47, 0, 126, 0, 252, 3, 225, 244, 11, 208, 11, 208, + 62, 31, 64, 252, 0, 125, 7, 208, 248, 15, 128, 3, 224, 188, 11, 193, 244, 0, 63, 15, 128, 125, 47, 64, + 2, 245, 244, 3, 226, 240, 0, 31, 95, 0, 46, 62, 0, 0, 250, 240, 2, 247, 208, 0, 15, 190, 0, 31, + 189, 0, 0, 191, 208, 0, 255, 192, 0, 7, 252, 0, 11, 248, 0, 0, 63, 128, 0, 127, 64, 0, 3, 248, + 0, 3, 244, 0, 127, 0, 0, 190, 11, 224, 0, 63, 0, 253, 0, 47, 64, 31, 128, 31, 128, 2, 244, 15, + 208, 0, 63, 7, 224, 0, 7, 227, 240, 0, 0, 254, 244, 0, 0, 31, 248, 0, 0, 2, 252, 0, 0, 0, + 255, 64, 0, 0, 191, 240, 0, 0, 126, 126, 0, 0, 47, 75, 208, 0, 31, 129, 252, 0, 15, 192, 47, 128, + 11, 208, 3, 244, 7, 224, 0, 126, 3, 244, 0, 11, 210, 248, 0, 1, 252, 189, 0, 0, 190, 127, 0, 1, + 252, 47, 64, 2, 244, 31, 192, 7, 240, 11, 224, 11, 208, 7, 240, 31, 192, 2, 248, 47, 64, 0, 252, 127, + 0, 0, 190, 189, 0, 0, 63, 248, 0, 0, 47, 244, 0, 0, 15, 224, 0, 0, 11, 208, 0, 0, 11, 208, + 0, 0, 11, 208, 0, 0, 11, 208, 0, 0, 11, 208, 0, 0, 11, 208, 0, 0, 11, 208, 0, 0, 11, 208, + 0, 47, 255, 255, 244, 191, 255, 255, 209, 85, 85, 191, 0, 0, 3, 244, 0, 0, 47, 128, 0, 1, 252, 0, + 0, 11, 208, 0, 0, 126, 0, 0, 3, 244, 0, 0, 47, 128, 0, 1, 252, 0, 0, 15, 208, 0, 0, 190, + 0, 0, 7, 240, 0, 0, 47, 64, 0, 1, 248, 0, 0, 15, 208, 0, 0, 190, 85, 85, 83, 255, 255, 255, + 143, 255, 255, 254, 255, 247, 255, 223, 149, 62, 0, 248, 3, 224, 15, 128, 62, 0, 248, 3, 224, 15, 128, 62, + 0, 248, 3, 224, 15, 128, 62, 0, 248, 3, 224, 15, 128, 62, 0, 248, 3, 229, 79, 255, 127, 253, 188, 0, + 1, 248, 0, 3, 240, 0, 7, 208, 0, 15, 128, 0, 47, 0, 0, 125, 0, 0, 248, 0, 2, 240, 0, 7, + 208, 0, 15, 128, 0, 47, 0, 0, 125, 0, 0, 248, 0, 2, 244, 0, 7, 224, 0, 15, 192, 0, 31, 64, + 0, 62, 0, 0, 188, 127, 249, 255, 225, 95, 128, 62, 0, 248, 3, 224, 15, 128, 62, 0, 248, 3, 224, 15, + 128, 62, 0, 248, 3, 224, 15, 128, 62, 0, 248, 3, 224, 15, 128, 62, 0, 248, 87, 231, 255, 159, 254, 0, + 24, 0, 0, 2, 224, 0, 0, 127, 64, 0, 11, 248, 0, 1, 247, 208, 0, 46, 46, 0, 3, 192, 244, 0, + 184, 11, 128, 15, 64, 61, 1, 224, 2, 224, 61, 0, 15, 71, 192, 0, 184, 248, 0, 3, 208, 21, 85, 85, + 79, 255, 255, 227, 255, 255, 248, 105, 1, 252, 1, 248, 1, 244, 1, 240, 1, 191, 224, 3, 255, 255, 64, 185, + 91, 240, 0, 0, 253, 0, 0, 47, 64, 5, 91, 208, 127, 255, 244, 191, 255, 253, 127, 80, 47, 111, 64, 11, + 219, 208, 2, 246, 244, 1, 253, 127, 150, 255, 75, 255, 227, 208, 191, 144, 244, 188, 0, 0, 11, 192, 0, 0, + 188, 0, 0, 11, 192, 0, 0, 188, 0, 0, 11, 192, 0, 0, 188, 111, 224, 11, 223, 255, 208, 191, 213, 191, + 11, 240, 2, 248, 189, 0, 15, 203, 208, 0, 188, 188, 0, 11, 219, 192, 0, 189, 188, 0, 11, 219, 208, 0, + 252, 189, 0, 15, 203, 240, 2, 248, 191, 229, 191, 11, 175, 255, 208, 180, 111, 224, 0, 0, 111, 232, 7, 255, + 252, 31, 229, 104, 47, 128, 0, 63, 0, 0, 126, 0, 0, 125, 0, 0, 189, 0, 0, 125, 0, 0, 126, 0, + 0, 63, 0, 0, 47, 64, 0, 31, 229, 108, 7, 255, 252, 0, 175, 228, 0, 0, 7, 224, 0, 0, 126, 0, + 0, 7, 224, 0, 0, 126, 0, 0, 7, 224, 0, 0, 126, 1, 191, 135, 224, 191, 255, 126, 31, 229, 191, 227, + 244, 1, 254, 127, 0, 11, 231, 224, 0, 126, 189, 0, 7, 235, 208, 0, 126, 189, 0, 7, 231, 224, 0, 126, + 127, 0, 11, 227, 244, 1, 254, 31, 229, 191, 224, 191, 255, 126, 1, 191, 131, 224, 0, 111, 224, 0, 127, 255, + 208, 15, 229, 191, 2, 244, 1, 248, 62, 0, 15, 199, 229, 85, 252, 127, 255, 255, 203, 255, 255, 252, 125, 0, + 0, 7, 224, 0, 0, 63, 0, 0, 2, 248, 0, 0, 15, 229, 91, 64, 127, 255, 244, 0, 111, 249, 0, 0, + 47, 228, 3, 255, 208, 47, 150, 0, 252, 0, 3, 224, 0, 15, 128, 2, 255, 253, 47, 255, 244, 87, 229, 64, + 15, 128, 0, 62, 0, 0, 248, 0, 3, 224, 0, 15, 128, 0, 62, 0, 0, 248, 0, 3, 224, 0, 15, 128, + 0, 62, 0, 0, 248, 0, 3, 224, 0, 1, 191, 131, 224, 191, 255, 126, 31, 229, 191, 227, 244, 1, 254, 127, + 0, 11, 231, 224, 0, 126, 189, 0, 7, 235, 208, 0, 126, 189, 0, 7, 231, 224, 0, 126, 126, 0, 11, 227, + 244, 0, 254, 31, 229, 191, 224, 191, 255, 126, 1, 191, 135, 224, 0, 0, 126, 0, 0, 7, 208, 0, 0, 189, + 16, 0, 31, 194, 233, 91, 248, 47, 255, 254, 0, 111, 254, 64, 188, 0, 0, 47, 0, 0, 11, 192, 0, 2, + 240, 0, 0, 188, 0, 0, 47, 0, 0, 11, 198, 254, 66, 247, 255, 248, 191, 229, 191, 111, 192, 11, 235, 224, + 1, 250, 244, 0, 62, 188, 0, 15, 175, 0, 3, 235, 192, 0, 250, 240, 0, 62, 188, 0, 15, 175, 0, 3, + 235, 192, 0, 250, 240, 0, 62, 188, 0, 15, 128, 184, 253, 184, 0, 0, 0, 188, 188, 188, 188, 188, 188, 188, + 188, 188, 188, 188, 188, 188, 188, 188, 0, 184, 0, 253, 0, 184, 0, 0, 0, 0, 0, 0, 0, 188, 0, 188, + 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, + 0, 188, 0, 188, 0, 188, 0, 188, 0, 252, 86, 248, 127, 244, 127, 144, 188, 0, 0, 47, 0, 0, 11, 192, + 0, 2, 240, 0, 0, 188, 0, 0, 47, 0, 0, 11, 192, 7, 242, 240, 7, 244, 188, 3, 244, 47, 3, 244, + 11, 194, 244, 2, 242, 248, 0, 189, 252, 0, 47, 255, 64, 11, 251, 244, 2, 244, 127, 0, 188, 11, 224, 47, + 0, 253, 11, 192, 31, 194, 240, 2, 248, 188, 0, 47, 128, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, + 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 184, 111, 224, 27, 249, 11, 159, 255, 215, 255, 244, 191, 213, 255, + 249, 111, 203, 240, 3, 253, 0, 253, 190, 0, 47, 128, 11, 219, 208, 2, 244, 0, 125, 188, 0, 47, 64, 7, + 219, 192, 2, 244, 0, 125, 188, 0, 47, 64, 7, 219, 192, 2, 244, 0, 125, 188, 0, 47, 64, 7, 219, 192, + 2, 244, 0, 125, 188, 0, 47, 64, 7, 219, 192, 2, 244, 0, 125, 188, 0, 47, 64, 7, 208, 184, 111, 228, + 46, 127, 255, 139, 254, 91, 246, 252, 0, 190, 190, 0, 31, 175, 64, 3, 235, 192, 0, 250, 240, 0, 62, 188, + 0, 15, 175, 0, 3, 235, 192, 0, 250, 240, 0, 62, 188, 0, 15, 175, 0, 3, 235, 192, 0, 248, 0, 175, + 228, 0, 31, 255, 248, 1, 254, 91, 248, 11, 208, 3, 244, 63, 0, 7, 225, 248, 0, 15, 203, 208, 0, 63, + 47, 64, 0, 252, 125, 0, 3, 241, 248, 0, 15, 195, 240, 0, 126, 11, 224, 3, 244, 15, 229, 191, 128, 31, + 255, 248, 0, 6, 254, 64, 0, 184, 111, 228, 11, 159, 255, 208, 191, 213, 191, 11, 240, 2, 248, 189, 0, 15, + 203, 208, 0, 252, 188, 0, 11, 219, 192, 0, 189, 188, 0, 11, 219, 208, 0, 252, 190, 0, 31, 203, 240, 2, + 248, 191, 229, 191, 11, 223, 255, 208, 188, 111, 224, 11, 192, 0, 0, 188, 0, 0, 11, 192, 0, 0, 188, 0, + 0, 11, 192, 0, 0, 188, 0, 0, 11, 192, 0, 0, 1, 191, 131, 224, 191, 255, 126, 31, 229, 191, 227, 244, + 1, 254, 127, 0, 11, 231, 224, 0, 126, 189, 0, 7, 235, 208, 0, 126, 189, 0, 7, 231, 224, 0, 126, 127, + 0, 11, 227, 244, 1, 254, 31, 229, 191, 224, 191, 255, 126, 1, 191, 135, 224, 0, 0, 126, 0, 0, 7, 224, + 0, 0, 126, 0, 0, 7, 224, 0, 0, 126, 0, 0, 7, 224, 0, 0, 126, 184, 47, 238, 63, 251, 238, 86, + 253, 0, 190, 0, 47, 64, 11, 192, 2, 240, 0, 188, 0, 47, 0, 11, 192, 2, 240, 0, 188, 0, 47, 0, + 11, 192, 0, 6, 255, 144, 191, 255, 215, 245, 111, 47, 64, 4, 189, 0, 1, 254, 0, 2, 255, 144, 1, 191, + 228, 0, 47, 244, 0, 11, 224, 0, 15, 208, 0, 63, 185, 87, 250, 255, 255, 129, 191, 228, 0, 1, 144, 0, + 45, 0, 3, 208, 0, 125, 0, 47, 255, 235, 255, 254, 27, 229, 64, 125, 0, 7, 208, 0, 125, 0, 7, 208, + 0, 125, 0, 7, 208, 0, 125, 0, 7, 208, 0, 126, 0, 3, 249, 80, 47, 254, 0, 111, 144, 252, 0, 15, + 191, 0, 3, 239, 192, 0, 251, 240, 0, 62, 252, 0, 15, 191, 0, 3, 239, 192, 0, 251, 240, 0, 62, 252, + 0, 31, 191, 0, 7, 239, 192, 2, 250, 248, 1, 254, 127, 150, 255, 139, 255, 247, 224, 111, 224, 184, 189, 0, + 3, 241, 248, 0, 31, 131, 240, 0, 189, 11, 208, 3, 240, 31, 128, 31, 128, 63, 0, 189, 0, 189, 3, 224, + 1, 248, 31, 64, 3, 240, 188, 0, 11, 211, 224, 0, 15, 159, 64, 0, 46, 188, 0, 0, 127, 224, 0, 0, + 255, 64, 0, 2, 252, 0, 0, 189, 0, 47, 128, 11, 215, 224, 3, 252, 0, 188, 63, 0, 127, 192, 15, 130, + 240, 11, 189, 1, 248, 47, 64, 246, 224, 47, 65, 248, 31, 95, 2, 240, 15, 194, 241, 244, 62, 0, 188, 46, + 15, 135, 208, 7, 211, 208, 188, 189, 0, 62, 124, 7, 203, 192, 3, 235, 128, 61, 248, 0, 47, 184, 3, 239, + 64, 1, 255, 64, 47, 240, 0, 15, 240, 1, 254, 0, 0, 190, 0, 15, 224, 0, 63, 64, 11, 224, 126, 0, + 127, 0, 189, 2, 244, 0, 252, 31, 128, 1, 248, 252, 0, 2, 255, 208, 0, 3, 254, 0, 0, 11, 244, 0, + 0, 127, 224, 0, 3, 251, 224, 0, 47, 143, 208, 1, 252, 31, 192, 15, 208, 47, 128, 190, 0, 63, 71, 240, + 0, 127, 0, 189, 0, 3, 241, 248, 0, 31, 131, 240, 0, 189, 11, 208, 3, 240, 31, 128, 31, 128, 63, 0, + 189, 0, 189, 3, 240, 0, 248, 31, 128, 2, 240, 189, 0, 7, 211, 224, 0, 15, 159, 64, 0, 47, 188, 0, + 0, 127, 224, 0, 0, 255, 64, 0, 1, 252, 0, 0, 7, 224, 0, 0, 47, 64, 0, 0, 252, 0, 0, 11, + 208, 0, 21, 191, 0, 0, 191, 240, 0, 1, 254, 0, 0, 0, 191, 255, 250, 255, 255, 229, 85, 127, 64, 1, + 248, 0, 15, 192, 0, 189, 0, 7, 224, 0, 63, 0, 2, 244, 0, 47, 128, 1, 248, 0, 15, 208, 0, 190, + 85, 87, 255, 255, 255, 255, 255, 192, 0, 10, 208, 7, 253, 0, 190, 64, 15, 192, 0, 248, 0, 15, 128, 0, + 248, 0, 15, 128, 0, 248, 0, 31, 64, 27, 240, 7, 248, 0, 127, 144, 0, 127, 64, 1, 248, 0, 15, 128, + 0, 248, 0, 15, 128, 0, 248, 0, 15, 128, 0, 252, 0, 11, 228, 0, 127, 208, 0, 173, 186, 235, 174, 186, + 235, 174, 186, 235, 174, 186, 235, 174, 186, 235, 174, 186, 235, 174, 186, 235, 174, 62, 64, 3, 254, 0, 27, 240, + 0, 47, 64, 1, 244, 0, 31, 64, 1, 244, 0, 31, 64, 1, 244, 0, 15, 128, 0, 190, 80, 1, 190, 0, + 47, 224, 11, 224, 1, 248, 0, 31, 64, 1, 244, 0, 31, 64, 1, 244, 0, 31, 64, 2, 244, 1, 191, 0, + 63, 208, 3, 228, 0, 31, 228, 0, 139, 255, 249, 108, 185, 111, 255, 200, 0, 111, 224, 46, 0, 125, 1, 244, + 253, 3, 248, 11, 243, 244, 15, 224, 47, 203, 128, 31, 64, 125, 46, 15, 211, 244, 184, + ], + arabic_ascent: 38, arabic_descent: 20, arabic_cap: 20, + arabic_glyphs: &[ + Glyph { c: '\u{060C}', adv: 9, x: 2, y: -7, w: 4, h: 7, off: 0 }, + Glyph { c: '\u{061B}', adv: 9, x: 2, y: -14, w: 5, h: 15, off: 7 }, + Glyph { c: '\u{061F}', adv: 12, x: 1, y: -19, w: 11, h: 20, off: 26 }, + Glyph { c: '\u{0640}', adv: 7, x: 0, y: -3, w: 9, h: 3, off: 81 }, + Glyph { c: '\u{0660}', adv: 15, x: 5, y: -11, w: 6, h: 6, off: 88 }, + Glyph { c: '\u{0661}', adv: 15, x: 4, y: -19, w: 6, h: 20, off: 97 }, + Glyph { c: '\u{0662}', adv: 15, x: 1, y: -18, w: 12, h: 19, off: 127 }, + Glyph { c: '\u{0663}', adv: 15, x: 0, y: -19, w: 15, h: 20, off: 184 }, + Glyph { c: '\u{0664}', adv: 15, x: 2, y: -19, w: 12, h: 19, off: 259 }, + Glyph { c: '\u{0665}', adv: 15, x: 2, y: -14, w: 11, h: 14, off: 316 }, + Glyph { c: '\u{0666}', adv: 15, x: 1, y: -19, w: 13, h: 20, off: 355 }, + Glyph { c: '\u{0667}', adv: 15, x: 0, y: -19, w: 15, h: 20, off: 420 }, + Glyph { c: '\u{0668}', adv: 15, x: 0, y: -19, w: 15, h: 20, off: 495 }, + Glyph { c: '\u{0669}', adv: 15, x: 2, y: -18, w: 12, h: 19, off: 570 }, + Glyph { c: '\u{06F0}', adv: 15, x: 5, y: -11, w: 6, h: 6, off: 627 }, + Glyph { c: '\u{06F1}', adv: 15, x: 4, y: -19, w: 6, h: 20, off: 636 }, + Glyph { c: '\u{06F2}', adv: 15, x: 1, y: -18, w: 12, h: 19, off: 666 }, + Glyph { c: '\u{06F3}', adv: 15, x: 0, y: -19, w: 15, h: 20, off: 723 }, + Glyph { c: '\u{06F4}', adv: 15, x: 1, y: -19, w: 13, h: 19, off: 798 }, + Glyph { c: '\u{06F5}', adv: 15, x: 2, y: -19, w: 12, h: 19, off: 860 }, + Glyph { c: '\u{06F6}', adv: 15, x: 2, y: -19, w: 11, h: 19, off: 917 }, + Glyph { c: '\u{06F7}', adv: 15, x: 0, y: -19, w: 15, h: 20, off: 970 }, + Glyph { c: '\u{06F8}', adv: 15, x: 0, y: -19, w: 15, h: 20, off: 1045 }, + Glyph { c: '\u{06F9}', adv: 15, x: 2, y: -18, w: 12, h: 19, off: 1120 }, + Glyph { c: '\u{FE7F}', adv: 7, x: 0, y: -17, w: 9, h: 17, off: 1177 }, + Glyph { c: '\u{FE80}', adv: 12, x: 1, y: -11, w: 11, h: 13, off: 1216 }, + Glyph { c: '\u{FE81}', adv: 7, x: -2, y: -23, w: 9, h: 23, off: 1252 }, + Glyph { c: '\u{FE82}', adv: 8, x: -2, y: -25, w: 12, h: 25, off: 1304 }, + Glyph { c: '\u{FE83}', adv: 7, x: 1, y: -27, w: 6, h: 27, off: 1379 }, + Glyph { c: '\u{FE84}', adv: 8, x: 1, y: -28, w: 10, h: 28, off: 1420 }, + Glyph { c: '\u{FE85}', adv: 12, x: 1, y: -18, w: 11, h: 24, off: 1490 }, + Glyph { c: '\u{FE86}', adv: 13, x: 1, y: -18, w: 14, h: 24, off: 1556 }, + Glyph { c: '\u{FE87}', adv: 7, x: 2, y: -18, w: 6, h: 26, off: 1640 }, + Glyph { c: '\u{FE88}', adv: 8, x: 2, y: -19, w: 8, h: 28, off: 1679 }, + Glyph { c: '\u{FE89}', adv: 21, x: 1, y: -14, w: 20, h: 20, off: 1735 }, + Glyph { c: '\u{FE8A}', adv: 20, x: 1, y: -13, w: 21, h: 19, off: 1835 }, + Glyph { c: '\u{FE8B}', adv: 8, x: 0, y: -19, w: 7, h: 19, off: 1935 }, + Glyph { c: '\u{FE8C}', adv: 10, x: 0, y: -17, w: 12, h: 17, off: 1969 }, + Glyph { c: '\u{FE8D}', adv: 7, x: 2, y: -19, w: 3, h: 19, off: 2020 }, + Glyph { c: '\u{FE8E}', adv: 8, x: 2, y: -19, w: 8, h: 19, off: 2035 }, + Glyph { c: '\u{FE8F}', adv: 27, x: 1, y: -11, w: 25, h: 17, off: 2073 }, + Glyph { c: '\u{FE90}', adv: 30, x: 1, y: -10, w: 31, h: 16, off: 2180 }, + Glyph { c: '\u{FE91}', adv: 8, x: 0, y: -12, w: 7, h: 17, off: 2304 }, + Glyph { c: '\u{FE92}', adv: 10, x: -1, y: -9, w: 12, h: 14, off: 2334 }, + Glyph { c: '\u{FE93}', adv: 11, x: 1, y: -19, w: 10, h: 19, off: 2376 }, + Glyph { c: '\u{FE94}', adv: 14, x: 1, y: -21, w: 15, h: 21, off: 2424 }, + Glyph { c: '\u{FE95}', adv: 27, x: 1, y: -14, w: 25, h: 15, off: 2503 }, + Glyph { c: '\u{FE96}', adv: 30, x: 1, y: -14, w: 31, h: 15, off: 2597 }, + Glyph { c: '\u{FE97}', adv: 8, x: 0, y: -17, w: 8, h: 17, off: 2714 }, + Glyph { c: '\u{FE98}', adv: 10, x: -1, y: -14, w: 13, h: 14, off: 2748 }, + Glyph { c: '\u{FE99}', adv: 27, x: 1, y: -17, w: 25, h: 18, off: 2794 }, + Glyph { c: '\u{FE9A}', adv: 30, x: 1, y: -17, w: 31, h: 18, off: 2907 }, + Glyph { c: '\u{FE9B}', adv: 8, x: 0, y: -20, w: 8, h: 20, off: 3047 }, + Glyph { c: '\u{FE9C}', adv: 10, x: -1, y: -17, w: 13, h: 17, off: 3087 }, + Glyph { c: '\u{FE9D}', adv: 18, x: 1, y: -12, w: 17, h: 23, off: 3143 }, + Glyph { c: '\u{FE9E}', adv: 18, x: 1, y: -12, w: 20, h: 22, off: 3241 }, + Glyph { c: '\u{FE9F}', adv: 16, x: -1, y: -10, w: 16, h: 15, off: 3351 }, + Glyph { c: '\u{FEA0}', adv: 17, x: 0, y: -10, w: 19, h: 15, off: 3411 }, + Glyph { c: '\u{FEA1}', adv: 18, x: 1, y: -12, w: 17, h: 23, off: 3483 }, + Glyph { c: '\u{FEA2}', adv: 18, x: 1, y: -12, w: 20, h: 23, off: 3581 }, + Glyph { c: '\u{FEA3}', adv: 16, x: 0, y: -10, w: 16, h: 10, off: 3696 }, + Glyph { c: '\u{FEA4}', adv: 17, x: 0, y: -10, w: 19, h: 10, off: 3736 }, + Glyph { c: '\u{FEA5}', adv: 18, x: 1, y: -18, w: 17, h: 29, off: 3784 }, + Glyph { c: '\u{FEA6}', adv: 18, x: 1, y: -18, w: 20, h: 29, off: 3908 }, + Glyph { c: '\u{FEA7}', adv: 16, x: 0, y: -16, w: 15, h: 16, off: 4053 }, + Glyph { c: '\u{FEA8}', adv: 17, x: 0, y: -16, w: 19, h: 16, off: 4113 }, + Glyph { c: '\u{FEA9}', adv: 13, x: 0, y: -13, w: 12, h: 13, off: 4189 }, + Glyph { c: '\u{FEAA}', adv: 15, x: 0, y: -13, w: 16, h: 13, off: 4228 }, + Glyph { c: '\u{FEAB}', adv: 13, x: 0, y: -18, w: 12, h: 18, off: 4280 }, + Glyph { c: '\u{FEAC}', adv: 15, x: 0, y: -19, w: 16, h: 19, off: 4334 }, + Glyph { c: '\u{FEAD}', adv: 10, x: -1, y: -10, w: 10, h: 17, off: 4410 }, + Glyph { c: '\u{FEAE}', adv: 11, x: -1, y: -10, w: 14, h: 16, off: 4453 }, + Glyph { c: '\u{FEAF}', adv: 10, x: -1, y: -15, w: 10, h: 22, off: 4509 }, + Glyph { c: '\u{FEB0}', adv: 11, x: -1, y: -16, w: 14, h: 22, off: 4564 }, + Glyph { c: '\u{FEB1}', adv: 34, x: 1, y: -12, w: 32, h: 18, off: 4641 }, + Glyph { c: '\u{FEB2}', adv: 36, x: 1, y: -10, w: 37, h: 16, off: 4785 }, + Glyph { c: '\u{FEB3}', adv: 22, x: -1, y: -12, w: 22, h: 12, off: 4933 }, + Glyph { c: '\u{FEB4}', adv: 24, x: 0, y: -10, w: 26, h: 10, off: 4999 }, + Glyph { c: '\u{FEB5}', adv: 34, x: 1, y: -18, w: 32, h: 24, off: 5064 }, + Glyph { c: '\u{FEB6}', adv: 36, x: 1, y: -18, w: 37, h: 24, off: 5256 }, + Glyph { c: '\u{FEB7}', adv: 22, x: 0, y: -18, w: 21, h: 18, off: 5478 }, + Glyph { c: '\u{FEB8}', adv: 24, x: 0, y: -18, w: 26, h: 18, off: 5573 }, + Glyph { c: '\u{FEB9}', adv: 36, x: 1, y: -10, w: 34, h: 17, off: 5690 }, + Glyph { c: '\u{FEBA}', adv: 37, x: 1, y: -11, w: 38, h: 17, off: 5835 }, + Glyph { c: '\u{FEBB}', adv: 25, x: -1, y: -10, w: 25, h: 11, off: 5997 }, + Glyph { c: '\u{FEBC}', adv: 26, x: -1, y: -10, w: 29, h: 11, off: 6066 }, + Glyph { c: '\u{FEBD}', adv: 36, x: 1, y: -16, w: 34, h: 23, off: 6146 }, + Glyph { c: '\u{FEBE}', adv: 37, x: 1, y: -16, w: 38, h: 22, off: 6342 }, + Glyph { c: '\u{FEBF}', adv: 25, x: -1, y: -16, w: 25, h: 17, off: 6551 }, + Glyph { c: '\u{FEC0}', adv: 26, x: -1, y: -16, w: 28, h: 17, off: 6658 }, + Glyph { c: '\u{FEC1}', adv: 22, x: 0, y: -19, w: 20, h: 19, off: 6777 }, + Glyph { c: '\u{FEC2}', adv: 23, x: 0, y: -19, w: 24, h: 19, off: 6872 }, + Glyph { c: '\u{FEC3}', adv: 19, x: -1, y: -19, w: 18, h: 19, off: 6986 }, + Glyph { c: '\u{FEC4}', adv: 20, x: -1, y: -19, w: 22, h: 19, off: 7072 }, + Glyph { c: '\u{FEC5}', adv: 22, x: 0, y: -19, w: 20, h: 19, off: 7177 }, + Glyph { c: '\u{FEC6}', adv: 23, x: 0, y: -19, w: 24, h: 19, off: 7272 }, + Glyph { c: '\u{FEC7}', adv: 19, x: -1, y: -19, w: 18, h: 19, off: 7386 }, + Glyph { c: '\u{FEC8}', adv: 20, x: -1, y: -19, w: 22, h: 19, off: 7472 }, + Glyph { c: '\u{FEC9}', adv: 14, x: 1, y: -14, w: 16, h: 25, off: 7577 }, + Glyph { c: '\u{FECA}', adv: 15, x: 1, y: -12, w: 16, h: 23, off: 7677 }, + Glyph { c: '\u{FECB}', adv: 14, x: 0, y: -13, w: 13, h: 13, off: 7769 }, + Glyph { c: '\u{FECC}', adv: 14, x: 0, y: -12, w: 16, h: 12, off: 7812 }, + Glyph { c: '\u{FECD}', adv: 14, x: 1, y: -20, w: 16, h: 31, off: 7860 }, + Glyph { c: '\u{FECE}', adv: 15, x: 1, y: -17, w: 16, h: 28, off: 7984 }, + Glyph { c: '\u{FECF}', adv: 14, x: 0, y: -18, w: 13, h: 18, off: 8096 }, + Glyph { c: '\u{FED0}', adv: 14, x: 0, y: -17, w: 16, h: 17, off: 8155 }, + Glyph { c: '\u{FED1}', adv: 27, x: 1, y: -20, w: 25, h: 21, off: 8223 }, + Glyph { c: '\u{FED2}', adv: 30, x: 1, y: -17, w: 31, h: 18, off: 8355 }, + Glyph { c: '\u{FED3}', adv: 13, x: 0, y: -20, w: 12, h: 20, off: 8495 }, + Glyph { c: '\u{FED4}', adv: 14, x: 0, y: -18, w: 15, h: 18, off: 8555 }, + Glyph { c: '\u{FED5}', adv: 21, x: 1, y: -17, w: 20, h: 22, off: 8623 }, + Glyph { c: '\u{FED6}', adv: 22, x: 1, y: -15, w: 23, h: 22, off: 8733 }, + Glyph { c: '\u{FED7}', adv: 13, x: 0, y: -19, w: 12, h: 19, off: 8860 }, + Glyph { c: '\u{FED8}', adv: 14, x: 0, y: -18, w: 15, h: 18, off: 8917 }, + Glyph { c: '\u{FED9}', adv: 24, x: 1, y: -19, w: 22, h: 20, off: 8985 }, + Glyph { c: '\u{FEDA}', adv: 25, x: 1, y: -19, w: 26, h: 20, off: 9095 }, + Glyph { c: '\u{FEDB}', adv: 11, x: -1, y: -20, w: 13, h: 20, off: 9225 }, + Glyph { c: '\u{FEDC}', adv: 14, x: 0, y: -20, w: 16, h: 20, off: 9290 }, + Glyph { c: '\u{FEDD}', adv: 19, x: 1, y: -19, w: 17, h: 26, off: 9370 }, + Glyph { c: '\u{FEDE}', adv: 20, x: 1, y: -19, w: 21, h: 25, off: 9481 }, + Glyph { c: '\u{FEDF}', adv: 7, x: 0, y: -19, w: 6, h: 19, off: 9613 }, + Glyph { c: '\u{FEE0}', adv: 8, x: 0, y: -19, w: 10, h: 19, off: 9642 }, + Glyph { c: '\u{FEE1}', adv: 14, x: 1, y: -11, w: 12, h: 22, off: 9690 }, + Glyph { c: '\u{FEE2}', adv: 16, x: 1, y: -10, w: 18, h: 21, off: 9756 }, + Glyph { c: '\u{FEE3}', adv: 15, x: 0, y: -10, w: 14, h: 10, off: 9851 }, + Glyph { c: '\u{FEE4}', adv: 16, x: 0, y: -10, w: 18, h: 11, off: 9886 }, + Glyph { c: '\u{FEE5}', adv: 19, x: 1, y: -14, w: 17, h: 20, off: 9936 }, + Glyph { c: '\u{FEE6}', adv: 20, x: 1, y: -14, w: 21, h: 20, off: 10021 }, + Glyph { c: '\u{FEE7}', adv: 8, x: 0, y: -17, w: 6, h: 17, off: 10126 }, + Glyph { c: '\u{FEE8}', adv: 10, x: 0, y: -14, w: 11, h: 14, off: 10152 }, + Glyph { c: '\u{FEE9}', adv: 11, x: 1, y: -14, w: 10, h: 14, off: 10191 }, + Glyph { c: '\u{FEEA}', adv: 14, x: 1, y: -15, w: 15, h: 15, off: 10226 }, + Glyph { c: '\u{FEEB}', adv: 16, x: 0, y: -15, w: 15, h: 15, off: 10283 }, + Glyph { c: '\u{FEEC}', adv: 14, x: -1, y: -12, w: 17, h: 18, off: 10340 }, + Glyph { c: '\u{FEED}', adv: 12, x: 1, y: -10, w: 11, h: 16, off: 10417 }, + Glyph { c: '\u{FEEE}', adv: 13, x: 1, y: -10, w: 14, h: 16, off: 10461 }, + Glyph { c: '\u{FEEF}', adv: 21, x: 1, y: -12, w: 20, h: 18, off: 10517 }, + Glyph { c: '\u{FEF0}', adv: 20, x: 1, y: -6, w: 21, h: 12, off: 10607 }, + Glyph { c: '\u{FEF1}', adv: 21, x: 1, y: -12, w: 20, h: 23, off: 10670 }, + Glyph { c: '\u{FEF2}', adv: 20, x: 1, y: -6, w: 21, h: 18, off: 10785 }, + Glyph { c: '\u{FEF3}', adv: 9, x: 0, y: -12, w: 7, h: 17, off: 10880 }, + Glyph { c: '\u{FEF4}', adv: 10, x: 0, y: -9, w: 13, h: 14, off: 10910 }, + ], + arabic_bits: &[ + 0, 46, 125, 188, 253, 255, 126, 11, 131, 225, 244, 188, 63, 31, 139, 224, 0, 0, 0, 0, 1, 244, 255, 63, + 199, 208, 6, 254, 144, 191, 255, 231, 250, 191, 127, 64, 24, 248, 0, 3, 224, 0, 11, 208, 0, 31, 208, 0, + 31, 208, 0, 31, 224, 0, 31, 208, 0, 31, 128, 0, 47, 0, 0, 188, 0, 0, 0, 0, 0, 0, 0, 125, + 0, 3, 252, 0, 15, 240, 0, 31, 64, 170, 170, 127, 255, 255, 255, 248, 4, 1, 224, 127, 135, 252, 15, 0, + 64, 4, 3, 224, 63, 2, 240, 47, 65, 248, 31, 128, 252, 15, 192, 188, 11, 208, 189, 7, 208, 126, 7, 224, + 62, 3, 224, 62, 3, 224, 0, 45, 0, 14, 62, 0, 31, 47, 0, 62, 47, 234, 253, 31, 255, 248, 31, 255, + 144, 15, 128, 0, 15, 192, 0, 11, 192, 0, 11, 208, 0, 11, 208, 0, 7, 208, 0, 7, 224, 0, 7, 224, + 0, 3, 224, 0, 3, 224, 0, 3, 224, 0, 3, 224, 0, 1, 64, 0, 0, 0, 0, 0, 180, 5, 7, 195, + 224, 45, 31, 75, 192, 240, 62, 47, 7, 192, 248, 127, 191, 239, 225, 255, 255, 255, 3, 255, 91, 228, 15, 192, + 0, 0, 47, 0, 0, 0, 189, 0, 0, 2, 244, 0, 0, 7, 208, 0, 0, 31, 128, 0, 0, 126, 0, 0, + 0, 248, 0, 0, 3, 224, 0, 0, 15, 128, 0, 0, 62, 0, 0, 0, 80, 0, 0, 0, 20, 0, 1, 252, + 0, 11, 253, 0, 47, 224, 0, 127, 64, 0, 188, 0, 0, 248, 0, 0, 253, 0, 0, 127, 252, 0, 31, 252, + 0, 11, 244, 0, 47, 128, 0, 126, 0, 0, 188, 0, 0, 248, 0, 0, 252, 0, 4, 191, 170, 188, 47, 255, + 252, 6, 255, 164, 1, 254, 0, 47, 254, 2, 254, 254, 15, 192, 253, 189, 1, 250, 240, 3, 239, 128, 11, 254, + 0, 47, 248, 0, 191, 240, 3, 251, 208, 31, 159, 234, 253, 31, 255, 208, 27, 249, 0, 16, 0, 0, 31, 170, + 174, 11, 255, 255, 128, 175, 255, 224, 0, 0, 248, 0, 0, 62, 0, 0, 15, 128, 0, 2, 240, 0, 0, 188, + 0, 0, 47, 0, 0, 11, 208, 0, 1, 244, 0, 0, 125, 0, 0, 15, 128, 0, 3, 224, 0, 0, 252, 0, + 0, 47, 0, 0, 11, 208, 0, 1, 244, 0, 0, 0, 8, 0, 0, 81, 244, 0, 3, 227, 240, 0, 31, 139, + 208, 0, 189, 31, 128, 3, 224, 63, 0, 47, 64, 189, 0, 252, 1, 248, 7, 224, 3, 240, 47, 64, 11, 208, + 248, 0, 31, 135, 208, 0, 63, 47, 0, 0, 189, 248, 0, 1, 251, 208, 0, 3, 255, 0, 0, 11, 248, 0, + 0, 31, 224, 0, 0, 63, 64, 0, 0, 252, 0, 0, 0, 0, 0, 0, 1, 64, 0, 0, 47, 64, 0, 0, + 190, 0, 0, 3, 252, 0, 0, 31, 244, 0, 0, 191, 208, 0, 3, 239, 128, 0, 31, 111, 0, 0, 188, 125, + 0, 3, 224, 248, 0, 31, 67, 240, 0, 188, 11, 208, 7, 224, 31, 128, 47, 64, 47, 0, 252, 0, 125, 7, + 224, 0, 252, 63, 0, 2, 245, 248, 0, 7, 230, 208, 0, 15, 129, 0, 0, 16, 6, 249, 0, 31, 255, 64, + 127, 175, 192, 189, 11, 208, 248, 3, 224, 248, 3, 240, 253, 2, 240, 191, 171, 240, 47, 255, 240, 6, 254, 240, + 0, 1, 244, 0, 1, 244, 0, 0, 244, 0, 0, 248, 0, 0, 184, 0, 0, 184, 0, 0, 188, 0, 0, 125, + 0, 0, 16, 4, 1, 224, 127, 135, 252, 15, 0, 64, 4, 3, 224, 63, 2, 240, 47, 65, 248, 31, 128, 252, + 15, 192, 188, 11, 208, 189, 7, 208, 126, 7, 224, 62, 3, 224, 62, 3, 224, 0, 45, 0, 14, 62, 0, 31, + 47, 0, 62, 47, 234, 253, 31, 255, 248, 31, 255, 144, 15, 128, 0, 15, 192, 0, 11, 192, 0, 11, 208, 0, + 11, 208, 0, 7, 208, 0, 7, 224, 0, 7, 224, 0, 3, 224, 0, 3, 224, 0, 3, 224, 0, 3, 224, 0, + 1, 64, 0, 0, 0, 0, 0, 180, 5, 7, 195, 224, 45, 31, 75, 192, 240, 62, 47, 7, 192, 248, 127, 191, + 239, 225, 255, 255, 255, 3, 255, 91, 228, 15, 192, 0, 0, 47, 0, 0, 0, 189, 0, 0, 2, 244, 0, 0, + 7, 208, 0, 0, 31, 128, 0, 0, 126, 0, 0, 0, 248, 0, 0, 3, 224, 0, 0, 15, 128, 0, 0, 62, + 0, 0, 0, 80, 0, 0, 5, 1, 164, 31, 130, 255, 3, 240, 255, 192, 188, 125, 0, 47, 95, 0, 7, 226, + 230, 192, 255, 255, 240, 63, 255, 248, 15, 234, 144, 2, 240, 0, 0, 189, 0, 0, 31, 64, 0, 7, 208, 0, + 1, 248, 0, 0, 62, 0, 0, 15, 128, 0, 3, 224, 0, 0, 248, 0, 0, 62, 0, 0, 0, 16, 0, 0, + 116, 0, 0, 253, 0, 0, 127, 0, 0, 255, 128, 2, 255, 208, 7, 227, 240, 15, 194, 244, 31, 64, 248, 62, + 0, 189, 125, 0, 125, 188, 0, 62, 248, 0, 47, 248, 0, 47, 248, 40, 47, 252, 60, 63, 190, 190, 190, 127, + 255, 252, 31, 215, 228, 0, 106, 64, 31, 254, 1, 255, 248, 11, 224, 0, 63, 0, 0, 248, 0, 3, 240, 0, + 7, 224, 24, 11, 246, 244, 11, 255, 208, 7, 248, 0, 127, 128, 3, 248, 0, 47, 128, 1, 252, 0, 11, 208, + 0, 126, 0, 2, 244, 0, 2, 128, 0, 0, 8, 0, 0, 81, 244, 0, 3, 227, 240, 0, 31, 139, 208, 0, + 189, 31, 128, 3, 224, 63, 0, 47, 64, 189, 0, 252, 1, 248, 7, 224, 3, 240, 47, 64, 11, 208, 248, 0, + 31, 135, 208, 0, 63, 47, 0, 0, 189, 248, 0, 1, 251, 208, 0, 3, 255, 0, 0, 11, 248, 0, 0, 31, + 224, 0, 0, 63, 64, 0, 0, 252, 0, 0, 0, 0, 0, 0, 1, 64, 0, 0, 47, 64, 0, 0, 190, 0, + 0, 3, 252, 0, 0, 31, 244, 0, 0, 191, 208, 0, 3, 239, 128, 0, 31, 111, 0, 0, 188, 125, 0, 3, + 224, 248, 0, 31, 67, 240, 0, 188, 11, 208, 7, 224, 31, 128, 47, 64, 47, 0, 252, 0, 125, 7, 224, 0, + 252, 63, 0, 2, 245, 248, 0, 7, 230, 208, 0, 15, 129, 0, 0, 16, 6, 249, 0, 31, 255, 64, 127, 175, + 192, 189, 11, 208, 248, 3, 224, 248, 3, 240, 253, 2, 240, 191, 171, 240, 47, 255, 240, 6, 254, 240, 0, 1, + 244, 0, 1, 244, 0, 0, 244, 0, 0, 248, 0, 0, 184, 0, 0, 184, 0, 0, 188, 0, 0, 125, 0, 0, + 16, 10, 128, 11, 248, 3, 71, 0, 209, 192, 63, 224, 6, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 6, 170, 167, 255, 254, 255, 255, 64, 0, 105, 0, 31, 252, 1, 255, 224, + 11, 208, 0, 62, 0, 0, 248, 0, 2, 240, 0, 7, 245, 184, 7, 255, 241, 191, 254, 79, 254, 64, 46, 64, + 0, 0, 0, 0, 26, 64, 47, 255, 230, 11, 228, 0, 0, 0, 0, 0, 62, 0, 15, 128, 3, 224, 0, 248, + 0, 62, 0, 15, 128, 3, 224, 0, 248, 0, 62, 0, 15, 128, 3, 224, 0, 248, 0, 62, 0, 15, 128, 3, + 224, 0, 248, 0, 62, 0, 15, 128, 26, 128, 64, 127, 255, 192, 36, 111, 128, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, + 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, + 252, 0, 0, 191, 168, 0, 127, 253, 0, 11, 252, 42, 75, 244, 240, 15, 0, 126, 223, 249, 164, 0, 0, 0, + 3, 224, 62, 3, 224, 62, 3, 224, 62, 3, 224, 62, 3, 224, 62, 3, 224, 62, 3, 224, 62, 3, 224, 62, + 3, 224, 62, 0, 42, 64, 11, 244, 0, 240, 0, 15, 0, 0, 121, 144, 7, 253, 0, 249, 0, 0, 0, 0, + 0, 0, 0, 248, 0, 15, 128, 0, 248, 0, 15, 128, 0, 248, 0, 15, 128, 0, 248, 0, 15, 128, 0, 248, + 0, 15, 128, 0, 248, 0, 15, 128, 0, 248, 0, 15, 128, 0, 248, 0, 15, 192, 0, 191, 168, 7, 255, 208, + 11, 252, 0, 169, 0, 11, 244, 0, 60, 0, 0, 240, 0, 1, 251, 64, 15, 249, 0, 41, 0, 0, 0, 0, + 0, 105, 0, 11, 254, 0, 191, 254, 7, 225, 252, 47, 1, 244, 248, 7, 227, 240, 15, 143, 250, 190, 31, 255, + 248, 27, 255, 208, 0, 63, 0, 2, 248, 1, 191, 193, 191, 248, 7, 255, 64, 14, 144, 0, 0, 189, 0, 0, + 47, 192, 0, 3, 192, 0, 0, 44, 0, 0, 1, 251, 64, 0, 63, 224, 0, 2, 80, 0, 0, 0, 0, 0, + 0, 105, 0, 0, 63, 248, 0, 11, 255, 224, 1, 248, 127, 0, 47, 1, 244, 3, 224, 15, 128, 63, 0, 248, + 3, 254, 175, 233, 31, 255, 255, 240, 111, 255, 254, 0, 3, 240, 0, 0, 190, 0, 1, 191, 192, 6, 255, 240, + 0, 127, 248, 0, 3, 228, 0, 0, 248, 15, 128, 248, 15, 128, 248, 15, 128, 248, 15, 128, 248, 15, 128, 248, + 15, 128, 248, 15, 128, 248, 15, 128, 248, 15, 128, 0, 2, 164, 191, 79, 0, 240, 7, 237, 255, 154, 64, 188, + 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, 0, 188, + 0, 188, 0, 188, 0, 189, 0, 127, 169, 47, 255, 6, 254, 0, 0, 25, 0, 127, 0, 240, 0, 240, 0, 185, + 128, 127, 208, 249, 0, 64, 0, 2, 164, 0, 0, 0, 11, 244, 0, 0, 0, 15, 0, 0, 27, 248, 15, 0, + 0, 191, 253, 7, 237, 2, 254, 188, 15, 249, 11, 224, 0, 10, 64, 31, 128, 0, 0, 0, 47, 0, 0, 16, + 0, 47, 0, 0, 125, 0, 31, 208, 0, 125, 0, 11, 254, 64, 188, 0, 1, 191, 224, 248, 0, 0, 11, 248, + 248, 0, 0, 0, 248, 252, 0, 0, 1, 244, 189, 0, 0, 7, 240, 127, 128, 0, 111, 208, 47, 254, 171, 255, + 64, 7, 255, 255, 248, 0, 0, 111, 254, 64, 0, 2, 244, 0, 0, 0, 2, 253, 0, 0, 0, 0, 176, 0, + 0, 0, 0, 45, 0, 0, 0, 0, 3, 237, 0, 0, 0, 2, 254, 64, 0, 0, 0, 100, 0, 0, 0, 0, + 64, 0, 0, 0, 0, 125, 0, 0, 16, 0, 31, 64, 0, 31, 144, 11, 192, 0, 11, 255, 167, 224, 0, 1, + 191, 255, 248, 0, 0, 2, 255, 191, 0, 0, 0, 62, 11, 208, 0, 0, 47, 129, 254, 0, 0, 111, 192, 47, + 254, 171, 255, 208, 1, 255, 255, 255, 128, 0, 6, 255, 233, 0, 0, 11, 192, 191, 3, 192, 11, 64, 31, 180, + 254, 65, 64, 0, 0, 1, 144, 15, 128, 47, 0, 125, 1, 248, 3, 224, 15, 128, 126, 107, 246, 255, 75, 228, + 0, 2, 160, 0, 11, 240, 0, 15, 0, 0, 15, 0, 0, 7, 168, 0, 11, 253, 0, 10, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 188, 0, 0, 184, 0, 0, 248, 0, 1, 248, 0, 2, 248, 0, 111, 255, 168, 191, 175, + 253, 186, 6, 253, 251, 239, 190, 251, 239, 190, 251, 239, 190, 251, 239, 190, 251, 239, 128, 248, 0, 248, 0, 248, + 0, 248, 0, 248, 0, 248, 0, 248, 0, 248, 0, 248, 0, 248, 0, 248, 0, 248, 0, 248, 0, 248, 0, 248, + 0, 252, 0, 191, 168, 127, 253, 11, 252, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 11, 199, 128, 0, + 0, 0, 1, 246, 240, 0, 0, 0, 0, 62, 248, 0, 0, 0, 0, 15, 254, 0, 0, 0, 0, 2, 255, 128, + 0, 0, 0, 0, 191, 244, 0, 0, 0, 0, 126, 191, 128, 0, 0, 1, 191, 79, 255, 170, 170, 191, 255, 128, + 191, 255, 255, 255, 254, 64, 1, 175, 255, 250, 148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 24, 0, 0, 0, 0, 0, 15, 128, 0, 0, 0, 0, 2, 208, 0, 0, 0, 84, 0, 0, 0, + 0, 0, 0, 1, 240, 0, 0, 0, 0, 0, 0, 11, 192, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, + 0, 164, 0, 248, 0, 0, 0, 0, 11, 224, 3, 240, 0, 0, 0, 0, 191, 128, 15, 208, 0, 0, 0, 47, + 254, 0, 31, 228, 0, 0, 27, 254, 191, 168, 47, 254, 170, 175, 255, 208, 255, 244, 47, 255, 255, 255, 228, 0, + 111, 208, 6, 191, 254, 164, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 188, 0, 0, 0, 0, 0, 0, 1, 224, 0, 0, 0, 0, + 0, 64, 31, 128, 63, 0, 188, 1, 244, 7, 224, 15, 128, 62, 1, 245, 175, 199, 253, 31, 144, 0, 0, 0, + 0, 96, 3, 224, 11, 64, 0, 0, 0, 0, 124, 0, 0, 124, 0, 0, 184, 0, 0, 248, 0, 1, 252, 0, + 43, 255, 169, 63, 223, 255, 62, 70, 254, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 248, 0, 0, 180, 0, + 6, 6, 0, 248, 248, 11, 75, 64, 0, 0, 0, 0, 0, 0, 0, 1, 208, 0, 127, 64, 3, 253, 0, 191, + 244, 31, 95, 195, 224, 189, 188, 3, 239, 128, 47, 248, 2, 255, 192, 126, 191, 175, 211, 255, 248, 11, 249, 0, + 1, 129, 128, 0, 15, 143, 128, 0, 45, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 62, 0, 0, 0, 248, 0, 0, 27, 224, 0, 11, 255, 128, 1, 255, 254, 0, 15, 228, 248, 0, 190, 3, 224, + 3, 240, 15, 128, 15, 128, 62, 0, 63, 64, 248, 0, 127, 255, 224, 0, 191, 255, 208, 0, 26, 175, 234, 0, + 0, 47, 253, 0, 0, 27, 240, 0, 0, 24, 24, 0, 0, 0, 0, 15, 143, 128, 0, 0, 0, 2, 210, 208, + 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 47, 30, 0, 0, 0, 0, 7, 219, 192, 0, 0, + 0, 0, 251, 224, 0, 0, 0, 0, 63, 248, 0, 0, 0, 0, 11, 254, 0, 0, 0, 0, 2, 255, 208, 0, + 0, 0, 1, 250, 254, 0, 0, 0, 6, 253, 63, 254, 170, 170, 255, 254, 2, 255, 255, 255, 255, 249, 0, 6, + 191, 255, 234, 80, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 188, 188, 0, 0, 0, 0, 0, 1, 225, + 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 1, 240, 0, 0, 0, + 0, 0, 0, 11, 192, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 164, 0, 248, 0, 0, 0, 0, + 11, 224, 3, 240, 0, 0, 0, 0, 191, 128, 15, 208, 0, 0, 0, 31, 254, 0, 47, 228, 0, 0, 27, 254, + 191, 168, 47, 254, 170, 175, 255, 208, 255, 244, 47, 255, 255, 255, 228, 0, 111, 208, 6, 191, 254, 164, 0, 0, + 0, 0, 45, 45, 62, 62, 24, 24, 0, 0, 0, 0, 0, 96, 3, 240, 2, 244, 1, 248, 0, 248, 0, 252, + 0, 188, 0, 188, 0, 248, 43, 244, 63, 224, 62, 64, 1, 129, 128, 0, 248, 248, 0, 45, 45, 0, 0, 0, + 0, 0, 0, 0, 0, 4, 0, 0, 3, 240, 0, 0, 248, 0, 0, 126, 0, 0, 47, 128, 0, 15, 224, 0, + 175, 255, 169, 63, 235, 255, 207, 144, 175, 224, 0, 0, 2, 208, 0, 0, 0, 0, 0, 248, 0, 0, 0, 0, + 0, 24, 0, 0, 0, 0, 0, 96, 96, 0, 0, 0, 0, 62, 62, 0, 0, 0, 0, 11, 75, 64, 0, 0, + 0, 0, 0, 0, 0, 80, 0, 0, 0, 0, 0, 188, 120, 0, 0, 0, 0, 31, 111, 0, 0, 0, 0, 3, + 239, 128, 0, 0, 0, 0, 255, 224, 0, 0, 0, 0, 47, 248, 0, 0, 0, 0, 11, 255, 64, 0, 0, 0, + 7, 235, 248, 0, 0, 0, 27, 244, 255, 250, 170, 171, 255, 248, 11, 255, 255, 255, 255, 228, 0, 26, 255, 255, + 169, 64, 0, 0, 0, 0, 144, 0, 0, 0, 0, 0, 0, 11, 192, 0, 0, 0, 0, 0, 0, 30, 0, 0, + 0, 0, 0, 0, 2, 66, 64, 0, 0, 0, 0, 0, 47, 47, 0, 0, 0, 0, 0, 0, 120, 120, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 124, 0, 0, 0, 0, 0, 0, + 2, 240, 0, 0, 0, 0, 0, 0, 15, 128, 0, 0, 0, 0, 41, 0, 62, 0, 0, 0, 0, 2, 248, 0, + 252, 0, 0, 0, 0, 47, 224, 3, 244, 0, 0, 0, 7, 255, 128, 11, 249, 0, 0, 6, 255, 175, 234, 11, + 255, 170, 171, 255, 244, 63, 253, 11, 255, 255, 255, 249, 0, 27, 244, 1, 175, 255, 169, 0, 0, 0, 0, 2, + 208, 3, 224, 1, 128, 45, 45, 62, 62, 24, 24, 0, 0, 0, 0, 0, 80, 3, 240, 2, 244, 1, 248, 0, + 248, 0, 188, 0, 188, 0, 188, 0, 248, 43, 244, 63, 224, 126, 64, 0, 45, 0, 0, 15, 128, 0, 1, 128, + 0, 6, 6, 0, 3, 227, 224, 0, 180, 180, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 128, 0, + 3, 224, 0, 1, 244, 0, 0, 189, 0, 0, 127, 128, 2, 191, 254, 161, 255, 191, 253, 126, 66, 255, 64, 26, + 164, 0, 0, 31, 255, 228, 0, 7, 255, 255, 148, 0, 64, 27, 255, 248, 0, 0, 47, 254, 0, 1, 191, 250, + 64, 2, 255, 144, 0, 7, 253, 0, 0, 7, 248, 0, 0, 3, 244, 0, 0, 2, 244, 0, 0, 1, 248, 0, + 0, 0, 189, 0, 0, 0, 47, 0, 24, 0, 15, 128, 15, 128, 3, 224, 2, 208, 0, 252, 0, 0, 0, 47, + 64, 0, 0, 7, 240, 0, 0, 0, 191, 64, 0, 20, 15, 255, 170, 255, 0, 191, 255, 255, 128, 1, 191, 249, + 64, 111, 250, 64, 0, 0, 127, 255, 249, 64, 0, 58, 175, 255, 254, 0, 0, 0, 111, 254, 0, 0, 1, 255, + 233, 0, 0, 31, 251, 192, 0, 0, 191, 67, 208, 0, 3, 248, 3, 224, 0, 11, 208, 2, 248, 0, 47, 64, + 1, 255, 168, 62, 0, 0, 127, 253, 189, 0, 0, 26, 253, 188, 0, 120, 0, 0, 248, 0, 188, 0, 0, 248, + 0, 36, 0, 0, 252, 0, 0, 0, 0, 189, 0, 0, 0, 0, 127, 0, 0, 0, 0, 47, 208, 0, 5, 0, + 15, 255, 170, 255, 0, 2, 255, 255, 254, 0, 0, 27, 255, 148, 0, 6, 254, 64, 0, 7, 255, 248, 0, 6, + 171, 255, 144, 0, 0, 47, 254, 0, 0, 7, 254, 0, 0, 111, 249, 0, 22, 255, 64, 42, 255, 244, 0, 63, + 255, 64, 0, 63, 148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 0, 0, 3, 224, 0, 0, + 2, 208, 0, 11, 254, 64, 0, 0, 63, 255, 208, 0, 0, 170, 191, 244, 0, 0, 0, 27, 255, 0, 0, 0, + 15, 253, 0, 0, 1, 255, 224, 0, 1, 191, 255, 64, 26, 255, 249, 127, 233, 191, 254, 64, 191, 254, 250, 64, + 0, 111, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 62, 0, 0, 0, 0, 180, + 0, 0, 0, 26, 164, 0, 0, 31, 255, 228, 0, 7, 255, 255, 148, 0, 64, 27, 255, 248, 0, 0, 47, 254, + 0, 1, 191, 250, 64, 2, 255, 144, 0, 7, 253, 0, 0, 7, 248, 0, 0, 3, 244, 0, 0, 2, 244, 0, + 0, 1, 248, 0, 0, 0, 189, 0, 0, 0, 47, 0, 0, 0, 15, 128, 0, 0, 3, 224, 0, 0, 0, 252, + 0, 0, 0, 47, 64, 0, 0, 7, 240, 0, 0, 0, 191, 64, 0, 20, 15, 255, 170, 255, 0, 191, 255, 255, + 128, 1, 191, 249, 64, 111, 249, 0, 0, 0, 127, 255, 228, 0, 0, 58, 175, 255, 233, 0, 0, 0, 111, 254, + 0, 0, 0, 191, 254, 0, 0, 11, 255, 208, 0, 0, 127, 211, 208, 0, 2, 253, 2, 224, 0, 11, 224, 2, + 248, 0, 31, 128, 0, 255, 168, 63, 0, 0, 127, 253, 125, 0, 0, 10, 253, 188, 0, 0, 0, 0, 248, 0, + 0, 0, 0, 248, 0, 0, 0, 0, 248, 0, 0, 0, 0, 252, 0, 0, 0, 0, 189, 0, 0, 0, 0, 127, + 64, 0, 0, 0, 47, 229, 0, 106, 0, 11, 255, 255, 255, 0, 1, 191, 255, 249, 0, 0, 5, 170, 64, 0, + 27, 250, 64, 0, 31, 255, 228, 0, 10, 171, 254, 64, 0, 0, 111, 252, 0, 0, 11, 252, 0, 0, 127, 248, + 0, 27, 254, 64, 171, 255, 224, 0, 255, 254, 64, 0, 254, 144, 0, 0, 27, 254, 64, 0, 0, 63, 255, 208, + 0, 0, 170, 191, 244, 0, 0, 0, 27, 255, 0, 0, 0, 11, 253, 0, 0, 1, 255, 228, 0, 1, 191, 255, + 64, 26, 255, 249, 127, 233, 191, 254, 64, 191, 255, 250, 64, 0, 111, 224, 0, 6, 0, 0, 0, 3, 224, 0, + 0, 0, 180, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 170, 64, 0, 1, 255, 254, + 64, 0, 127, 255, 249, 64, 4, 1, 191, 255, 128, 0, 2, 255, 224, 0, 27, 255, 164, 0, 47, 249, 0, 0, + 127, 208, 0, 0, 127, 128, 0, 0, 63, 64, 0, 0, 47, 64, 0, 0, 31, 128, 0, 0, 11, 208, 0, 0, + 2, 240, 0, 0, 0, 248, 0, 0, 0, 62, 0, 0, 0, 15, 192, 0, 0, 2, 244, 0, 0, 0, 127, 0, + 0, 0, 11, 244, 0, 1, 64, 255, 250, 175, 240, 11, 255, 255, 248, 0, 27, 255, 148, 0, 0, 1, 128, 0, + 0, 0, 3, 224, 0, 0, 0, 2, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 111, 249, 0, 0, 0, 127, 255, 228, 0, 0, 58, 175, 255, 233, 0, 0, 0, 111, 254, 0, 0, 1, + 191, 254, 0, 0, 11, 255, 208, 0, 0, 127, 211, 208, 0, 2, 253, 2, 224, 0, 11, 224, 2, 248, 0, 31, + 128, 0, 255, 168, 63, 0, 0, 127, 253, 125, 0, 0, 10, 253, 188, 0, 0, 0, 0, 248, 0, 0, 0, 0, + 248, 0, 0, 0, 0, 248, 0, 0, 0, 0, 252, 0, 0, 0, 0, 189, 0, 0, 0, 0, 127, 64, 0, 0, + 0, 47, 229, 0, 106, 0, 11, 255, 255, 255, 0, 1, 191, 255, 249, 0, 0, 5, 170, 64, 0, 2, 208, 0, + 0, 15, 128, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 191, 160, 0, 7, + 255, 249, 0, 10, 175, 254, 64, 0, 1, 255, 224, 0, 1, 255, 128, 0, 47, 250, 0, 27, 253, 2, 175, 255, + 128, 15, 255, 224, 0, 63, 164, 0, 0, 2, 208, 0, 0, 0, 15, 128, 0, 0, 0, 24, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 228, 0, 0, 3, 255, 253, 0, 0, 10, + 171, 255, 64, 0, 0, 1, 191, 240, 0, 0, 0, 255, 192, 0, 0, 31, 254, 0, 0, 27, 255, 224, 1, 175, + 255, 151, 250, 155, 255, 228, 11, 255, 239, 164, 0, 6, 254, 0, 7, 64, 0, 31, 192, 0, 11, 208, 0, 3, + 240, 0, 1, 248, 0, 0, 252, 0, 0, 125, 0, 0, 62, 0, 0, 62, 20, 0, 190, 47, 171, 253, 127, 255, + 244, 10, 255, 144, 0, 7, 64, 0, 0, 31, 128, 0, 0, 11, 208, 0, 0, 3, 240, 0, 0, 2, 244, 0, + 0, 0, 252, 0, 0, 0, 125, 0, 0, 0, 62, 0, 0, 0, 63, 0, 20, 0, 191, 128, 47, 171, 255, 249, + 127, 255, 251, 255, 10, 255, 144, 190, 0, 24, 0, 0, 62, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 64, 0, 31, 192, 0, 11, 208, 0, 3, 240, 0, 1, 248, 0, 0, 252, 0, 0, 125, 0, 0, 62, 0, + 0, 62, 20, 0, 190, 47, 171, 253, 127, 255, 244, 10, 255, 144, 0, 96, 0, 0, 0, 248, 0, 0, 0, 180, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 31, 0, 0, 0, 31, 128, 0, 0, 11, + 208, 0, 0, 3, 240, 0, 0, 2, 244, 0, 0, 0, 248, 0, 0, 0, 125, 0, 0, 0, 62, 0, 0, 0, + 63, 0, 20, 0, 191, 128, 63, 171, 255, 249, 127, 255, 247, 255, 26, 254, 128, 190, 0, 1, 0, 1, 244, 0, + 31, 128, 0, 252, 0, 7, 208, 0, 126, 0, 3, 224, 0, 62, 0, 7, 208, 0, 189, 0, 31, 128, 7, 244, + 2, 253, 6, 255, 64, 127, 144, 3, 144, 0, 0, 0, 0, 0, 1, 0, 0, 1, 244, 0, 0, 31, 128, 0, + 0, 252, 0, 0, 7, 208, 0, 0, 127, 0, 0, 3, 244, 0, 0, 63, 233, 0, 7, 255, 240, 0, 189, 190, + 0, 31, 192, 0, 11, 244, 0, 6, 253, 0, 6, 255, 64, 0, 127, 144, 0, 3, 144, 0, 0, 0, 24, 0, + 3, 224, 0, 45, 0, 0, 0, 0, 0, 0, 0, 16, 0, 31, 64, 1, 248, 0, 15, 192, 0, 125, 0, 7, + 224, 0, 62, 0, 3, 224, 0, 125, 0, 11, 208, 1, 248, 0, 127, 64, 47, 208, 111, 244, 7, 249, 0, 57, + 0, 0, 0, 0, 0, 96, 0, 0, 15, 128, 0, 0, 180, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 8, 0, 0, 3, 224, 0, 0, 47, 0, 0, 1, 244, 0, 0, 15, 128, 0, 0, 189, 0, 0, 11, + 224, 0, 0, 191, 232, 0, 15, 255, 208, 1, 249, 252, 0, 127, 64, 0, 31, 224, 0, 11, 248, 0, 11, 254, + 0, 0, 191, 64, 0, 7, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, + 252, 0, 0, 0, 0, 0, 0, 0, 189, 0, 0, 0, 0, 0, 0, 0, 125, 0, 0, 0, 46, 0, 15, 128, + 62, 0, 0, 0, 47, 0, 15, 64, 63, 16, 0, 0, 31, 64, 31, 64, 47, 61, 0, 0, 31, 128, 47, 64, + 47, 125, 0, 0, 15, 192, 63, 64, 62, 188, 0, 0, 15, 250, 255, 234, 253, 248, 0, 0, 11, 255, 251, 255, + 248, 248, 0, 0, 15, 175, 224, 191, 144, 252, 0, 0, 31, 128, 0, 0, 0, 189, 0, 0, 47, 64, 0, 0, + 0, 127, 64, 1, 190, 0, 0, 0, 0, 47, 250, 175, 252, 0, 0, 0, 0, 7, 255, 255, 224, 0, 0, 0, + 0, 0, 111, 250, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 125, 0, 0, 0, 0, 0, 0, 1, + 0, 15, 64, 0, 0, 0, 3, 224, 0, 244, 3, 208, 0, 0, 0, 0, 252, 0, 125, 0, 248, 0, 16, 0, + 0, 47, 0, 31, 0, 62, 0, 31, 64, 0, 7, 208, 11, 192, 15, 192, 7, 208, 0, 1, 252, 7, 244, 7, + 248, 2, 240, 0, 0, 63, 235, 255, 171, 255, 232, 248, 0, 0, 15, 255, 251, 255, 246, 255, 126, 0, 0, 3, + 235, 244, 111, 228, 31, 223, 192, 0, 1, 244, 0, 0, 0, 0, 2, 244, 0, 0, 252, 0, 0, 0, 0, 0, + 127, 64, 1, 254, 0, 0, 0, 0, 0, 11, 254, 171, 254, 0, 0, 0, 0, 0, 0, 127, 255, 254, 0, 0, + 0, 0, 0, 0, 1, 191, 233, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 64, 0, 0, 0, 1, 248, + 0, 0, 0, 0, 15, 192, 0, 0, 4, 0, 188, 0, 184, 0, 244, 7, 208, 11, 192, 31, 64, 126, 0, 248, + 1, 244, 3, 224, 31, 128, 47, 0, 62, 2, 248, 3, 244, 7, 210, 255, 234, 255, 234, 252, 127, 239, 255, 191, + 255, 71, 224, 191, 225, 191, 144, 0, 0, 0, 0, 11, 128, 0, 0, 0, 0, 0, 184, 0, 0, 228, 2, 240, + 11, 192, 0, 31, 64, 46, 0, 188, 0, 2, 240, 3, 224, 11, 208, 0, 47, 0, 126, 0, 190, 0, 7, 244, + 11, 224, 15, 244, 6, 255, 234, 255, 235, 255, 233, 191, 191, 255, 191, 253, 127, 255, 145, 191, 146, 254, 65, 190, + 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 1, 129, 128, 0, 0, 0, 0, 0, 3, 227, 224, 0, 0, 0, 0, 0, 2, 210, 208, 0, + 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 252, 0, 0, 0, 0, 0, 0, 0, 189, + 0, 0, 0, 0, 0, 0, 0, 125, 0, 0, 0, 46, 0, 15, 128, 62, 0, 0, 0, 47, 0, 15, 64, 63, + 16, 0, 0, 31, 64, 31, 64, 47, 61, 0, 0, 31, 128, 47, 64, 47, 125, 0, 0, 15, 192, 63, 64, 62, + 188, 0, 0, 15, 250, 255, 234, 253, 248, 0, 0, 11, 255, 251, 255, 248, 248, 0, 0, 15, 175, 224, 191, 144, + 252, 0, 0, 31, 128, 0, 0, 0, 189, 0, 0, 47, 64, 0, 0, 0, 127, 64, 1, 190, 0, 0, 0, 0, + 47, 250, 175, 252, 0, 0, 0, 0, 7, 255, 255, 224, 0, 0, 0, 0, 0, 111, 250, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 64, 0, 0, 0, 0, 0, 0, 0, 11, 94, 0, 0, 0, 0, 0, 0, 0, 3, 235, 192, 0, 0, 0, 0, + 0, 0, 0, 96, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 125, 0, 0, 0, 0, 0, 0, 0, 0, 15, 64, 0, 0, 0, 2, + 224, 0, 244, 3, 208, 0, 0, 0, 0, 252, 0, 60, 0, 248, 0, 16, 0, 0, 47, 0, 31, 0, 62, 0, + 15, 64, 0, 7, 208, 11, 128, 15, 192, 7, 208, 0, 1, 252, 3, 240, 7, 248, 2, 240, 0, 0, 63, 235, + 255, 171, 255, 232, 248, 0, 0, 15, 255, 247, 255, 246, 255, 126, 0, 0, 3, 235, 228, 111, 228, 47, 223, 192, + 0, 1, 244, 0, 0, 0, 0, 2, 244, 0, 0, 252, 0, 0, 0, 0, 0, 127, 64, 1, 254, 0, 0, 0, + 0, 0, 11, 254, 171, 254, 0, 0, 0, 0, 0, 0, 127, 255, 254, 0, 0, 0, 0, 0, 0, 1, 191, 233, + 0, 0, 0, 0, 0, 0, 0, 0, 2, 208, 0, 0, 0, 0, 248, 0, 0, 0, 0, 24, 0, 0, 0, 0, + 180, 180, 0, 0, 0, 62, 62, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 80, 0, 0, 0, 0, 252, + 0, 0, 0, 0, 47, 64, 0, 0, 0, 7, 208, 14, 64, 47, 0, 248, 7, 208, 11, 192, 63, 2, 240, 3, + 224, 11, 192, 188, 1, 248, 2, 240, 127, 64, 190, 0, 249, 191, 250, 191, 250, 253, 191, 191, 255, 255, 254, 62, + 70, 254, 75, 249, 0, 0, 0, 2, 208, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 1, 128, 0, 0, + 0, 0, 2, 210, 208, 0, 0, 0, 0, 62, 62, 0, 0, 0, 0, 1, 129, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 128, 0, 0, 0, 0, 0, 184, 0, 0, 228, + 2, 240, 11, 192, 0, 31, 64, 47, 0, 188, 0, 2, 240, 3, 224, 11, 208, 0, 47, 0, 126, 0, 190, 0, + 7, 244, 11, 224, 15, 244, 6, 255, 234, 255, 235, 255, 233, 191, 191, 255, 191, 254, 127, 255, 145, 191, 146, 254, + 65, 190, 0, 0, 0, 0, 0, 0, 10, 249, 0, 0, 0, 0, 0, 0, 11, 255, 248, 0, 0, 0, 5, 0, + 2, 254, 175, 208, 0, 0, 3, 224, 1, 254, 0, 126, 0, 0, 0, 63, 0, 63, 64, 2, 241, 0, 0, 2, + 240, 15, 208, 0, 47, 125, 0, 0, 31, 130, 244, 0, 7, 235, 192, 0, 0, 254, 189, 0, 2, 253, 188, 0, + 0, 15, 255, 234, 171, 255, 143, 128, 0, 0, 255, 255, 255, 255, 208, 248, 0, 0, 15, 134, 191, 254, 144, 15, + 192, 0, 1, 244, 0, 0, 0, 0, 189, 0, 0, 63, 0, 0, 0, 0, 7, 248, 0, 31, 208, 0, 0, 0, + 0, 47, 250, 175, 248, 0, 0, 0, 0, 0, 127, 255, 254, 0, 0, 0, 0, 0, 0, 111, 249, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 164, 0, 0, 0, 0, 0, 0, 0, 6, 255, 244, 0, 0, 0, + 0, 0, 0, 2, 255, 255, 208, 0, 0, 0, 2, 224, 0, 191, 64, 190, 0, 0, 0, 0, 62, 0, 47, 128, + 3, 240, 1, 0, 0, 2, 240, 11, 224, 0, 47, 0, 61, 0, 0, 31, 130, 248, 0, 3, 224, 7, 208, 0, + 1, 254, 126, 0, 1, 253, 0, 188, 0, 0, 15, 255, 234, 171, 255, 250, 159, 128, 0, 0, 255, 255, 255, 255, + 255, 255, 248, 0, 0, 15, 134, 191, 254, 144, 111, 239, 192, 0, 1, 244, 0, 0, 0, 0, 0, 189, 0, 0, + 63, 0, 0, 0, 0, 0, 7, 244, 0, 31, 208, 0, 0, 0, 0, 0, 47, 250, 175, 248, 0, 0, 0, 0, + 0, 0, 127, 255, 254, 0, 0, 0, 0, 0, 0, 0, 111, 249, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 111, 228, 0, 0, 0, 1, 255, 255, 64, 1, 0, 2, 255, 175, 240, 2, 240, 2, 253, 0, 189, 0, 248, + 2, 248, 0, 15, 128, 126, 2, 248, 0, 3, 224, 47, 129, 248, 0, 2, 244, 191, 244, 252, 0, 6, 252, 127, + 175, 254, 170, 191, 253, 30, 66, 255, 255, 255, 248, 0, 0, 22, 255, 254, 144, 0, 0, 0, 0, 0, 111, 228, + 0, 0, 0, 0, 1, 255, 255, 64, 0, 1, 0, 2, 255, 175, 240, 0, 2, 240, 2, 253, 0, 189, 0, 0, + 248, 2, 248, 0, 15, 128, 0, 126, 2, 248, 0, 3, 224, 0, 47, 129, 248, 0, 2, 244, 0, 191, 244, 252, + 0, 6, 255, 168, 127, 175, 254, 170, 191, 255, 255, 94, 66, 255, 255, 255, 249, 175, 208, 0, 22, 255, 254, 144, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, + 0, 2, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 249, 0, 0, 0, 0, 0, 0, 11, 255, 248, 0, 0, + 0, 5, 0, 2, 254, 175, 208, 0, 0, 3, 224, 1, 254, 0, 126, 0, 0, 0, 63, 0, 63, 64, 2, 241, + 0, 0, 2, 240, 15, 208, 0, 47, 125, 0, 0, 31, 130, 244, 0, 7, 235, 192, 0, 0, 254, 189, 0, 2, + 253, 188, 0, 0, 15, 255, 234, 171, 255, 143, 128, 0, 0, 255, 255, 255, 255, 208, 248, 0, 0, 15, 134, 191, + 254, 144, 15, 192, 0, 1, 244, 0, 0, 0, 0, 189, 0, 0, 63, 0, 0, 0, 0, 7, 248, 0, 31, 208, + 0, 0, 0, 0, 47, 250, 175, 248, 0, 0, 0, 0, 0, 127, 255, 254, 0, 0, 0, 0, 0, 0, 111, 249, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 64, 0, 0, 0, 0, 0, 0, 0, 111, 255, 64, + 0, 0, 0, 0, 0, 0, 31, 255, 253, 0, 0, 0, 0, 46, 0, 11, 249, 11, 224, 0, 0, 0, 3, 224, + 2, 248, 0, 63, 0, 16, 0, 0, 47, 0, 190, 0, 2, 240, 3, 208, 0, 1, 248, 31, 128, 0, 62, 0, + 125, 0, 0, 31, 231, 224, 0, 31, 208, 11, 192, 0, 0, 255, 254, 170, 191, 255, 169, 248, 0, 0, 15, 255, + 255, 255, 255, 255, 255, 128, 0, 0, 248, 107, 255, 233, 6, 254, 252, 0, 0, 31, 64, 0, 0, 0, 0, 11, + 208, 0, 3, 240, 0, 0, 0, 0, 0, 127, 64, 1, 254, 0, 0, 0, 0, 0, 2, 255, 170, 255, 128, 0, + 0, 0, 0, 0, 7, 255, 255, 224, 0, 0, 0, 0, 0, 0, 6, 255, 160, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 24, 0, 0, 0, 0, 0, 15, 128, 0, 0, 0, 0, 2, 208, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 254, 64, 0, 0, 0, 31, 255, + 244, 0, 16, 0, 47, 250, 255, 0, 47, 0, 47, 208, 11, 208, 15, 128, 47, 128, 0, 248, 7, 224, 47, 128, + 0, 62, 2, 248, 31, 128, 0, 47, 75, 255, 79, 128, 0, 111, 199, 250, 255, 234, 171, 255, 209, 228, 47, 255, + 255, 255, 128, 0, 1, 111, 255, 233, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 62, 0, 0, + 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 111, 228, 0, 0, 0, 0, 7, 255, 253, 0, 0, 16, 0, 47, 250, 255, + 0, 0, 188, 0, 191, 64, 47, 64, 0, 248, 2, 248, 0, 15, 128, 1, 248, 11, 224, 0, 15, 128, 2, 248, + 31, 128, 0, 47, 64, 47, 253, 62, 0, 1, 191, 233, 127, 175, 254, 170, 191, 255, 255, 121, 11, 255, 255, 255, + 234, 254, 0, 1, 111, 255, 233, 0, 0, 0, 62, 0, 0, 0, 0, 62, 0, 0, 0, 0, 62, 0, 0, 0, + 0, 62, 0, 0, 0, 0, 62, 0, 0, 0, 0, 62, 0, 0, 0, 0, 62, 0, 0, 0, 0, 62, 0, 0, + 0, 0, 62, 0, 175, 144, 0, 62, 11, 255, 248, 0, 62, 47, 234, 253, 0, 62, 254, 64, 126, 0, 63, 244, + 0, 47, 0, 63, 208, 0, 47, 0, 63, 64, 0, 126, 0, 126, 0, 6, 253, 186, 254, 170, 191, 248, 191, 255, + 255, 255, 208, 175, 255, 255, 233, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, + 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, + 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 90, 64, 0, 0, 62, 6, 255, 244, 0, 0, 62, 47, 255, + 253, 0, 0, 62, 191, 128, 190, 0, 0, 63, 248, 0, 63, 0, 0, 63, 224, 0, 47, 0, 0, 63, 128, 0, + 62, 0, 0, 126, 0, 1, 253, 0, 170, 254, 170, 191, 255, 169, 191, 255, 255, 255, 255, 255, 191, 255, 255, 233, + 6, 254, 3, 224, 0, 0, 0, 62, 0, 0, 0, 3, 224, 0, 0, 0, 62, 0, 0, 0, 3, 224, 0, 0, + 0, 62, 0, 0, 0, 3, 224, 0, 0, 0, 62, 0, 0, 0, 3, 224, 1, 164, 0, 62, 2, 255, 244, 3, + 225, 255, 255, 208, 62, 191, 144, 190, 3, 255, 128, 3, 240, 63, 224, 0, 47, 3, 248, 0, 3, 224, 63, 0, + 1, 253, 47, 234, 171, 255, 135, 255, 255, 255, 208, 127, 255, 254, 144, 0, 3, 224, 0, 0, 0, 0, 62, 0, + 0, 0, 0, 3, 224, 0, 0, 0, 0, 62, 0, 0, 0, 0, 3, 224, 0, 0, 0, 0, 62, 0, 0, 0, + 0, 3, 224, 0, 0, 0, 0, 62, 0, 0, 0, 0, 3, 224, 1, 164, 0, 0, 62, 6, 255, 244, 0, 3, + 225, 255, 255, 208, 0, 62, 191, 144, 190, 0, 3, 255, 128, 3, 240, 0, 63, 224, 0, 47, 0, 3, 248, 0, + 7, 224, 0, 127, 0, 6, 253, 0, 47, 234, 175, 255, 250, 151, 255, 255, 255, 255, 255, 127, 255, 254, 144, 111, + 224, 0, 62, 0, 0, 0, 0, 62, 0, 0, 0, 0, 62, 0, 0, 0, 0, 62, 0, 6, 0, 0, 62, 0, + 15, 128, 0, 62, 0, 11, 64, 0, 62, 0, 0, 0, 0, 62, 0, 0, 0, 0, 62, 0, 175, 144, 0, 62, + 11, 255, 248, 0, 62, 47, 234, 253, 0, 62, 254, 64, 126, 0, 63, 244, 0, 47, 0, 63, 208, 0, 47, 0, + 63, 64, 0, 126, 0, 126, 0, 6, 253, 186, 254, 170, 191, 248, 191, 255, 255, 255, 208, 175, 255, 255, 233, 0, + 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 120, 0, 0, 0, 62, 0, 188, 0, 0, + 0, 62, 0, 36, 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, + 0, 62, 0, 90, 64, 0, 0, 62, 6, 255, 244, 0, 0, 62, 47, 255, 253, 0, 0, 62, 191, 128, 190, 0, + 0, 63, 248, 0, 63, 0, 0, 63, 224, 0, 47, 0, 0, 63, 128, 0, 62, 0, 0, 126, 0, 1, 253, 0, + 170, 254, 170, 191, 255, 169, 191, 255, 255, 255, 255, 255, 191, 255, 255, 233, 6, 254, 3, 224, 0, 0, 0, 62, + 0, 0, 0, 3, 224, 0, 0, 0, 62, 0, 30, 0, 3, 224, 2, 240, 0, 62, 0, 9, 0, 3, 224, 0, + 0, 0, 62, 0, 0, 0, 3, 224, 1, 164, 0, 62, 2, 255, 244, 3, 225, 255, 255, 208, 62, 191, 144, 190, + 3, 255, 128, 3, 240, 63, 224, 0, 47, 3, 248, 0, 3, 224, 63, 0, 1, 253, 47, 234, 171, 255, 135, 255, + 255, 255, 208, 127, 255, 254, 144, 0, 3, 224, 0, 0, 0, 0, 62, 0, 0, 0, 0, 3, 224, 0, 0, 0, + 0, 62, 0, 9, 0, 0, 3, 224, 2, 240, 0, 0, 62, 0, 30, 0, 0, 3, 224, 0, 0, 0, 0, 62, + 0, 0, 0, 0, 3, 224, 1, 164, 0, 0, 62, 6, 255, 244, 0, 3, 225, 255, 255, 208, 0, 62, 191, 144, + 190, 0, 3, 255, 128, 3, 240, 0, 63, 224, 0, 47, 0, 3, 248, 0, 7, 224, 0, 127, 0, 6, 253, 0, + 47, 234, 175, 255, 250, 151, 255, 255, 255, 255, 255, 127, 255, 254, 144, 107, 224, 0, 106, 80, 0, 2, 255, 224, + 0, 15, 255, 208, 0, 47, 144, 64, 0, 63, 0, 0, 0, 62, 0, 0, 0, 63, 0, 0, 0, 47, 128, 106, + 0, 15, 251, 255, 0, 7, 255, 254, 0, 2, 255, 128, 0, 11, 244, 0, 0, 31, 192, 0, 0, 63, 0, 0, + 0, 125, 0, 0, 0, 188, 0, 0, 0, 248, 0, 0, 0, 248, 0, 0, 0, 248, 0, 0, 0, 189, 0, 0, + 0, 126, 0, 0, 0, 63, 208, 0, 21, 15, 254, 170, 254, 2, 255, 255, 255, 0, 27, 254, 148, 0, 22, 164, + 0, 1, 191, 254, 0, 11, 255, 255, 64, 31, 144, 47, 128, 31, 128, 15, 128, 11, 224, 31, 64, 2, 248, 62, + 0, 0, 190, 252, 0, 0, 47, 244, 0, 0, 127, 255, 169, 2, 254, 255, 255, 11, 224, 26, 254, 47, 128, 0, + 0, 126, 0, 0, 0, 188, 0, 0, 0, 248, 0, 0, 0, 248, 0, 0, 0, 252, 0, 0, 0, 190, 0, 0, + 0, 127, 148, 5, 184, 47, 255, 255, 248, 7, 255, 255, 224, 0, 90, 165, 0, 0, 26, 148, 0, 47, 253, 0, + 63, 255, 64, 47, 144, 64, 15, 192, 0, 3, 224, 0, 0, 248, 0, 0, 47, 64, 0, 7, 244, 6, 64, 127, + 175, 234, 175, 255, 251, 255, 255, 144, 255, 165, 0, 0, 0, 22, 164, 0, 1, 255, 254, 0, 11, 255, 255, 64, + 31, 144, 47, 128, 31, 128, 15, 128, 15, 224, 31, 64, 2, 248, 63, 0, 0, 190, 253, 0, 0, 127, 244, 0, + 171, 255, 255, 169, 255, 250, 255, 255, 254, 64, 26, 254, 0, 24, 0, 0, 0, 62, 0, 0, 0, 45, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 106, 80, 0, 2, 255, 224, 0, 15, 255, 208, 0, + 47, 144, 64, 0, 63, 0, 0, 0, 62, 0, 0, 0, 63, 0, 0, 0, 47, 128, 106, 0, 15, 251, 255, 0, + 7, 255, 254, 0, 2, 255, 128, 0, 11, 244, 0, 0, 31, 192, 0, 0, 63, 0, 0, 0, 125, 0, 0, 0, + 188, 0, 0, 0, 248, 0, 0, 0, 248, 0, 0, 0, 248, 0, 0, 0, 189, 0, 0, 0, 126, 0, 0, 0, + 63, 208, 0, 21, 15, 254, 170, 254, 2, 255, 255, 255, 0, 27, 254, 148, 0, 7, 128, 0, 0, 11, 192, 0, + 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 164, 0, 1, 191, 254, 0, 11, 255, 255, 64, + 31, 144, 47, 128, 31, 128, 15, 128, 11, 224, 31, 64, 2, 248, 62, 0, 0, 190, 252, 0, 0, 47, 244, 0, + 0, 127, 255, 169, 2, 254, 255, 255, 11, 224, 26, 254, 47, 128, 0, 0, 126, 0, 0, 0, 188, 0, 0, 0, + 248, 0, 0, 0, 248, 0, 0, 0, 252, 0, 0, 0, 190, 0, 0, 0, 127, 148, 5, 184, 47, 255, 255, 248, + 7, 255, 255, 224, 0, 90, 165, 0, 0, 11, 64, 0, 3, 224, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0, + 0, 6, 165, 0, 11, 255, 64, 15, 255, 208, 11, 228, 16, 3, 240, 0, 0, 248, 0, 0, 62, 0, 0, 11, + 208, 0, 1, 253, 1, 144, 31, 251, 250, 171, 255, 254, 255, 255, 228, 63, 233, 64, 0, 0, 11, 64, 0, 0, + 15, 128, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 164, 0, 1, 255, 254, 0, 11, + 255, 255, 64, 31, 144, 47, 128, 31, 64, 15, 128, 15, 224, 31, 64, 2, 248, 63, 0, 0, 190, 253, 0, 0, + 127, 244, 0, 171, 255, 255, 169, 255, 250, 255, 255, 254, 64, 26, 254, 0, 0, 0, 0, 6, 0, 0, 0, 0, + 0, 3, 224, 0, 0, 0, 0, 0, 180, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 105, 0, 0, 0, 0, 0, 191, 240, 0, 0, 0, 0, 127, 255, 0, + 0, 0, 0, 63, 11, 208, 0, 0, 0, 31, 65, 249, 224, 0, 0, 11, 192, 63, 188, 0, 0, 2, 244, 11, + 254, 0, 0, 0, 191, 171, 255, 128, 0, 0, 15, 255, 255, 224, 0, 0, 0, 191, 191, 253, 0, 0, 0, 0, + 15, 175, 224, 0, 0, 0, 11, 211, 255, 234, 170, 170, 175, 240, 47, 255, 255, 255, 255, 244, 0, 107, 255, 255, + 254, 144, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 248, 0, 0, 0, 0, 0, 0, 2, + 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 11, 228, 0, 0, 0, 0, 0, 0, 255, 248, 0, 100, 0, 0, 0, 15, 235, 244, + 2, 240, 0, 0, 0, 126, 7, 224, 11, 128, 0, 0, 2, 240, 15, 192, 62, 0, 0, 0, 11, 192, 47, 0, + 248, 0, 0, 0, 31, 128, 248, 3, 244, 0, 0, 0, 63, 155, 208, 11, 244, 0, 0, 0, 127, 255, 170, 15, + 255, 170, 170, 171, 255, 255, 253, 11, 255, 255, 255, 255, 250, 175, 244, 1, 175, 255, 255, 169, 0, 0, 0, 0, + 24, 0, 0, 62, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 128, 1, 255, 240, 3, + 251, 248, 7, 208, 188, 11, 128, 125, 15, 128, 62, 15, 208, 126, 11, 255, 254, 3, 255, 254, 0, 106, 189, 0, + 1, 252, 106, 175, 244, 191, 255, 208, 191, 233, 0, 0, 9, 0, 0, 0, 188, 0, 0, 1, 224, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 164, 0, 0, 127, 252, 0, 3, 255, 248, 0, 47, 131, 244, + 0, 252, 7, 224, 3, 224, 15, 128, 15, 128, 126, 0, 47, 66, 244, 0, 63, 191, 128, 42, 255, 254, 169, 255, + 255, 255, 255, 254, 149, 175, 224, 0, 0, 1, 129, 128, 0, 0, 3, 227, 224, 0, 0, 2, 210, 208, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 64, 0, 0, 0, 191, 224, 0, 0, 2, 255, 244, 0, + 0, 7, 225, 252, 0, 0, 11, 192, 125, 41, 0, 15, 128, 126, 126, 0, 15, 192, 62, 188, 0, 15, 250, 190, + 188, 0, 7, 255, 254, 248, 0, 1, 191, 253, 248, 0, 0, 0, 125, 252, 0, 0, 0, 252, 190, 0, 0, 2, + 244, 127, 128, 0, 31, 224, 47, 254, 171, 255, 128, 7, 255, 255, 254, 0, 0, 111, 254, 144, 0, 0, 0, 1, + 225, 224, 0, 0, 0, 11, 203, 192, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 105, 0, 0, 0, 0, 11, 254, 0, 0, 0, 0, 191, 254, 0, 0, 0, 7, 225, 252, + 0, 0, 0, 47, 2, 244, 2, 64, 0, 248, 7, 224, 15, 128, 3, 240, 15, 128, 125, 0, 11, 250, 191, 166, + 240, 0, 31, 255, 255, 255, 128, 0, 27, 255, 255, 190, 0, 0, 0, 31, 64, 252, 0, 0, 0, 248, 2, 244, + 0, 0, 11, 208, 7, 248, 0, 2, 254, 0, 11, 255, 170, 255, 224, 0, 11, 255, 255, 253, 0, 0, 1, 191, + 250, 64, 0, 0, 1, 225, 224, 2, 242, 240, 0, 144, 144, 0, 0, 0, 0, 0, 0, 0, 111, 128, 1, 255, + 240, 3, 251, 248, 7, 208, 188, 11, 128, 125, 15, 128, 62, 15, 208, 126, 11, 255, 254, 3, 255, 254, 0, 106, + 189, 0, 1, 252, 106, 175, 244, 191, 255, 208, 191, 233, 0, 0, 144, 144, 0, 11, 203, 192, 0, 30, 30, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 164, 0, 0, 127, 252, 0, 3, 255, 248, 0, 47, + 131, 244, 0, 252, 7, 224, 3, 224, 15, 128, 15, 128, 126, 0, 47, 66, 244, 0, 63, 191, 128, 42, 255, 254, + 169, 255, 255, 255, 255, 254, 150, 175, 224, 0, 0, 0, 0, 3, 224, 0, 0, 0, 0, 62, 0, 0, 0, 0, + 3, 224, 0, 0, 0, 0, 62, 0, 0, 2, 128, 3, 224, 0, 0, 253, 0, 62, 0, 0, 47, 64, 3, 224, + 0, 3, 224, 0, 62, 0, 0, 47, 64, 3, 224, 0, 0, 184, 0, 62, 120, 0, 11, 192, 3, 235, 192, 11, + 248, 0, 62, 248, 0, 249, 0, 3, 239, 128, 4, 0, 0, 62, 248, 0, 0, 0, 3, 239, 208, 0, 0, 0, + 125, 191, 128, 0, 0, 47, 195, 255, 234, 170, 191, 248, 11, 255, 255, 255, 253, 0, 6, 191, 255, 169, 0, 0, + 0, 0, 0, 3, 224, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 3, 224, 0, 0, 0, 0, 0, 62, + 0, 0, 0, 0, 80, 3, 224, 0, 0, 0, 127, 0, 62, 0, 0, 0, 31, 208, 3, 224, 0, 0, 2, 240, + 0, 62, 0, 0, 0, 31, 128, 3, 224, 1, 0, 0, 126, 0, 62, 0, 124, 0, 7, 240, 3, 224, 11, 192, + 7, 253, 0, 62, 0, 248, 0, 126, 64, 3, 224, 15, 128, 1, 0, 0, 62, 0, 248, 0, 0, 0, 3, 240, + 15, 208, 0, 0, 0, 127, 64, 191, 128, 0, 0, 47, 254, 147, 255, 234, 170, 191, 251, 255, 11, 255, 255, 255, + 253, 11, 224, 6, 191, 255, 165, 0, 0, 0, 0, 0, 0, 0, 6, 128, 0, 27, 244, 0, 111, 248, 0, 191, + 224, 1, 255, 128, 1, 254, 0, 0, 126, 0, 0, 31, 224, 0, 1, 254, 0, 0, 11, 224, 0, 0, 190, 0, + 0, 11, 208, 0, 0, 252, 0, 0, 31, 64, 0, 3, 224, 0, 1, 248, 10, 171, 253, 3, 255, 253, 0, 255, + 232, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 2, 254, 0, 0, 47, 253, 0, 1, 255, 144, 0, 11, 249, + 0, 0, 47, 208, 0, 0, 63, 0, 0, 0, 47, 128, 0, 0, 11, 240, 0, 0, 2, 252, 0, 0, 0, 190, + 0, 0, 0, 47, 128, 0, 0, 11, 208, 0, 0, 3, 240, 0, 0, 2, 248, 0, 0, 2, 254, 0, 106, 175, + 255, 232, 191, 255, 143, 253, 191, 249, 1, 189, 0, 0, 0, 15, 128, 0, 0, 3, 224, 0, 0, 0, 248, 0, + 0, 0, 62, 0, 0, 0, 15, 128, 0, 0, 3, 224, 0, 0, 0, 248, 0, 0, 0, 62, 0, 0, 0, 15, + 128, 0, 0, 3, 224, 0, 0, 0, 248, 0, 0, 0, 62, 0, 0, 0, 15, 128, 0, 0, 3, 226, 64, 0, + 0, 249, 244, 0, 0, 62, 188, 0, 0, 15, 174, 0, 0, 7, 223, 128, 0, 1, 247, 224, 0, 0, 188, 252, + 0, 0, 62, 47, 128, 0, 47, 67, 249, 0, 111, 128, 127, 255, 255, 192, 6, 255, 255, 128, 0, 6, 169, 0, + 0, 0, 0, 0, 15, 128, 0, 0, 0, 3, 224, 0, 0, 0, 0, 248, 0, 0, 0, 0, 62, 0, 0, 0, + 0, 15, 128, 0, 0, 0, 3, 224, 0, 0, 0, 0, 248, 0, 0, 0, 0, 62, 0, 0, 0, 0, 15, 128, + 0, 0, 0, 3, 224, 0, 0, 0, 0, 248, 0, 0, 0, 0, 62, 0, 0, 0, 0, 15, 128, 0, 0, 0, + 3, 224, 3, 208, 0, 0, 252, 1, 244, 0, 0, 63, 64, 188, 0, 0, 15, 250, 126, 0, 0, 3, 255, 255, + 128, 0, 1, 249, 251, 240, 0, 0, 190, 0, 189, 0, 0, 127, 64, 31, 208, 0, 191, 128, 2, 255, 170, 255, + 128, 0, 31, 255, 255, 128, 0, 0, 111, 249, 0, 0, 0, 3, 224, 62, 3, 224, 62, 3, 224, 62, 3, 224, + 62, 3, 224, 62, 3, 224, 62, 3, 224, 62, 3, 224, 126, 111, 219, 248, 185, 0, 3, 224, 0, 62, 0, 3, + 224, 0, 62, 0, 3, 224, 0, 62, 0, 3, 224, 0, 62, 0, 3, 224, 0, 62, 0, 3, 224, 0, 62, 0, + 3, 224, 0, 62, 0, 3, 240, 0, 127, 64, 111, 254, 155, 251, 255, 185, 11, 224, 0, 26, 64, 1, 255, 224, + 7, 255, 248, 15, 209, 253, 31, 64, 126, 5, 0, 47, 0, 0, 47, 0, 106, 175, 11, 255, 254, 47, 255, 254, + 126, 64, 88, 188, 0, 0, 248, 0, 0, 248, 0, 0, 248, 0, 0, 184, 0, 0, 188, 0, 0, 188, 0, 0, + 125, 0, 0, 62, 0, 0, 62, 0, 0, 41, 0, 0, 0, 1, 164, 0, 0, 1, 191, 224, 0, 0, 191, 255, + 0, 0, 47, 209, 248, 0, 11, 224, 15, 192, 1, 254, 0, 125, 0, 63, 248, 3, 244, 7, 219, 224, 63, 232, + 188, 63, 235, 255, 223, 128, 255, 250, 253, 248, 1, 190, 0, 15, 128, 0, 0, 0, 248, 0, 0, 0, 11, 192, + 0, 0, 0, 188, 0, 0, 0, 7, 208, 0, 0, 0, 125, 0, 0, 0, 3, 224, 0, 0, 0, 63, 0, 0, + 0, 2, 240, 0, 0, 0, 30, 64, 0, 0, 0, 0, 6, 248, 0, 1, 255, 240, 0, 127, 191, 128, 11, 192, + 253, 1, 244, 7, 224, 47, 0, 62, 11, 244, 7, 230, 255, 250, 253, 127, 127, 255, 139, 144, 111, 224, 0, 1, + 164, 0, 0, 0, 255, 224, 0, 0, 63, 255, 64, 0, 11, 210, 252, 0, 1, 244, 15, 208, 0, 62, 0, 191, + 0, 11, 244, 7, 248, 6, 251, 208, 127, 249, 127, 31, 175, 255, 247, 128, 127, 249, 190, 0, 1, 190, 0, 0, + 0, 1, 128, 0, 0, 0, 248, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 11, 0, 0, 0, 11, 208, 0, 0, 0, 248, 16, 0, 0, 47, 15, 64, 0, 7, 215, 208, 0, 1, 250, 240, + 0, 0, 62, 248, 0, 0, 15, 190, 0, 0, 7, 239, 192, 0, 2, 246, 244, 0, 1, 252, 127, 64, 1, 253, + 11, 254, 171, 254, 0, 191, 255, 253, 0, 2, 191, 228, 0, 0, 1, 128, 0, 0, 0, 0, 248, 0, 0, 0, + 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 224, 0, 0, 0, 0, 252, 0, 16, 0, 0, 47, 0, 15, 64, 0, 7, 208, 7, 208, 0, 1, 252, 2, 240, + 0, 0, 63, 233, 248, 0, 0, 15, 255, 254, 0, 0, 3, 235, 239, 192, 0, 1, 244, 2, 244, 0, 0, 252, + 0, 127, 64, 1, 254, 0, 11, 254, 171, 255, 0, 0, 191, 255, 254, 0, 0, 2, 191, 233, 0, 0, 11, 64, + 248, 6, 0, 0, 0, 0, 20, 11, 192, 125, 7, 208, 62, 2, 240, 47, 2, 240, 62, 175, 223, 248, 249, 0, + 2, 208, 0, 15, 128, 0, 24, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 31, 0, 0, 124, 0, 2, 224, + 0, 15, 128, 0, 127, 0, 43, 255, 169, 255, 127, 255, 228, 111, 224, 0, 0, 0, 29, 0, 7, 244, 0, 63, + 208, 11, 255, 65, 245, 252, 62, 11, 219, 192, 62, 248, 2, 255, 128, 47, 252, 7, 235, 250, 253, 63, 255, 128, + 191, 144, 0, 2, 240, 0, 0, 11, 192, 0, 1, 191, 0, 0, 191, 252, 0, 15, 255, 240, 0, 255, 75, 192, + 11, 224, 47, 0, 63, 0, 188, 0, 248, 2, 240, 3, 248, 11, 192, 7, 255, 255, 0, 7, 255, 254, 0, 1, + 170, 255, 160, 0, 2, 255, 208, 0, 1, 191, 0, 0, 16, 0, 0, 1, 224, 0, 0, 15, 224, 0, 0, 31, + 240, 0, 2, 255, 244, 0, 31, 255, 244, 0, 189, 47, 244, 3, 224, 63, 240, 15, 128, 255, 224, 47, 7, 219, + 208, 126, 127, 31, 128, 191, 244, 62, 171, 255, 235, 247, 255, 255, 255, 207, 164, 27, 248, 0, 0, 2, 248, 0, + 0, 2, 255, 192, 0, 2, 251, 244, 0, 1, 248, 126, 0, 0, 252, 15, 128, 0, 125, 3, 224, 0, 47, 1, + 244, 0, 11, 192, 188, 0, 3, 225, 253, 0, 10, 255, 255, 250, 131, 255, 255, 255, 244, 255, 208, 111, 253, 2, + 240, 2, 224, 0, 190, 0, 188, 0, 15, 224, 126, 0, 1, 255, 255, 64, 0, 31, 255, 128, 0, 0, 106, 64, + 0, 0, 105, 0, 11, 254, 0, 191, 254, 7, 225, 252, 47, 1, 244, 248, 7, 227, 240, 15, 143, 250, 190, 31, + 255, 248, 27, 255, 208, 0, 63, 0, 2, 248, 1, 191, 193, 191, 248, 7, 255, 64, 14, 144, 0, 0, 105, 0, + 0, 47, 248, 0, 11, 255, 224, 1, 248, 127, 0, 47, 1, 244, 3, 224, 15, 128, 63, 0, 248, 3, 254, 175, + 233, 31, 255, 255, 240, 111, 255, 254, 0, 3, 240, 0, 0, 190, 0, 1, 191, 192, 6, 255, 240, 0, 127, 248, + 0, 3, 228, 0, 0, 0, 0, 0, 27, 248, 0, 0, 0, 191, 253, 0, 0, 2, 254, 188, 0, 0, 11, 224, + 0, 0, 0, 31, 128, 0, 0, 0, 47, 0, 0, 16, 0, 47, 0, 0, 125, 0, 31, 208, 0, 125, 0, 11, + 254, 64, 188, 0, 1, 191, 224, 248, 0, 0, 11, 248, 248, 0, 0, 0, 248, 252, 0, 0, 1, 244, 189, 0, + 0, 7, 240, 127, 128, 0, 111, 208, 47, 254, 171, 255, 64, 7, 255, 255, 248, 0, 0, 111, 254, 64, 0, 16, + 0, 0, 0, 0, 15, 64, 0, 4, 0, 7, 208, 0, 7, 228, 2, 240, 0, 2, 255, 233, 248, 0, 0, 111, + 255, 254, 0, 0, 0, 191, 239, 192, 0, 0, 15, 130, 244, 0, 0, 11, 224, 127, 128, 0, 27, 240, 11, 255, + 170, 255, 244, 0, 127, 255, 255, 224, 0, 1, 191, 250, 64, 0, 0, 0, 0, 27, 248, 0, 0, 0, 191, 253, + 0, 0, 2, 254, 188, 0, 0, 11, 224, 0, 0, 0, 31, 128, 0, 0, 0, 47, 0, 0, 16, 0, 47, 0, + 0, 125, 0, 31, 208, 0, 125, 0, 11, 254, 64, 188, 0, 1, 191, 224, 248, 0, 0, 11, 248, 248, 0, 0, + 0, 248, 252, 0, 0, 1, 244, 189, 0, 0, 7, 240, 127, 128, 0, 111, 208, 47, 254, 171, 255, 64, 7, 255, + 255, 248, 0, 0, 111, 254, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, + 15, 143, 128, 0, 0, 11, 75, 64, 0, 16, 0, 0, 0, 0, 15, 64, 0, 4, 0, 7, 208, 0, 7, 228, + 2, 240, 0, 2, 255, 233, 248, 0, 0, 111, 255, 254, 0, 0, 0, 191, 239, 192, 0, 0, 15, 130, 244, 0, + 0, 11, 224, 127, 128, 0, 27, 240, 11, 255, 170, 255, 244, 0, 127, 255, 255, 224, 0, 1, 191, 250, 64, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 120, 0, 0, 0, 47, 47, + 0, 0, 0, 2, 66, 64, 0, 0, 0, 64, 31, 128, 63, 0, 188, 1, 244, 7, 224, 15, 128, 62, 1, 246, + 175, 207, 253, 62, 144, 0, 0, 0, 6, 6, 62, 62, 180, 180, 0, 0, 0, 0, 31, 64, 0, 7, 208, 0, + 2, 240, 0, 0, 252, 0, 0, 127, 64, 6, 191, 254, 161, 255, 191, 253, 126, 66, 255, 64, 0, 0, 0, 0, + 0, 0, 24, 24, 0, 15, 143, 128, 2, 210, 208, 0, + ], + hindi_glyphs: &[ + Glyph { c: '\u{0901}', adv: 0, x: -7, y: -21, w: 9, h: 6, off: 0 }, + Glyph { c: '\u{0902}', adv: 0, x: -4, y: -19, w: 3, h: 3, off: 14 }, + Glyph { c: '\u{0903}', adv: 5, x: 0, y: -14, w: 5, h: 13, off: 17 }, + Glyph { c: '\u{0905}', adv: 18, x: 0, y: -14, w: 18, h: 14, off: 34 }, + Glyph { c: '\u{0906}', adv: 24, x: 0, y: -14, w: 24, h: 14, off: 97 }, + Glyph { c: '\u{0907}', adv: 11, x: 0, y: -14, w: 11, h: 18, off: 181 }, + Glyph { c: '\u{0908}', adv: 11, x: 0, y: -20, w: 11, h: 24, off: 231 }, + Glyph { c: '\u{0909}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 297 }, + Glyph { c: '\u{090A}', adv: 18, x: 0, y: -14, w: 18, h: 15, off: 343 }, + Glyph { c: '\u{090B}', adv: 20, x: 0, y: -14, w: 20, h: 16, off: 411 }, + Glyph { c: '\u{090D}', adv: 13, x: 0, y: -20, w: 13, h: 22, off: 491 }, + Glyph { c: '\u{090F}', adv: 13, x: 0, y: -14, w: 13, h: 17, off: 563 }, + Glyph { c: '\u{0910}', adv: 13, x: 0, y: -20, w: 13, h: 23, off: 619 }, + Glyph { c: '\u{0911}', adv: 24, x: 0, y: -20, w: 24, h: 20, off: 694 }, + Glyph { c: '\u{0913}', adv: 24, x: 0, y: -20, w: 24, h: 20, off: 814 }, + Glyph { c: '\u{0914}', adv: 24, x: 0, y: -20, w: 24, h: 20, off: 934 }, + Glyph { c: '\u{0915}', adv: 18, x: 0, y: -14, w: 18, h: 14, off: 1054 }, + Glyph { c: '\u{0916}', adv: 19, x: 0, y: -14, w: 19, h: 14, off: 1117 }, + Glyph { c: '\u{0917}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 1184 }, + Glyph { c: '\u{0918}', adv: 14, x: 0, y: -14, w: 14, h: 14, off: 1230 }, + Glyph { c: '\u{0919}', adv: 15, x: 0, y: -14, w: 15, h: 14, off: 1279 }, + Glyph { c: '\u{091A}', adv: 15, x: 0, y: -14, w: 15, h: 14, off: 1332 }, + Glyph { c: '\u{091B}', adv: 16, x: 0, y: -14, w: 16, h: 14, off: 1385 }, + Glyph { c: '\u{091C}', adv: 17, x: 0, y: -14, w: 17, h: 14, off: 1441 }, + Glyph { c: '\u{091D}', adv: 17, x: 0, y: -14, w: 17, h: 18, off: 1501 }, + Glyph { c: '\u{091E}', adv: 17, x: 0, y: -14, w: 17, h: 14, off: 1578 }, + Glyph { c: '\u{091F}', adv: 12, x: 0, y: -14, w: 12, h: 14, off: 1638 }, + Glyph { c: '\u{0920}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 1680 }, + Glyph { c: '\u{0921}', adv: 12, x: 0, y: -14, w: 12, h: 14, off: 1726 }, + Glyph { c: '\u{0922}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 1768 }, + Glyph { c: '\u{0923}', adv: 17, x: 0, y: -14, w: 17, h: 14, off: 1814 }, + Glyph { c: '\u{0924}', adv: 13, x: 0, y: -14, w: 13, h: 15, off: 1874 }, + Glyph { c: '\u{0925}', adv: 15, x: 1, y: -14, w: 14, h: 14, off: 1923 }, + Glyph { c: '\u{0926}', adv: 12, x: 0, y: -14, w: 12, h: 16, off: 1972 }, + Glyph { c: '\u{0927}', adv: 15, x: 1, y: -14, w: 14, h: 14, off: 2020 }, + Glyph { c: '\u{0928}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 2069 }, + Glyph { c: '\u{092A}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 2115 }, + Glyph { c: '\u{092B}', adv: 18, x: 0, y: -14, w: 18, h: 14, off: 2161 }, + Glyph { c: '\u{092C}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 2224 }, + Glyph { c: '\u{092D}', adv: 16, x: 1, y: -14, w: 15, h: 14, off: 2270 }, + Glyph { c: '\u{092E}', adv: 14, x: 0, y: -14, w: 14, h: 14, off: 2323 }, + Glyph { c: '\u{092F}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 2372 }, + Glyph { c: '\u{0930}', adv: 10, x: 0, y: -14, w: 10, h: 15, off: 2418 }, + Glyph { c: '\u{0932}', adv: 16, x: 0, y: -14, w: 16, h: 15, off: 2456 }, + Glyph { c: '\u{0933}', adv: 17, x: 0, y: -14, w: 17, h: 14, off: 2516 }, + Glyph { c: '\u{0935}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 2576 }, + Glyph { c: '\u{0936}', adv: 16, x: 0, y: -14, w: 16, h: 15, off: 2622 }, + Glyph { c: '\u{0937}', adv: 13, x: 0, y: -14, w: 13, h: 14, off: 2682 }, + Glyph { c: '\u{0938}', adv: 16, x: 0, y: -14, w: 16, h: 15, off: 2728 }, + Glyph { c: '\u{0939}', adv: 12, x: 0, y: -14, w: 12, h: 18, off: 2788 }, + Glyph { c: '\u{093C}', adv: 0, x: -8, y: 1, w: 3, h: 4, off: 2842 }, + Glyph { c: '\u{093E}', adv: 6, x: 0, y: -14, w: 6, h: 14, off: 2845 }, + Glyph { c: '\u{093F}', adv: 6, x: 0, y: -20, w: 17, h: 20, off: 2866 }, + Glyph { c: '\u{0940}', adv: 6, x: -5, y: -20, w: 11, h: 20, off: 2951 }, + Glyph { c: '\u{0941}', adv: 0, x: -11, y: -1, w: 12, h: 8, off: 3006 }, + Glyph { c: '\u{0942}', adv: 0, x: -7, y: -1, w: 11, h: 8, off: 3030 }, + Glyph { c: '\u{0943}', adv: 0, x: -6, y: 0, w: 7, h: 7, off: 3052 }, + Glyph { c: '\u{0945}', adv: 0, x: -8, y: -20, w: 9, h: 5, off: 3065 }, + Glyph { c: '\u{0947}', adv: 0, x: -10, y: -21, w: 8, h: 8, off: 3077 }, + Glyph { c: '\u{0948}', adv: 0, x: -10, y: -21, w: 8, h: 8, off: 3093 }, + Glyph { c: '\u{0949}', adv: 6, x: -3, y: -20, w: 10, h: 20, off: 3109 }, + Glyph { c: '\u{094B}', adv: 6, x: -4, y: -20, w: 10, h: 20, off: 3159 }, + Glyph { c: '\u{094C}', adv: 6, x: -4, y: -20, w: 10, h: 20, off: 3209 }, + Glyph { c: '\u{094D}', adv: 0, x: -5, y: 0, w: 8, h: 6, off: 3259 }, + Glyph { c: '\u{0964}', adv: 8, x: 4, y: -14, w: 3, h: 14, off: 3271 }, + Glyph { c: '\u{0965}', adv: 13, x: 4, y: -14, w: 8, h: 14, off: 3282 }, + Glyph { c: '\u{0966}', adv: 11, x: 1, y: -12, w: 9, h: 10, off: 3310 }, + Glyph { c: '\u{0967}', adv: 11, x: 2, y: -14, w: 7, h: 15, off: 3333 }, + Glyph { c: '\u{0968}', adv: 12, x: 1, y: -14, w: 10, h: 15, off: 3360 }, + Glyph { c: '\u{0969}', adv: 11, x: 1, y: -14, w: 9, h: 17, off: 3398 }, + Glyph { c: '\u{096A}', adv: 12, x: 1, y: -14, w: 10, h: 14, off: 3437 }, + Glyph { c: '\u{096B}', adv: 11, x: 1, y: -15, w: 10, h: 15, off: 3472 }, + Glyph { c: '\u{096C}', adv: 11, x: 2, y: -14, w: 9, h: 17, off: 3510 }, + Glyph { c: '\u{096D}', adv: 12, x: 1, y: -14, w: 10, h: 14, off: 3549 }, + Glyph { c: '\u{096E}', adv: 12, x: 2, y: -14, w: 9, h: 14, off: 3584 }, + Glyph { c: '\u{096F}', adv: 12, x: 2, y: -14, w: 8, h: 15, off: 3616 }, + ], + hindi_bits: &[ + 1, 64, 40, 241, 143, 20, 242, 249, 184, 47, 248, 1, 84, 0, 163, 202, 0, 255, 255, 240, 0, 0, 45, 15, + 194, 208, 0, 0, 0, 2, 208, 252, 45, 0, 0, 175, 144, 255, 240, 31, 255, 15, 255, 0, 128, 184, 15, 0, + 0, 11, 128, 240, 0, 1, 244, 15, 0, 2, 254, 0, 240, 44, 47, 249, 191, 2, 208, 11, 255, 240, 31, 0, + 125, 95, 0, 184, 7, 192, 240, 3, 230, 248, 15, 0, 11, 254, 0, 240, 0, 21, 64, 15, 0, 0, 0, 0, + 240, 0, 175, 144, 255, 255, 255, 1, 255, 240, 255, 255, 255, 0, 128, 184, 15, 0, 240, 0, 0, 184, 15, 0, + 240, 0, 1, 244, 15, 0, 240, 0, 47, 224, 15, 0, 240, 44, 47, 249, 191, 0, 240, 45, 0, 191, 255, 0, + 240, 31, 0, 125, 95, 0, 240, 11, 128, 124, 15, 0, 240, 3, 230, 248, 15, 0, 240, 0, 191, 224, 15, 0, + 240, 0, 21, 64, 15, 0, 240, 0, 0, 0, 15, 0, 240, 255, 255, 255, 255, 255, 240, 0, 60, 0, 85, 240, + 31, 255, 192, 249, 85, 3, 208, 0, 11, 149, 64, 15, 255, 208, 10, 95, 128, 0, 31, 11, 128, 188, 63, 255, + 208, 111, 249, 0, 31, 0, 0, 47, 0, 0, 46, 0, 0, 16, 0, 0, 7, 248, 0, 191, 224, 3, 224, 0, + 15, 64, 0, 45, 0, 0, 45, 15, 255, 255, 255, 255, 255, 0, 3, 192, 5, 95, 1, 255, 252, 15, 149, 80, + 61, 0, 0, 185, 84, 0, 255, 253, 0, 165, 248, 0, 1, 240, 180, 11, 195, 255, 253, 7, 255, 144, 1, 224, + 0, 2, 224, 0, 3, 224, 0, 6, 0, 255, 255, 255, 255, 255, 255, 240, 0, 11, 128, 0, 1, 240, 0, 0, + 124, 0, 1, 189, 1, 66, 254, 1, 240, 103, 208, 61, 0, 120, 7, 128, 15, 0, 244, 3, 192, 31, 66, 240, + 2, 255, 244, 0, 27, 228, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 184, 0, 0, 0, 7, 192, + 0, 0, 0, 124, 0, 0, 0, 111, 64, 0, 20, 47, 224, 84, 7, 193, 239, 191, 224, 61, 0, 127, 159, 129, + 224, 3, 208, 124, 15, 64, 62, 3, 192, 125, 11, 208, 184, 1, 255, 248, 31, 64, 6, 254, 1, 224, 0, 0, + 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 60, 0, 0, 1, 80, 60, 5, 0, 47, + 248, 60, 31, 128, 62, 111, 124, 31, 192, 16, 11, 189, 111, 128, 0, 3, 255, 255, 128, 0, 11, 254, 83, 208, + 1, 191, 188, 11, 224, 27, 248, 60, 47, 144, 31, 128, 60, 60, 0, 4, 0, 60, 60, 4, 0, 0, 60, 62, + 109, 0, 0, 0, 31, 252, 0, 0, 0, 1, 80, 1, 64, 20, 1, 224, 30, 0, 62, 111, 64, 7, 255, 128, + 0, 21, 0, 0, 0, 0, 15, 255, 255, 255, 255, 255, 255, 15, 0, 60, 3, 192, 15, 0, 240, 3, 192, 60, + 1, 240, 15, 1, 184, 3, 192, 189, 0, 184, 9, 0, 31, 208, 0, 0, 191, 64, 0, 2, 248, 0, 0, 11, + 128, 0, 1, 240, 0, 0, 184, 0, 0, 5, 0, 255, 255, 255, 255, 255, 255, 240, 240, 3, 192, 60, 0, 240, + 15, 0, 60, 3, 192, 31, 0, 240, 11, 192, 60, 11, 224, 15, 129, 224, 1, 248, 0, 0, 31, 224, 0, 0, + 127, 64, 0, 1, 248, 0, 0, 31, 0, 0, 7, 192, 0, 1, 224, 0, 0, 0, 0, 1, 190, 0, 0, 63, + 240, 0, 0, 45, 0, 0, 3, 192, 0, 0, 180, 0, 0, 30, 15, 255, 255, 255, 255, 255, 255, 15, 0, 60, + 3, 192, 15, 0, 240, 3, 192, 60, 1, 240, 15, 0, 124, 3, 192, 190, 0, 248, 30, 0, 31, 129, 0, 1, + 254, 0, 0, 11, 244, 0, 0, 47, 64, 0, 1, 240, 0, 0, 124, 0, 0, 46, 0, 0, 0, 0, 0, 0, + 0, 5, 0, 80, 0, 0, 0, 15, 0, 180, 0, 0, 0, 11, 64, 240, 0, 0, 0, 7, 235, 224, 0, 0, + 0, 2, 255, 128, 0, 0, 0, 0, 21, 0, 0, 111, 144, 255, 255, 255, 2, 255, 240, 255, 255, 255, 1, 128, + 184, 15, 0, 240, 0, 0, 184, 15, 0, 240, 0, 0, 180, 15, 0, 240, 0, 27, 240, 15, 0, 240, 40, 47, + 233, 175, 0, 240, 61, 21, 255, 255, 0, 240, 30, 0, 125, 95, 0, 240, 11, 128, 124, 15, 0, 240, 3, 230, + 248, 15, 0, 240, 0, 191, 224, 15, 0, 240, 0, 21, 64, 15, 0, 240, 0, 0, 0, 15, 0, 240, 0, 0, + 0, 7, 248, 0, 0, 0, 0, 7, 255, 0, 0, 0, 0, 0, 11, 64, 0, 0, 0, 0, 3, 192, 0, 0, + 0, 0, 2, 208, 0, 0, 0, 0, 1, 224, 1, 191, 144, 255, 255, 255, 1, 255, 244, 255, 255, 255, 0, 64, + 184, 15, 0, 240, 0, 0, 184, 15, 0, 240, 0, 1, 244, 15, 0, 240, 0, 47, 224, 15, 0, 240, 60, 47, + 249, 191, 0, 240, 45, 0, 191, 255, 0, 240, 31, 0, 125, 95, 0, 240, 11, 128, 124, 15, 0, 240, 3, 230, + 248, 15, 0, 240, 0, 191, 224, 15, 0, 240, 0, 21, 64, 15, 0, 240, 0, 0, 0, 15, 0, 240, 0, 0, + 0, 7, 248, 0, 0, 0, 0, 3, 254, 0, 0, 0, 0, 1, 91, 64, 0, 0, 0, 11, 250, 128, 0, 0, + 0, 6, 111, 208, 0, 0, 0, 0, 2, 224, 1, 191, 144, 255, 255, 255, 1, 255, 244, 255, 255, 255, 0, 64, + 184, 15, 0, 240, 0, 0, 184, 15, 0, 240, 0, 1, 244, 15, 0, 240, 0, 47, 224, 15, 0, 240, 60, 47, + 249, 191, 0, 240, 45, 0, 191, 255, 0, 240, 31, 0, 125, 95, 0, 240, 11, 128, 124, 15, 0, 240, 3, 230, + 248, 15, 0, 240, 0, 191, 224, 15, 0, 240, 0, 21, 64, 15, 0, 240, 0, 0, 0, 15, 0, 240, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 0, 0, 240, 0, 0, 5, 79, 0, 0, 11, 253, 241, 80, 2, 249, 143, 191, + 192, 61, 0, 254, 126, 3, 208, 15, 129, 240, 61, 2, 244, 15, 2, 249, 191, 0, 240, 11, 254, 240, 46, 0, + 21, 79, 7, 208, 0, 0, 240, 40, 0, 0, 15, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 11, + 128, 0, 240, 0, 30, 1, 83, 192, 0, 184, 127, 223, 0, 102, 211, 229, 60, 3, 255, 15, 0, 240, 15, 244, + 60, 3, 192, 47, 0, 249, 191, 0, 61, 1, 255, 252, 0, 125, 0, 84, 240, 0, 126, 64, 27, 192, 0, 127, + 255, 255, 0, 0, 27, 254, 124, 0, 255, 255, 255, 255, 255, 255, 240, 60, 3, 192, 15, 0, 240, 3, 192, 60, + 1, 240, 15, 3, 252, 3, 192, 255, 0, 240, 47, 192, 60, 2, 224, 15, 0, 0, 3, 192, 0, 0, 240, 0, + 0, 60, 0, 0, 15, 0, 255, 255, 255, 255, 255, 255, 255, 61, 0, 60, 3, 208, 3, 192, 46, 84, 60, 0, + 191, 131, 192, 31, 148, 60, 1, 224, 3, 192, 30, 0, 124, 0, 249, 175, 192, 7, 255, 252, 0, 5, 83, 192, + 0, 0, 60, 0, 0, 3, 192, 255, 255, 255, 255, 255, 255, 255, 240, 0, 15, 0, 0, 21, 124, 0, 7, 255, + 240, 0, 46, 85, 65, 64, 180, 0, 15, 2, 229, 80, 40, 2, 255, 244, 0, 1, 150, 240, 2, 128, 3, 192, + 31, 144, 31, 0, 27, 255, 248, 0, 6, 254, 64, 0, 255, 255, 255, 255, 255, 255, 255, 240, 0, 0, 240, 5, + 85, 83, 192, 127, 255, 79, 0, 91, 228, 60, 0, 61, 0, 240, 0, 240, 3, 192, 3, 208, 31, 0, 11, 234, + 252, 0, 11, 255, 240, 0, 5, 83, 192, 0, 0, 15, 0, 0, 0, 60, 0, 255, 255, 255, 255, 255, 255, 255, + 255, 0, 0, 15, 0, 1, 84, 47, 128, 31, 244, 191, 240, 62, 81, 250, 248, 60, 1, 224, 124, 46, 84, 244, + 124, 11, 248, 125, 124, 11, 228, 4, 184, 15, 64, 1, 240, 15, 128, 27, 208, 7, 255, 255, 64, 1, 191, 228, + 0, 255, 255, 255, 255, 255, 255, 255, 255, 240, 0, 0, 3, 192, 0, 0, 0, 240, 20, 1, 85, 188, 31, 2, + 255, 255, 3, 208, 62, 91, 192, 120, 3, 192, 240, 15, 64, 180, 60, 1, 240, 45, 15, 0, 47, 175, 67, 192, + 2, 255, 128, 240, 0, 5, 0, 60, 0, 0, 0, 15, 0, 255, 255, 255, 255, 255, 255, 255, 255, 240, 0, 61, + 3, 192, 5, 95, 64, 240, 31, 255, 208, 60, 15, 149, 80, 15, 3, 208, 0, 3, 192, 185, 85, 85, 240, 15, + 255, 255, 252, 0, 165, 190, 95, 0, 64, 15, 3, 192, 248, 11, 192, 240, 63, 255, 208, 60, 6, 255, 144, 15, + 0, 31, 0, 0, 0, 1, 244, 0, 0, 0, 46, 0, 0, 0, 1, 0, 0, 0, 255, 255, 255, 255, 255, 255, + 255, 255, 240, 0, 0, 3, 192, 0, 21, 0, 240, 0, 127, 224, 60, 0, 30, 190, 15, 2, 128, 7, 219, 192, + 244, 0, 255, 240, 31, 64, 125, 188, 2, 249, 190, 15, 0, 31, 254, 3, 192, 0, 84, 0, 240, 0, 0, 0, + 60, 0, 0, 0, 15, 0, 255, 255, 255, 255, 255, 255, 0, 3, 192, 0, 3, 192, 0, 27, 192, 6, 255, 192, + 31, 229, 64, 46, 0, 0, 61, 0, 0, 61, 0, 0, 45, 0, 0, 31, 64, 104, 11, 255, 252, 1, 191, 144, + 255, 255, 255, 255, 255, 255, 240, 0, 60, 0, 0, 15, 0, 0, 23, 192, 0, 191, 253, 0, 254, 155, 192, 188, + 0, 184, 61, 0, 15, 15, 64, 3, 194, 224, 0, 240, 125, 1, 184, 11, 255, 248, 0, 111, 228, 0, 255, 255, + 255, 255, 255, 255, 0, 0, 240, 0, 85, 240, 7, 255, 240, 15, 149, 80, 15, 64, 0, 11, 149, 64, 2, 255, + 244, 0, 165, 188, 52, 0, 60, 126, 64, 124, 31, 255, 248, 1, 191, 144, 255, 255, 255, 255, 255, 255, 240, 0, + 15, 0, 0, 91, 192, 2, 255, 240, 3, 250, 84, 2, 244, 0, 0, 244, 5, 64, 61, 31, 253, 15, 75, 155, + 130, 227, 192, 240, 125, 180, 184, 7, 255, 253, 0, 47, 249, 0, 255, 255, 255, 255, 255, 255, 255, 255, 241, 224, + 45, 15, 0, 120, 11, 67, 192, 30, 2, 208, 240, 7, 128, 180, 60, 1, 224, 45, 15, 0, 124, 15, 67, 192, + 15, 155, 192, 240, 1, 255, 208, 60, 0, 5, 64, 15, 0, 0, 0, 3, 192, 0, 0, 0, 240, 0, 0, 0, + 60, 0, 255, 255, 255, 255, 255, 255, 240, 0, 3, 192, 0, 0, 240, 0, 85, 188, 2, 255, 255, 2, 249, 91, + 192, 244, 0, 240, 60, 0, 60, 15, 64, 15, 2, 224, 3, 192, 61, 0, 240, 7, 208, 60, 0, 180, 15, 0, + 0, 0, 0, 27, 208, 255, 247, 255, 143, 255, 120, 124, 31, 7, 131, 192, 240, 45, 124, 15, 0, 75, 128, 240, + 27, 240, 15, 7, 248, 0, 240, 46, 0, 47, 1, 250, 111, 240, 6, 255, 255, 0, 5, 80, 240, 0, 0, 15, + 0, 0, 0, 240, 255, 255, 255, 255, 255, 255, 0, 0, 240, 0, 86, 240, 7, 255, 240, 31, 229, 80, 46, 0, + 0, 61, 0, 0, 61, 1, 228, 46, 3, 252, 15, 231, 252, 6, 255, 244, 0, 21, 240, 0, 0, 184, 0, 0, + 124, 0, 0, 16, 27, 224, 255, 243, 255, 143, 255, 120, 124, 61, 7, 135, 131, 192, 120, 16, 60, 2, 229, 67, + 192, 11, 252, 60, 0, 249, 67, 192, 31, 0, 60, 1, 240, 11, 192, 15, 155, 252, 0, 127, 251, 192, 0, 84, + 60, 0, 0, 3, 192, 255, 255, 255, 255, 255, 255, 240, 0, 3, 192, 0, 0, 240, 0, 0, 60, 5, 85, 111, + 3, 255, 255, 192, 255, 86, 240, 31, 192, 60, 1, 224, 15, 0, 0, 3, 192, 0, 0, 240, 0, 0, 60, 0, + 0, 15, 0, 255, 255, 255, 255, 255, 255, 240, 240, 3, 192, 60, 0, 240, 15, 0, 60, 3, 192, 15, 0, 240, + 3, 192, 45, 1, 240, 7, 230, 252, 0, 191, 255, 0, 1, 83, 192, 0, 0, 240, 0, 0, 60, 0, 0, 15, + 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 15, 0, 240, 0, 0, 240, 15, 0, 0, 15, 0, 241, 80, 0, + 240, 15, 191, 192, 15, 0, 254, 126, 0, 244, 15, 129, 240, 11, 235, 240, 15, 0, 63, 255, 0, 240, 0, 84, + 240, 46, 0, 0, 15, 7, 208, 0, 0, 240, 40, 0, 0, 15, 0, 0, 255, 255, 255, 255, 255, 255, 240, 0, + 3, 192, 1, 85, 240, 11, 255, 124, 11, 249, 143, 3, 219, 3, 192, 240, 240, 240, 61, 30, 124, 11, 230, 255, + 0, 191, 255, 192, 1, 85, 240, 0, 0, 60, 0, 0, 15, 0, 47, 144, 255, 254, 255, 195, 255, 255, 15, 64, + 124, 61, 46, 0, 240, 126, 184, 3, 192, 22, 224, 15, 0, 27, 149, 188, 1, 255, 255, 240, 3, 249, 91, 192, + 11, 208, 15, 0, 6, 0, 60, 0, 0, 0, 240, 0, 0, 3, 192, 0, 0, 15, 0, 255, 255, 255, 255, 255, + 255, 255, 7, 192, 15, 0, 124, 0, 240, 7, 192, 15, 0, 124, 0, 240, 27, 213, 111, 3, 255, 255, 240, 63, + 213, 111, 1, 252, 0, 240, 6, 64, 15, 0, 0, 0, 240, 0, 0, 15, 0, 0, 0, 240, 255, 255, 255, 255, + 255, 255, 240, 45, 3, 192, 7, 128, 240, 2, 224, 60, 6, 244, 15, 7, 248, 3, 192, 244, 0, 240, 46, 0, + 188, 3, 250, 255, 0, 47, 251, 192, 1, 80, 240, 0, 0, 60, 0, 0, 15, 0, 255, 255, 255, 255, 255, 0, + 31, 0, 1, 240, 0, 31, 2, 227, 224, 63, 253, 2, 255, 64, 31, 128, 0, 125, 0, 2, 244, 0, 11, 208, + 0, 47, 64, 0, 180, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 3, 192, 0, 0, 3, 192, + 1, 80, 23, 192, 11, 254, 255, 192, 47, 171, 231, 192, 61, 11, 195, 192, 60, 11, 67, 192, 61, 6, 3, 192, + 46, 0, 3, 192, 15, 128, 3, 192, 3, 244, 3, 192, 0, 176, 3, 192, 0, 0, 0, 0, 255, 255, 255, 255, + 255, 255, 255, 255, 240, 0, 0, 60, 0, 0, 0, 15, 0, 0, 84, 7, 208, 2, 255, 159, 254, 1, 249, 191, + 235, 224, 184, 11, 192, 124, 61, 2, 224, 15, 15, 64, 244, 3, 194, 208, 125, 1, 240, 126, 191, 230, 244, 11, + 253, 47, 248, 0, 84, 1, 84, 0, 255, 255, 255, 255, 255, 255, 240, 0, 3, 192, 1, 84, 240, 11, 255, 124, + 11, 229, 143, 3, 224, 3, 192, 244, 0, 240, 62, 0, 188, 7, 230, 255, 0, 191, 255, 192, 1, 84, 240, 0, + 0, 60, 0, 0, 15, 0, 6, 249, 15, 255, 15, 255, 79, 255, 30, 11, 129, 240, 30, 3, 192, 240, 15, 211, + 192, 240, 2, 231, 192, 240, 0, 11, 128, 240, 125, 47, 64, 240, 127, 253, 0, 240, 47, 244, 0, 240, 1, 244, + 0, 240, 0, 125, 0, 240, 0, 47, 0, 240, 0, 15, 64, 240, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, + 243, 252, 7, 192, 251, 129, 240, 61, 120, 124, 15, 75, 95, 3, 208, 183, 192, 184, 15, 240, 31, 154, 252, 2, + 255, 255, 0, 5, 87, 192, 0, 1, 240, 0, 0, 124, 0, 0, 31, 0, 255, 255, 255, 255, 255, 255, 255, 255, + 0, 120, 3, 192, 0, 124, 3, 192, 0, 124, 3, 192, 45, 184, 3, 192, 63, 249, 87, 192, 63, 255, 255, 192, + 31, 5, 87, 192, 15, 64, 3, 192, 7, 208, 3, 192, 1, 244, 3, 192, 0, 189, 3, 192, 0, 45, 3, 192, + 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 0, 0, 240, 0, 86, 240, 11, 255, 240, 15, 149, 80, 15, 0, + 0, 11, 85, 64, 3, 255, 224, 11, 230, 244, 15, 64, 120, 15, 0, 120, 15, 65, 244, 11, 192, 160, 3, 244, + 0, 0, 191, 64, 0, 27, 0, 0, 0, 0, 21, 247, 196, 255, 255, 255, 15, 0, 240, 15, 0, 240, 15, 0, + 240, 15, 0, 240, 15, 0, 240, 15, 0, 240, 2, 191, 144, 0, 7, 255, 255, 128, 2, 244, 1, 189, 0, 244, + 0, 7, 208, 61, 0, 0, 125, 11, 128, 0, 3, 223, 255, 0, 0, 3, 255, 192, 0, 0, 15, 0, 0, 0, + 3, 192, 0, 0, 0, 240, 0, 0, 0, 60, 0, 0, 0, 15, 0, 0, 0, 3, 192, 0, 0, 0, 240, 0, + 0, 0, 60, 0, 0, 0, 15, 0, 0, 0, 3, 192, 0, 0, 0, 240, 0, 0, 0, 60, 0, 0, 0, 31, + 224, 1, 255, 240, 15, 130, 224, 61, 3, 208, 180, 7, 129, 224, 30, 0, 3, 255, 192, 15, 255, 0, 3, 192, + 0, 15, 0, 0, 60, 0, 0, 240, 0, 3, 192, 0, 15, 0, 0, 60, 0, 0, 240, 0, 3, 192, 0, 15, + 0, 0, 60, 0, 0, 240, 0, 5, 64, 0, 127, 244, 36, 57, 184, 124, 0, 60, 47, 64, 60, 11, 230, 252, + 1, 255, 244, 0, 21, 64, 5, 80, 0, 191, 244, 11, 230, 244, 61, 1, 240, 244, 2, 226, 246, 131, 210, 254, + 6, 65, 80, 0, 27, 65, 253, 15, 64, 61, 0, 189, 164, 191, 224, 85, 0, 100, 2, 158, 1, 227, 230, 244, + 127, 248, 1, 80, 0, 21, 0, 127, 208, 38, 244, 0, 120, 0, 60, 0, 29, 0, 30, 0, 0, 21, 0, 63, + 208, 22, 240, 21, 56, 127, 236, 22, 189, 0, 46, 0, 0, 20, 1, 67, 192, 60, 47, 175, 128, 191, 224, 1, + 84, 0, 0, 0, 3, 255, 192, 63, 252, 0, 60, 0, 3, 192, 0, 60, 0, 3, 192, 0, 60, 0, 3, 192, + 0, 60, 0, 3, 192, 0, 60, 0, 3, 192, 0, 60, 0, 3, 192, 111, 128, 3, 255, 0, 0, 180, 0, 3, + 192, 0, 45, 0, 1, 224, 0, 255, 240, 15, 255, 0, 15, 0, 0, 240, 0, 15, 0, 0, 240, 0, 15, 0, + 0, 240, 0, 15, 0, 0, 240, 0, 15, 0, 0, 240, 0, 15, 0, 0, 240, 63, 128, 3, 254, 0, 21, 180, + 11, 250, 128, 106, 253, 0, 2, 224, 0, 255, 240, 15, 255, 0, 15, 0, 0, 240, 0, 15, 0, 0, 240, 0, + 15, 0, 0, 240, 0, 15, 0, 0, 240, 0, 15, 0, 0, 240, 0, 15, 0, 0, 240, 21, 0, 63, 208, 22, + 244, 0, 124, 0, 30, 0, 4, 163, 207, 60, 243, 207, 60, 243, 207, 60, 243, 192, 160, 40, 240, 60, 240, 60, + 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 1, 80, + 7, 255, 71, 230, 246, 224, 46, 244, 7, 253, 1, 251, 128, 185, 249, 189, 31, 253, 0, 84, 0, 31, 209, 255, + 223, 130, 252, 7, 180, 44, 250, 208, 190, 11, 224, 254, 1, 190, 0, 127, 0, 46, 0, 124, 1, 240, 2, 64, + 27, 249, 2, 255, 244, 20, 11, 128, 0, 124, 0, 3, 193, 64, 124, 126, 11, 135, 251, 240, 63, 249, 0, 110, + 0, 0, 244, 0, 11, 128, 0, 61, 0, 2, 224, 0, 4, 0, 43, 244, 31, 255, 129, 1, 240, 0, 60, 0, + 31, 1, 175, 65, 255, 192, 20, 184, 0, 15, 5, 3, 207, 210, 243, 255, 244, 111, 228, 1, 240, 0, 46, 0, + 3, 192, 0, 64, 0, 84, 1, 95, 128, 47, 244, 1, 255, 128, 46, 125, 7, 210, 245, 244, 7, 253, 0, 127, + 224, 31, 95, 67, 208, 120, 61, 7, 194, 224, 188, 31, 255, 64, 111, 144, 0, 0, 1, 224, 0, 63, 0, 11, + 192, 0, 244, 0, 15, 64, 116, 244, 15, 203, 128, 252, 63, 175, 129, 255, 244, 1, 87, 64, 0, 56, 0, 3, + 192, 0, 60, 0, 2, 128, 27, 248, 31, 254, 15, 128, 3, 208, 0, 180, 0, 31, 149, 3, 255, 66, 249, 64, + 244, 0, 61, 5, 11, 67, 241, 250, 252, 31, 253, 0, 91, 64, 0, 240, 0, 45, 0, 0, 0, 40, 0, 7, + 192, 0, 184, 21, 11, 71, 248, 244, 250, 223, 79, 30, 244, 240, 255, 75, 143, 244, 47, 251, 128, 110, 124, 2, + 210, 249, 188, 11, 255, 0, 5, 64, 0, 40, 0, 47, 64, 31, 128, 31, 128, 15, 128, 11, 192, 7, 208, 2, + 224, 0, 244, 0, 61, 0, 11, 128, 33, 249, 190, 31, 254, 0, 84, 0, 27, 228, 127, 253, 248, 46, 244, 31, + 244, 47, 185, 189, 63, 244, 15, 208, 2, 248, 0, 189, 0, 47, 0, 31, 0, 31, 0, 46, 0, 9, + ], +}; diff --git a/apps/watch-replies/src/gesture.rs b/apps/watch-replies/src/gesture.rs new file mode 100644 index 0000000..ad17346 --- /dev/null +++ b/apps/watch-replies/src/gesture.rs @@ -0,0 +1,45 @@ +//! What a touch was, from where the finger went down and came up. + +/// A touch that moved this far (and mostly in one direction) is a swipe. +pub const SWIPE_PX: i32 = 60; +/// A touch that stayed within this far is a tap or a hold. +pub const TAP_PX: i32 = 28; +/// A touch held this long (and still) is a hold. +pub const HOLD_MS: u32 = 600; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Gesture { + None, + Tap, + Hold, + SwipeUp, + SwipeDown, +} + +/// `dx`, `dy`: how far the finger went from where it came down (right and down are positive); `held_ms`: for how long. +/// Sideways swipes are not read here: a right swipe is the watch's own "back" (`BUTTON`). +pub fn classify(dx: i32, dy: i32, held_ms: u32) -> Gesture { + let (ax, ay) = (dx.abs(), dy.abs()); + if ay >= SWIPE_PX && ay >= 2 * ax { + return if dy > 0 { Gesture::SwipeDown } else { Gesture::SwipeUp }; + } + if ax.max(ay) <= TAP_PX { + return if held_ms >= HOLD_MS { Gesture::Hold } else { Gesture::Tap }; + } + Gesture::None +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn taps_holds_and_vertical_swipes() { + assert_eq!(classify(3, -4, 120), Gesture::Tap); + assert_eq!(classify(0, 0, 700), Gesture::Hold); + assert_eq!(classify(10, -120, 200), Gesture::SwipeUp); + assert_eq!(classify(-20, 90, 300), Gesture::SwipeDown); + assert_eq!(classify(150, 20, 200), Gesture::None); // sideways: the watch's back + assert_eq!(classify(40, 45, 100), Gesture::None); + } +} diff --git a/apps/watch-replies/src/icons.rs b/apps/watch-replies/src/icons.rs new file mode 100644 index 0000000..559c450 --- /dev/null +++ b/apps/watch-replies/src/icons.rs @@ -0,0 +1,226 @@ +//! The three app signs, 64x64, made from the pictures of the real icons and stored as colour runs on black. +//! Made once from the reference picture of the real icons. + +use cmf_wp2_ui::Surface; + +pub const SIZE: i32 = 64; +const MESSENGER_PAL: [u16; 14] = [0, 65535, 31359, 39422, 19263, 47611, 53814, 15327, 64175, 60018, 25343, 18768, 48607, 41563]; +const MESSENGER: [u8; 935] = [1, 252, 0, 5, 96, 0, 11, 40, 128, 75, 96, 0, 6, 80, 0, 11, 0, 148, 72, 4, 181, 0, 6, 68, 0, 11, 16, 148, 200, 0, 180, 128, 7, 60, 0, 11, 12, 97, 9, 80, 128, 11, 60, 0, 7, 52, 0, 11, 24, 97, 9, 84, 128, 11, 52, 0, 7, 48, 0, 11, 36, 97, 9, 84, 128, 11, 44, 0, 7, 40, 0, 11, 52, 96, 201, 84, 128, 11, 40, 0, 8, 36, 0, 11, 0, 83, 134, 16, 149, 8, 0, 178, 64, 8, 32, 0, 11, 12, 83, 134, 12, 149, 8, 0, 178, 0, 8, 28, 0, 11, 20, 83, 134, 16, 148, 200, 0, 177, 192, 8, 24, 0, 11, 32, 83, 134, 12, 148, 200, 0, 177, 128, 8, 20, 0, 11, 40, 83, 134, 16, 148, 136, 0, 177, 64, 7, 20, 3, 69, 56, 97, 9, 68, 128, 11, 16, 0, 7, 16, 0, 11, 60, 83, 70, 16, 148, 72, 16, 0, 9, 12, 0, 11, 0, 52, 5, 56, 97, 9, 60, 128, 11, 12, 0, 8, 12, 0, 5, 4, 52, 5, 56, 97, 9, 60, 128, 192, 9, 8, 0, 11, 16, 52, 5, 56, 97, 9, 52, 128, 11, 8, 0, 7, 8, 1, 131, 68, 83, 70, 16, 147, 72, 8, 0, 9, 4, 0, 11, 32, 52, 5, 56, 97, 9, 44, 128, 11, 4, 0, 8, 4, 0, 66, 32, 52, 5, 60, 97, 9, 40, 128, 64, 10, 0, 0, 11, 12, 34, 3, 64, 83, 134, 16, 146, 72, 0, 176, 0, 9, 0, 0, 11, 20, 33, 195, 68, 84, 6, 4, 146, 72, 0, 0, 11, 0, 1, 194, 32, 52, 5, 48, 96, 12, 4, 16, 12, 8, 145, 200, 0, 0, 15, 0, 178, 66, 32, 48, 133, 0, 208, 12, 4, 16, 76, 28, 82, 70, 12, 16, 12, 12, 145, 136, 0, 176, 15, 0, 178, 130, 32, 48, 5, 0, 193, 65, 0, 193, 197, 24, 96, 12, 16, 16, 70, 16, 145, 8, 0, 176, 13, 52, 33, 131, 0, 210, 1, 0, 193, 197, 12, 96, 12, 16, 16, 12, 12, 97, 9, 12, 128, 11, 56, 33, 67, 0, 194, 65, 0, 194, 5, 0, 97, 129, 20, 97, 9, 8, 128, 11, 64, 32, 131, 0, 195, 1, 0, 193, 69, 0, 193, 129, 32, 97, 9, 0, 128, 10, 72, 32, 13, 56, 16, 12, 12, 80, 12, 24, 16, 12, 36, 97, 9, 7, 72, 32, 12, 64, 16, 76, 32, 19, 6, 8, 144, 5, 68, 32, 12, 108, 19, 134, 4, 144, 6, 0, 164, 2, 108, 16, 12, 4, 83, 134, 6, 8, 163, 66, 0, 198, 193, 16, 83, 6, 6, 12, 162, 194, 0, 214, 193, 24, 82, 198, 12, 0, 65, 10, 36, 32, 12, 24, 16, 76, 0, 208, 12, 60, 16, 12, 32, 82, 70, 11, 8, 64, 202, 28, 32, 12, 24, 16, 12, 12, 32, 12, 56, 18, 133, 32, 96, 14, 0, 176, 132, 16, 161, 66, 24, 16, 12, 20, 32, 13, 0, 194, 193, 0, 194, 197, 24, 96, 11, 15, 0, 176, 196, 16, 160, 194, 0, 193, 1, 0, 192, 13, 32, 32, 12, 36, 16, 12, 56, 81, 6, 0, 176, 15, 0, 177, 68, 16, 160, 2, 0, 193, 1, 0, 194, 194, 0, 208, 12, 28, 16, 13, 64, 80, 134, 0, 176, 14, 0, 1, 196, 12, 161, 1, 0, 195, 66, 0, 48, 12, 20, 16, 13, 4, 52, 5, 4, 96, 0, 15, 0, 0, 11, 28, 64, 74, 0, 192, 193, 0, 196, 2, 4, 192, 65, 0, 192, 13, 16, 52, 5, 0, 0, 14, 0, 0, 11, 36, 64, 10, 4, 16, 12, 0, 164, 130, 0, 48, 77, 28, 51, 133, 0, 176, 0, 9, 4, 2, 132, 0, 160, 12, 12, 165, 2, 32, 51, 5, 4, 0, 9, 4, 0, 11, 44, 65, 10, 80, 34, 3, 40, 80, 11, 4, 0, 7, 8, 3, 4, 16, 165, 66, 32, 50, 5, 8, 0, 10, 8, 0, 11, 4, 114, 196, 16, 165, 66, 32, 49, 69, 0, 176, 128, 9, 8, 0, 11, 12, 114, 196, 16, 165, 2, 32, 49, 5, 12, 0, 10, 12, 0, 11, 12, 114, 196, 16, 165, 2, 32, 48, 133, 0, 176, 192, 9, 16, 0, 4, 12, 114, 196, 16, 165, 66, 32, 48, 5, 16, 0, 9, 20, 1, 71, 44, 64, 202, 88, 33, 67, 0, 80, 11, 16, 0, 9, 20, 0, 11, 20, 115, 4, 12, 165, 66, 16, 48, 11, 20, 0, 9, 24, 0, 11, 24, 114, 196, 16, 165, 66, 4, 48, 11, 24, 0, 8, 28, 0, 11, 28, 114, 132, 20, 165, 2, 0, 177, 192, 8, 32, 0, 11, 28, 114, 196, 16, 164, 130, 0, 178, 0, 8, 36, 0, 11, 32, 114, 196, 16, 163, 194, 0, 178, 64, 8, 36, 0, 11, 36, 114, 196, 16, 163, 2, 0, 178, 192, 7, 40, 2, 199, 44, 65, 10, 36, 32, 11, 48, 0, 7, 40, 3, 7, 44, 65, 10, 24, 32, 75, 52, 0, 7, 40, 3, 135, 44, 64, 202, 12, 32, 11, 64, 0, 7, 40, 4, 7, 40, 64, 202, 0, 32, 11, 72, 0, 7, 40, 2, 135, 4, 65, 7, 44, 64, 11, 84, 0, 10, 40, 0, 4, 24, 112, 4, 0, 177, 0, 8, 177, 68, 12, 182, 0, 6, 40, 0, 4, 16, 112, 4, 0, 187, 0]; +const WHATSAPP_PAL: [u16; 17] = [0, 1838, 65535, 193, 483, 42937, 1644, 645, 1419, 10064, 1161, 18291, 57341, 34711, 935, 51163, 28566]; +const WHATSAPP: [u8; 804] = [1, 252, 0, 1, 252, 0, 1, 252, 0, 13, 96, 0, 3, 0, 112, 10, 0, 128, 6, 12, 16, 6, 0, 128, 10, 0, 112, 4, 96, 0, 7, 84, 0, 4, 0, 163, 193, 0, 160, 4, 84, 0, 7, 76, 0, 7, 0, 100, 193, 0, 96, 7, 76, 0, 6, 68, 0, 7, 0, 102, 1, 0, 116, 64, 7, 60, 0, 3, 0, 134, 193, 0, 128, 3, 60, 0, 5, 56, 0, 7, 124, 16, 7, 56, 0, 5, 52, 0, 14, 132, 16, 10, 52, 0, 5, 48, 0, 10, 140, 16, 8, 48, 0, 5, 44, 0, 10, 148, 16, 8, 44, 0, 5, 40, 0, 14, 156, 16, 10, 40, 0, 5, 36, 0, 7, 164, 16, 7, 36, 0, 5, 32, 0, 3, 172, 16, 3, 32, 0, 10, 32, 0, 8, 32, 16, 16, 0, 192, 5, 0, 151, 129, 0, 98, 0, 10, 28, 0, 7, 28, 16, 9, 0, 192, 194, 0, 151, 129, 0, 113, 192, 8, 28, 0, 6, 28, 16, 15, 16, 32, 5, 124, 17, 192, 9, 24, 0, 7, 28, 16, 11, 24, 32, 9, 120, 16, 14, 24, 0, 8, 24, 0, 6, 24, 16, 9, 28, 32, 5, 124, 17, 128, 9, 20, 0, 4, 28, 16, 16, 32, 32, 9, 120, 16, 7, 20, 0, 9, 20, 0, 10, 28, 16, 13, 32, 32, 5, 120, 16, 8, 20, 0, 7, 20, 2, 1, 0, 210, 2, 0, 199, 193, 20, 0, 9, 16, 0, 3, 32, 16, 13, 32, 32, 12, 124, 16, 7, 16, 0, 9, 16, 0, 7, 32, 16, 13, 32, 32, 5, 124, 16, 14, 16, 0, 9, 16, 0, 10, 32, 16, 13, 32, 32, 9, 124, 16, 8, 16, 0, 9, 16, 0, 8, 32, 16, 9, 28, 32, 16, 128, 16, 6, 16, 0, 8, 16, 0, 6, 36, 16, 15, 24, 32, 9, 132, 17, 0, 8, 16, 2, 129, 0, 177, 130, 0, 152, 65, 0, 48, 192, 8, 16, 2, 193, 0, 241, 66, 0, 184, 65, 0, 48, 192, 8, 16, 2, 193, 0, 145, 66, 0, 88, 65, 0, 48, 192, 8, 16, 3, 1, 0, 177, 66, 0, 88, 1, 0, 48, 192, 8, 16, 0, 6, 48, 16, 12, 20, 32, 5, 124, 17, 0, 9, 16, 0, 8, 48, 16, 9, 0, 193, 66, 0, 87, 129, 16, 0, 12, 16, 0, 10, 52, 16, 9, 0, 193, 66, 0, 82, 129, 0, 148, 1, 0, 129, 0, 16, 16, 0, 7, 56, 16, 9, 0, 193, 66, 0, 82, 1, 0, 80, 2, 0, 240, 13, 0, 147, 65, 0, 161, 0, 16, 16, 0, 4, 60, 16, 9, 0, 193, 66, 0, 192, 11, 20, 16, 5, 16, 32, 5, 0, 146, 193, 0, 113, 0, 13, 20, 4, 1, 0, 145, 194, 0, 208, 193, 0, 81, 194, 0, 240, 9, 36, 16, 3, 16, 0, 13, 20, 0, 10, 64, 16, 5, 32, 32, 15, 0, 208, 15, 36, 32, 12, 32, 16, 8, 20, 0, 9, 20, 0, 4, 68, 16, 5, 84, 32, 11, 28, 16, 7, 20, 0, 9, 24, 0, 6, 68, 16, 9, 0, 196, 194, 0, 177, 193, 24, 0, 9, 24, 0, 7, 76, 16, 5, 72, 32, 9, 24, 16, 10, 24, 0, 9, 28, 5, 1, 0, 144, 5, 60, 32, 5, 28, 16, 3, 24, 0, 10, 28, 0, 7, 84, 16, 9, 0, 83, 2, 0, 81, 193, 0, 225, 192, 11, 32, 0, 8, 88, 16, 16, 0, 194, 2, 0, 192, 9, 28, 16, 6, 32, 0, 11, 32, 0, 4, 100, 16, 11, 0, 80, 12, 12, 32, 5, 36, 16, 4, 32, 0, 9, 32, 0, 4, 116, 16, 11, 1, 0, 9, 36, 16, 14, 36, 0, 5, 32, 0, 14, 164, 16, 8, 40, 0, 5, 32, 0, 8, 160, 16, 8, 44, 0, 4, 32, 10, 1, 0, 131, 0, 5, 28, 0, 4, 156, 16, 8, 52, 0, 5, 28, 0, 7, 152, 16, 14, 56, 0, 6, 28, 0, 8, 144, 16, 6, 0, 67, 192, 7, 28, 2, 1, 0, 96, 10, 100, 16, 14, 68, 0, 11, 24, 0, 3, 24, 16, 8, 0, 64, 128, 0, 229, 65, 0, 160, 3, 72, 0, 13, 24, 0, 7, 12, 16, 6, 0, 224, 3, 24, 0, 7, 0, 131, 193, 0, 128, 7, 84, 0, 16, 24, 0, 10, 4, 16, 8, 0, 67, 0, 0, 112, 14, 0, 128, 6, 24, 16, 8, 0, 160, 7, 0, 53, 192, 7, 24, 0, 8, 0, 224, 3, 76, 0, 195, 116, 0, 1, 252, 0, 1, 252, 0, 1, 252, 0, 1, 252, 0, 1, 252, 0, 1, 252, 0]; +const TELEGRAM_PAL: [u16; 6] = [0, 9434, 65535, 59262, 4749, 38492]; +const TELEGRAM: [u8; 728] = [5, 100, 0, 132, 20, 16, 132, 100, 0, 5, 84, 0, 4, 68, 16, 68, 80, 0, 5, 72, 0, 68, 88, 16, 4, 72, 0, 5, 64, 0, 4, 108, 16, 4, 64, 0, 5, 56, 0, 68, 116, 16, 68, 56, 0, 5, 52, 0, 4, 132, 16, 68, 48, 0, 5, 44, 0, 4, 148, 16, 4, 44, 0, 5, 40, 0, 4, 156, 16, 4, 40, 0, 5, 36, 0, 4, 164, 16, 4, 36, 0, 5, 32, 0, 4, 172, 16, 4, 32, 0, 5, 28, 0, 4, 180, 16, 4, 28, 0, 5, 24, 0, 4, 188, 16, 4, 24, 0, 5, 20, 0, 4, 196, 16, 4, 20, 0, 4, 20, 12, 193, 0, 65, 0, 5, 16, 0, 4, 204, 16, 4, 16, 0, 5, 12, 0, 4, 212, 16, 4, 12, 0, 5, 12, 0, 4, 212, 16, 4, 12, 0, 5, 8, 0, 4, 220, 16, 4, 8, 0, 6, 8, 10, 65, 8, 82, 193, 0, 64, 128, 10, 4, 0, 4, 152, 16, 69, 0, 48, 66, 0, 51, 1, 0, 64, 64, 9, 4, 9, 1, 4, 80, 3, 16, 32, 3, 48, 16, 4, 4, 0, 9, 4, 8, 65, 4, 80, 3, 28, 32, 5, 52, 16, 4, 0, 0, 10, 0, 0, 4, 124, 16, 5, 4, 50, 66, 0, 83, 65, 0, 64, 0, 9, 0, 7, 65, 4, 80, 3, 16, 32, 67, 20, 35, 193, 0, 0, 10, 0, 6, 193, 0, 80, 3, 24, 32, 131, 16, 32, 3, 60, 16, 0, 10, 0, 70, 1, 4, 80, 3, 24, 32, 195, 20, 32, 3, 60, 16, 4, 10, 0, 69, 65, 4, 80, 3, 32, 32, 195, 24, 32, 5, 60, 16, 4, 10, 0, 68, 193, 0, 80, 67, 32, 32, 195, 32, 32, 5, 60, 16, 4, 8, 0, 68, 1, 4, 80, 3, 40, 32, 195, 36, 36, 65, 8, 60, 16, 5, 4, 50, 130, 16, 50, 66, 0, 52, 65, 8, 48, 16, 5, 4, 51, 2, 16, 50, 130, 0, 52, 65, 7, 48, 16, 3, 48, 33, 67, 44, 32, 5, 68, 16, 8, 52, 16, 69, 0, 49, 194, 24, 51, 2, 0, 84, 65, 7, 64, 16, 5, 4, 48, 194, 24, 51, 66, 72, 16, 6, 76, 16, 5, 32, 51, 66, 0, 52, 129, 6, 0, 69, 1, 24, 51, 130, 0, 84, 129, 8, 0, 69, 1, 0, 81, 3, 60, 32, 5, 68, 16, 4, 7, 0, 69, 1, 0, 80, 195, 64, 36, 129, 0, 64, 8, 0, 69, 65, 0, 81, 3, 52, 32, 3, 72, 16, 4, 10, 0, 5, 65, 0, 80, 67, 8, 80, 3, 48, 32, 5, 72, 16, 0, 10, 0, 5, 129, 0, 80, 3, 16, 80, 3, 40, 32, 5, 72, 16, 0, 12, 0, 0, 4, 84, 16, 5, 0, 49, 133, 0, 49, 194, 0, 52, 129, 0, 64, 0, 13, 0, 0, 4, 84, 16, 5, 0, 49, 5, 8, 16, 5, 24, 32, 5, 72, 16, 4, 0, 0, 9, 4, 5, 129, 16, 81, 1, 0, 81, 66, 0, 84, 129, 4, 0, 12, 4, 0, 4, 84, 16, 197, 24, 16, 5, 0, 48, 130, 0, 52, 129, 0, 64, 64, 10, 8, 0, 4, 80, 16, 69, 40, 16, 3, 4, 32, 3, 72, 16, 128, 7, 8, 0, 4, 136, 16, 69, 72, 16, 4, 8, 0, 4, 12, 0, 4, 216, 16, 192, 5, 12, 0, 4, 212, 16, 4, 12, 0, 5, 16, 0, 4, 204, 16, 4, 16, 0, 4, 16, 0, 4, 204, 17, 64, 5, 20, 0, 4, 196, 16, 4, 20, 0, 5, 24, 0, 4, 188, 16, 4, 24, 0, 5, 28, 0, 4, 180, 16, 4, 28, 0, 5, 32, 0, 4, 172, 16, 4, 32, 0, 5, 36, 0, 4, 164, 16, 4, 36, 0, 5, 40, 0, 4, 156, 16, 4, 40, 0, 5, 44, 0, 4, 148, 16, 4, 44, 0, 5, 52, 0, 4, 136, 16, 4, 48, 0, 5, 56, 0, 4, 124, 16, 4, 56, 0, 5, 64, 0, 4, 108, 16, 4, 64, 0, 5, 72, 0, 4, 92, 16, 4, 72, 0, 5, 80, 0, 68, 68, 16, 68, 80, 0, 5, 92, 0, 196, 28, 16, 196, 92, 0]; + +const WHATSAPP_S_PAL: [u16; 16] = [0, 1838, 65535, 193, 677, 34711, 1128, 387, 22388, 838, 1580, 1322, 51163, 8016, 59390, 44986]; +const WHATSAPP_S: [u8; 565] = [1, 172, 0, 1, 172, 0, 13, 60, 0, 3, 0, 64, 6, 0, 176, 10, 4, 16, 10, 0, 176, 6, 0, 64, 3, 60, 0, 7, 52, 0, 4, 0, 178, 193, 0, 160, 4, 52, 0, 7, 44, 0, 4, 0, 163, 193, 0, 160, 4, 44, 0, 5, 40, 0, 6, 76, 16, 11, 40, 0, 7, 32, 0, 3, 0, 165, 65, 0, 160, 3, 32, 0, 6, 28, 0, 3, 0, 166, 1, 0, 113, 192, 6, 24, 0, 3, 0, 166, 129, 0, 49, 128, 5, 24, 0, 11, 108, 16, 10, 24, 0, 9, 20, 0, 6, 20, 16, 8, 0, 80, 13, 80, 16, 6, 20, 0, 9, 16, 0, 3, 20, 16, 12, 4, 32, 14, 84, 16, 7, 16, 0, 9, 16, 0, 6, 16, 16, 5, 12, 32, 5, 80, 16, 11, 16, 0, 8, 12, 0, 3, 16, 16, 13, 20, 37, 65, 0, 112, 192, 9, 12, 0, 6, 16, 16, 8, 20, 32, 5, 80, 16, 6, 12, 0, 8, 12, 0, 10, 16, 16, 8, 20, 32, 12, 84, 16, 192, 9, 8, 0, 3, 20, 16, 8, 20, 32, 12, 84, 16, 7, 8, 0, 9, 8, 0, 4, 20, 16, 8, 20, 32, 8, 84, 16, 4, 8, 0, 8, 8, 0, 9, 24, 17, 2, 0, 245, 129, 0, 96, 128, 9, 8, 0, 6, 24, 16, 5, 12, 32, 5, 88, 16, 6, 8, 0, 8, 8, 0, 6, 28, 16, 194, 0, 197, 129, 0, 96, 128, 9, 8, 0, 6, 28, 16, 8, 12, 32, 5, 84, 16, 6, 8, 0, 9, 8, 0, 9, 32, 16, 15, 12, 32, 5, 80, 16, 6, 8, 0, 9, 8, 0, 4, 36, 16, 12, 12, 32, 5, 76, 16, 9, 8, 0, 15, 8, 0, 3, 40, 16, 12, 12, 32, 5, 16, 16, 13, 0, 224, 12, 0, 80, 13, 32, 16, 4, 8, 0, 13, 12, 2, 193, 0, 192, 194, 0, 224, 13, 4, 16, 13, 16, 32, 15, 0, 209, 129, 12, 0, 12, 12, 0, 6, 40, 16, 8, 20, 32, 12, 0, 81, 130, 0, 225, 65, 0, 176, 192, 10, 12, 0, 4, 44, 16, 8, 0, 195, 66, 0, 209, 1, 0, 64, 192, 8, 16, 0, 10, 48, 16, 5, 48, 33, 1, 0, 161, 0, 10, 16, 0, 4, 52, 16, 13, 0, 82, 66, 0, 81, 1, 0, 65, 0, 11, 20, 0, 11, 56, 16, 13, 0, 193, 66, 0, 224, 8, 16, 16, 10, 20, 0, 11, 20, 0, 7, 68, 16, 8, 0, 80, 12, 0, 32, 5, 24, 16, 3, 20, 0, 5, 20, 0, 4, 112, 16, 4, 24, 0, 5, 20, 0, 6, 108, 16, 9, 28, 0, 4, 20, 6, 193, 0, 146, 0, 5, 16, 0, 3, 104, 16, 4, 36, 0, 8, 16, 0, 4, 20, 16, 10, 68, 16, 6, 0, 50, 128, 12, 16, 0, 6, 12, 16, 6, 0, 112, 0, 0, 48, 6, 52, 16, 11, 0, 51, 0, 15, 16, 0, 10, 0, 16, 10, 0, 144, 3, 16, 0, 3, 0, 64, 11, 28, 16, 11, 0, 144, 3, 56, 0, 9, 16, 0, 6, 0, 67, 0, 0, 112, 68, 0, 112, 3, 72, 0, 1, 172, 0, 1, 172, 0, 1, 172, 0, 1, 172, 0]; +const MESSENGER_S_PAL: [u16; 14] = [0, 17247, 49658, 59987, 53783, 31359, 64176, 65535, 39422, 25279, 43483, 22898, 33, 36127]; +const MESSENGER_S: [u8; 768] = [7, 40, 0, 12, 16, 2, 76, 16, 0, 12, 40, 0, 13, 36, 0, 12, 8, 0, 12, 4, 176, 3, 28, 96, 3, 4, 176, 12, 8, 0, 12, 36, 0, 10, 28, 0, 12, 4, 0, 12, 0, 176, 195, 48, 96, 11, 4, 194, 128, 9, 32, 0, 12, 0, 176, 4, 20, 51, 134, 0, 176, 12, 32, 0, 11, 20, 0, 12, 0, 0, 12, 0, 176, 132, 24, 51, 134, 0, 176, 12, 24, 0, 11, 16, 0, 12, 0, 0, 11, 0, 33, 68, 24, 51, 70, 0, 176, 12, 20, 0, 11, 12, 0, 12, 0, 0, 11, 8, 33, 68, 24, 51, 70, 0, 176, 12, 16, 0, 11, 8, 0, 12, 0, 0, 11, 16, 33, 132, 20, 51, 70, 0, 176, 12, 12, 0, 12, 4, 0, 12, 0, 0, 11, 0, 161, 66, 24, 65, 131, 48, 96, 11, 0, 192, 128, 11, 8, 0, 12, 8, 161, 194, 16, 65, 195, 44, 96, 11, 0, 0, 12, 0, 0, 12, 0, 192, 0, 0, 192, 11, 12, 161, 194, 20, 65, 131, 40, 96, 3, 0, 192, 64, 11, 0, 192, 0, 0, 192, 72, 16, 161, 130, 24, 65, 67, 40, 96, 12, 4, 0, 10, 4, 1, 8, 16, 161, 130, 20, 65, 131, 32, 96, 3, 0, 192, 0, 10, 0, 0, 11, 20, 129, 10, 24, 33, 132, 24, 49, 198, 0, 176, 0, 11, 0, 192, 11, 4, 81, 72, 16, 161, 130, 20, 65, 131, 24, 96, 3, 0, 192, 12, 0, 192, 8, 12, 81, 8, 16, 160, 2, 0, 161, 66, 20, 65, 67, 24, 96, 12, 15, 0, 177, 69, 20, 128, 138, 0, 128, 77, 0, 129, 2, 20, 64, 67, 4, 112, 13, 4, 49, 6, 0, 176, 14, 0, 177, 133, 20, 128, 10, 0, 208, 199, 0, 209, 2, 16, 64, 199, 0, 64, 195, 8, 96, 11, 9, 36, 81, 8, 24, 112, 8, 20, 32, 4, 16, 113, 131, 4, 96, 11, 44, 80, 72, 32, 112, 13, 0, 160, 130, 0, 209, 7, 4, 65, 131, 0, 96, 10, 4, 146, 133, 0, 210, 135, 4, 32, 13, 16, 112, 2, 12, 65, 67, 7, 8, 146, 5, 0, 132, 135, 0, 209, 68, 16, 48, 6, 16, 145, 133, 76, 112, 66, 24, 64, 131, 7, 20, 145, 5, 0, 132, 135, 16, 33, 68, 4, 48, 10, 28, 144, 133, 20, 112, 13, 0, 130, 135, 0, 208, 10, 16, 33, 132, 14, 0, 144, 1, 24, 144, 5, 0, 209, 7, 8, 80, 8, 0, 210, 7, 0, 32, 10, 20, 33, 68, 14, 0, 176, 65, 20, 144, 13, 12, 112, 13, 20, 80, 13, 24, 112, 13, 8, 161, 130, 8, 64, 11, 15, 0, 176, 193, 12, 144, 199, 0, 209, 197, 0, 128, 13, 12, 112, 13, 0, 129, 10, 24, 32, 4, 0, 176, 15, 0, 193, 1, 4, 144, 13, 8, 112, 13, 0, 146, 69, 0, 208, 71, 0, 208, 200, 12, 161, 130, 0, 192, 12, 0, 193, 129, 0, 144, 7, 0, 208, 201, 36, 81, 200, 16, 160, 194, 0, 160, 12, 10, 0, 0, 11, 28, 17, 137, 40, 81, 72, 16, 160, 130, 0, 176, 0, 9, 4, 2, 1, 28, 146, 133, 20, 128, 202, 0, 32, 10, 4, 0, 10, 4, 0, 11, 36, 17, 137, 44, 81, 72, 8, 160, 12, 0, 0, 12, 9, 0, 0, 76, 40, 17, 201, 40, 81, 72, 0, 160, 11, 8, 192, 12, 0, 0, 12, 0, 0, 12, 40, 17, 201, 44, 81, 8, 0, 176, 0, 0, 192, 0, 11, 4, 0, 12, 0, 0, 11, 48, 17, 137, 40, 80, 136, 0, 176, 76, 4, 0, 9, 8, 0, 12, 0, 0, 11, 48, 17, 137, 44, 80, 11, 16, 0, 11, 12, 0, 12, 0, 0, 11, 48, 17, 201, 32, 80, 11, 0, 0, 12, 12, 0, 7, 24, 0, 11, 52, 17, 137, 20, 80, 75, 24, 0, 11, 16, 0, 76, 0, 179, 129, 28, 144, 133, 0, 176, 12, 0, 0, 12, 20, 0, 12, 16, 0, 12, 0, 0, 11, 64, 17, 73, 0, 80, 11, 4, 192, 0, 0, 193, 128, 9, 16, 0, 12, 0, 0, 11, 68, 16, 201, 0, 176, 12, 44, 0, 12, 16, 0, 12, 0, 0, 11, 20, 16, 203, 20, 16, 137, 4, 176, 128, 4, 194, 64, 11, 16, 0, 12, 0, 0, 11, 16, 16, 12, 12, 2, 12, 12, 0, 12, 44, 0]; +const TELEGRAM_S_PAL: [u16; 6] = [0, 9434, 65535, 0, 4815, 38557]; +const TELEGRAM_S: [u8; 564] = [11, 36, 0, 67, 8, 0, 3, 12, 64, 193, 12, 64, 67, 0, 0, 131, 36, 0, 10, 32, 0, 3, 8, 0, 3, 0, 67, 129, 0, 64, 128, 0, 50, 0, 9, 28, 0, 3, 0, 0, 67, 76, 16, 67, 0, 0, 3, 28, 0, 11, 24, 0, 3, 0, 0, 3, 0, 69, 65, 0, 64, 3, 0, 0, 3, 24, 0, 9, 16, 0, 67, 0, 0, 4, 100, 16, 4, 0, 0, 67, 16, 0, 9, 12, 0, 67, 0, 0, 4, 108, 16, 4, 0, 0, 67, 12, 0, 9, 12, 0, 3, 0, 0, 4, 116, 16, 4, 0, 0, 67, 8, 0, 7, 8, 0, 3, 0, 0, 4, 124, 16, 4, 16, 0, 8, 4, 0, 3, 0, 0, 4, 132, 16, 4, 4, 48, 64, 5, 0, 0, 131, 140, 16, 131, 0, 0, 5, 8, 48, 4, 140, 16, 4, 8, 48, 7, 0, 48, 0, 0, 57, 65, 0, 48, 0, 0, 48, 6, 4, 7, 1, 4, 81, 193, 0, 64, 67, 8, 0, 0, 4, 104, 16, 5, 8, 34, 1, 0, 48, 0, 8, 0, 0, 4, 92, 16, 5, 20, 34, 1, 0, 64, 3, 7, 0, 53, 65, 0, 81, 194, 0, 82, 65, 0, 48, 7, 0, 68, 129, 4, 82, 66, 0, 82, 65, 0, 48, 6, 0, 68, 1, 4, 82, 194, 40, 16, 4, 6, 0, 67, 65, 4, 83, 130, 40, 16, 4, 6, 0, 66, 129, 4, 84, 2, 0, 82, 193, 5, 36, 16, 69, 72, 32, 5, 44, 16, 4, 32, 21, 66, 0, 82, 193, 4, 36, 16, 69, 72, 35, 1, 4, 48, 16, 5, 64, 35, 1, 6, 0, 67, 65, 0, 83, 66, 0, 83, 1, 7, 0, 67, 65, 0, 83, 66, 0, 82, 193, 0, 64, 5, 0, 67, 129, 52, 35, 1, 0, 64, 8, 0, 51, 129, 0, 80, 2, 8, 82, 2, 48, 16, 3, 8, 0, 51, 193, 0, 33, 5, 20, 32, 5, 48, 16, 3, 9, 0, 48, 4, 56, 16, 197, 8, 17, 2, 48, 16, 4, 0, 48, 10, 0, 0, 4, 56, 16, 133, 16, 16, 5, 8, 35, 1, 0, 64, 0, 10, 0, 48, 0, 0, 69, 129, 0, 80, 2, 0, 83, 1, 0, 0, 3, 7, 0, 48, 0, 0, 57, 65, 0, 64, 0, 0, 48, 5, 8, 48, 4, 140, 16, 4, 8, 48, 9, 0, 0, 3, 0, 0, 3, 140, 16, 3, 0, 0, 3, 0, 0, 8, 4, 0, 67, 0, 72, 65, 0, 64, 0, 0, 48, 64, 7, 16, 0, 4, 124, 16, 4, 0, 0, 3, 8, 0, 9, 8, 0, 67, 0, 0, 4, 116, 16, 4, 0, 0, 3, 12, 0, 9, 12, 0, 67, 0, 0, 4, 108, 16, 4, 0, 0, 67, 12, 0, 9, 16, 0, 67, 0, 0, 4, 100, 16, 4, 0, 0, 67, 16, 0, 10, 24, 0, 3, 0, 0, 3, 0, 69, 65, 4, 64, 0, 0, 49, 128, 11, 28, 0, 3, 0, 0, 3, 0, 68, 193, 0, 64, 3, 0, 0, 3, 28, 0, 9, 32, 0, 3, 8, 0, 68, 52, 16, 68, 8, 0, 3, 32, 0, 11, 36, 0, 131, 0, 0, 67, 8, 65, 65, 8, 64, 67, 0, 0, 131, 36, 0]; + +/// Draws icon `app` (1 WhatsApp, 2 Messenger, 3 Telegram) with its centre at (cx, cy), on a black background. +/// Returns false for any other app. +const INSTAGRAM_PAL: [u16; 37] = [0, 65535, 64810, 31256, 64105, 64520, 55792, 51636, 58712, 64328, 43414, 59980, 25176, 65338, 56339, 65010, 10375, 19127, 6211, 14865, 53773, 39273, 18596, 16619, 16552, 17012, 33138, 29007, 43911, 22852, 52038, 45453, 12450, 47559, 43717, 52264, 49642]; +const INSTAGRAM: [u8; 1545] = [12, 24, 0, 82, 5, 0, 23, 84, 196, 67, 1, 112, 16, 1, 128, 16, 1, 33, 128, 11, 20, 0, 80, 1, 48, 25, 1, 21, 12, 72, 48, 138, 5, 160, 80, 20, 0, 11, 16, 0, 16, 1, 48, 17, 88, 196, 67, 28, 160, 27, 1, 0, 18, 12, 0, 10, 12, 0, 16, 1, 48, 17, 84, 196, 67, 40, 160, 26, 5, 0, 128, 10, 8, 0, 16, 1, 48, 17, 80, 196, 67, 56, 160, 16, 1, 32, 64, 10, 4, 0, 16, 1, 48, 17, 76, 196, 67, 64, 160, 26, 1, 0, 64, 10, 0, 0, 16, 1, 48, 17, 72, 196, 131, 72, 160, 27, 1, 0, 0, 8, 1, 32, 16, 1, 20, 140, 68, 53, 74, 1, 0, 18, 9, 1, 32, 19, 60, 192, 131, 84, 128, 14, 68, 160, 26, 1, 0, 11, 1, 0, 25, 48, 192, 3, 0, 128, 13, 108, 16, 72, 52, 160, 26, 1, 128, 9, 1, 2, 204, 0, 48, 8, 132, 16, 8, 44, 160, 7, 1, 0, 9, 1, 113, 204, 12, 48, 8, 140, 16, 8, 28, 160, 199, 0, 160, 11, 20, 193, 67, 0, 209, 193, 8, 211, 200, 8, 209, 193, 0, 208, 202, 28, 112, 13, 0, 194, 67, 0, 129, 1, 0, 208, 8, 100, 160, 8, 0, 209, 1, 0, 128, 10, 36, 112, 9, 36, 48, 8, 16, 16, 8, 116, 160, 8, 16, 16, 8, 36, 112, 11, 32, 48, 10, 16, 20, 202, 32, 112, 10, 4, 112, 10, 0, 225, 1, 36, 112, 15, 16, 48, 202, 0, 128, 193, 0, 130, 138, 64, 112, 14, 0, 128, 14, 8, 112, 8, 12, 16, 14, 32, 112, 15, 0, 49, 202, 0, 208, 129, 0, 209, 74, 84, 112, 8, 8, 16, 8, 8, 112, 13, 8, 16, 13, 32, 112, 11, 32, 160, 193, 0, 128, 10, 104, 113, 1, 0, 224, 71, 0, 128, 193, 32, 112, 11, 28, 160, 7, 12, 22, 199, 0, 225, 1, 0, 128, 135, 12, 16, 14, 28, 112, 20, 20, 160, 71, 0, 224, 193, 52, 112, 14, 0, 128, 13, 12, 16, 13, 0, 128, 14, 12, 96, 7, 16, 16, 14, 8, 112, 193, 0, 225, 199, 21, 4, 161, 71, 0, 128, 129, 0, 210, 7, 8, 96, 14, 0, 210, 65, 0, 208, 14, 8, 96, 14, 8, 16, 8, 12, 112, 13, 8, 16, 8, 28, 112, 18, 28, 112, 8, 8, 16, 13, 8, 113, 198, 0, 131, 65, 0, 128, 198, 0, 224, 7, 0, 96, 199, 0, 208, 129, 0, 129, 199, 15, 28, 112, 8, 8, 16, 13, 32, 96, 11, 0, 131, 193, 0, 129, 70, 12, 112, 13, 8, 16, 8, 28, 112, 22, 24, 112, 6, 0, 128, 129, 0, 129, 198, 0, 176, 8, 20, 16, 8, 0, 224, 75, 0, 224, 8, 20, 16, 8, 20, 96, 135, 0, 208, 129, 0, 129, 199, 26, 8, 113, 6, 0, 128, 129, 0, 128, 11, 12, 96, 11, 0, 96, 11, 0, 225, 1, 0, 128, 6, 20, 176, 6, 0, 129, 1, 0, 225, 70, 0, 112, 6, 0, 128, 129, 0, 129, 199, 22, 24, 96, 11, 0, 128, 129, 0, 128, 11, 0, 97, 75, 0, 208, 193, 0, 224, 203, 16, 96, 11, 0, 224, 193, 0, 209, 198, 0, 128, 129, 0, 129, 199, 22, 24, 96, 11, 0, 128, 129, 0, 129, 75, 0, 64, 14, 12, 16, 8, 0, 65, 203, 4, 96, 11, 0, 128, 193, 0, 225, 134, 0, 128, 129, 0, 129, 199, 20, 12, 96, 203, 0, 128, 129, 0, 129, 132, 0, 128, 193, 40, 176, 6, 0, 176, 6, 12, 16, 8, 0, 177, 70, 0, 128, 129, 0, 129, 199, 22, 0, 97, 75, 0, 64, 8, 8, 16, 8, 24, 64, 13, 8, 16, 8, 8, 66, 11, 0, 96, 11, 0, 128, 129, 0, 209, 134, 0, 128, 129, 0, 129, 199, 18, 12, 176, 196, 0, 128, 129, 0, 129, 68, 0, 176, 193, 0, 225, 68, 28, 176, 14, 12, 17, 134, 0, 128, 129, 0, 129, 199, 20, 0, 177, 132, 0, 128, 129, 0, 129, 68, 0, 176, 193, 0, 177, 196, 24, 176, 193, 0, 96, 11, 16, 96, 8, 8, 16, 8, 0, 97, 135, 19, 28, 64, 8, 8, 16, 8, 20, 64, 11, 12, 16, 11, 36, 65, 11, 12, 16, 6, 0, 177, 6, 0, 128, 129, 0, 128, 6, 24, 112, 21, 28, 64, 8, 8, 16, 8, 20, 64, 11, 12, 16, 14, 44, 64, 75, 0, 224, 193, 0, 96, 11, 12, 96, 11, 0, 128, 129, 0, 128, 6, 24, 112, 20, 28, 64, 8, 8, 16, 8, 24, 64, 13, 8, 16, 15, 52, 64, 8, 8, 16, 13, 0, 177, 6, 0, 176, 8, 8, 16, 8, 0, 97, 135, 19, 28, 64, 8, 8, 16, 8, 24, 64, 8, 12, 19, 4, 0, 176, 193, 0, 128, 11, 16, 96, 11, 0, 128, 129, 0, 128, 70, 20, 112, 20, 28, 64, 8, 8, 16, 8, 24, 64, 11, 12, 16, 15, 44, 64, 8, 12, 16, 14, 8, 176, 134, 0, 176, 8, 8, 16, 8, 8, 97, 7, 20, 28, 64, 8, 8, 16, 8, 28, 64, 13, 12, 16, 15, 36, 64, 14, 12, 16, 13, 12, 176, 134, 0, 176, 8, 8, 16, 8, 12, 96, 199, 21, 28, 64, 15, 8, 16, 8, 28, 64, 5, 16, 16, 15, 28, 64, 8, 16, 16, 14, 0, 64, 203, 4, 96, 11, 0, 128, 129, 0, 128, 198, 12, 112, 27, 28, 64, 15, 8, 16, 13, 0, 64, 9, 16, 64, 9, 0, 64, 15, 16, 16, 13, 0, 240, 139, 0, 224, 15, 20, 16, 8, 4, 65, 11, 0, 96, 11, 0, 208, 129, 0, 129, 6, 8, 112, 20, 28, 64, 15, 8, 16, 13, 0, 65, 201, 0, 64, 8, 60, 16, 8, 12, 64, 203, 0, 96, 11, 0, 208, 129, 0, 128, 11, 16, 96, 71, 19, 20, 64, 9, 0, 64, 15, 8, 16, 13, 36, 144, 4, 0, 243, 65, 0, 241, 68, 16, 176, 13, 8, 16, 8, 0, 177, 6, 4, 112, 21, 20, 64, 9, 0, 64, 15, 8, 16, 13, 40, 144, 4, 0, 32, 13, 36, 16, 13, 0, 177, 132, 16, 176, 13, 8, 16, 8, 0, 177, 70, 0, 112, 21, 12, 64, 137, 0, 64, 15, 12, 16, 5, 48, 144, 2, 0, 240, 13, 12, 16, 13, 0, 240, 11, 36, 64, 203, 12, 16, 14, 0, 177, 70, 0, 112, 19, 4, 65, 73, 0, 32, 193, 0, 32, 9, 28, 81, 9, 0, 64, 73, 4, 80, 9, 52, 64, 139, 12, 16, 14, 0, 177, 70, 0, 112, 13, 28, 144, 5, 12, 16, 15, 0, 146, 133, 16, 148, 4, 0, 176, 4, 0, 128, 193, 32, 96, 14, 20, 144, 69, 0, 144, 13, 8, 16, 13, 52, 81, 137, 56, 64, 13, 8, 16, 13, 0, 177, 198, 13, 12, 145, 5, 0, 240, 193, 0, 243, 133, 16, 147, 68, 0, 224, 193, 0, 224, 11, 28, 96, 12, 8, 145, 133, 16, 16, 15, 56, 81, 9, 44, 64, 14, 16, 16, 6, 0, 177, 198, 13, 4, 145, 197, 0, 241, 1, 0, 243, 197, 16, 146, 4, 0, 225, 1, 0, 224, 11, 32, 96, 19, 0, 145, 197, 0, 32, 5, 0, 209, 1, 0, 208, 15, 8, 34, 5, 16, 145, 196, 0, 176, 15, 0, 209, 1, 0, 128, 75, 32, 96, 10, 0, 145, 133, 12, 32, 13, 28, 21, 77, 28, 16, 13, 12, 177, 198, 10, 0, 65, 69, 20, 32, 13, 140, 16, 8, 4, 64, 139, 24, 96, 7, 11, 1, 0, 197, 32, 32, 15, 128, 16, 13, 0, 224, 68, 16, 177, 70, 1, 0, 14, 1, 208, 30, 4, 82, 194, 0, 240, 13, 108, 16, 13, 0, 225, 4, 12, 177, 6, 1, 240, 22, 15, 2, 0, 33, 0, 32, 5, 56, 33, 15, 40, 209, 207, 0, 224, 11, 28, 64, 203, 16, 96, 31, 1, 32, 11, 1, 32, 16, 104, 33, 69, 12, 147, 132, 8, 176, 198, 1, 64, 16, 1, 32, 13, 0, 0, 22, 1, 87, 66, 16, 81, 9, 40, 64, 203, 4, 96, 20, 1, 80, 22, 0, 0, 12, 4, 0, 29, 2, 39, 2, 16, 80, 201, 44, 65, 11, 1, 64, 21, 1, 96, 64, 12, 8, 0, 29, 1, 198, 194, 20, 80, 201, 40, 64, 203, 1, 64, 21, 1, 96, 128, 11, 12, 0, 29, 1, 198, 194, 16, 80, 201, 40, 64, 203, 1, 80, 22, 12, 0, 11, 16, 0, 29, 1, 86, 130, 20, 80, 137, 48, 64, 11, 1, 80, 22, 16, 0, 15, 20, 0, 22, 1, 0, 28, 2, 53, 194, 20, 80, 137, 36, 64, 11, 2, 64, 21, 1, 0, 22, 20, 0, 17, 24, 0, 18, 2, 0, 29, 1, 0, 5, 24, 32, 79, 52, 33, 5, 12, 145, 132, 4, 176, 16, 1, 96, 82, 24, 0]; +const INSTAGRAM_S_PAL: [u16; 18] = [0, 65535, 31256, 62058, 47572, 64521, 63067, 10375, 53777, 65068, 39286, 64360, 23289, 64715, 57869, 65272, 54067, 60434]; +const INSTAGRAM_S: [u8; 946] = [6, 24, 115, 12, 52, 32, 74, 0, 193, 135, 5, 16, 115, 76, 52, 33, 74, 16, 112, 5, 8, 115, 76, 52, 34, 74, 8, 112, 7, 4, 115, 76, 48, 34, 138, 0, 64, 10, 4, 112, 6, 4, 114, 204, 44, 35, 138, 0, 64, 71, 6, 0, 114, 140, 32, 36, 10, 16, 64, 7, 11, 0, 113, 140, 0, 32, 12, 0, 32, 70, 68, 16, 70, 8, 161, 132, 0, 112, 7, 20, 192, 130, 1, 5, 193, 1, 1, 196, 0, 160, 10, 0, 192, 2, 0, 193, 2, 0, 97, 1, 60, 97, 1, 0, 97, 196, 12, 24, 32, 16, 8, 16, 6, 1, 3, 74, 12, 64, 16, 0, 96, 129, 1, 1, 132, 9, 20, 32, 10, 8, 16, 6, 32, 163, 4, 0, 96, 129, 24, 64, 15, 4, 32, 202, 0, 96, 65, 0, 97, 10, 52, 64, 16, 0, 96, 17, 4, 64, 6, 4, 16, 17, 20, 64, 14, 20, 160, 6, 4, 16, 16, 0, 164, 4, 1, 0, 129, 1, 16, 4, 1, 0, 65, 0, 97, 68, 15, 20, 160, 129, 36, 64, 8, 13, 0, 8, 0, 64, 72, 1, 0, 129, 0, 96, 4, 0, 128, 129, 20, 64, 16, 4, 160, 196, 4, 16, 6, 12, 65, 8, 0, 97, 65, 0, 96, 136, 0, 96, 65, 1, 0, 68, 8, 17, 68, 16, 16, 64, 16, 4, 16, 6, 24, 128, 17, 36, 16, 17, 4, 128, 80, 4, 128, 4, 0, 96, 65, 1, 1, 4, 18, 8, 64, 8, 0, 64, 16, 4, 16, 6, 16, 128, 14, 1, 16, 193, 12, 96, 193, 1, 17, 72, 0, 96, 65, 1, 1, 4, 20, 16, 128, 16, 4, 16, 6, 0, 224, 136, 0, 224, 8, 8, 16, 6, 1, 16, 206, 1, 16, 6, 8, 17, 72, 0, 96, 65, 1, 1, 4, 26, 12, 128, 14, 1, 16, 65, 0, 96, 14, 12, 48, 6, 4, 16, 6, 0, 48, 14, 0, 48, 14, 4, 128, 14, 0, 128, 6, 4, 16, 6, 0, 224, 200, 0, 96, 65, 1, 1, 4, 19, 12, 128, 14, 1, 16, 65, 0, 97, 3, 8, 16, 17, 16, 48, 14, 0, 128, 14, 1, 16, 129, 16, 128, 6, 4, 16, 16, 16, 64, 19, 4, 224, 131, 1, 16, 65, 0, 96, 195, 1, 16, 65, 0, 97, 195, 4, 224, 6, 4, 16, 17, 12, 128, 6, 4, 16, 16, 16, 64, 20, 16, 48, 17, 4, 16, 6, 12, 48, 17, 4, 16, 15, 32, 48, 14, 0, 96, 65, 1, 16, 14, 8, 128, 6, 4, 16, 16, 4, 128, 132, 19, 16, 48, 17, 4, 16, 15, 12, 48, 17, 4, 16, 15, 36, 48, 6, 4, 16, 17, 0, 224, 136, 0, 96, 65, 1, 0, 136, 4, 64, 20, 16, 48, 17, 4, 16, 15, 12, 48, 13, 4, 16, 6, 36, 48, 6, 4, 16, 17, 0, 224, 72, 0, 224, 6, 4, 16, 16, 8, 128, 68, 19, 16, 48, 17, 4, 16, 15, 16, 48, 129, 0, 209, 195, 1, 16, 129, 0, 128, 14, 4, 128, 14, 0, 96, 65, 1, 0, 200, 0, 64, 21, 16, 48, 13, 4, 16, 15, 16, 48, 15, 4, 16, 6, 28, 48, 6, 4, 16, 6, 0, 224, 3, 0, 224, 8, 0, 224, 6, 4, 16, 16, 16, 128, 19, 16, 48, 13, 4, 16, 15, 16, 48, 11, 8, 16, 6, 0, 80, 195, 1, 16, 6, 8, 16, 131, 8, 224, 6, 4, 16, 16, 16, 128, 19, 16, 48, 13, 4, 16, 15, 0, 48, 203, 0, 48, 13, 12, 16, 143, 0, 96, 193, 1, 16, 195, 4, 224, 6, 4, 16, 16, 16, 128, 15, 16, 48, 5, 4, 16, 15, 20, 176, 3, 0, 210, 65, 1, 17, 67, 0, 224, 6, 4, 16, 16, 16, 128, 15, 8, 48, 11, 0, 48, 5, 8, 17, 203, 0, 80, 15, 20, 16, 15, 32, 48, 6, 4, 16, 16, 16, 128, 13, 4, 48, 139, 0, 80, 129, 28, 80, 139, 0, 208, 9, 4, 210, 67, 0, 128, 129, 20, 128, 12, 20, 176, 15, 4, 16, 9, 32, 80, 75, 48, 48, 17, 4, 16, 6, 0, 225, 8, 14, 8, 176, 69, 0, 176, 9, 4, 16, 15, 36, 80, 203, 36, 48, 6, 4, 16, 17, 0, 225, 8, 13, 4, 176, 197, 0, 208, 129, 0, 242, 133, 8, 177, 195, 0, 96, 129, 0, 128, 14, 16, 128, 16, 0, 177, 69, 0, 144, 129, 0, 240, 9, 4, 209, 69, 12, 177, 67, 1, 16, 6, 8, 16, 17, 0, 225, 72, 13, 0, 177, 5, 0, 208, 5, 0, 241, 65, 52, 240, 6, 16, 16, 17, 4, 48, 14, 16, 128, 9, 0, 48, 197, 12, 208, 9, 92, 16, 17, 8, 48, 78, 12, 128, 12, 0, 112, 69, 24, 208, 9, 4, 244, 65, 0, 240, 17, 16, 48, 78, 8, 128, 7, 11, 0, 112, 5, 20, 212, 9, 8, 208, 5, 0, 178, 3, 4, 224, 72, 0, 112, 10, 4, 112, 205, 36, 144, 205, 16, 80, 139, 40, 48, 78, 0, 128, 71, 13, 4, 112, 3, 0, 144, 13, 48, 145, 13, 12, 80, 75, 36, 48, 14, 0, 128, 14, 4, 112, 9, 8, 112, 11, 56, 144, 205, 12, 80, 75, 40, 48, 14, 8, 112, 9, 16, 112, 13, 52, 144, 141, 12, 80, 139, 28, 48, 14, 16, 112, 10, 24, 112, 5, 0, 210, 137, 12, 208, 197, 4, 177, 67, 0, 225, 135]; +const X_PAL: [u16; 8] = [0, 10566, 65535, 54970, 4291, 25356, 35954, 48599]; +const X: [u8; 907] = [5, 100, 0, 4, 36, 16, 4, 100, 0, 5, 84, 0, 4, 68, 16, 4, 84, 0, 5, 72, 0, 4, 92, 16, 4, 72, 0, 5, 64, 0, 4, 108, 16, 4, 64, 0, 3, 60, 7, 193, 60, 0, 3, 52, 8, 193, 52, 0, 3, 48, 9, 65, 48, 0, 5, 40, 0, 4, 156, 16, 4, 40, 0, 3, 36, 10, 193, 36, 0, 3, 32, 11, 65, 32, 0, 3, 28, 11, 193, 28, 0, 5, 24, 0, 4, 188, 16, 4, 24, 0, 3, 24, 12, 65, 24, 0, 3, 20, 12, 193, 20, 0, 3, 16, 13, 65, 16, 0, 10, 16, 2, 129, 0, 113, 195, 0, 100, 65, 0, 112, 67, 44, 17, 0, 11, 12, 2, 193, 0, 82, 2, 0, 83, 193, 0, 48, 66, 0, 99, 1, 12, 0, 19, 8, 0, 4, 44, 16, 4, 0, 96, 66, 0, 96, 133, 0, 112, 2, 0, 51, 129, 0, 112, 66, 0, 96, 4, 48, 16, 4, 8, 0, 16, 8, 3, 129, 0, 48, 2, 0, 112, 4, 8, 16, 3, 0, 32, 7, 48, 16, 6, 4, 32, 7, 60, 16, 128, 17, 4, 0, 4, 56, 16, 5, 4, 32, 6, 8, 16, 5, 4, 32, 5, 40, 16, 5, 4, 32, 3, 64, 16, 4, 4, 0, 13, 4, 4, 1, 0, 96, 66, 12, 16, 7, 4, 34, 65, 0, 80, 66, 0, 52, 129, 4, 0, 13, 4, 4, 65, 0, 48, 2, 0, 112, 193, 0, 48, 2, 0, 114, 1, 8, 36, 193, 4, 0, 16, 0, 0, 4, 72, 16, 66, 0, 96, 129, 0, 80, 66, 0, 81, 129, 0, 48, 66, 0, 84, 193, 0, 64, 0, 13, 0, 4, 193, 0, 96, 66, 12, 16, 6, 4, 33, 65, 0, 112, 66, 0, 101, 65, 0, 0, 15, 0, 5, 1, 0, 112, 2, 0, 48, 193, 0, 48, 2, 0, 112, 193, 0, 112, 66, 0, 101, 129, 0, 0, 14, 0, 5, 65, 4, 32, 6, 8, 16, 5, 4, 32, 6, 4, 16, 6, 4, 32, 7, 92, 16, 0, 14, 0, 69, 65, 0, 96, 66, 0, 80, 129, 0, 96, 66, 0, 16, 5, 4, 32, 3, 96, 16, 4, 10, 92, 16, 7, 0, 32, 3, 12, 16, 3, 0, 32, 3, 8, 38, 129, 7, 96, 16, 66, 0, 96, 193, 12, 32, 5, 104, 16, 10, 96, 16, 5, 4, 32, 5, 8, 16, 6, 4, 32, 6, 0, 70, 129, 9, 100, 16, 7, 0, 32, 3, 12, 16, 7, 0, 32, 7, 108, 16, 7, 104, 16, 66, 0, 96, 193, 4, 32, 6, 104, 16, 9, 104, 16, 5, 4, 32, 5, 8, 16, 6, 4, 32, 5, 100, 16, 10, 104, 16, 4, 0, 112, 2, 0, 48, 193, 0, 112, 2, 0, 54, 65, 7, 108, 16, 130, 0, 112, 193, 4, 32, 6, 96, 16, 9, 104, 16, 3, 12, 32, 5, 8, 16, 5, 4, 32, 5, 92, 16, 11, 100, 16, 3, 4, 32, 5, 0, 96, 66, 12, 16, 7, 0, 32, 3, 92, 16, 15, 0, 69, 193, 0, 112, 66, 0, 96, 4, 0, 16, 3, 0, 32, 7, 12, 16, 66, 0, 101, 65, 0, 64, 15, 0, 5, 129, 0, 96, 66, 0, 112, 129, 0, 80, 66, 0, 80, 129, 0, 80, 66, 0, 85, 1, 0, 0, 14, 0, 5, 65, 0, 96, 66, 0, 49, 1, 0, 96, 66, 12, 16, 7, 0, 32, 3, 80, 16, 0, 15, 0, 5, 1, 0, 80, 66, 0, 49, 129, 0, 48, 2, 0, 112, 193, 0, 48, 2, 0, 116, 193, 0, 0, 15, 0, 0, 4, 76, 16, 130, 28, 16, 5, 4, 32, 6, 8, 16, 5, 4, 32, 5, 68, 16, 4, 0, 0, 13, 4, 4, 129, 0, 48, 66, 0, 82, 1, 0, 96, 66, 12, 16, 6, 4, 36, 65, 4, 0, 15, 4, 4, 65, 0, 112, 66, 0, 98, 129, 0, 48, 2, 0, 112, 193, 0, 48, 2, 0, 116, 1, 4, 0, 16, 4, 0, 4, 60, 16, 7, 4, 32, 6, 48, 16, 66, 0, 96, 129, 0, 80, 66, 0, 83, 129, 0, 64, 64, 16, 8, 3, 129, 0, 96, 66, 0, 115, 65, 0, 96, 66, 0, 16, 4, 0, 16, 0, 0, 96, 66, 56, 16, 128, 17, 8, 0, 4, 44, 16, 4, 0, 80, 66, 0, 51, 193, 0, 112, 2, 0, 48, 197, 4, 32, 7, 48, 16, 4, 8, 0, 10, 12, 2, 193, 0, 80, 66, 0, 52, 65, 32, 32, 6, 44, 16, 192, 10, 16, 2, 129, 0, 112, 67, 0, 84, 65, 0, 82, 3, 40, 17, 0, 3, 16, 13, 65, 16, 0, 3, 20, 12, 193, 20, 0, 3, 24, 12, 65, 24, 0, 5, 24, 0, 4, 188, 16, 4, 24, 0, 3, 28, 11, 193, 28, 0, 3, 32, 11, 65, 32, 0, 3, 36, 10, 193, 36, 0, 5, 40, 0, 4, 156, 16, 4, 40, 0, 3, 48, 9, 65, 48, 0, 3, 52, 8, 193, 52, 0, 3, 60, 7, 193, 60, 0, 5, 64, 0, 4, 108, 16, 4, 64, 0, 5, 72, 0, 4, 92, 16, 4, 72, 0, 5, 84, 0, 4, 68, 16, 4, 84, 0, 5, 100, 0, 4, 36, 16, 4, 100, 0]; +const X_S_PAL: [u16; 8] = [0, 10566, 65535, 42260, 19018, 33808, 59164, 50712]; +const X_S: [u8; 582] = [3, 64, 2, 65, 64, 0, 3, 52, 3, 193, 52, 0, 3, 44, 4, 193, 44, 0, 3, 36, 5, 193, 36, 0, 3, 32, 6, 65, 32, 0, 3, 28, 6, 193, 28, 0, 3, 24, 7, 65, 24, 0, 3, 20, 7, 193, 20, 0, 3, 16, 8, 65, 16, 0, 3, 12, 8, 193, 12, 0, 11, 8, 1, 193, 0, 81, 3, 0, 82, 193, 0, 80, 3, 0, 65, 193, 8, 0, 13, 8, 1, 193, 0, 80, 66, 4, 96, 66, 0, 66, 65, 0, 80, 2, 0, 114, 1, 8, 0, 13, 4, 2, 65, 0, 112, 2, 0, 64, 65, 4, 98, 1, 0, 64, 2, 0, 98, 129, 4, 0, 15, 4, 2, 129, 0, 32, 7, 4, 16, 4, 0, 32, 3, 24, 16, 4, 0, 32, 6, 0, 66, 129, 4, 0, 15, 0, 2, 193, 0, 80, 2, 0, 80, 65, 0, 48, 2, 0, 65, 65, 0, 96, 2, 0, 67, 1, 0, 0, 13, 0, 3, 1, 0, 48, 2, 0, 64, 65, 4, 97, 1, 0, 112, 2, 0, 83, 65, 0, 0, 14, 0, 3, 65, 0, 96, 7, 4, 16, 4, 0, 32, 3, 8, 16, 3, 0, 32, 5, 56, 16, 0, 13, 56, 16, 4, 0, 32, 5, 4, 16, 3, 0, 32, 4, 0, 0, 3, 0, 32, 3, 64, 16, 10, 60, 16, 3, 0, 32, 4, 4, 16, 70, 0, 80, 2, 0, 116, 65, 7, 64, 16, 70, 4, 16, 4, 4, 32, 6, 72, 16, 9, 64, 16, 4, 0, 32, 3, 4, 16, 5, 0, 32, 5, 72, 16, 8, 68, 16, 3, 0, 32, 4, 4, 16, 7, 0, 100, 129, 8, 72, 16, 7, 0, 96, 65, 0, 64, 2, 0, 116, 65, 9, 72, 16, 3, 0, 32, 3, 4, 16, 5, 0, 32, 5, 64, 16, 10, 68, 16, 5, 0, 32, 6, 0, 32, 5, 4, 16, 7, 0, 36, 1, 12, 64, 16, 5, 0, 32, 7, 0, 16, 7, 0, 96, 65, 0, 64, 2, 0, 115, 193, 13, 60, 16, 4, 0, 32, 6, 4, 16, 4, 0, 32, 3, 4, 16, 5, 0, 32, 5, 56, 16, 16, 0, 3, 65, 0, 64, 6, 0, 32, 4, 8, 16, 5, 0, 32, 5, 4, 16, 7, 0, 32, 4, 48, 16, 0, 13, 0, 3, 65, 0, 96, 2, 0, 65, 1, 0, 112, 2, 8, 16, 2, 0, 115, 1, 0, 0, 15, 0, 3, 1, 0, 112, 2, 0, 81, 65, 0, 64, 2, 0, 112, 65, 0, 80, 2, 0, 82, 193, 0, 0, 15, 4, 2, 129, 0, 48, 2, 0, 49, 193, 0, 80, 2, 0, 80, 65, 0, 48, 2, 0, 66, 65, 4, 0, 14, 4, 2, 65, 0, 80, 2, 0, 114, 65, 0, 112, 2, 0, 64, 65, 0, 96, 7, 36, 16, 64, 12, 8, 1, 193, 0, 80, 2, 0, 114, 193, 4, 32, 70, 4, 32, 3, 28, 16, 128, 9, 8, 1, 193, 4, 48, 4, 44, 16, 4, 20, 49, 193, 8, 0, 3, 12, 8, 193, 12, 0, 3, 16, 8, 65, 16, 0, 3, 20, 7, 193, 20, 0, 3, 24, 7, 65, 24, 0, 3, 28, 6, 193, 28, 0, 3, 32, 6, 65, 32, 0, 3, 36, 5, 193, 36, 0, 3, 44, 4, 193, 44, 0, 3, 52, 3, 193, 52, 0, 3, 64, 2, 65, 64, 0]; +const DISCORD_PAL: [u16; 10] = [0, 23358, 65535, 59231, 44447, 2148, 6377, 17049, 12787, 10638]; +const DISCORD: [u8; 1030] = [11, 84, 0, 69, 4, 96, 9, 4, 113, 65, 4, 112, 9, 4, 96, 69, 84, 0, 11, 72, 0, 69, 4, 96, 8, 0, 115, 65, 0, 112, 8, 4, 96, 69, 72, 0, 11, 64, 0, 5, 4, 96, 8, 0, 116, 193, 0, 112, 8, 4, 96, 5, 64, 0, 9, 56, 0, 5, 4, 96, 7, 100, 16, 7, 4, 96, 5, 56, 0, 7, 52, 0, 70, 0, 119, 65, 0, 112, 70, 52, 0, 9, 44, 0, 5, 0, 96, 8, 132, 16, 8, 0, 96, 5, 44, 0, 9, 40, 0, 5, 0, 96, 7, 140, 16, 7, 0, 96, 5, 40, 0, 7, 36, 0, 5, 0, 105, 193, 0, 96, 5, 36, 0, 7, 32, 0, 5, 0, 106, 65, 0, 96, 5, 32, 0, 7, 28, 0, 5, 0, 106, 193, 0, 96, 5, 28, 0, 7, 24, 0, 5, 0, 107, 65, 0, 96, 5, 24, 0, 7, 20, 0, 5, 0, 107, 193, 0, 96, 5, 20, 0, 7, 16, 0, 5, 0, 108, 65, 0, 96, 5, 16, 0, 7, 16, 0, 6, 0, 124, 65, 0, 112, 6, 16, 0, 7, 12, 0, 6, 0, 140, 193, 0, 128, 6, 12, 0, 7, 8, 0, 5, 0, 109, 65, 0, 96, 5, 8, 0, 11, 8, 0, 6, 0, 116, 193, 0, 66, 193, 0, 68, 193, 0, 112, 6, 8, 0, 17, 4, 0, 5, 0, 100, 65, 0, 64, 3, 4, 32, 3, 36, 16, 3, 4, 32, 3, 0, 68, 65, 0, 96, 5, 4, 0, 15, 4, 0, 6, 0, 115, 129, 0, 64, 3, 20, 34, 68, 20, 32, 3, 0, 67, 129, 0, 112, 6, 4, 0, 11, 0, 0, 5, 0, 99, 129, 0, 54, 66, 0, 51, 129, 0, 96, 5, 0, 0, 11, 0, 0, 5, 0, 131, 65, 0, 54, 194, 0, 51, 65, 0, 128, 5, 0, 0, 11, 0, 0, 6, 0, 115, 1, 0, 71, 66, 0, 67, 1, 0, 112, 6, 0, 0, 9, 0, 80, 6, 52, 16, 3, 116, 32, 3, 52, 16, 6, 0, 80, 9, 0, 80, 8, 48, 16, 4, 124, 32, 4, 48, 16, 8, 0, 80, 9, 0, 96, 7, 48, 16, 3, 124, 32, 3, 48, 16, 7, 0, 96, 5, 0, 99, 65, 132, 35, 65, 0, 96, 7, 0, 147, 1, 0, 56, 66, 0, 67, 1, 0, 144, 5, 0, 115, 1, 140, 35, 1, 0, 112, 7, 0, 114, 193, 0, 72, 194, 0, 66, 193, 0, 112, 11, 48, 16, 4, 32, 32, 3, 8, 66, 66, 8, 64, 3, 32, 32, 4, 48, 16, 11, 48, 16, 3, 28, 32, 3, 16, 17, 194, 16, 16, 3, 28, 32, 3, 48, 16, 9, 48, 18, 2, 20, 16, 4, 20, 32, 4, 20, 18, 2, 48, 16, 11, 44, 16, 4, 28, 32, 3, 24, 17, 66, 24, 16, 3, 28, 32, 4, 44, 16, 13, 44, 16, 4, 28, 32, 3, 24, 16, 3, 12, 32, 3, 24, 16, 3, 28, 32, 4, 44, 16, 11, 44, 16, 4, 28, 32, 3, 24, 17, 66, 24, 16, 3, 28, 32, 4, 44, 16, 14, 0, 114, 129, 0, 50, 2, 0, 65, 1, 0, 65, 66, 0, 65, 65, 32, 32, 3, 40, 16, 7, 13, 0, 114, 129, 0, 50, 2, 0, 49, 1, 28, 33, 1, 0, 50, 2, 0, 50, 129, 0, 112, 11, 0, 146, 129, 0, 50, 130, 8, 66, 66, 8, 66, 130, 0, 50, 129, 0, 144, 7, 0, 98, 129, 0, 57, 66, 0, 50, 129, 0, 96, 9, 0, 96, 7, 36, 16, 3, 148, 32, 3, 36, 16, 7, 0, 96, 9, 0, 80, 8, 36, 16, 3, 148, 32, 3, 36, 16, 8, 0, 80, 15, 0, 80, 6, 36, 16, 3, 28, 32, 3, 0, 68, 66, 0, 64, 3, 28, 32, 3, 36, 16, 6, 0, 80, 21, 0, 0, 6, 0, 114, 65, 0, 49, 130, 0, 48, 65, 0, 64, 3, 44, 32, 3, 0, 64, 65, 0, 49, 130, 0, 50, 65, 0, 112, 6, 0, 0, 19, 0, 0, 5, 0, 130, 129, 0, 49, 194, 0, 48, 129, 8, 64, 195, 8, 64, 129, 0, 49, 194, 0, 50, 129, 0, 128, 5, 0, 0, 13, 0, 0, 5, 0, 99, 1, 0, 49, 130, 60, 17, 130, 0, 51, 1, 0, 96, 5, 0, 0, 17, 4, 0, 6, 0, 115, 1, 0, 64, 3, 12, 32, 4, 60, 16, 4, 12, 32, 3, 0, 67, 1, 0, 112, 6, 4, 0, 15, 4, 0, 5, 0, 99, 193, 0, 64, 2, 0, 52, 65, 0, 48, 2, 4, 67, 129, 0, 96, 5, 4, 0, 7, 8, 0, 6, 0, 125, 65, 0, 112, 6, 8, 0, 7, 8, 0, 5, 0, 109, 65, 0, 96, 5, 8, 0, 7, 12, 0, 6, 0, 140, 193, 0, 128, 6, 12, 0, 7, 16, 0, 6, 0, 124, 65, 0, 112, 6, 16, 0, 7, 16, 0, 5, 0, 108, 65, 0, 96, 5, 16, 0, 7, 20, 0, 5, 0, 107, 193, 0, 96, 5, 20, 0, 7, 24, 0, 5, 0, 107, 65, 0, 96, 5, 24, 0, 7, 28, 0, 5, 0, 106, 193, 0, 96, 5, 28, 0, 7, 32, 0, 5, 0, 106, 65, 0, 96, 5, 32, 0, 7, 36, 0, 5, 0, 105, 193, 0, 96, 5, 36, 0, 9, 40, 0, 5, 0, 96, 7, 140, 16, 7, 0, 96, 5, 40, 0, 9, 44, 0, 5, 0, 96, 8, 132, 16, 8, 0, 96, 5, 44, 0, 7, 52, 0, 70, 0, 119, 65, 0, 112, 70, 52, 0, 9, 56, 0, 5, 4, 96, 7, 100, 16, 7, 4, 96, 5, 56, 0, 11, 64, 0, 5, 4, 96, 8, 0, 116, 193, 0, 112, 8, 4, 96, 5, 64, 0, 11, 72, 0, 69, 4, 96, 8, 0, 115, 65, 0, 112, 8, 4, 96, 69, 72, 0, 11, 84, 0, 69, 4, 96, 9, 4, 113, 65, 4, 112, 9, 4, 96, 69, 84, 0]; +const DISCORD_S_PAL: [u16; 11] = [0, 23358, 65535, 38142, 2115, 48703, 12820, 6409, 8557, 17049, 4262]; +const DISCORD_S: [u8; 684] = [13, 48, 0, 4, 0, 112, 4, 4, 128, 73, 12, 16, 73, 4, 128, 4, 0, 112, 4, 48, 0, 11, 40, 0, 4, 4, 112, 6, 0, 146, 193, 0, 144, 6, 4, 112, 4, 40, 0, 9, 32, 0, 4, 4, 112, 6, 68, 16, 6, 4, 112, 4, 32, 0, 7, 28, 0, 68, 0, 101, 65, 0, 96, 68, 28, 0, 9, 24, 0, 10, 0, 112, 9, 92, 16, 9, 0, 112, 10, 24, 0, 7, 20, 0, 10, 0, 118, 193, 0, 112, 10, 20, 0, 7, 16, 0, 10, 0, 119, 65, 0, 112, 10, 16, 0, 7, 12, 0, 10, 0, 119, 193, 0, 112, 10, 12, 0, 7, 8, 0, 4, 0, 120, 65, 0, 112, 4, 8, 0, 7, 4, 0, 68, 0, 152, 65, 0, 144, 68, 4, 0, 7, 4, 0, 7, 0, 104, 193, 0, 96, 7, 4, 0, 13, 0, 0, 4, 0, 115, 1, 0, 48, 5, 28, 16, 5, 0, 51, 1, 0, 112, 4, 0, 0, 19, 0, 0, 7, 0, 98, 65, 0, 48, 5, 8, 32, 5, 0, 16, 195, 0, 16, 5, 8, 32, 5, 0, 50, 65, 0, 96, 7, 0, 0, 7, 4, 66, 65, 0, 84, 66, 0, 82, 65, 4, 64, 9, 0, 112, 6, 32, 16, 3, 76, 32, 3, 32, 16, 6, 0, 112, 7, 0, 64, 9, 32, 21, 66, 32, 16, 9, 0, 64, 7, 0, 130, 1, 0, 53, 66, 0, 50, 1, 0, 128, 5, 0, 130, 1, 92, 34, 1, 0, 128, 7, 0, 145, 193, 0, 53, 194, 0, 49, 193, 0, 144, 7, 0, 145, 193, 0, 85, 194, 0, 81, 193, 0, 144, 11, 32, 17, 130, 0, 48, 1, 0, 49, 66, 0, 48, 1, 0, 49, 130, 32, 16, 11, 32, 17, 66, 0, 48, 129, 0, 48, 194, 0, 48, 129, 0, 49, 66, 32, 16, 9, 28, 16, 3, 20, 33, 1, 12, 33, 1, 20, 32, 3, 28, 16, 9, 28, 16, 3, 20, 33, 1, 12, 33, 1, 20, 32, 3, 28, 16, 15, 0, 145, 129, 0, 81, 66, 0, 48, 129, 0, 48, 194, 0, 48, 129, 0, 49, 66, 0, 81, 129, 0, 144, 15, 0, 145, 129, 0, 81, 130, 0, 48, 1, 0, 49, 66, 0, 48, 1, 0, 49, 130, 0, 81, 129, 0, 144, 7, 0, 129, 129, 0, 86, 66, 0, 81, 129, 0, 128, 7, 0, 129, 129, 0, 86, 66, 0, 81, 129, 0, 128, 13, 0, 64, 9, 20, 16, 5, 20, 32, 5, 44, 32, 5, 20, 32, 5, 20, 16, 9, 0, 64, 17, 0, 112, 6, 24, 16, 5, 16, 32, 5, 4, 48, 5, 20, 32, 5, 4, 48, 5, 16, 32, 5, 24, 16, 6, 0, 112, 11, 4, 65, 193, 0, 49, 2, 0, 82, 65, 0, 81, 2, 0, 49, 193, 4, 64, 13, 0, 0, 7, 0, 98, 1, 0, 48, 130, 44, 16, 130, 0, 50, 1, 0, 96, 7, 0, 0, 11, 0, 0, 4, 0, 114, 129, 4, 50, 193, 4, 50, 129, 0, 112, 4, 0, 0, 7, 4, 0, 7, 0, 104, 193, 0, 96, 7, 4, 0, 7, 4, 0, 68, 0, 152, 65, 0, 144, 68, 4, 0, 7, 8, 0, 4, 0, 120, 65, 0, 112, 4, 8, 0, 7, 12, 0, 10, 0, 119, 193, 0, 112, 10, 12, 0, 7, 16, 0, 10, 0, 119, 65, 0, 112, 10, 16, 0, 7, 20, 0, 10, 0, 118, 193, 0, 112, 10, 20, 0, 9, 24, 0, 10, 0, 112, 9, 92, 16, 9, 0, 112, 10, 24, 0, 7, 28, 0, 68, 0, 101, 65, 0, 96, 68, 28, 0, 9, 32, 0, 4, 4, 112, 6, 68, 16, 6, 4, 112, 4, 32, 0, 11, 40, 0, 4, 4, 112, 6, 0, 146, 193, 0, 144, 6, 4, 112, 4, 40, 0, 13, 48, 0, 4, 0, 112, 4, 4, 128, 73, 12, 16, 73, 4, 128, 4, 0, 112, 4, 48, 0]; + +pub fn draw(s: &mut impl Surface, app: u8, cx: i32, cy: i32) -> bool { + draw_in(s, app, cx, cy, false) +} + +/// The same sign, 44 px (`SMALL`) for the top of a conversation. +pub fn draw_small(s: &mut impl Surface, app: u8, cx: i32, cy: i32) -> bool { + draw_in(s, app, cx, cy, true) +} + +pub const SMALL: i32 = 44; + + +/// The palette and packed rows of sign `app` (1 WhatsApp, 2 Messenger, 3 Telegram, 4 Instagram, 5 X, 6 Discord). +fn sign(app: u8, small: bool) -> Option<(&'static [u16], &'static [u8])> { + Some(match (app, small) { + (1, false) => (&WHATSAPP_PAL, &WHATSAPP), + (2, false) => (&MESSENGER_PAL, &MESSENGER), + (3, false) => (&TELEGRAM_PAL, &TELEGRAM), + (1, true) => (&WHATSAPP_S_PAL, &WHATSAPP_S), + (2, true) => (&MESSENGER_S_PAL, &MESSENGER_S), + (3, true) => (&TELEGRAM_S_PAL, &TELEGRAM_S), + (4, false) => (&INSTAGRAM_PAL, &INSTAGRAM), + (5, false) => (&X_PAL, &X), + (6, false) => (&DISCORD_PAL, &DISCORD), + (4, true) => (&INSTAGRAM_S_PAL, &INSTAGRAM_S), + (5, true) => (&X_S_PAL, &X_S), + (6, true) => (&DISCORD_S_PAL, &DISCORD_S), + _ => return None, + }) +} + +/// Walks the packed rows of a sign and calls `f(row, x, len, palette index)` for each colour run. A row is one byte (the +/// number of runs) followed by the runs, 12 bits each (6 bits of `len - 1`, then 6 bits of palette index), padded to a byte. +fn runs(data: &[u8], mut f: impl FnMut(i32, i32, i32, usize)) { + let (mut i, mut y) = (0, 0); + while i < data.len() { + let n = data[i] as usize; + i += 1; + let mut x = 0; + for k in 0..n { + let at = i + k * 3 / 2; + let v = if k % 2 == 0 { + (data[at] as usize) << 4 | (data[at + 1] as usize) >> 4 + } else { + ((data[at] as usize) & 15) << 8 | data[at + 1] as usize + }; + let len = (v >> 6) as i32 + 1; + f(y, x, len, v & 63); + x += len; + } + i += (3 * n + 1) / 2; + y += 1; + } +} + +fn draw_in(s: &mut impl Surface, app: u8, cx: i32, cy: i32, small: bool) -> bool { + let Some((pal, data)) = sign(app, small) else { return false }; + let size = if small { SMALL } else { SIZE }; + let (x0, y0) = (cx - size / 2, cy - size / 2); + runs(data, |y, x, len, p| { + if p != 0 { + s.rect(x0 + x, y0 + y, len, 1, pal[p]); + } + }); + true +} + +/// Paints black round the sign of `app` (a ring `m` px wide that follows its outline, tail and all), so the sign can sit +/// half on a card with a clean cut-out. False for any other app. +pub fn cutout(s: &mut impl Surface, app: u8, cx: i32, cy: i32, m: i32) -> bool { + cutout_in(s, app, cx, cy, m, false) +} + +/// A colour (RGB565) that is more than black: some channel of it is at least 3/31 bright. +fn shows(c: u16) -> bool { + (c >> 11) >= 3 || (c >> 5) & 63 >= 6 || c & 31 >= 3 +} + +/// The first and last lit column (end exclusive) of each row of a sign, and its side; `None` for any other app. +fn lit_spans(app: u8, small: bool) -> Option<([(i32, i32); SIZE as usize], i32)> { + let (pal, data) = sign(app, small)?; + let size = if small { SMALL } else { SIZE }; + let mut span = [(i32::MAX, i32::MIN); SIZE as usize]; + runs(data, |y, x, len, p| { + // the small signs have black and near-black colours under other numbers than 0: only a pixel that shows counts + let lit = if small { shows(pal[p]) } else { p != 0 }; + if lit && (y as usize) < size as usize { + let s = &mut span[y as usize]; + s.0 = s.0.min(x); + s.1 = s.1.max(x + len); + } + }); + Some((span, size)) +} + +fn cutout_in(s: &mut impl Surface, app: u8, cx: i32, cy: i32, m: i32, small: bool) -> bool { + let Some((span, size)) = lit_spans(app, small) else { return false }; + let (x0, y0) = (cx - size / 2, cy - size / 2); + for row in -m..size + m { + let (mut lo, mut hi) = (i32::MAX, i32::MIN); + for dy in -m..=m { + let r = row + dy; + if !(0..size).contains(&r) || span[r as usize].0 == i32::MAX { + continue; + } + let mut dx = 0; + while (dx + 1) * (dx + 1) + dy * dy <= m * m { + dx += 1; + } + lo = lo.min(span[r as usize].0 - dx); + hi = hi.max(span[r as usize].1 + dx); + } + if lo < hi { + s.rect(x0 + lo, y0 + row, hi - lo, 1, 0); + } + } + true +} + +/// `c` (RGB565) faded towards black by `a` of 256. +fn fade(c: u16, a: i32) -> u16 { + let k = (256 - a) as u32; + let (r, g, b) = ((c >> 11) as u32 & 31, (c >> 5) as u32 & 63, c as u32 & 31); + (((r * k / 256) << 11) | ((g * k / 256) << 5) | (b * k / 256)) as u16 +} + +/// A smooth black rim `m` px wide round the 44 px sign of `app` (its outline, tail and all). Its edge is anti-aliased +/// against what lies under it: `under(x, y)` is that colour (RGB565), since the screen only takes opaque rects. +/// Draw the sign on top afterwards. False for any other app. +pub fn rim_small(s: &mut impl Surface, app: u8, cx: i32, cy: i32, m: i32, under: impl Fn(i32, i32) -> u16) -> bool { + let Some((span, size)) = lit_spans(app, true) else { return false }; + let (x0, y0) = (cx - size / 2, cy - size / 2); + // how black a pixel is (0..=256): by its distance to the nearest lit pixel, full up to m - 1/2, none from m + 1/2 + let level = |x: i32, row: i32| -> i32 { + let mut best = i32::MAX; + for dy in -m..=m { + let r = row + dy; + if !(0..size).contains(&r) || span[r as usize].0 == i32::MAX { + continue; + } + let (lo, hi) = span[r as usize]; + let dx = (lo - x).max(x - (hi - 1)).max(0); + best = best.min(dx * dx + dy * dy); + } + if best == i32::MAX || 4 * best >= (2 * m + 1) * (2 * m + 1) { + 0 + } else if 4 * best <= (2 * m - 1) * (2 * m - 1) { + 256 + } else { + let d = ((best as u32) << 16).isqrt() as i32; // the distance in 1/256 px + (m * 256 + 128 - d).clamp(0, 256) + } + }; + for row in -m..size + m { + // the pixels that are surely black (up to m - 1/2 from a lit one) and the ones that may be touched at all + let (mut slo, mut shi, mut olo, mut ohi) = (i32::MAX, i32::MIN, i32::MAX, i32::MIN); + for dy in -m..=m { + let r = row + dy; + if !(0..size).contains(&r) || span[r as usize].0 == i32::MAX { + continue; + } + let (lo, hi) = span[r as usize]; + let v = (2 * m - 1) * (2 * m - 1) - 4 * dy * dy; + if v >= 0 { + let w = (v as u32).isqrt() as i32 / 2; + slo = slo.min(lo - w); + shi = shi.max(hi + w); + } + let v = (2 * m + 1) * (2 * m + 1) - 4 * dy * dy; + if v > 0 { + let w = ((v - 1) as u32).isqrt() as i32 / 2; + olo = olo.min(lo - w); + ohi = ohi.max(hi + w); + } + } + if olo >= ohi { + continue; + } + let y = y0 + row; + if slo < shi { + s.rect(x0 + slo, y, shi - slo, 1, 0); + } + for x in (olo..ohi).filter(|x| slo >= shi || *x < slo || *x >= shi) { + let a = level(x, row); + if a > 0 { + s.rect(x0 + x, y, 1, 1, fade(under(x0 + x, y), a)); + } + } + } + true +} diff --git a/apps/watch-replies/src/keys.rs b/apps/watch-replies/src/keys.rs new file mode 100644 index 0000000..b14f4c7 --- /dev/null +++ b/apps/watch-replies/src/keys.rs @@ -0,0 +1,395 @@ +//! The keyboard: English, Arabic and Hindi letters plus a numbers page. +//! Holding Space switches between the phone's two chosen keyboards; tapping Space inserts a normal space. + +pub const MAX_KEYS: usize = 40; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Page { + Letters, + Numbers, + ArabicLetters, + ArabicNumbers, + /// Hindi consonants, then more letters and the vowel signs, then the vowels: Shift steps through them. + HindiLetters, + HindiMore, + HindiVowels, + HindiNumbers, +} + +/// The keyboards the phone can choose: 0 English, 1 Arabic, 2 Hindi (the second one can also be 3, none). +pub const NO_KEYBOARD: u8 = 3; + +/// The keyboard to go to when Space is held: the other of the two, or none (the same one) if there is only one. +pub fn next_language(cur: u8, kb1: u8, kb2: u8) -> u8 { + if kb2 >= NO_KEYBOARD || kb2 == kb1 || cur != kb1 { kb1.min(2) } else { kb2 } +} + +impl Page { + pub const fn lang(self) -> u8 { + match self { + Self::Letters | Self::Numbers => 0, + Self::ArabicLetters | Self::ArabicNumbers => 1, + _ => 2, + } + } + + pub const fn letters(lang: u8) -> Self { + match lang { + 1 => Self::ArabicLetters, + 2 => Self::HindiLetters, + _ => Self::Letters, + } + } + + pub const fn is_hindi(self) -> bool { + self.lang() == 2 + } + + /// Shift on the Hindi keyboard: the next page of letters. + pub const fn next_hindi(self) -> Self { + match self { + Self::HindiLetters => Self::HindiMore, + Self::HindiMore => Self::HindiVowels, + _ => Self::HindiLetters, + } + } +} + +impl Page { + pub const fn is_arabic(self) -> bool { + matches!(self, Self::ArabicLetters | Self::ArabicNumbers) + } + + pub const fn is_letters(self) -> bool { + matches!(self, Self::Letters | Self::ArabicLetters) + } + + pub const fn toggle_numbers(self) -> Self { + match self { + Self::Letters => Self::Numbers, + Self::Numbers => Self::Letters, + Self::ArabicLetters => Self::ArabicNumbers, + Self::ArabicNumbers => Self::ArabicLetters, + Self::HindiNumbers => Self::HindiLetters, + _ => Self::HindiNumbers, + } + } +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Key { + /// ASCII input uses its byte value. Arabic letters and Arabic-Indic digits use private key codes + /// which `character()` converts to Unicode before a character is appended to the reply. + Ch(u8), + /// A Hindi letter or sign: its place in `HINDI`. + Hi(u8), + Shift, + Back, + Space, + Page, +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub struct Cell { + pub key: Key, + pub x: i32, + pub y: i32, + pub w: i32, + pub h: i32, +} + +pub const KEY_H: i32 = 62; +pub const TOP: i32 = 150; + +const ARABIC_LETTERS: [char; 28] = [ + 'ض', 'ص', 'ث', 'ق', 'ف', 'غ', 'ع', 'ه', 'خ', 'ح', + 'ش', 'س', 'ي', 'ب', 'ل', 'ا', 'ت', 'ن', 'م', + 'ج', 'د', 'ذ', 'ر', 'ز', 'ط', 'ظ', 'ك', 'و', +]; + +const ARABIC_KEY_BASE: u8 = 0x80; +const ARABIC_VARIANT_BASE: u8 = 0xC0; +const ARABIC_PUNCT_BASE: u8 = 0xD0; +const ARABIC_DIGIT_BASE: u8 = 0xE0; +const ARABIC_VARIANTS: [char; 8] = ['ة', 'ى', 'ء', 'أ', 'إ', 'آ', 'ؤ', 'ئ']; +const ARABIC_PUNCTUATION: [char; 3] = ['،', '؛', '؟']; + +const HINDI: &[char] = &[ + 'क', 'ख', 'ग', 'घ', 'ङ', 'च', 'छ', 'ज', 'झ', 'ञ', 'ट', 'ठ', 'ड', 'ढ', 'ण', 'त', 'थ', 'द', 'ध', 'न', 'प', 'फ', 'ब', 'भ', 'म', 'य', 'र', + 'ल', 'व', 'श', 'ष', 'स', 'ह', 'ळ', 'ा', 'ि', 'ी', 'ु', 'ू', 'ृ', 'े', 'ै', 'ॅ', 'ॉ', 'ो', 'ौ', '्', 'ं', 'ँ', 'ः', '़', '।', '॥', + 'अ', 'आ', 'इ', 'ई', 'उ', 'ऊ', 'ऋ', 'ए', 'ऐ', 'ओ', 'औ', 'ऍ', 'ऑ', +]; + +/// The character of a Hindi key. +pub fn hindi(i: u8) -> char { + HINDI.get(i as usize).copied().unwrap_or('?') +} + +fn hi(c: char) -> Key { + Key::Hi(HINDI.iter().position(|&v| v == c).unwrap_or(0) as u8) +} + +/// Converts an internal keyboard code to the Unicode character it represents. +pub fn character(code: u8) -> char { + if (ARABIC_KEY_BASE..ARABIC_KEY_BASE + ARABIC_LETTERS.len() as u8).contains(&code) { + return ARABIC_LETTERS[(code - ARABIC_KEY_BASE) as usize]; + } + if (ARABIC_VARIANT_BASE..ARABIC_VARIANT_BASE + ARABIC_VARIANTS.len() as u8).contains(&code) { + return ARABIC_VARIANTS[(code - ARABIC_VARIANT_BASE) as usize]; + } + if (ARABIC_PUNCT_BASE..ARABIC_PUNCT_BASE + ARABIC_PUNCTUATION.len() as u8).contains(&code) { + return ARABIC_PUNCTUATION[(code - ARABIC_PUNCT_BASE) as usize]; + } + if (ARABIC_DIGIT_BASE..ARABIC_DIGIT_BASE + 10).contains(&code) { + return char::from_u32(0x0660 + (code - ARABIC_DIGIT_BASE) as u32).unwrap_or('?'); + } + code as char +} + +fn arabic_key(c: char) -> Key { + let i = ARABIC_LETTERS.iter().position(|&v| v == c).unwrap_or(0); + Key::Ch(ARABIC_KEY_BASE + i as u8) +} + +fn row_of(page: Page, r: usize) -> ([(Key, i32); 10], usize) { + let mut out = [(Key::Space, 0); 10]; + let mut n = 0; + let mut put = |k: Key, w: i32| { + out[n] = (k, w); + n += 1; + }; + + match (page, r) { + (Page::Letters, 0) => b"qwertyuiop".iter().for_each(|&c| put(Key::Ch(c), 43)), + (Page::Letters, 1) => b"asdfghjkl".iter().for_each(|&c| put(Key::Ch(c), 50)), + (Page::Letters, 2) => { + put(Key::Shift, 52); + b"zxcvbnm".iter().for_each(|&c| put(Key::Ch(c), 43)); + put(Key::Ch(b'.'), 52); + } + (Page::ArabicLetters, 0) => "ضصثقفغعهخح".chars().for_each(|c| put(arabic_key(c), 43)), + (Page::ArabicLetters, 1) => "شسيبلاتنم".chars().for_each(|c| put(arabic_key(c), 50)), + (Page::ArabicLetters, 2) => { + put(arabic_key('ج'), 52); + "دذرزطظك".chars().for_each(|c| put(arabic_key(c), 43)); + put(arabic_key('و'), 52); + } + // Hindi: consonants / the rest and the vowel signs / the vowels. Shift (left) goes to the next page. + (Page::HindiLetters, 0) => "कखगघङचछजझञ".chars().for_each(|c| put(hi(c), 43)), + (Page::HindiLetters, 1) => "टठडढणतथदध".chars().for_each(|c| put(hi(c), 50)), + (Page::HindiLetters, 2) | (Page::HindiMore, 2) | (Page::HindiVowels, 2) => { + put(Key::Shift, 52); + let mids = match page { Page::HindiLetters => "नपफबभमय", Page::HindiMore => "्ंँः़।॥", _ => "ािीुूेै" }; + mids.chars().for_each(|c| put(hi(c), 43)); + put(match page { Page::HindiLetters => hi('र'), Page::HindiMore => Key::Ch(b'.'), _ => hi('ो') }, 52); + } + (Page::HindiMore, 0) => "लवशषसहळािी".chars().for_each(|c| put(hi(c), 43)), + (Page::HindiMore, 1) => "ुूृेैॅॉोौ".chars().for_each(|c| put(hi(c), 50)), + (Page::HindiVowels, 0) => "अआइईउऊऋएऐओ".chars().take(10).for_each(|c| put(hi(c), 43)), + (Page::HindiVowels, 1) => { + "औऍऑ".chars().for_each(|c| put(hi(c), 49)); + b"!?,'\"-".iter().for_each(|&c| put(Key::Ch(c), 49)); + } + (Page::Numbers | Page::HindiNumbers, 0) => b"1234567890".iter().for_each(|&c| put(Key::Ch(c), 43)), + (Page::ArabicNumbers, 0) => (0..10).for_each(|i| put(Key::Ch(ARABIC_DIGIT_BASE + i), 43)), + (Page::Numbers | Page::HindiNumbers, 1) => b"-/:;()$&@".iter().for_each(|&c| put(Key::Ch(c), 49)), + (Page::ArabicNumbers, 1) => (0..ARABIC_VARIANTS.len()).for_each(|i| put(Key::Ch(ARABIC_VARIANT_BASE + i as u8), 49)), + (Page::Numbers | Page::HindiNumbers, 2) => { + put(Key::Ch(b'#'), 52); + b".,?!'\"+".iter().for_each(|&c| put(Key::Ch(c), 42)); + put(Key::Ch(b'%'), 52); + } + (Page::ArabicNumbers, 2) => { + put(Key::Ch(b'#'), 52); + for i in 0..3 { put(Key::Ch(ARABIC_PUNCT_BASE + i), 42); } + b".!'\"".iter().for_each(|&c| put(Key::Ch(c), 42)); + put(Key::Ch(b'%'), 52); + } + (_, 3) => { + // A smaller space bar leaves room for a bigger delete key. + put(Key::Page, 90); + put(Key::Space, 118); + put(Key::Back, 110); + } + _ => {} + } + (out, n) +} + +pub fn layout(page: Page) -> ( [Cell; MAX_KEYS], usize ) { + let mut out = [Cell { key: Key::Space, x: 0, y: 0, w: 0, h: 0 }; MAX_KEYS]; + let mut n = 0; + for r in 0..4 { + let (row, len) = row_of(page, r); + let total: i32 = row[..len].iter().map(|k| k.1).sum(); + let mut x = crate::C - total / 2; + for &(key, w) in &row[..len] { + let h = if key == Key::Space { KEY_H + 18 } else { KEY_H }; + out[n] = Cell { key, x, y: TOP + r as i32 * KEY_H, w, h }; + n += 1; + x += w; + } + } + (out, n) +} + +pub fn key_at(page: Page, x: i32, y: i32) -> Option { + let row = (y - TOP).div_euclid(KEY_H); + if row < 0 || y >= TOP + 4 * KEY_H + 18 { return None; } + let row = row.min(3); + let (cells, n) = layout(page); + if y >= TOP + 4 * KEY_H { + return cells[..n].iter().find(|c| c.key == Key::Space && x >= c.x && x < c.x + c.w).copied(); + } + let mut in_row = cells[..n].iter().filter(|c| c.y == TOP + row * KEY_H); + let first = *in_row.clone().next()?; + let last = *in_row.clone().last()?; + if x < first.x - 20 || x >= last.x + last.w + 20 { return None; } + if x < first.x { return Some(first); } + in_row.find(|c| x >= c.x && x < c.x + c.w).copied().or(Some(last)) +} + +pub fn sentence_start(text: &[u8]) -> bool { + let Ok(s) = core::str::from_utf8(text) else { return false; }; + let t = s.trim_end_matches(' '); + if t.is_empty() { return true; } + if t.len() == s.len() { return false; } + matches!(t.chars().last(), Some('.' | '?' | '!' | '؟' | '۔' | '।')) +} + +/// The character a key types (Hindi keys too); `shift` makes English letters capitals. +pub fn typed_char(key: Key, shift: bool) -> Option { + match key { + Key::Hi(i) => Some(hindi(i)), + _ => typed(key, shift).map(character), + } +} + +/// The byte code for the character a key types. Arabic codes are expanded by Draft::push. +pub fn typed(key: Key, shift: bool) -> Option { + match key { + Key::Ch(c) if c < 0x80 => Some(if shift { c.to_ascii_uppercase() } else { c }), + Key::Ch(c) => Some(c), + Key::Space => Some(b' '), + _ => None, + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{C, SIZE}; + + const ALL_PAGES: [Page; 8] = [Page::Letters, Page::Numbers, Page::ArabicLetters, Page::ArabicNumbers, Page::HindiLetters, Page::HindiMore, Page::HindiVowels, Page::HindiNumbers]; + + fn inside(x: i32, y: i32) -> bool { + let (dx, dy) = (x - C, y - C); + dx * dx + dy * dy <= (SIZE / 2 - 4) * (SIZE / 2 - 4) + } + + #[test] + fn all_layouts_tile_the_rows_and_stay_on_the_round_screen() { + for page in ALL_PAGES { + let (cells, n) = layout(page); + for (i, c) in cells[..n].iter().enumerate() { + assert!(inside(c.x + c.w / 2, c.y + c.h / 2), "{page:?} {:?}", c.key); + assert!(inside(c.x + c.w / 2, c.y + 12) && inside(c.x + c.w / 2, c.y + c.h - 12), "{:?}", c.key); + for d in &cells[i + 1..n] { + let apart = c.x + c.w <= d.x || d.x + d.w <= c.x || c.y + c.h <= d.y || d.y + d.h <= c.y; + assert!(apart, "{page:?}: {:?} overlaps {:?}", c.key, d.key); + } + } + for r in 0..4 { + let row: std::vec::Vec<_> = cells[..n].iter().filter(|c| c.y == TOP + r * KEY_H).collect(); + for w in row.windows(2) { assert_eq!(w[0].x + w[0].w, w[1].x, "{page:?} row {r}"); } + } + } + } + + #[test] + fn all_english_and_arabic_letters_are_represented_once() { + let (cells, n) = layout(Page::Letters); + for ch in b'a'..=b'z' { assert_eq!(cells[..n].iter().filter(|c| c.key == Key::Ch(ch)).count(), 1, "{}", ch as char); } + let (cells, n) = layout(Page::ArabicLetters); + assert_eq!(cells[..n].iter().filter(|c| matches!(c.key, Key::Ch(v) if v >= ARABIC_KEY_BASE && v < ARABIC_KEY_BASE + 28)).count(), 28); + for ch in ARABIC_LETTERS { + let key = arabic_key(ch); + assert_eq!(character(match key { Key::Ch(code) => code, _ => 0 }), ch); + } + } + + #[test] + fn arabic_digits_and_language_switch_are_correct() { + let (cells, n) = layout(Page::ArabicNumbers); + for i in 0..10 { assert!(cells[..n].iter().any(|c| c.key == Key::Ch(ARABIC_DIGIT_BASE + i))); } + for i in 0..ARABIC_VARIANTS.len() { assert!(cells[..n].iter().any(|c| c.key == Key::Ch(ARABIC_VARIANT_BASE + i as u8))); } + for i in 0..ARABIC_PUNCTUATION.len() { assert!(cells[..n].iter().any(|c| c.key == Key::Ch(ARABIC_PUNCT_BASE + i as u8))); } + assert_eq!(character(ARABIC_DIGIT_BASE + 4), '٤'); + assert_eq!(character(ARABIC_VARIANT_BASE), 'ة'); + assert_eq!(character(ARABIC_VARIANT_BASE + 7), 'ئ'); + assert_eq!(character(ARABIC_PUNCT_BASE + 2), '؟'); + assert_eq!((Page::Letters.lang(), Page::ArabicNumbers.lang(), Page::HindiMore.lang()), (0, 1, 2)); + // hold Space: the other of the two chosen keyboards; with none as the second, nothing changes + assert_eq!((next_language(0, 0, 1), next_language(1, 0, 1), next_language(2, 0, 1)), (1, 0, 0)); + assert_eq!((next_language(2, 2, 0), next_language(0, 2, 0), next_language(1, 2, 0)), (0, 2, 2)); + assert_eq!((next_language(1, 1, NO_KEYBOARD), next_language(0, 1, NO_KEYBOARD), next_language(2, 2, 2)), (1, 1, 2)); + assert_eq!(Page::HindiLetters.next_hindi().next_hindi().next_hindi(), Page::HindiLetters); + assert_eq!(Page::ArabicLetters.toggle_numbers(), Page::ArabicNumbers); + } + + #[test] + fn touches_find_keys_in_every_layout() { + for page in ALL_PAGES { + let (cells, n) = layout(page); + for c in &cells[..n] { + let mid = key_at(page, c.x + c.w / 2, c.y + c.h / 2).unwrap(); + assert_eq!(mid.key, c.key); + let low = key_at(page, c.x + 1, c.y + c.h - 1).unwrap(); + assert_eq!(low.key, c.key); + } + } + } + + #[test] + fn shift_only_changes_english_letters() { + assert_eq!(typed(Key::Ch(b'a'), true), Some(b'A')); + assert_eq!(character(typed(arabic_key('ض'), true).unwrap()), 'ض'); + assert_eq!(typed(Key::Space, false), Some(b' ')); + assert!(sentence_start("انتهى؟ ".as_bytes())); + assert!(!sentence_start("انتهى؟".as_bytes())); + assert_eq!(typed(Key::Back, false), None); + + // The spacebar is slightly narrower, Backspace has a larger target, and letter keys are wider. + let (cells, n) = layout(Page::Letters); + let page = cells[..n].iter().find(|c| c.key == Key::Page).unwrap(); + let space = cells[..n].iter().find(|c| c.key == Key::Space).unwrap(); + let back = cells[..n].iter().find(|c| c.key == Key::Back).unwrap(); + assert_eq!((page.w, space.w, back.w), (90, 118, 110)); + assert_eq!(page.x + page.w, space.x); + assert_eq!(space.x + space.w, back.x); + + let (english, en_n) = layout(Page::Letters); + assert_eq!(english[..en_n].iter().find(|c| c.key == Key::Ch(b'q')).unwrap().w, 43); + assert_eq!(english[..en_n].iter().find(|c| c.key == Key::Ch(b'a')).unwrap().w, 50); + let (arabic, ar_n) = layout(Page::ArabicLetters); + let first_arabic = arabic[..ar_n].iter().find(|c| matches!(c.key, Key::Ch(code) if code >= 0x80)).unwrap(); + assert_eq!(first_arabic.w, 43); + } + + #[test] + fn every_hindi_letter_has_a_key_and_a_glyph() { + let mut seen = std::collections::BTreeSet::new(); + for page in [Page::HindiLetters, Page::HindiMore, Page::HindiVowels] { + let (cells, n) = layout(page); + let mut here = std::collections::BTreeSet::new(); + for c in &cells[..n] { + if let Key::Hi(i) = c.key { assert!(here.insert(i), "{page:?} {} twice", hindi(i)); seen.insert(i); } + } + } + for c in "कखगघङचछजझञटठडढणतथदधनपफबभमयरलवशषसहळ".chars() { + assert!(seen.contains(&(HINDI.iter().position(|&v| v == c).unwrap() as u8)), "{c} has no key"); + } + assert_eq!(typed_char(hi('क'), false), Some('क')); + for &c in HINDI { assert!(crate::fonts::B.covers(&std::string::String::from(c)), "{c}"); } + } +} diff --git a/apps/watch-replies/src/main.rs b/apps/watch-replies/src/main.rs new file mode 100644 index 0000000..24efba9 --- /dev/null +++ b/apps/watch-replies/src/main.rs @@ -0,0 +1,855 @@ +#![cfg_attr(any(target_os = "none", wp2_sim), no_main, cfg_attr(target_os = "none", no_std))] + +//! Watch Replies: the messages that come to the phone (WhatsApp, Messenger, Telegram), as cards on the watch, and a +//! keyboard to answer them. The phone side is the Watch Menu app. Protocol: `proto.rs`. + +mod font; +mod arabic; +mod gesture; +#[rustfmt::skip] +mod fonts; +mod icons; +mod keys; +mod proto; +mod stream; +mod view; +mod words; + +pub use cmf_wp2_ui::{C, SIZE}; + +#[cfg(not(any(target_os = "none", wp2_sim)))] +fn main() {} + +#[cfg(any(target_os = "none", wp2_sim))] +mod device { + use crate::gesture::{Gesture, classify}; + use crate::keys::{self, Cell, Key, Page}; + use crate::proto::{self, Effect, Model, REPLY_MAX}; + use crate::view; + use cmf_wp2_app::{Api, BUTTON, CROWN, MSG_MAX, PAUSE, RESUME, TOUCH_DOWN, TOUCH_UP}; + + cmf_wp2_app::entry!(main); + cmf_wp2_app::app_icon!(); + // a tile beside the watch face with the latest message; a tap on it opens the app + cmf_wp2_app::app_features!(cmf_wp2_app::WIDGET); + + /// Say hello to the phone again this often while it has not answered (doubling up to a minute). + const HELLO_MS: u32 = 3000; + /// A reply that the phone does not answer in this long has failed. + const SEND_MS: u32 = 15000; + /// "Sent" stays this long, "Not sent" a little longer. + const SENT_MS: u32 = 1400; + const FAILED_MS: u32 = 2600; + /// How long after a reply the phone may send it back as a message (its own echo). + const ECHO_MS: u32 = 8000; + /// Tell the phone which conversation is open; the phone expires this focus if heartbeats stop. + const FOCUS_MS: u32 = 2500; + const GAP_MS: u32 = 20; + const FRAME_MS: u32 = 16; + + static mut MODEL: Model = Model::new(); + // the watch microphone, streamed to the phone while a dictation runs (stream.rs) + static mut STREAM: crate::stream::Stream = crate::stream::Stream::new(); + + #[derive(Clone, Copy, PartialEq, Eq)] + enum Screen { + Inbox, + Detail, + Keyboard, + Sending, + Sent, + Failed, + } + + /// What a finger came down on in the keyboard. + #[derive(Clone, Copy, PartialEq, Eq)] + enum Target { + Key(Cell), + Chip(usize), + Send, + } + + fn put(buf: &mut [u8], at: &mut usize, s: &[u8]) { + for &b in s { + if *at < buf.len() { + buf[*at] = b; + *at += 1; + } + } + } + + /// Puts the unread messages of each app on the widget tile, up to two apps ("2 WhatsApp"), once per + /// change (it is a NAND write). The title is always "Watch Replies". + fn publish(api: &Api, m: &Model, last: &mut u32) { + const NAMES: [&[u8]; 6] = [b"WhatsApp", b"Messenger", b"Telegram", b"Instagram", b"X", b"Discord"]; + let mut un = [0u8; 6]; + for c in &m.chats[..m.n] { + if (1..=6).contains(&c.app) { + un[c.app as usize - 1] = un[c.app as usize - 1].saturating_add(c.unread); + } + } + let h = un.iter().fold(5381u32, |h, &n| h.wrapping_mul(33) ^ n as u32); + if h == *last { + return; + } + *last = h; + let (mut v, mut vl, mut k) = ([0u8; 39], 0, 0); + for (i, &n) in un.iter().enumerate() { + if n == 0 || k == 2 { + continue; + } + if k == 1 { + put(&mut v, &mut vl, b"\n"); + } + if n > 9 { + put(&mut v, &mut vl, b"9+"); + } else { + put(&mut v, &mut vl, &[b'0' + n]); + } + put(&mut v, &mut vl, b" "); + put(&mut v, &mut vl, NAMES[i]); + k += 1; + } + if k == 0 { + put(&mut v, &mut vl, b"No new messages"); + } + api.widget("Watch Replies", core::str::from_utf8(&v[..vl]).unwrap_or("")); + } + + // true on RESUME, false on BUTTON + fn paused(api: &Api) -> bool { + loop { + match api.event(u32::MAX).map(|e| e.kind) { + Some(RESUME) => return true, + Some(BUTTON) => return false, + _ => {} + } + } + } + + struct Draft { + text: [u8; REPLY_MAX], + len: usize, + to: [u8; 40], + to_len: usize, + chat: u8, + page: Page, + shift: bool, + cur: usize, // where the caret is (a byte of the text, at the start of a character) + vs: usize, // where the visible part of the text starts + } + + impl Draft { + /// The text before the caret: what the suggestions and the capital letters go by. + fn head(&self) -> &[u8] { + &self.text[..self.cur] + } + + fn show_caret(&mut self) { + let t = core::str::from_utf8(&self.text[..self.len]).unwrap_or(""); + self.vs = view::window(t, self.cur, self.vs); + } + + /// Replaces bytes `a..b` with `bytes`; false (nothing changes) when it would not fit. + fn splice(&mut self, a: usize, b: usize, bytes: &[u8]) -> bool { + let n = self.len - (b - a) + bytes.len(); + if n > REPLY_MAX { return false; } + self.text.copy_within(b..self.len, a + bytes.len()); + self.text[a..a + bytes.len()].copy_from_slice(bytes); + self.len = n; + true + } + + fn bytes(&self) -> &[u8] { + &self.text[..self.len] + } + + /// Puts a completed speech-recognition result in at the caret (a space first when it follows a word), preserving UTF-8. + fn replace(&mut self, input: &[u8]) { + if self.cur > 0 && self.text[self.cur - 1] != b' ' && self.splice(self.cur, self.cur, b" ") { + self.cur += 1; + } + let cap = input.len().min(REPLY_MAX - self.len); + let n = (0..=cap).rev().find(|&i| core::str::from_utf8(&input[..i]).is_ok()).unwrap_or(0); + if self.splice(self.cur, self.cur, &input[..n]) { + self.cur += n; + } + self.show_caret(); + } + + fn to(&self) -> &str { + core::str::from_utf8(&self.to[..self.to_len]).unwrap_or("") + } + + /// Starts a reply to `c`. + fn open(&mut self, c: &proto::Chat) { + let b = c.name(); + let mut n = 0; + let take = b.len().min(self.to.len()); + // not in the middle of a letter + let take = (0..=take).rev().find(|&i| b.is_char_boundary(i)).unwrap_or(0); + self.to[n..n + take].copy_from_slice(&b.as_bytes()[..take]); + n += take; + // the language of the last reply stays while it is one of the phone's two keyboards + let (a, b) = (proto::KB1.load(core::sync::atomic::Ordering::Relaxed), proto::KB2.load(core::sync::atomic::Ordering::Relaxed)); + let cur = self.page.lang(); + let page = Page::letters(if cur == a || cur == b { cur } else { a }); + (self.to_len, self.chat, self.len, self.page, self.shift) = (n, c.id, 0, page, page == Page::Letters); + (self.cur, self.vs) = (0, 0); + } + + /// Appends one complete Unicode character; never leaves a partial UTF-8 sequence in the draft. + fn push(&mut self, code: u8) -> bool { + self.push_char(keys::character(code)) + } + + fn push_char(&mut self, ch: char) -> bool { + let mut encoded = [0u8; 4]; + let bytes = ch.encode_utf8(&mut encoded).as_bytes(); + if !self.splice(self.cur, self.cur, bytes) { + return false; + } + self.cur += bytes.len(); + self.show_caret(); + true + } + + /// Removes the character before the caret, not merely its final byte. + fn backspace(&mut self) { + if self.cur == 0 { return; } + let mut start = self.cur - 1; + while start > 0 && (self.text[start] & 0xC0) == 0x80 { start -= 1; } + self.splice(start, self.cur, &[]); + self.cur = start; + self.show_caret(); + } + } + + fn main(api: &'static Api) -> i32 { + // SAFETY: the app has one thread and this is the only reference. + let m = unsafe { &mut *core::ptr::addr_of_mut!(MODEL) }; + let stream = unsafe { &mut *core::ptr::addr_of_mut!(STREAM) }; + m.set_defaults(); + api.own_back(true); // a right swipe or the crown press is "back" here: keyboard -> messages -> leave + let mut d = Draft { text: [0; REPLY_MAX], len: 0, to: [0; 40], to_len: 0, chat: 0, page: Page::Letters, shift: true, cur: 0, vs: 0 }; + let mut screen = Screen::Inbox; + let mut top = 0usize; + let mut widget_hash = 0u32; + let mut dirty = true; + let mut drawn_end = 0u32; + let mut hello_at: Option = None; + let mut tries = 0u32; + let mut touch0: Option<(u32, i32, i32)> = None; + let mut card_down: Option = None; + let mut det_chat = 0u8; // the chat on the full-message screen + let mut open_msg: Option = None; // the long message that is shown whole there (its key), if any + let mut dscroll = 0usize; // target scroll in pixels + let mut dscroll_anim = 0usize; // currently rendered scroll position + let mut dscroll_max = 0usize; // cached content height; do not re-measure every animation frame + let mut frame_at = 0u32; // when the last glide frame was drawn + let mut rep_down = false; + let drop = false; // the old drop under the caret is gone: the crown moves the caret now + let mut edit = 0u8; // a touch that began on the text + let mut voice_listening = false; + let mut voice_error = false; + let mut voice_parts = [0u8; REPLY_MAX]; + let mut voice_len = 0usize; + let mut live_at = 0usize; // where the live words of the dictation start in the draft + let mut live_len = 0usize; // how many bytes of the draft are live words (they are replaced by the next ones) + let mut voice_next = 0u8; + let mut target: Option = None; + let mut until: Option = None; // when a status page ends (Sent, Failed) or a reply times out (Sending) + let mut keep_on = false; + let mut echo_at = 0u32; + let mut focus_at = api.now().wrapping_sub(FOCUS_MS); + let mut last_focus_chat: Option = None; + loop { + let now = api.now(); + let focused_chat = if matches!(screen, Screen::Detail | Screen::Keyboard | Screen::Sending | Screen::Sent | Screen::Failed) { det_chat } else { 0 }; + if last_focus_chat != Some(focused_chat) || now.wrapping_sub(focus_at) >= FOCUS_MS { + let _ = api.send(&proto::focus(focused_chat)); + last_focus_chat = Some(focused_chat); + focus_at = now; + } + if !m.heard && hello_at.is_none_or(|t| now.wrapping_sub(t) >= (HELLO_MS << tries.min(4)).min(60_000)) { + api.send(&proto::hello()); // -107 while the phone is not listening: asked again + hello_at = Some(now); + tries += 1; + } + if stream.running() { + match stream.service(api) { + crate::stream::Svc::Run => {} + crate::stream::Svc::Drained => { + // every sample is out: tell the phone to finish; it answers with the text + if api.send(&proto::dictation_toggle(stream.lang)) >= 0 { + stream.close(api); + } + } + crate::stream::Svc::MicFailed => { + let _ = api.send(&proto::dictation_toggle(stream.lang)); + stream.close(api); + voice_listening = false; + voice_error = true; + dirty = true; + } + } + } + let on = matches!(screen, Screen::Keyboard | Screen::Sending); + if on != keep_on { + keep_on = on; + api.keep_screen_on(on); + } + if let Some(t) = until.filter(|&t| now.wrapping_sub(t) as i32 >= 0) { + until = None; + let _ = t; + match screen { + Screen::Sending => { + screen = Screen::Failed; + until = Some(now.wrapping_add(FAILED_MS)); + } + Screen::Sent => screen = Screen::Inbox, + Screen::Failed => screen = Screen::Keyboard, + _ => {} + } + dirty = true; + } + let cadence = if screen == Screen::Detail { FRAME_MS } else { GAP_MS }; + if dirty && now.wrapping_sub(drawn_end) >= cadence { + let mut s = api; + match screen { + Screen::Inbox => { + top = top.min(view::max_top(m.n)); + if m.n == 0 { + view::idle(&mut s, m.heard); + } else { + view::page(&mut s, &m.chats[top], top, m.n, card_down.is_some()); + } + } + Screen::Detail => match m.find(det_chat) { + Some(i) => { + dscroll = dscroll.min(dscroll_max); + dscroll_anim = dscroll_anim.min(dscroll_max); + let diff = dscroll as i32 - dscroll_anim as i32; + if diff != 0 { + // the glide takes the same time however long a frame takes to draw: a slow frame moves further + let dt = now.wrapping_sub(frame_at).clamp(10, 48) as i32; + // Keep the same ease-out glide, but settle sooner and cap missed-frame jumps. + let step = if diff.abs() <= 2 { diff } else { diff * dt / (dt + 34) }; + let step = if step == 0 { diff.signum() } else { step }; + dscroll_anim = (dscroll_anim as i32 + step) as usize; + } + frame_at = now; + view::detail(&mut s, &m.chats[i], open_msg, dscroll_anim, rep_down); + } + None => screen = Screen::Inbox, // the chat is gone: drawn as the inbox on the next round + }, + Screen::Keyboard => view::keyboard_cur(&mut s, m, d.to(), d.bytes(), d.cur, d.vs, drop, d.page, d.shift, voice_listening, voice_error), + Screen::Sending => view::status(&mut s, 0, "Sending…", ""), + Screen::Sent => view::status(&mut s, 1, "Sent", d.to()), + Screen::Failed => view::status(&mut s, 2, "Not sent", "Is Watch Menu open?"), + } + api.show(); + let animate = screen == Screen::Detail && dscroll_anim != dscroll; + (dirty, drawn_end) = (animate, api.now()); + continue; + } + let mut wait = if dirty { cadence.saturating_sub(now.wrapping_sub(drawn_end)).max(1) } else { 1000 }; + if let Some(t) = until { + wait = wait.min((t.wrapping_sub(now) as i32).max(1) as u32); + } + if !m.heard { + wait = wait.min(500); + } + if stream.running() { + wait = wait.min(25); // the mic keeps 256 ms; read it often + } + let mut ev = api.event(wait); + while let Some(e) = ev { + match e { + e if e.kind == BUTTON => match screen { + Screen::Inbox => { let _ = api.send(&proto::close_focus()); return 0; }, + Screen::Keyboard => { + if stream.running() { + stream.close(api); + } + if voice_listening { + let _ = api.send(&proto::dictation_toggle(d.page.lang())); + voice_listening = false; + } + voice_error = false; + (screen, until, dirty) = (if m.find(det_chat).is_some() { Screen::Detail } else { Screen::Inbox }, None, true); + target = None; + } + Screen::Sending => { + (screen, until, dirty) = (if m.find(det_chat).is_some() { Screen::Detail } else { Screen::Inbox }, None, true); + target = None; + } + _ => (screen, until, dirty) = (Screen::Inbox, None, true), + }, + e if e.kind == CROWN && screen == Screen::Detail => { + if let Some(i) = m.find(det_chat) { + let max = dscroll_max; + let amount = (e.delta.unsigned_abs() as usize).clamp(1, 3) * 30; + let next = if e.delta > 0 { (dscroll + amount).min(max) } else { dscroll.saturating_sub(amount) }; + if next != dscroll { + (dscroll, dirty) = (next, true); + } + } + } + e if e.kind == CROWN && screen == Screen::Inbox => { + let next = if e.delta > 0 { top + 1 } else { top.saturating_sub(1) }; + let next = next.min(view::max_top(m.n)); + if next != top { + (top, dirty) = (next, true); + } + } + e if e.kind == CROWN && screen == Screen::Keyboard => { + // the crown walks the caret through the text, one letter per click (never inside a letter) + let steps = (e.delta.unsigned_abs() as usize).clamp(1, 3); + for _ in 0..steps { + if e.delta > 0 { + if d.cur < d.len { + d.cur += 1; + while d.cur < d.len && (d.text[d.cur] & 0xC0) == 0x80 { d.cur += 1; } + } + } else if d.cur > 0 { + d.cur -= 1; + while d.cur > 0 && (d.text[d.cur] & 0xC0) == 0x80 { d.cur -= 1; } + } + } + d.show_caret(); + dirty = true; + } + e if e.kind == TOUCH_DOWN => { + touch0 = Some((api.now(), e.x as i32, e.y as i32)); + let (x, y) = (e.x as i32, e.y as i32); + match screen { + Screen::Inbox => { + card_down = (m.n > 0 && view::page_at(x, y)).then_some(top); + dirty |= card_down.is_some(); + } + Screen::Detail => { + rep_down = view::reply_at(x, y); + dirty |= rep_down; + } + Screen::Keyboard => { + edit = if d.len > 0 && y < 78 && x >= 50 { + 1 + } else { + 0 + }; + target = if edit != 0 { + None + } else if view::send_at(x, y, voice_listening) { + Some(Target::Send) + } else if view::chip_at(&m.items(d.head()).0[..m.items(d.head()).1], x, y).is_some() { + view::chip_at(&m.items(d.head()).0[..m.items(d.head()).1], x, y).map(Target::Chip) + } else { + keys::key_at(d.page, x, y).map(Target::Key) + }; + if let Some(Target::Key(c)) = target { + let mut s = api; + view::key(&mut s, &c, d.page, d.shift, true); + api.show(); + drawn_end = api.now(); + } + } + _ => {} + } + } + e if e.kind == TOUCH_UP => { + let Some((t, x0, y0)) = touch0.take() else { + ev = api.event(0); + continue; + }; + let (x, y) = (e.x as i32, e.y as i32); + let held = api.now().wrapping_sub(t); + match screen { + Screen::Inbox => { + let down = card_down.take(); + dirty |= down.is_some(); + match classify(x - x0, y - y0, held) { + Gesture::SwipeUp => { + top = (top + 1).min(view::max_top(m.n)); + dirty = true; + } + Gesture::SwipeDown => { + top = top.saturating_sub(1); + dirty = true; + } + Gesture::Hold => { + // hold a chat to pin it (or to let it go): a pinned chat stays when new ones come + if let Some(i) = down.filter(|&i| i < m.n && view::page_at(x, y)) { + let on = !m.chats[i].pinned; + m.chats[i].pinned = on; + let _ = api.send(&proto::pin(m.chats[i].id, on)); + dirty = true; + } + } + Gesture::Tap => { + if let Some(i) = down.filter(|&i| i < m.n && view::page_at(x, y)) { + // the whole message first; reply is on that screen + (det_chat, open_msg, dscroll_max) = (m.chats[i].id, None, view::detail_max(&m.chats[i], None)); + dscroll = dscroll_max; + dscroll_anim = dscroll; + (screen, dirty) = (Screen::Detail, true); + m.chats[i].unread = 0; + publish(api, m, &mut widget_hash); + } + } + Gesture::None => {} + } + } + Screen::Detail => { + let down = core::mem::take(&mut rep_down); + dirty |= down; + let max = dscroll_max; + match classify(x - x0, y - y0, held) { + Gesture::SwipeUp => { + // Scroll by the actual finger travel, not a fixed 96 px jump. + let distance = (y0 - y).abs().clamp(36, 160) as usize; + dscroll = (dscroll + distance).min(max); + frame_at = api.now(); + dirty = true; + } + Gesture::SwipeDown => { + let distance = (y0 - y).abs().clamp(36, 160) as usize; + dscroll = dscroll.saturating_sub(distance); + frame_at = api.now(); + dirty = true; + } + Gesture::Tap | Gesture::Hold => { + if let Some(i) = m.find(det_chat) { + if let Some(key) = view::more_at(&m.chats[i], open_msg, dscroll_anim, x, y) { + // "Show more" opens that message whole (and folds the one that was open); "Show less" folds it + open_msg = if open_msg == Some(key) { None } else { Some(key) }; + dscroll_max = view::detail_max(&m.chats[i], open_msg); + dscroll = dscroll.min(dscroll_max); + dscroll_anim = dscroll_anim.min(dscroll_max); + dirty = true; + } else if down && view::reply_at(x, y) { + d.open(&m.chats[i]); + (screen, dirty) = (Screen::Keyboard, true); + } + } + } + Gesture::None => {} + } + } + Screen::Keyboard => { + let ed = core::mem::take(&mut edit); + if ed != 0 && matches!(classify(x - x0, y - y0, held), Gesture::Tap | Gesture::Hold) { + // a tap on the text puts the caret there + let t = core::str::from_utf8(d.bytes()).unwrap_or(""); + d.cur = view::cursor_at(t, d.vs, x); + d.show_caret(); + let mut s = api; + view::text_changed_cur(&mut s, m, d.to(), d.bytes(), d.cur, d.vs, drop, voice_listening, voice_error); + api.show(); + drawn_end = api.now(); + ev = api.event(0); + continue; + } + let down = target.take(); + // the key is drawn as it was, whatever the touch did + if let Some(Target::Key(c)) = down { + let mut s = api; + view::key(&mut s, &c, d.page, d.shift, false); + api.show(); + drawn_end = api.now(); + } + let same = match down { + Some(Target::Key(c)) => keys::key_at(d.page, x, y).is_some_and(|u| u.key == c.key), + Some(Target::Chip(i)) => view::chip_at(&m.items(d.head()).0[..m.items(d.head()).1], x, y) == Some(i), + Some(Target::Send) => view::send_at(x, y, voice_listening), + None => false, + }; + if !same { + ev = api.event(0); + continue; + } + let mut changed = false; + match down { + Some(Target::Key(c)) => match c.key { + Key::Ch(_) | Key::Hi(_) => { + if let Some(ch) = keys::typed_char(c.key, d.shift && d.page == Page::Letters) { + changed = d.push_char(ch); + } + let shift = d.page == Page::Letters && keys::sentence_start(d.head()); + if shift != d.shift { + d.shift = shift; + let mut s = api; + view::all_keys(&mut s, d.page, d.shift); + } + } + Key::Space => { + if held >= crate::gesture::HOLD_MS { + // Hold Space: switch to the phone's other keyboard without inserting a space + // (with no second keyboard chosen, nothing changes). + let lang = keys::next_language(d.page.lang(), proto::KB1.load(core::sync::atomic::Ordering::Relaxed), proto::KB2.load(core::sync::atomic::Ordering::Relaxed)); + if lang != d.page.lang() { d.page = Page::letters(lang); } + d.shift = d.page == Page::Letters && keys::sentence_start(d.head()); + let mut s = api; + view::keyboard_cur(&mut s, m, d.to(), d.bytes(), d.cur, d.vs, drop, d.page, d.shift, voice_listening, voice_error); + api.show(); + drawn_end = api.now(); + } else { + // Tap Space: insert a normal space. + changed = d.push(b' '); + let shift = d.page == Page::Letters && keys::sentence_start(d.head()); + if shift != d.shift { + d.shift = shift; + let mut s = api; + view::all_keys(&mut s, d.page, d.shift); + } + } + } + Key::Back => { + if held >= crate::gesture::HOLD_MS { + (d.len, d.cur, d.vs) = (0, 0, 0); // holding backspace clears the lot + } else { + d.backspace(); + } + changed = true; + let shift = d.page == Page::Letters && keys::sentence_start(d.head()); + if shift != d.shift { + d.shift = shift; + let mut s = api; + view::all_keys(&mut s, d.page, d.shift); + } + } + Key::Shift if d.page.is_hindi() => { + d.page = d.page.next_hindi(); + let mut s = api; + view::all_keys(&mut s, d.page, d.shift); + api.show(); + } + Key::Shift => { + d.shift = !d.shift; + let mut s = api; + view::all_keys(&mut s, d.page, d.shift); + api.show(); + } + Key::Page => { + d.page = d.page.toggle_numbers(); + d.shift = d.page == Page::Letters && keys::sentence_start(d.head()); + let mut s = api; + view::keyboard_cur(&mut s, m, d.to(), d.bytes(), d.cur, d.vs, drop, d.page, d.shift, voice_listening, voice_error); + api.show(); + } + }, + Some(Target::Chip(i)) => { + if d.len == 0 { + let q = m.quick(i).as_bytes(); + let n = q.len().min(REPLY_MAX); + d.text[..n].copy_from_slice(&q[..n]); + d.len = n; + d.cur = n; + d.show_caret(); + } else { + // finish the word being typed, and a space after it + let (items, _) = m.items(d.head()); + let w = items[i].as_bytes(); + let fl = crate::words::fragment(d.head()).len(); + let cap = d.head()[d.cur - fl..].first().is_some_and(|b| b.is_ascii_uppercase()); + let mut buf = [0u8; 64]; + if w.len() < buf.len() { + buf[..w.len()].copy_from_slice(w); + if cap { buf[0] = buf[0].to_ascii_uppercase(); } + buf[w.len()] = b' '; + let from = d.cur - fl; + if d.splice(from, d.cur, &buf[..w.len() + 1]) { + d.cur = from + w.len() + 1; + d.show_caret(); + } + } + } + changed = true; + d.shift = false; + dirty = true; // the keys change case too + } + Some(Target::Send) if d.len == 0 || voice_listening || held >= crate::gesture::HOLD_MS => { + // an empty draft, a recording in progress, or a long press on send: start / stop the dictation + if voice_listening && stream.running() { + // second tap: the last audio goes out first, then the stop message + stream.request_stop(); + } else if voice_listening { + let _ = api.send(&proto::dictation_toggle(d.page.lang())); + } else if api.send(&proto::dictation_toggle(d.page.lang())) >= 0 { + voice_error = false; + if stream.start(api, d.page.lang()) { + voice_listening = true; + } else { + // the mic would not open: cancel the phone's session + let _ = api.send(&proto::dictation_toggle(d.page.lang())); + voice_error = true; + } + } else { + voice_listening = false; + voice_error = true; + } + dirty = true; + } + Some(Target::Send) if d.len > 0 => { + if stream.running() { + stream.close(api); + let _ = api.send(&proto::dictation_toggle(d.page.lang())); + voice_listening = false; + } + let mut buf = [0u8; MSG_MAX]; + let mut ok = true; + for i in 0..proto::pieces(d.len) { + let n = proto::reply_piece(d.chat, d.bytes(), i, &mut buf); + ok &= api.send(&buf[..n]) >= 0; + } + if ok { + m.arm_echo(d.chat, d.bytes()); + echo_at = api.now(); + (screen, until) = (Screen::Sending, Some(api.now().wrapping_add(SEND_MS))); + } else { + (screen, until) = (Screen::Failed, Some(api.now().wrapping_add(FAILED_MS))); + } + dirty = true; + } + _ => {} + } + if changed && !dirty { + let mut s = api; + view::text_changed_cur(&mut s, m, d.to(), d.bytes(), d.cur, d.vs, drop, voice_listening, voice_error); + api.show(); + drawn_end = api.now(); + } + } + _ => {} + } + } + e if e.kind == PAUSE => { + (touch0, card_down, target, rep_down) = (None, None, None, false); + if stream.running() { + stream.close(api); + } + if voice_listening { + let _ = api.send(&proto::dictation_toggle(d.page.lang())); + voice_listening = false; + } + if !paused(api) { + return 0; + } + // messages were refused meanwhile: ask for everything again + (m.heard, hello_at, tries, dirty) = (false, None, 0, true); + } + _ => {} + } + ev = api.event(0); + } + let mut buf = [0u8; MSG_MAX]; + while let Some(msg) = api.recv(&mut buf) { + // Voice state and text are small r1 protocol messages, separate from chat updates. + if msg.len() >= 4 && msg.starts_with(b"r1S") { + voice_listening = msg[3] == 1; + voice_error = msg[3] == 2; + if msg[3] == 1 { live_len = 0; } // a new dictation starts: the words already in the draft stay (the final text of the last one may still be on its way, so the end of a dictation does not clear this) + if msg[3] != 1 { + stream.close(api); // the phone is done (or failed): the mic is no longer needed + } + dirty |= screen == Screen::Keyboard; + tries = 0; + continue; + } + if msg.len() >= 4 && msg.starts_with(b"r1T") { + if screen == Screen::Keyboard { + let flags = msg[3]; + let partial = flags & 0x40 != 0; // live words while the person still talks, not the final text + let index = flags & 15; + if index == 0 { voice_len = 0; voice_next = 0; } + let part = &msg[4..]; + if index == voice_next && voice_len + part.len() <= REPLY_MAX { + voice_parts[voice_len..voice_len + part.len()].copy_from_slice(part); + voice_len += part.len(); + voice_next = voice_next.wrapping_add(1); + if flags & 0x80 != 0 { + if !partial { + stream.close(api); + } + // the words of the last update come out of the draft, the new ones go in (at the caret) + if live_len > 0 && live_at + live_len <= d.len { + d.splice(live_at, live_at + live_len, &[]); + d.cur = live_at; + } else { + live_at = d.cur; + } + d.replace(&voice_parts[..voice_len]); + live_len = if partial { d.cur - live_at } else { 0 }; + d.shift = d.page == Page::Letters && keys::sentence_start(d.head()); + if !partial { + voice_listening = false; + } + voice_error = false; + voice_len = 0; + voice_next = 0; + dirty = true; + } + } else { + voice_len = 0; + voice_next = 0; + voice_listening = false; + voice_error = true; + dirty = true; + } + } + tries = 0; + continue; + } + if api.now().wrapping_sub(echo_at) >= ECHO_MS { + m.disarm_echo(); + } + let following_latest = screen == Screen::Detail && dscroll.saturating_add(16) >= dscroll_max; + match m.apply(msg) { + Effect::Ignored => {} + Effect::Changed => { + // the keyboard is not redrawn under the person's fingers, except for its quick replies + if screen == Screen::Inbox || screen == Screen::Detail { + dirty = true; + } + // A new message for the selected chat follows the latest message. + // Messages arriving for other chats do not move the conversation being read. + if (screen == Screen::Detail || screen == Screen::Keyboard) && msg.len() >= 4 && (msg[2] == b'L' || msg[2] == b'U' || msg[2] == b'M') && msg[3] == det_chat { + if let Some(i) = m.find(det_chat) { + dscroll_max = view::detail_max(&m.chats[i], open_msg); + if screen == Screen::Keyboard || following_latest { dscroll = dscroll_max; } + else { dscroll = dscroll.min(dscroll_max); } + } + } + // what is on screen has been read + if let Some(i) = m.find(det_chat) { + if screen == Screen::Detail || screen == Screen::Keyboard { m.chats[i].unread = 0; } + } + publish(api, m, &mut widget_hash); + } + Effect::Result(id, status) => { + if screen == Screen::Sending && id == d.chat { + if status == 0 { + m.sent(id, d.bytes()); + if let Some(i) = m.find(det_chat) { + dscroll_max = view::detail_max(&m.chats[i], open_msg); + dscroll = dscroll_max; + (screen, until) = (Screen::Detail, None); + } else { + (screen, until) = (Screen::Inbox, None); + } + } else { + m.disarm_echo(); + (screen, until) = (Screen::Failed, Some(api.now().wrapping_add(FAILED_MS))); + } + dirty = true; + } + } + } + if m.heard && screen == Screen::Inbox && m.n == 0 { + dirty = true; + } + tries = 0; + } + } + } +} diff --git a/apps/watch-replies/src/proto.rs b/apps/watch-replies/src/proto.rs new file mode 100644 index 0000000..a01da07 --- /dev/null +++ b/apps/watch-replies/src/proto.rs @@ -0,0 +1,761 @@ +//! The messages between Watch Replies and the phone (the Watch Menu app). Every message starts with `r1` and a kind +//! byte, so the phone and the other watch apps tell them apart; 1..=128 bytes each. +//! +//! Phone -> watch: +//! `r1C` forget every chat (a fresh list follows) +//! `r1L` id app hh mm nlen name msg a chat has a new message: `app` 1 WhatsApp, 2 Messenger, 3 Telegram, anything else; +//! `hh mm` the time it came; the name is `nlen` bytes, the message is the rest; plain +//! ASCII (the phone replaces what the watch cannot draw). The newest chat is first. +//! `r1D` id that chat is gone (answered or dismissed on the phone) +//! `r1Q` n (len text)* up to 3 quick replies +//! `r1M` id flags text the rest of a long message: the whole line of the chat's newest message, in pieces of up to +//! `CHUNK` bytes (`flags` bit 7 = last piece, bits 0..3 = piece number, 0 first). It follows +//! the `r1L` / `r1U` that carried the first `TEXT_MAX` bytes, and replaces that message. +//! `r1R` id status the answer to a reply: 0 sent, 1 could not be sent +//! `r1U` id app hh mm nlen name msg quiet update for the conversation currently open; does not move its inbox card +//! `r1S` state dictation state: 0 ready, 1 listening, 2 error +//! `r1T` flags text recognized UTF-8 text; flags bit 7 = last piece, bits 0..3 = piece number +//! Watch -> phone: +//! `r1h` version hello: the app is open (repeated until the phone answers) +//! `r1x` id flags text a reply for chat `id`; `flags` bit 7 = the last piece, bits 0..3 = the piece number +//! `r1m` language start / stop a dictation; `a` Arabic (Egypt), `e` English, `h` Hindi. The sound is the +//! watch's own microphone: after the start come `r1a` messages, and the stop (second +//! `r1m`) follows the last of them +//! `r1a` seq block 8 kHz speech: one IMA ADPCM block of 240 samples (`stream.rs`); `seq` counts from 0 +//! `r1f` id heartbeat: conversation `id` is open (0 = inbox / no focused chat) +//! `r1z` app is closing; clear the focused conversation immediately +//! (0 first); the pieces are `CHUNK` bytes of text each + +pub const PREFIX: [u8; 2] = *b"r1"; +pub const VERSION: u8 = 1; +pub const MAX_CHATS: usize = 6; +pub const NAME_MAX: usize = 24; +pub const TEXT_MAX: usize = 96; +/// Bytes of earlier messages kept per chat (messages separated by a newline, oldest first). +pub const LOG_MAX: usize = 160; +/// First byte of a log entry that is a reply sent from the watch. +const MINE: u8 = 1; +/// The most of a sent reply that is kept in the log. +const MINE_MAX: usize = 120; +pub const QUICK_MAX: usize = 3; +pub const QUICK_LEN: usize = 24; +/// Bytes of reply text in one message. +pub const CHUNK: usize = 100; +/// The longest reply (two messages: the watch's outbox holds four). +pub const REPLY_MAX: usize = 2 * CHUNK; + +pub const APP_WHATSAPP: u8 = 1; +pub const APP_MESSENGER: u8 = 2; +pub const APP_TELEGRAM: u8 = 3; +pub const APP_INSTAGRAM: u8 = 4; +pub const APP_X: u8 = 5; +pub const APP_DISCORD: u8 = 6; +pub const APP_GENERIC: u8 = 7; + +/// The two keyboards the phone chose for holding Space (see `keys::next_language`). +pub static KB1: core::sync::atomic::AtomicU8 = core::sync::atomic::AtomicU8::new(0); +pub static KB2: core::sync::atomic::AtomicU8 = core::sync::atomic::AtomicU8::new(1); + +/// How the chat looks, set from the phone (percent): the text size and the bubble padding/spacing. +pub static TEXT_PCT: core::sync::atomic::AtomicI32 = core::sync::atomic::AtomicI32::new(100); +pub static BUBBLE_PCT: core::sync::atomic::AtomicI32 = core::sync::atomic::AtomicI32::new(100); + +pub fn hello() -> [u8; 4] { + [b'r', b'1', b'h', VERSION] +} + +/// Start or stop a dictation (the sound follows as `r1a` messages). Phone replies with r1S state and r1T transcript chunks. +pub fn dictation_toggle(lang: u8) -> [u8; 4] { + [b'r', b'1', b'm', match lang { 1 => b'a', 2 => b'h', _ => b'e' }] +} + +/// Heartbeat sent while the watch app is open. `0` means the inbox, not a conversation. +pub fn focus(chat_id: u8) -> [u8; 4] { + [b'r', b'1', b'f', chat_id] +} + +/// Pin (`on`) or unpin chat `chat_id`. +pub fn pin(chat_id: u8, on: bool) -> [u8; 5] { + [b'r', b'1', b'p', chat_id, on as u8] +} + +/// Explicit close; the phone also expires focus if this message is lost. +pub fn close_focus() -> [u8; 3] { + *b"r1z" +} + +#[derive(Clone, Copy)] +pub struct Chat { + pub id: u8, + pub app: u8, + pub hh: u8, + pub mm: u8, + nlen: u8, + mlen: u8, + name: [u8; NAME_MAX], + msg: [u8; TEXT_MAX], + llen: u16, + log: [u8; LOG_MAX], + /// Messages that came in since this chat was last opened. + pub unread: u8, + /// Kept in the list: a new chat never pushes it out (the phone keeps its reply action too). + pub pinned: bool, +} + +fn text(b: &[u8]) -> &str { + core::str::from_utf8(b).unwrap_or("?") +} + +impl Chat { + pub const EMPTY: Chat = Chat { id: 0, app: 0, hh: 0, mm: 0, nlen: 0, mlen: 0, name: [0; NAME_MAX], msg: [0; TEXT_MAX], llen: 0, log: [0; LOG_MAX], unread: 0, pinned: false }; + + pub fn name(&self) -> &str { + text(&self.name[..self.nlen as usize]) + } + + pub fn msg(&self) -> &str { + let t = text(&self.msg[..self.mlen as usize]); + t.rsplit('\u{2}').next().unwrap_or(t) + } + + /// Every message kept for this chat, oldest first (the replies sent from the watch too). + pub fn log(&self) -> impl Iterator { + self.entries().map(|(_, t)| t) + } + + /// Every kept message, oldest first: `(true, text)` for a reply sent from the watch, `(false, text)` for one that came in. + pub fn entries(&self) -> impl Iterator { + let l = &self.log[..self.llen as usize]; + l.split(|&b| b == b'\n').filter(|e| !e.is_empty()).map(|e| match e.split_first() { + Some((&MINE, rest)) => (true, text(rest)), + _ => (false, text(e)), + }) + } + + /// Adds the newest message to the log (not again if it is the same as the last one); the oldest fall off when full. + fn remember(&mut self, body: &[u8]) { + let last = self.log[..self.llen as usize].rsplit(|&b| b == b'\n').next(); + // the first part of a long message (it came whole afterwards) is the same message again, not a new one + let known_start = body.len() + 4 >= TEXT_MAX && last.is_some_and(|l| l.len() > body.len() && l.starts_with(body)); + if body.is_empty() || last == Some(body) || known_start { + return; + } + self.push_entry(body); + } + + /// More of the newest message (a later piece of a long one): added to its end, dropping the oldest messages when the + /// log is full and cutting what still does not fit. True when something was added. + fn append_last(&mut self, part: &[u8]) -> bool { + let mut l = self.llen as usize; + if l == 0 || part.is_empty() { + return false; + } + while l + part.len() > LOG_MAX { + let Some(p) = self.log[..l].iter().position(|&b| b == b'\n') else { break }; + self.log.copy_within(p + 1..l, 0); + l -= p + 1; + } + let part = cut(&part[..part.len().min(LOG_MAX - l)]); + self.log[l..l + part.len()].copy_from_slice(part); + self.llen = (l + part.len()) as u16; + !part.is_empty() + } + + /// The newest message turned out to be longer than what came first: `body` is all of it. It replaces that message + /// (only when it continues it). True when the log changed. + fn replace_last(&mut self, body: &[u8]) -> bool { + let l = self.llen as usize; + let start = self.log[..l].iter().rposition(|&b| b == b'\n').map_or(0, |i| i + 1); + let cur = &self.log[start..l]; + if body.len() <= cur.len() || !body.starts_with(cur) { + return false; + } + self.llen = start.saturating_sub(1) as u16; // without the old entry and the newline before it + self.push_entry(body); + true + } + + /// Keeps a reply sent from the watch (shown as a grey bubble of its own). + pub fn remember_mine(&mut self, body: &[u8]) { + let body = cut(&body[..body.len().min(MINE_MAX)]); + if body.is_empty() { + return; + } + let mut e = [0u8; MINE_MAX + 1]; + e[0] = MINE; + e[1..=body.len()].copy_from_slice(body); + self.push_entry(&e[..=body.len()]); + } + + fn push_entry(&mut self, body: &[u8]) { + let body = cut(&body[..body.len().min(LOG_MAX - 1)]); + while self.llen > 0 && self.llen as usize + 1 + body.len() > LOG_MAX { + let l = self.llen as usize; + let cut_at = self.log[..l].iter().position(|&b| b == b'\n').map_or(l, |i| i + 1); + self.log.copy_within(cut_at..l, 0); + self.llen = (l - cut_at) as u16; + } + let l = self.llen as usize; + let at = if l > 0 { self.log[l] = b'\n'; l + 1 } else { 0 }; + self.log[at..at + body.len()].copy_from_slice(body); + self.llen = (at + body.len()) as u16; + } + + /// "9:05 a.m." for the time the message came. + pub fn clock<'a>(&self, buf: &'a mut [u8; 10]) -> &'a str { + let (h, m) = (self.hh.min(23), self.mm.min(59)); + let h12 = if h % 12 == 0 { 12 } else { h % 12 }; + let mut n = 0; + if h12 >= 10 { + buf[n] = b'0' + h12 / 10; + n += 1; + } + buf[n] = b'0' + h12 % 10; + buf[n + 1] = b':'; + buf[n + 2] = b'0' + m / 10; + buf[n + 3] = b'0' + m % 10; + n += 4; + let suffix: &[u8] = if h < 12 { b" a.m." } else { b" p.m." }; + buf[n..n + 5].copy_from_slice(suffix); + text(&buf[..n + 5]) + } +} + +#[derive(PartialEq, Eq, Debug, Clone, Copy)] +pub enum Effect { + Ignored, + /// The chats or the quick replies changed. + Changed, + /// The phone answered a reply: (chat, status). + Result(u8, u8), +} + +pub struct Model { + pub chats: [Chat; MAX_CHATS], + pub n: usize, + quick: [[u8; QUICK_LEN]; QUICK_MAX], + qlen: [u8; QUICK_MAX], + pub nq: usize, + /// Something from the phone has arrived since the app opened. + pub heard: bool, + /// The reply just sent from the watch, for a little while: the chat app puts it in the notification, so the phone + /// sends it back as if it were a new message from the other side. That echo must not become a bubble of theirs. + echo: [u8; MINE_MAX], + echo_len: u8, + echo_id: u8, + echo_on: bool, + /// The long message that is coming in pieces (`r1M`): its chat and the piece that is next. + more_id: u8, + more_next: u8, +} + +impl Model { + pub const fn new() -> Model { + Model { chats: [Chat::EMPTY; MAX_CHATS], n: 0, quick: [[0; QUICK_LEN]; QUICK_MAX], qlen: [0; QUICK_MAX], nq: 0, heard: false, echo: [0; MINE_MAX], echo_len: 0, echo_id: 0, echo_on: false, more_id: 0, more_next: 0 } + } + + /// A reply to chat `id` has just been sent: the phone may send it straight back as a message of that chat. + pub fn arm_echo(&mut self, id: u8, body: &[u8]) { + let body = cut(&body[..body.len().min(MINE_MAX)]); + self.echo[..body.len()].copy_from_slice(body); + (self.echo_len, self.echo_id, self.echo_on) = (body.len() as u8, id, !body.is_empty()); + } + + /// The reply was not sent, or long enough has passed: a message like it is a new one. + pub fn disarm_echo(&mut self) { + self.echo_on = false; + } + + /// `body`, a message that came in for chat `id`, is my own reply coming back (the same text, or with the sender's + /// name in front: "You: ok"). + fn is_echo(&self, id: u8, body: &[u8]) -> bool { + let e = &self.echo[..self.echo_len as usize]; + self.echo_on && self.echo_id == id && !e.is_empty() && (body == e || (body.len() > e.len() + 2 && body.ends_with(e) && body[body.len() - e.len() - 2..][..2] == *b": ")) + } + + /// The quick replies the app has before the phone sends its own. + pub fn set_defaults(&mut self) { + for (i, t) in ["Ok", "On my way", "Thanks!"].iter().enumerate() { + self.quick[i][..t.len()].copy_from_slice(t.as_bytes()); + self.qlen[i] = t.len() as u8; + } + self.nq = 3; + } + + /// What the row under the text shows: the quick replies while nothing is typed, else words that continue the word being typed. + pub fn items<'a>(&'a self, text: &[u8]) -> ([&'a str; 3], usize) { + let mut out = [""; 3]; + if text.is_empty() { + for i in 0..self.nq.min(3) { + out[i] = self.quick(i); + } + return (out, self.nq.min(3)); + } + let mut sug = [""; 3]; + let n = if text.last() == Some(&b' ') { + crate::words::predict_next(text, &mut sug) + } else { + crate::words::suggest(crate::words::fragment(text), &mut sug) + }; + out[..n].copy_from_slice(&sug[..n]); + (out, n) + } + + pub fn quick(&self, i: usize) -> &str { + text(&self.quick[i][..self.qlen[i] as usize]) + } + + /// A reply to chat `id` went out: it joins that chat's messages as a bubble of mine. + pub fn sent(&mut self, id: u8, body: &[u8]) { + if let Some(i) = self.find(id) { + self.chats[i].remember_mine(body); + } + } + + pub fn find(&self, id: u8) -> Option { + self.chats[..self.n].iter().position(|c| c.id == id) + } + + /// Replace a chat in place for a message arriving from the conversation currently on screen. + /// It updates the visible thread without moving that thread to the front of the inbox. + fn update_in_place(&mut self, mut c: Chat) { + if let Some(i) = self.find(c.id) { + let old = self.chats[i]; + if c.llen == 0 { + (c.llen, c.log) = (old.llen, old.log); + } + let last = c.msg; + let ml = c.mlen as usize; + c.remember(&last[..ml]); + self.chats[i] = c; + } else { + self.put_first(c); + } + } + + fn remove(&mut self, i: usize) { + self.chats.copy_within(i + 1..self.n, i); + self.n -= 1; + } + + /// The chat comes first in the list; the oldest falls off when it is full. + fn put_first(&mut self, c: Chat) { + // one page per chat: the phone gives every chat its own id (names can look alike when letters are replaced by dots) + let mut c = c; + while let Some(i) = self.chats[..self.n].iter().position(|o| o.id == c.id) { + // the messages that came before stay, so the second screen shows everything that was missed + let old = self.chats[i]; + if c.llen == 0 { + (c.llen, c.log) = (old.llen, old.log); + } + self.remove(i); + } + let last = c.msg; + let ml = c.mlen as usize; + c.remember(&last[..ml]); + if self.n == MAX_CHATS { + // the oldest chat that is not pinned goes; with every slot pinned nothing new comes in + match self.chats[..self.n].iter().rposition(|o| !o.pinned) { + Some(i) => self.remove(i), + None => return, + } + } + self.chats.copy_within(0..self.n, 1); + self.chats[0] = c; + self.n += 1; + } + + pub fn apply(&mut self, msg: &[u8]) -> Effect { + if msg.len() < 3 || msg[..2] != PREFIX { + return Effect::Ignored; + } + self.heard = true; + let d = &msg[3..]; + match msg[2] { + b'C' => { + self.n = 0; + Effect::Changed + } + b'K' if d.len() >= 2 => { + KB1.store(d[0].min(2), core::sync::atomic::Ordering::Relaxed); + KB2.store(d[1].min(3), core::sync::atomic::Ordering::Relaxed); + Effect::Ignored + } + b'W' if d.len() >= 2 => { + TEXT_PCT.store((d[0] as i32).clamp(60, 150), core::sync::atomic::Ordering::Relaxed); + BUBBLE_PCT.store((d[1] as i32).clamp(60, 150), core::sync::atomic::Ordering::Relaxed); + Effect::Changed + } + b'L' | b'U' if d.len() >= 6 => { + let nlen = (d[4] as usize).min(NAME_MAX).min(d.len() - 5); + let rest = &d[5 + nlen..]; + let mlen = rest.len().min(TEXT_MAX); + let mut c = Chat { id: d[0], app: d[1] & 0x7F, pinned: d[1] & 0x80 != 0, hh: d[2], mm: d[3], nlen: nlen as u8, mlen: mlen as u8, ..Chat::EMPTY }; + // a cut that fell inside a letter is dropped, not shown as a question mark + let name = cut(&d[5..5 + nlen]); + let body = cut(&rest[..mlen]); + // a leading \u{1} marks a message I sent (from another device/app): show it on my side + let (mine_msg, body) = match body.split_first() { Some((&MINE, r)) => (true, r), _ => (false, body) }; + if self.is_echo(d[0], body) { + self.echo_on = false; // once: a later message like it is theirs + return Effect::Ignored; + } + c.nlen = name.len() as u8; + c.name[..name.len()].copy_from_slice(name); + let id = d[0]; + let before = self.find(id).map_or(0, |i| self.chats[i].unread); + c.unread = before.saturating_add(!mine_msg as u8); + if mine_msg { + // keep it out of "their" log; add it as mine once the chat is in place + c.mlen = 0; + if msg[2] == b'U' { self.update_in_place(c); } else { self.put_first(c); } + if let Some(i) = self.find(id) { + let ch = &mut self.chats[i]; + let shown = body.split(|&b| b == 2).last().unwrap_or(body); + ch.remember_mine(shown); + let n = shown.len().min(ch.msg.len()); + ch.msg[..n].copy_from_slice(&shown[..n]); + ch.mlen = n as u8; + } + } else { + c.mlen = body.len() as u8; + c.msg[..body.len()].copy_from_slice(body); + if msg[2] == b'U' { self.update_in_place(c); } else { self.put_first(c); } + } + Effect::Changed + } + b'M' if d.len() >= 2 => { + let (id, n, last) = (d[0], d[1] & 15, d[1] & 0x80 != 0); + if n == 0 { + (self.more_id, self.more_next) = (id, 0); + } + let Some(i) = self.find(id) else { return Effect::Ignored }; + if self.more_id != id || self.more_next != n { + self.more_id = 0; // a piece went missing: what came stays as it is + return Effect::Ignored; + } + self.more_next += 1; + // the first piece is the message from its start (it replaces what came first); the rest is added to it + let ok = if n == 0 { self.chats[i].replace_last(&d[2..]) } else { self.chats[i].append_last(&d[2..]) }; + if !ok || last { + self.more_id = 0; + } + if ok { Effect::Changed } else { Effect::Ignored } + } + b'D' if !d.is_empty() => match self.find(d[0]) { + Some(i) => { + self.remove(i); + Effect::Changed + } + None => Effect::Ignored, + }, + b'Q' if !d.is_empty() => { + self.nq = 0; + let mut at = 1; + for _ in 0..(d[0] as usize).min(QUICK_MAX) { + let Some(&l) = d.get(at) else { break }; + let l = (l as usize).min(QUICK_LEN); + let Some(t) = d.get(at + 1..at + 1 + l) else { break }; + let t = cut(t); + self.quick[self.nq][..t.len()].copy_from_slice(t); + self.qlen[self.nq] = t.len() as u8; + self.nq += 1; + at += 1 + l; + } + Effect::Changed + } + b'R' if d.len() >= 2 => Effect::Result(d[0], d[1]), + _ => Effect::Ignored, + } + } +} + +impl Default for Model { + fn default() -> Self { + Model::new() + } +} + +/// `b` without a letter that was cut in half at its end. +fn cut(b: &[u8]) -> &[u8] { + match core::str::from_utf8(b) { + Ok(_) => b, + Err(e) => &b[..e.valid_up_to()], + } +} + +/// How many messages a reply of `len` bytes takes. +pub fn pieces(len: usize) -> usize { + len.div_ceil(CHUNK).max(1) +} + +/// Piece `i` of the reply `text` for chat `id`, written to `out`; returns its length. +pub fn reply_piece(id: u8, text: &[u8], i: usize, out: &mut [u8; 128]) -> usize { + let part = &text[(i * CHUNK).min(text.len())..((i + 1) * CHUNK).min(text.len())]; + let last = (i + 1) * CHUNK >= text.len(); + out[..3].copy_from_slice(b"r1x"); + out[3] = id; + out[4] = (i as u8 & 15) | if last { 0x80 } else { 0 }; + out[5..5 + part.len()].copy_from_slice(part); + 5 + part.len() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn same_chat_is_one_page_and_the_ninth_drops_the_oldest() { + let mut m = Model::new(); + m.apply(&chat(1, 1, "Group", "first")); + m.apply(&chat(1, 1, "Group", "second")); // same chat (same id) + m.apply(&chat(3, 2, "Group", "other app")); + m.apply(&chat(4, 1, "Group", "same name, other chat")); // names can look alike (Arabic names become dots) + assert_eq!(m.n, 3); + assert_eq!(m.chats[2].msg(), "second"); + let mut m = Model::new(); + for i in 0..9u8 { + m.apply(&chat(i, 1, &std::format!("P{i}"), "x")); + } + assert_eq!(m.n, MAX_CHATS); + assert_eq!(m.chats[0].name(), "P8"); + assert_eq!(m.chats[MAX_CHATS - 1].name(), "P3"); + } + + #[test] + fn a_long_message_comes_whole_in_pieces_and_is_not_shown_twice() { + let mut m = Model::new(); + let full: std::string::String = (0..20).map(|i| std::format!("word{i} ")).collect::().trim().into(); + assert!(full.len() > TEXT_MAX + 20 && full.len() < LOG_MAX); + let preview = &full[..TEXT_MAX]; + m.apply(&chat(1, 1, "Sam", preview)); + assert_eq!(m.chats[0].log().next(), Some(preview)); + let bytes = full.as_bytes(); + let n = bytes.len().div_ceil(CHUNK); + for i in 0..n { + let mut v = std::vec![b'r', b'1', b'M', 1, i as u8 | if i + 1 == n { 0x80 } else { 0 }]; + v.extend_from_slice(&bytes[i * CHUNK..((i + 1) * CHUNK).min(bytes.len())]); + let e = m.apply(&v); + assert_eq!(e, Effect::Changed); + } + assert_eq!(m.chats[0].log().collect::>(), std::vec![full.as_str()]); + // the same message sent again (an update of the notification) is not a second bubble + m.apply(&chat(1, 1, "Sam", preview)); + assert_eq!(m.chats[0].log().count(), 1); + // a short one that follows is + m.apply(&chat(1, 1, "Sam", "ok")); + assert_eq!(m.chats[0].log().count(), 2); + // a piece that goes missing leaves the first part as it was + let mut m = Model::new(); + m.apply(&chat(1, 1, "Sam", preview)); + let mut v = std::vec![b'r', b'1', b'M', 1, 1]; + v.extend_from_slice(b"stray"); + assert_eq!(m.apply(&v), Effect::Ignored); + assert_eq!(m.chats[0].log().next(), Some(preview)); + } + + fn chat(id: u8, app: u8, name: &str, msg: &str) -> std::vec::Vec { + let mut v = std::vec![b'r', b'1', b'L', id, app, 10, 20, name.len() as u8]; + v.extend_from_slice(name.as_bytes()); + v.extend_from_slice(msg.as_bytes()); + v + } + + #[test] + fn a_focused_chat_update_does_not_move_its_inbox_card() { + let mut m = Model::new(); + m.apply(&chat(1, 1, "Jane", "first")); + m.apply(&chat(2, 1, "Bob", "other")); + let mut update = chat(1, 1, "Jane", "new message"); + update[2] = b'U'; + assert_eq!(m.apply(&update), Effect::Changed); + assert_eq!(m.chats[0].name(), "Bob"); + assert_eq!(m.chats[1].name(), "Jane"); + assert_eq!(m.chats[1].msg(), "new message"); + assert_eq!(m.chats[1].log().last(), Some("new message")); + } + + #[test] + fn a_chat_comes_in_first_and_an_update_moves_it_up() { + let mut m = Model::new(); + assert_eq!(m.apply(&chat(1, 1, "Jane", "hi")), Effect::Changed); + m.apply(&chat(2, 3, "Bob", "yo")); + assert_eq!((m.n, m.chats[0].name(), m.chats[1].name()), (2, "Bob", "Jane")); + m.apply(&chat(1, 1, "Jane", "are you there?")); + assert_eq!((m.n, m.chats[0].name(), m.chats[0].msg(), m.chats[1].name()), (2, "Jane", "are you there?", "Bob")); + let mut b = [0; 10]; + assert_eq!(m.chats[0].clock(&mut b), "10:20 a.m."); + let mut c = Chat::EMPTY; + (c.hh, c.mm) = (0, 5); + assert_eq!(c.clock(&mut b), "12:05 a.m."); + (c.hh, c.mm) = (13, 40); + assert_eq!(c.clock(&mut b), "1:40 p.m."); + (c.hh, c.mm) = (12, 0); + assert_eq!(c.clock(&mut b), "12:00 p.m."); + assert!(m.heard); + } + + #[test] + fn the_phone_chooses_the_two_keyboards() { + let mut m = Model::new(); + m.apply(&[b'r', b'1', b'K', 2, 0]); + assert_eq!((KB1.load(core::sync::atomic::Ordering::Relaxed), KB2.load(core::sync::atomic::Ordering::Relaxed)), (2, 0)); + m.apply(&[b'r', b'1', b'K', 0, 1]); // back to the defaults for the other tests + assert_eq!(dictation_toggle(2)[3], b'h'); + } + + #[test] + fn pinned_chats_stay_and_new_ones_push_out_the_oldest_unpinned() { + let pinned = |id: u8| { + let mut v = chat(id, 1, &std::format!("P{id}"), "x"); + v[4] |= 0x80; // the app byte: bit 7 = pinned + v + }; + let mut m = Model::new(); + m.apply(&pinned(1)); + for i in 2..=8 { + m.apply(&chat(i, 1, &std::format!("P{i}"), "x")); + } + assert_eq!(m.n, MAX_CHATS); + assert!(m.chats[MAX_CHATS - 1].pinned && m.chats[MAX_CHATS - 1].name() == "P1"); + m.apply(&chat(9, 1, "P9", "x")); // pushes out P2, the oldest that is not pinned + assert_eq!((m.n, m.chats[0].name(), m.chats[MAX_CHATS - 1].name()), (MAX_CHATS, "P9", "P1")); + assert!(m.find(2).is_none()); + // every slot pinned: a new chat does not come in + let mut m = Model::new(); + for i in 1..=8 { + m.apply(&pinned(i)); + } + m.apply(&chat(9, 1, "P9", "x")); + assert!(m.find(9).is_none() && m.n == MAX_CHATS); + // a pinned chat that talks again stays pinned and goes to the front + m.apply(&pinned(3)); + assert_eq!((m.chats[0].id, m.chats[0].pinned), (3, true)); + } + + #[test] + fn the_list_holds_six_and_chats_can_go() { + let mut m = Model::new(); + for i in 0..10u8 { + m.apply(&chat(i, 1, &std::format!("n{i}"), "y")); + } + assert_eq!((m.n, m.chats[0].id, m.chats[5].id), (6, 9, 4)); + assert_eq!(m.apply(&[b'r', b'1', b'D', 9]), Effect::Changed); + assert_eq!((m.n, m.chats[0].id), (5, 8)); + assert_eq!(m.apply(&[b'r', b'1', b'D', 77]), Effect::Ignored); + m.apply(b"r1C"); + assert_eq!(m.n, 0); + } + + #[test] + fn other_apps_messages_and_short_ones_are_ignored() { + let mut m = Model::new(); + assert_eq!(m.apply(b"n1S"), Effect::Ignored); + assert_eq!(m.apply(b"r1"), Effect::Ignored); + assert!(!m.heard); + assert_eq!(m.apply(b"r1L\x01"), Effect::Ignored); // a short one from the phone still shows it is there + assert!(m.heard); + } + + #[test] + fn a_letter_cut_in_half_is_dropped() { + let mut m = Model::new(); + let mut v = chat(1, 1, "Jane", "ab"); + v.extend_from_slice(&"é".as_bytes()[..1]); + m.apply(&v); + assert_eq!(m.chats[0].msg(), "ab"); + } + + #[test] + fn quick_replies_and_results() { + let mut m = Model::new(); + m.apply(b"r1Q\x02\x02Ok\x0bOn my way!!"); + assert_eq!((m.nq, m.quick(0), m.quick(1)), (2, "Ok", "On my way!!")); + assert_eq!(m.apply(&[b'r', b'1', b'R', 4, 1]), Effect::Result(4, 1)); + } + + #[test] + fn a_reply_is_cut_into_pieces() { + let text = [b'a'; 150]; + assert_eq!((pieces(0), pieces(100), pieces(101), pieces(200)), (1, 1, 2, 2)); + let mut out = [0u8; 128]; + let n = reply_piece(7, &text, 0, &mut out); + assert_eq!((n, &out[..3], out[3], out[4]), (105, &b"r1x"[..], 7, 0)); + let n = reply_piece(7, &text, 1, &mut out); + assert_eq!((n, out[4]), (55, 0x81)); + let n = reply_piece(7, b"hello", 0, &mut out); + assert_eq!((n, out[4], &out[5..10]), (10, 0x80, &b"hello"[..])); + // exactly one full piece is a single, last piece + let n = reply_piece(7, &text[..100], 0, &mut out); + assert_eq!((n, out[4]), (105, 0x80)); + } +} + +#[cfg(test)] +mod history_tests { + use super::*; + fn l(id: u8, name: &str, msg: &str) -> Vec { + let mut v = vec![b'r', b'1', b'L', id, 1, 9, 5, name.len() as u8]; + v.extend(name.as_bytes()); + v.extend(msg.as_bytes()); + v + } + #[test] + fn new_messages_pile_up_in_their_chat() { + let mut m = Model::new(); + for t in ["one", "two", "two", "three"] { + m.apply(&l(7, "Sam", t)); + } + assert_eq!(m.n, 1); + assert_eq!(m.chats[0].msg(), "three"); + assert_eq!(m.chats[0].log().collect::>(), ["one", "two", "three"]); + let long = "x".repeat(90); + for _ in 0..8 { + m.apply(&l(7, "Sam", &long)); + m.apply(&l(7, "Sam", "y")); + } + assert!(m.chats[0].llen as usize <= LOG_MAX); + assert_eq!(m.chats[0].log().last(), Some("y")); + m.apply(b"r1C"); + m.apply(&l(7, "Sam", "fresh")); + assert_eq!(m.chats[0].log().collect::>(), ["fresh"]); + } + + #[test] + fn sent_replies_are_kept_as_mine() { + let mut m = Model::new(); + m.apply(&l(7, "Sam", "hi")); + m.sent(7, b"hello"); + m.sent(7, b"hello"); + m.apply(&l(7, "Sam", "ok")); + let e: Vec<_> = m.chats[0].entries().collect(); + assert_eq!(e, [(false, "hi"), (true, "hello"), (true, "hello"), (false, "ok")]); + assert_eq!(m.chats[0].log().collect::>(), ["hi", "hello", "hello", "ok"]); + } + + #[test] + fn my_reply_coming_back_from_the_phone_is_not_a_message_from_them() { + let mut m = Model::new(); + m.apply(&l(7, "Sam", "hi")); + m.arm_echo(7, b"yo"); + // the chat app shows my reply in the notification; the phone sends it as a new message: not theirs + assert_eq!(m.apply(&l(7, "Sam", "yo")), Effect::Ignored); + m.sent(7, b"yo"); + assert_eq!(m.chats[0].entries().collect::>(), [(false, "hi"), (true, "yo")]); + // it only counts once: the same words from them later are theirs + m.apply(&l(7, "Sam", "yo")); + assert_eq!(m.chats[0].entries().last(), Some((false, "yo"))); + // with the name in front, and when the echo comes after the phone said it was sent + m.arm_echo(7, b"ok"); + m.sent(7, b"ok"); + assert_eq!(m.apply(&l(7, "Sam", "You: ok")), Effect::Ignored); + assert_eq!(m.chats[0].entries().last(), Some((true, "ok"))); + // another chat, a different text, and a reply that was disarmed are all theirs + m.arm_echo(7, b"hey"); + assert_eq!(m.apply(&l(8, "Al", "hey")), Effect::Changed); + assert_eq!(m.apply(&l(7, "Sam", "hey there")), Effect::Changed); + m.arm_echo(7, b"late"); + m.disarm_echo(); + assert_eq!(m.apply(&l(7, "Sam", "late")), Effect::Changed); + } +} diff --git a/apps/watch-replies/src/stream.rs b/apps/watch-replies/src/stream.rs new file mode 100644 index 0000000..1cce96d --- /dev/null +++ b/apps/watch-replies/src/stream.rs @@ -0,0 +1,149 @@ +//! The watch's own microphone, streamed to the phone: 8 kHz speech as IMA ADPCM blocks, one block to a message. +//! The phone decodes them and feeds its speech recognizer; the text comes back as `r1T`, as before. +//! +//! Wire (watch -> phone): `r1a` seq block; the block is `adpcm::encode_block` of `BLOCK_SAMPLES` samples +//! (3 header bytes + 120 code bytes), so a message is 127 bytes. 33 messages a second, about 4.2 KB/s. + +use cmf_wp2_app::adpcm::{self, State, BLOCK_HEADER}; +use cmf_wp2_app::mic::Voice; +use cmf_wp2_app::{Api, MSG_MAX}; + +/// Samples (8 kHz) in one message. +pub const BLOCK_SAMPLES: usize = 240; +const BLOCK_BYTES: usize = BLOCK_HEADER + BLOCK_SAMPLES / 2; +const _: () = assert!(4 + BLOCK_BYTES <= MSG_MAX); +/// One block plus one read of slack; while the outbox is full, newer samples are dropped (the RAM of the app is tight). +const CAP: usize = BLOCK_SAMPLES + 64; +/// The real watch's mic always gives two channels (measured 2026-11-26), so skip the 400 ms of measuring that +/// `Voice` does, which would swallow the first words. Set to false to measure (the emulator gives one channel). +const ASSUME_STEREO: bool = true; + +#[derive(PartialEq, Eq, Clone, Copy)] +pub enum Svc { + /// Streaming (or nothing to do). + Run, + /// Stop was asked and every sample is sent: send the stop message to the phone, then call `close`. + Drained, + /// The mic could not be read. + MicFailed, +} + +pub struct Stream { + voice: Option, + samples: [i16; CAP], + len: usize, + state: State, + seq: u8, + /// `r1a` seq block, built once and kept until the outbox takes it. + msg: [u8; MSG_MAX], + pending: usize, + stopping: bool, + /// The language byte the phone was asked to listen in (for the stop message). + pub lang: u8, +} + +impl Stream { + pub const fn new() -> Stream { + Stream { + voice: None, + samples: [0; CAP], + len: 0, + state: State { predictor: 0, index: 0 }, + seq: 0, + msg: [0; MSG_MAX], + pending: 0, + stopping: false, + lang: 0, + } + } + + pub fn running(&self) -> bool { + self.voice.is_some() + } + + /// Opens the mic. False if it would not open. + pub fn start(&mut self, api: &Api, lang: u8) -> bool { + self.close(api); + let (mut v, rc) = Voice::start(api); + if rc < 0 { + Voice::stop(api); + return false; + } + if ASSUME_STEREO { + v.channels = 2; + } + self.voice = Some(v); + self.len = 0; + self.pending = 0; + self.seq = 0; + self.state = State { predictor: 0, index: 0 }; + self.stopping = false; + self.lang = lang; + self.msg[..3].copy_from_slice(b"r1a"); + true + } + + /// The person is done talking: what is already recorded still goes out, then `service` says `Drained`. + pub fn request_stop(&mut self) { + self.stopping = true; + } + + /// Closes the mic and drops what has not been sent. + pub fn close(&mut self, api: &Api) { + if self.voice.take().is_some() { + Voice::stop(api); + } + self.len = 0; + self.pending = 0; + self.stopping = false; + } + + /// Call often (every 25 ms or less while `running`): takes what the mic has and sends what the outbox allows. + pub fn service(&mut self, api: &Api) -> Svc { + let Self { voice, samples, len, .. } = self; + let Some(v) = voice else { return Svc::Run }; + let rc = v.pump(api, |s| { + if *len < CAP { + samples[*len] = s; + *len += 1; + } + }); + if rc < 0 { + return Svc::MicFailed; + } + self.flush(api); + if self.stopping && self.pending == 0 { + if self.len > 0 { + // the last, short block: padded with silence + self.samples[self.len..BLOCK_SAMPLES].fill(0); + self.len = BLOCK_SAMPLES; + self.flush(api); + } + if self.pending == 0 && self.len == 0 { + return Svc::Drained; + } + } + Svc::Run + } + + fn flush(&mut self, api: &Api) { + loop { + if self.pending == 0 { + if self.len < BLOCK_SAMPLES { + return; + } + self.msg[3] = self.seq; + let n = adpcm::encode_block(&mut self.state, &self.samples[..BLOCK_SAMPLES], &mut self.msg[4..]); + debug_assert_eq!(n, BLOCK_BYTES); + self.samples.copy_within(BLOCK_SAMPLES..self.len, 0); + self.len -= BLOCK_SAMPLES; + self.pending = 4 + n; + } + if api.send(&self.msg[..self.pending]) < 0 { + return; // outbox full (-11): the same message goes out next time + } + self.pending = 0; + self.seq = self.seq.wrapping_add(1); + } + } +} diff --git a/apps/watch-replies/src/view.rs b/apps/watch-replies/src/view.rs new file mode 100644 index 0000000..6c7681b --- /dev/null +++ b/apps/watch-replies/src/view.rs @@ -0,0 +1,1341 @@ +//! Every screen of Watch Replies: the empty screen with the three app icons, the message cards, the keyboard and the +//! short status pages. Everything is drawn with rectangles and `font.rs` text over a black screen. + +use crate::font::{Font, poly}; +use crate::fonts::{B, B as T}; // one 27 px font for all text: the 32 px one was too big for the watch's memory +use crate::keys::{self, Cell, Key, Page}; +use crate::proto::{self, Chat, Model}; +use cmf_wp2_ui::color::{BLACK, WHITE}; +use cmf_wp2_ui::draw::{disc, line, ring}; +use cmf_wp2_ui::{C, Rgb, SIZE, Surface}; + +const GREY: Rgb = Rgb(150, 150, 160); +const DIM: Rgb = Rgb(84, 86, 96); +const CARD: Rgb = Rgb(38, 46, 66); +const CARD_DOWN: Rgb = Rgb(52, 62, 88); +const KEY_DOWN: Rgb = Rgb(104, 110, 124); +const CHIP: Rgb = Rgb(52, 56, 61); +const KEY_FACE: Rgb = Rgb(52, 56, 61); +const SPACE_FACE: Rgb = Rgb(44, 48, 52); +const KEY_SPECIAL: Rgb = Rgb(52, 56, 61); +const BAR_TRACK: Rgb = Rgb(60, 62, 70); +const BLUE_LIGHT: Rgb = Rgb(138, 180, 248); +const GREEN: Rgb = Rgb(60, 200, 110); +const RED: Rgb = Rgb(235, 80, 70); + +// ---- shapes ---- + +/// A rectangle with round corners of radius `r`, antialiased against black. +fn rounded(s: &mut impl Surface, x: i32, y: i32, w: i32, h: i32, r: i32, c: Rgb) { + // the four discs must not overlap each other (their soft edges would show inside the shape) + let r = r.min(h / 4).min(w / 4); + disc(s, x + r, y + r, r, c, BLACK); + disc(s, x + w - 1 - r, y + r, r, c, BLACK); + disc(s, x + r, y + h - 1 - r, r, c, BLACK); + disc(s, x + w - 1 - r, y + h - 1 - r, r, c, BLACK); + let c = c.rgb565(); + s.rect(x + r, y, w - 2 * r, h, c); + s.rect(x, y + r, w, h - 2 * r, c); +} + +fn scaled(cx: i32, cy: i32, r: i32, pts: &[(i32, i32)], out: &mut [(i32, i32); 8]) -> usize { + // points are in 1/100 of the radius + for (o, p) in out.iter_mut().zip(pts) { + *o = (cx + (p.0 * r + 50 * p.0.signum()) / 100, cy + (p.1 * r + 50 * p.1.signum()) / 100); + } + pts.len() +} + +// ---- the three app icons (drawn, not pictures) ---- + +/// The sign of an app on a disc of radius `r`; `behind` is the colour round it. +pub fn app_icon(s: &mut impl Surface, app: u8, cx: i32, cy: i32, r: i32, behind: Rgb) { + let white = WHITE.rgb565(); + let mut p = [(0, 0); 8]; + // the real-looking pictures (64 px, on black); the drawn fallback below is for any other app + if behind == BLACK && crate::icons::draw(s, app, cx, cy) { + return; + } + match app { + proto::APP_WHATSAPP => { + let green = Rgb(37, 211, 102); + disc(s, cx, cy, r, green, behind); + let g = green.rgb565(); + // a speech bubble: a ring with a tail at the bottom left, and a handset inside + let n = scaled(cx, cy, r, &[(-50, 30), (-66, 68), (-14, 56)], &mut p); + poly(s, &p[..n], g, |_| white); + ring(s, cx, cy - r / 40, r * 5 / 10, r * 65 / 100, WHITE, green); + let w = (r * 22 / 100).max(3); + line(s, cx - r * 16 / 100, cy - r * 18 / 100, cx + r * 18 / 100, cy + r * 16 / 100, w, WHITE, green); + } + proto::APP_MESSENGER => { + let blue = Rgb(0, 132, 255); + disc(s, cx, cy, r, blue, behind); + let b = blue.rgb565(); + let n = scaled(cx, cy, r, &[(-34, 40), (-50, 70), (0, 50)], &mut p); + poly(s, &p[..n], white, |_| white); + disc(s, cx, cy - r / 25, r * 58 / 100, WHITE, blue); + let n = scaled(cx, cy - r / 25, r, &[(-38, 14), (6, -36), (6, -8), (38, -8), (-6, 36), (-6, 6)], &mut p); + poly(s, &p[..n], white, |_| b); + } + proto::APP_TELEGRAM => { + let sky = Rgb(42, 171, 238); + disc(s, cx, cy, r, sky, behind); + let n = scaled(cx, cy, r, &[(-46, -2), (46, -38), (24, 42), (0, 20), (-16, 34), (-18, 8)], &mut p); + poly(s, &p[..n], sky.rgb565(), |_| white); + } + _ => { + let grey = Rgb(110, 112, 124); + disc(s, cx, cy, r, grey, behind); + disc(s, cx, cy - r / 25, r * 52 / 100, WHITE, grey); + let n = scaled(cx, cy, r, &[(-30, 36), (-44, 62), (0, 48)], &mut p); + poly(s, &p[..n], grey.rgb565(), |_| white); + disc(s, cx, cy - r / 25, r * 38 / 100, Rgb(110, 112, 124), WHITE); + } + } +} + +// ---- text ---- + +fn put(s: &mut impl Surface, f: &Font, x: i32, base: i32, t: &str, fg: Rgb, bg: Rgb) -> i32 { + f.draw(s, x, base, t, fg.rgb565(), bg.rgb565()) +} + +fn centred(s: &mut impl Surface, f: &Font, cx: i32, base: i32, t: &str, max: i32, fg: Rgb, bg: Rgb) { + f.centre(s, cx, base, t, max, fg.rgb565(), bg.rgb565()); +} + +/// `t` cut into a first line that fits `max` px (at a space if it can) and what is left. +pub fn first_line<'a>(f: &Font, t: &'a str, max: i32) -> (&'a str, &'a str) { + if f.width(t) <= max { + return (t, ""); + } + let (mut w, mut end, mut space) = (0, 0, None); + for (i, c) in t.char_indices() { + let next = i + c.len_utf8(); + let measured = f.width(&t[..next]); + if measured > max { break; } + w = measured; + end = next; + if c == ' ' { space = Some(i); } + } + let at = space.filter(|&i| i > 0).unwrap_or(end); + (t[..at].trim_end(), t[at..].trim_start()) +} + +// ---- the empty screen and the status pages ---- + +pub fn idle(s: &mut impl Surface, heard: bool) { + s.rect(0, 0, SIZE, SIZE, 0); + centred(s, &T, C, 232, "No messages", 340, WHITE, BLACK); + let sub = if heard { "New ones show up here" } else { "Waiting for the phone…" }; + centred(s, &B, C, 274, sub, 340, GREY, BLACK); +} + +/// A page with one line of big text, a smaller line under it and a sign above: `kind` 0 none, 1 tick, 2 cross. +pub fn status(s: &mut impl Surface, kind: u8, title: &str, sub: &str) { + s.rect(0, 0, SIZE, SIZE, 0); + match kind { + 1 => { + disc(s, C, 170, 40, GREEN, BLACK); + line(s, C - 18, 172, C - 5, 186, 7, WHITE, GREEN); + line(s, C - 6, 186, C + 20, 156, 7, WHITE, GREEN); + } + 2 => { + disc(s, C, 170, 40, RED, BLACK); + line(s, C - 15, 155, C + 15, 185, 7, WHITE, RED); + line(s, C + 15, 155, C - 15, 185, 7, WHITE, RED); + } + _ => {} + } + centred(s, &T, C, 262, title, 320, WHITE, BLACK); + if !sub.is_empty() { + centred(s, &B, C, 300, sub, 320, GREY, BLACK); + } +} + +// ---- one message on a page ---- + +pub const PAGE_X: i32 = 56; +pub const PAGE_Y: i32 = 98; +pub const PAGE_W: i32 = 354; +pub const PAGE_H: i32 = 276; +const BODY_LINES: usize = 5; +const BODY_W: i32 = 296; + +/// The last page the list can show. +pub fn max_top(n: usize) -> usize { + n.saturating_sub(1) +} + +/// A touch is on the message's page. +pub fn page_at(x: i32, y: i32) -> bool { + x >= PAGE_X && x < PAGE_X + PAGE_W && y >= PAGE_Y - 34 && y < PAGE_Y + PAGE_H +} + +/// One chat on its own page, like a phone's notification: the app's sign in the middle at the top, then who wrote, when, +/// and the message in big letters. `n` chats in all, this is number `i`; `down`: a finger is on the page. +/// The pin sign (26 x 36, 4 levels: 0 none .. 3 white), blended over `behind`, centred on (cx, cy). +const PIN_W: i32 = 26; +const PIN_H: i32 = 36; +const PIN: [u8; 234] = [0, 0, 0, 4, 0, 0, 0, 0, 0, 3, 228, 0, 0, 0, 0, 0, 191, 224, 0, 0, 0, 0, 31, 255, 208, 0, 0, 0, 2, 255, 255, 144, 0, 0, 0, 47, 255, 255, 128, 0, 0, 1, 255, 255, 255, 64, 0, 0, 7, 255, 255, 253, 0, 0, 0, 127, 255, 255, 224, 0, 0, 15, 255, 255, 253, 0, 0, 2, 255, 255, 255, 128, 0, 0, 127, 255, 255, 240, 0, 0, 31, 255, 253, 104, 0, 0, 3, 255, 255, 128, 0, 2, 253, 191, 255, 244, 0, 0, 191, 255, 255, 254, 0, 0, 31, 255, 255, 255, 208, 0, 3, 255, 255, 255, 248, 0, 0, 127, 255, 255, 255, 64, 0, 2, 255, 255, 255, 224, 0, 0, 6, 255, 255, 255, 128, 0, 0, 7, 255, 255, 254, 0, 0, 0, 27, 255, 255, 240, 0, 0, 0, 31, 255, 255, 64, 0, 0, 10, 47, 255, 240, 0, 0, 1, 240, 111, 254, 0, 0, 0, 61, 0, 127, 192, 0, 0, 7, 128, 1, 164, 0, 0, 0, 240, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 7, 128, 0, 0, 0, 0, 0, 244, 0, 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 7, 192, 0, 0, 0, 0, 0, 180, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0]; + +/// The pin is drawn about 27% smaller than its 26 x 36 bitmap: 19 x 26, each output pixel averaging the bitmap pixels under it. +const PIN_OUT_W: i32 = 19; +const PIN_OUT_H: i32 = 26; + +fn pushpin(s: &mut impl Surface, cx: i32, cy: i32, behind: Rgb) { + let (x0, y0) = (cx - PIN_OUT_W / 2, cy - PIN_OUT_H / 2); + let level = |i: usize| ((PIN[i / 4] >> (6 - 2 * (i % 4))) & 3) as i32; + // common units: a bitmap pixel is PIN_OUT_W wide and PIN_OUT_H tall, an output pixel is PIN_W wide and PIN_H tall + let overlap = |o: i32, o_len: i32, i: i32, i_len: i32| ((o + 1) * o_len).min((i + 1) * i_len) - (o * o_len).max(i * i_len); + let total = PIN_W * PIN_H; + for oy in 0..PIN_OUT_H { + for ox in 0..PIN_OUT_W { + let mut sum = 0; + for y in (oy * PIN_H / PIN_OUT_H)..=(((oy + 1) * PIN_H - 1) / PIN_OUT_H).min(PIN_H - 1) { + let wy = overlap(oy, PIN_H, y, PIN_OUT_H); + if wy <= 0 { continue; } + for x in (ox * PIN_W / PIN_OUT_W)..=(((ox + 1) * PIN_W - 1) / PIN_OUT_W).min(PIN_W - 1) { + let wx = overlap(ox, PIN_W, x, PIN_OUT_W); + if wx > 0 { sum += wx * wy * level((y * PIN_W + x) as usize); } + } + } + if sum > 0 { + let mix = |b: u8| (b as i32 + (255 - b as i32) * sum / (3 * total)) as u8; + s.rect(x0 + ox, y0 + oy, 1, 1, Rgb(mix(behind.0), mix(behind.1), mix(behind.2)).rgb565()); + } + } + } +} + +pub fn page(s: &mut impl Surface, c: &Chat, i: usize, n: usize, down: bool) { + s.rect(0, 0, SIZE, SIZE, 0); + page_card(s, c, down); + page_dots(s, i, n); +} + +fn page_card(s: &mut impl Surface, c: &Chat, down: bool) { + let body = if down { CARD_DOWN } else { CARD }; + rounded(s, PAGE_X, PAGE_Y, PAGE_W, PAGE_H, 62, body); + // the sign sits on the card's top edge, half above it, with a thin black gap round it + if !crate::icons::cutout(s, c.app, C, PAGE_Y, 5) { + disc(s, C, PAGE_Y, 38, BLACK, BLACK); + } + app_icon(s, c.app, C, PAGE_Y, 32, BLACK); + if c.pinned { + pushpin(s, PAGE_X + PAGE_W - 35, PAGE_Y + 35, body); // this chat is pinned, tucked into the top right corner + } + centred(s, if c.name().is_ascii() { &T } else { &B }, C, PAGE_Y + 76, c.name(), 300, WHITE, body); + let mut clock = [0u8; 10]; + centred(s, &B, C, PAGE_Y + 108, c.clock(&mut clock), 300, GREY, body); + // the message, centred, as many lines as fit; the last one ends in "…" if there is more + let mut rest = c.msg(); + for line in 0..BODY_LINES { + let base = PAGE_Y + 146 + line as i32 * 29; + let (l, more) = first_line(&B, rest, BODY_W); + if line + 1 == BODY_LINES && !more.is_empty() { + let (cut, _) = B.fit(rest, BODY_W - 20); + let w = B.width(cut) + B.width("…"); + let x = C - w / 2; + let end = put(s, &B, x, base, cut, WHITE, body); + put(s, &B, end, base, "…", WHITE, body); + break; + } + if !l.is_empty() { + centred(s, &B, C, base, l, BODY_W, WHITE, body); + } + rest = more; + if rest.is_empty() { + break; + } + } +} + +fn page_dots(s: &mut impl Surface, i: usize, n: usize) { + if n > 1 { + let gap = 18; + let y0 = C - (n as i32 - 1) * gap / 2; + for k in 0..n { + let on = k == i; + disc(s, 438, y0 + k as i32 * gap, if on { 5 } else { 3 }, if on { WHITE } else { DIM }, BLACK); + } + } +} + + +// ---- the whole message ---- + +/// One step of the conversation's scrolling, in pixels. +/// The part of the screen the bubbles live in. +const VIEW_TOP: i32 = 78; +const VIEW_BOTTOM: i32 = 354; +const TEXT_W: i32 = 284; +/// Room between a bubble's edge and its text, sideways and above and below. +const NAME_H: i32 = 25; +/// How far the tail of a bubble reaches out past its side, from the bottom row up. +const TAIL: [i32; 10] = [14, 11, 8, 6, 4, 3, 2, 1, 1, 0]; + +/// A bubble with a pointed tail at its bottom corner (the left one for `left`, else the right one), like a messages app. +fn bubble(s: &mut impl Surface, x: i32, y: i32, w: i32, h: i32, c: Rgb, left: bool, has_tail: bool) { + let c = c.rgb565(); + let n = ROUND.len() as i32; + let row = |s: &mut dyn FnMut(i32, i32, i32, i32), r: i32| { + let from_bottom = h - 1 - r; + let (mut l, mut rt) = if r < n { (ROUND[r as usize], ROUND[r as usize]) } else if from_bottom < n { (ROUND[from_bottom as usize], ROUND[from_bottom as usize]) } else { (0, 0) }; + if has_tail && from_bottom < n { + let out = TAIL.get(from_bottom as usize).copied().unwrap_or(0); + if left { l = -out } else { rt = -out } + } + s(x + l, y + r, w - l - rt, 1); + }; + let mut fill = |x: i32, y: i32, w: i32, h: i32| s.rect(x, y, w, h, c); + for r in 0..n { + row(&mut fill, r); + } + fill(x, y + n, w, h - 2 * n); + for r in h - n..h { + row(&mut fill, r); + } +} + +/// The corner of a bubble: how far in each row from the edge starts. +const ROUND: [i32; 15] = [15, 12, 10, 8, 7, 6, 5, 4, 3, 3, 2, 2, 1, 1, 1]; + +/// The font and the line height of a bubble's text: the big English font when the text is plain English, else the one that +/// also has the Arabic letters. +fn text_font(_t: &str) -> (&'static Font, i32) { + // B contains both Latin and Arabic at 27 px. Scale it to 32 px so messages containing + // Arabic/Unicode are not visibly smaller than ASCII-only messages. + (&B, (35 * text_pct() + 50) / 100) +} + +const BODY_SCALE_DEN: i32 = 27; + +fn text_pct() -> i32 { proto::TEXT_PCT.load(core::sync::atomic::Ordering::Relaxed) } +/// The bubble's padding and spacing follow the text size (the phone has one slider), so a bigger text gets a bigger bubble. +fn bubble_pct() -> i32 { text_pct() } +/// The text scale numerator (32 is the normal size; the phone's slider changes it). +fn body_num() -> i32 { ((32 * text_pct() + 50) / 100).max(16) } +fn padx() -> i32 { (17 * bubble_pct() + 50) / 100 } +fn pady() -> i32 { (11 * bubble_pct() + 50) / 100 } +fn gap(n: i32) -> i32 { (n * bubble_pct() + 50) / 100 } + +fn first_line_body<'a>(f: &Font, t: &'a str, max: i32) -> (&'a str, &'a str) { + if f.width_scaled(t, body_num(), BODY_SCALE_DEN) <= max { return (t, ""); } + let (mut end, mut space) = (0, None); + for (i, c) in t.char_indices() { + let next = i + c.len_utf8(); + if f.width_scaled(&t[..next], body_num(), BODY_SCALE_DEN) > max { break; } + end = next; + if c == ' ' { space = Some(i); } + } + let at = space.filter(|&i| i > 0).unwrap_or(end); + (t[..at].trim_end(), t[at..].trim_start()) +} + +/// The font of a name (one font only: the small Latin one was dropped to make room for the Hindi glyphs). +fn name_font(_n: &str) -> &'static Font { + &B +} +const REPLY_X: i32 = 108; +const REPLY_Y: i32 = 364; +const REPLY_W: i32 = 250; +const REPLY_H: i32 = 58; + +/// A touch is on the message box. +pub fn reply_at(x: i32, y: i32) -> bool { + x >= REPLY_X - 10 && x < REPLY_X + REPLY_W + 10 && y >= REPLY_Y - 10 && y < REPLY_Y + REPLY_H + 14 +} + +/// How far a thing at height `y` is pulled in from the side to follow the round screen (0 in the middle). +pub fn sag(y: i32) -> i32 { + (C - circle_half_width(y.clamp(0, SIZE - 1))).max(0) +} + +/// Draws only inside the rows `from..to` (a bubble can be half scrolled out of the conversation). +struct Clip<'a, S: Surface> { + s: &'a mut S, + from: i32, + to: i32, +} + +// The watch has a round 480 px display. Clip bubble and glyph rectangles to both +// the conversation viewport and the circular panel, not just the rectangular framebuffer. +const fn half_table() -> [i16; SIZE as usize] { + let mut t = [-1i16; SIZE as usize]; + let radius = SIZE / 2; + let mut y = 0; + while y < SIZE { + let dy = y - C; + let remaining = radius * radius - dy * dy; + if remaining >= 0 { + let (mut low, mut high) = (0, radius); + while low < high { + let mid = (low + high + 1) / 2; + if mid * mid <= remaining { low = mid } else { high = mid - 1 } + } + t[y as usize] = low as i16; + } + y += 1; + } + t +} +/// Worked out when the app is built, so drawing does not search for square roots row by row. +static HALF: [i16; SIZE as usize] = half_table(); + +fn circle_half_width(y: i32) -> i32 { + if (0..SIZE).contains(&y) { HALF[y as usize] as i32 } else { -1 } +} + +impl Surface for Clip<'_, S> { + fn rect(&mut self, x: i32, y: i32, w: i32, h: i32, c: u16) { + if w <= 0 || h <= 0 { + return; + } + let y0 = y.max(self.from).max(0); + let y1 = (y + h).min(self.to).min(SIZE); + let requested_left = x.max(0); + let requested_right = (x + w).min(SIZE); + if y1 <= y0 || requested_right <= requested_left { + return; + } + for row in y0..y1 { + let half = circle_half_width(row); + if half < 0 { + continue; + } + let left = requested_left.max(C - half); + let right = requested_right.min(C + half + 1); + if right > left { + self.s.rect(left, row, right - left, 1, c); + } + } + } + fn text(&mut self, _: i32, _: i32, _: &str, _: u16) {} +} + +/// The most lines of one message that are laid out. +const MAX_LINES: i32 = 40; +/// A message of more lines than this is folded: only `FOLDED` lines show, then "Show more" (and "Show less" once opened). +const FOLD_AT: i32 = 6; +const FOLDED: i32 = 4; +const MORE: &str = "Show more"; +const LESS: &str = "Show less"; + +/// Lines and widest line of a bubble's text. +fn measure(t: &str) -> (i32, i32) { + let (mut rest, mut lines, mut w) = (t, 0, 0); + let font = text_font(t).0; + while !rest.is_empty() && lines < MAX_LINES { + let (l, more) = first_line_body(font, rest, TEXT_W); + if l.is_empty() { + break; + } + w = w.max(font.width_scaled(l, body_num(), BODY_SCALE_DEN)); + lines += 1; + rest = more; + } + (lines.max(1), w) +} + +/// One bubble of the conversation, as `bubbles` hands it out. +struct Row<'a> { + top: i32, + mine: bool, + named: bool, + tail: bool, + index: usize, + w: i32, + h: i32, + msg: &'a str, + who: &'a str, + /// Lines of the text that are drawn (fewer than the text has while it is folded). + shown: i32, + /// 0 none, 1 "Show more" under the text, 2 "Show less". + button: u8, + /// Which message it is (the same text gives the same key): what is open is remembered by it. + key: u32, +} + +/// A key for a message: what stays the same while the conversation scrolls and older messages fall off. +pub fn key_of(t: &str) -> u32 { + t.bytes().fold(2166136261u32, |h, b| (h ^ b as u32).wrapping_mul(16777619)) +} + +/// The row under the last line of a folded or opened message holding "Show more" / "Show less". +fn button_h(pitch: i32) -> i32 { + pitch + 6 +} + +/// The bubbles, top to bottom: `f(row)` for each; returns the height of them all. +/// A reply of mine is on the right; the first bubble of a run from the other side carries the name. A long message is +/// folded to a few lines with a "Show more" button, unless it is the one `open` (a message key): then all of it shows. +fn bubbles(c: &Chat, open: Option, mut f: impl FnMut(&Row)) -> i32 { + let (mut y, mut prev, mut incoming_index) = (0, None, 0usize); + let mut prev_who = ""; + for (mine, raw) in c.entries() { + // group chats: the phone sends "sender\u{2}text"; the sender is shown above the bubble, small + let (who, msg) = match raw.split_once('\u{2}') { + Some((w, m)) if !mine => (w, m), + _ => (c.name(), raw), + }; + let group_start = prev != Some(mine); + let named = !mine && (group_start || who != prev_who); + if !mine { prev_who = who; } + let (lines, mut w) = measure(msg); + let key = key_of(raw); + let (shown, button) = if lines <= FOLD_AT { (lines, 0) } else if open == Some(key) { (lines, 2) } else { (FOLDED, 1) }; + let (font, pitch) = text_font(msg); + if button != 0 { + let label = if button == 1 { MORE } else { LESS }; + w = w.max(font.width_scaled(label, body_num(), BODY_SCALE_DEN).min(TEXT_W)); + } + if named { + w = w.max(name_font(who).width(who).min(TEXT_W)); + } + let h = 2 * pady() + shown * pitch + if button != 0 { button_h(pitch) } else { 0 } + if named { NAME_H } else { 0 }; + y += match prev { + None => 0, + Some(p) if p == mine => gap(5), + _ => gap(11), + }; + f(&Row { top: y, mine, named, tail: group_start || named, index: incoming_index, w: w + 2 * padx(), h, msg, who, shown, button, key }); + if !mine { incoming_index += 1; } + y += h; + prev = Some(mine); + } + y +} + +/// How far the conversation can scroll (in steps). +pub fn detail_max(c: &Chat, open: Option) -> usize { + let over = bubbles(c, open, |_| {}) + 8 - (VIEW_BOTTOM - VIEW_TOP); + over.max(0) as usize +} + +/// A tap at (`x`, `y`) on the "Show more" / "Show less" of a bubble of the conversation scrolled to `scroll_px`: the +/// message's key. +pub fn more_at(c: &Chat, open: Option, scroll_px: usize, x: i32, y: i32) -> Option { + let off = VIEW_TOP + 4 - scroll_px as i32; + let mut hit = None; + bubbles(c, open, |r| { + if r.button == 0 { + return; + } + let top = off + r.top; + let wall = circle_half_width(top.clamp(VIEW_TOP, VIEW_BOTTOM - 1)).min(circle_half_width((top + r.h).clamp(VIEW_TOP, VIEW_BOTTOM - 1))); + let left = if r.mine { C + wall - r.w - 18 } else { C - wall + 20 }; + let row_top = top + r.h - button_h(text_font(r.msg).1) - pady(); + // a generous target: the row of the button and a little around it + if x >= left - 6 && x < left + r.w + 6 && y >= row_top - 8 && y < top + r.h + 6 && y >= VIEW_TOP && y < VIEW_BOTTOM { + hit = Some(r.key); + } + }); + hit +} + +fn lighter(c: Rgb) -> Rgb { + Rgb((c.0 as u32 * 2 / 5 + 153) as u8, (c.1 as u32 * 2 / 5 + 153) as u8, (c.2 as u32 * 2 / 5 + 153) as u8) +} + +/// Is the app one of the three that have a colour of their own. +fn known(app: u8) -> bool { + matches!(app, proto::APP_WHATSAPP | proto::APP_MESSENGER | proto::APP_TELEGRAM | proto::APP_INSTAGRAM | proto::APP_X | proto::APP_DISCORD | proto::APP_GENERIC) +} + +/// The colour of the other side's bubbles: the app's own. +fn bubble_colour(app: u8) -> Rgb { + match app { + proto::APP_WHATSAPP => Rgb(24, 140, 76), + proto::APP_MESSENGER => Rgb(20, 98, 232), + proto::APP_TELEGRAM => Rgb(52, 160, 222), + proto::APP_INSTAGRAM => Rgb(193, 53, 132), + proto::APP_X => Rgb(62, 64, 72), + proto::APP_DISCORD => Rgb(88, 101, 242), + proto::APP_GENERIC => Rgb(110, 112, 124), + _ => Rgb(206, 208, 214), + } +} + +/// The conversation of one chat like a messages app on a watch: their bubbles (green, blue, light blue or dark grey by +/// app) on the left with the name, my replies in light grey on the right, and a box that says "Message" under them; the +/// bubbles scroll by `scroll` steps. A thin bar on the right shows where you are when there is more than fits. +pub fn detail(s: &mut impl Surface, c: &Chat, open: Option, scroll_px: usize, reply_down: bool) { + s.rect(0, 0, SIZE, SIZE, 0); + let theirs = bubble_colour(c.app); + let mine = Rgb(80, 82, 90); + let off = VIEW_TOP + 4 - scroll_px as i32; + // the bubbles that lie under the sign at the top, to blend the edge of its black rim into + let mut under = [(0, 0, 0, 0, 0u16); 4]; + let mut under_n = 0; + let total = { + let mut clip = Clip { s: &mut *s, from: 0, to: SIZE }; + bubbles(c, open, |r| { + let (top, is_mine, named, has_tail, incoming_index, w, h, msg, who) = (r.top, r.mine, r.named, r.tail, r.index, r.w, r.h, r.msg, r.who); + let y = off + top; + if y + h <= 0 || y >= SIZE { + return; + } + // Alternate incoming bubbles between a centered lane and a much farther-left lane. + // curved list: bubbles stick to the round wall — theirs to the left one, mine to the right one — and follow + // it as they scroll (the wall is as far in as its tightest row inside the conversation) + let wall = circle_half_width(y.clamp(VIEW_TOP, VIEW_BOTTOM - 1)).min(circle_half_width((y + h).clamp(VIEW_TOP, VIEW_BOTTOM - 1))); + let _ = incoming_index; + let x = if is_mine { C + wall - w - 18 } else { C - wall + 20 }; + let (face, ink) = if is_mine { (mine, WHITE) } else if known(c.app) { (theirs, WHITE) } else { (theirs, Rgb(24, 24, 28)) }; + if y < 70 && y + h > 14 && x < C + 32 && x + w > C - 32 && under_n < under.len() { + under[under_n] = (x, y, w, h, face.rgb565()); + under_n += 1; + } + bubble(&mut clip, x, y, w, h, face, !is_mine, has_tail); + let (font, pitch) = text_font(msg); + let scaled_cap = (font.cap * body_num() + BODY_SCALE_DEN / 2) / BODY_SCALE_DEN; + let mut base = y + pady() + scaled_cap + 1; + if named { + let nf = name_font(who); + let (n, _) = nf.fit(who, TEXT_W); + let tint = if known(c.app) { lighter(face) } else { Rgb(96, 98, 108) }; + nf.draw(&mut clip, x + padx(), y + pady() + nf.cap + 1, n, tint.rgb565(), face.rgb565()); + base += NAME_H; + } + let mut rest = msg; + for _ in 0..r.shown { + let (l, more) = first_line_body(font, rest, TEXT_W); + if l.is_empty() { + break; + } + font.draw_scaled(&mut clip, x + padx(), base, l, ink.rgb565(), face.rgb565(), body_num(), BODY_SCALE_DEN); + base += pitch; + rest = more; + } + if r.button != 0 { + // "Show more" / "Show less", underlined, in the lighter shade of the bubble + let label = if r.button == 1 { MORE } else { LESS }; + let tint = if is_mine { lighter(face) } else if known(c.app) { lighter(face) } else { Rgb(96, 98, 108) }; + font.draw_scaled(&mut clip, x + padx(), base + 4, label, tint.rgb565(), face.rgb565(), body_num(), BODY_SCALE_DEN); + let lw = font.width_scaled(label, body_num(), BODY_SCALE_DEN); + clip.rect(x + padx(), base + 7, lw, 1, tint.rgb565()); + } + }) + }; + let view = VIEW_BOTTOM - VIEW_TOP; + if total + 8 > view { + let (y0, h) = (170, 150); + s.rect(436, y0, 4, h, BAR_TRACK.rgb565()); + let range = (total + 8 - view).max(1); + let thumb = (h * view / (total + 8)).max(14); + let at = y0 + (h - thumb) * (scroll_px as i32).min(range) / range; + s.rect(436, at, 4, thumb, WHITE.rgb565()); + } + // the sign and the message box float over the bubbles, each with a black rim round it + // no circle: a smooth black rim follows the sign's own outline (tail and all) + let behind = |px: i32, py: i32| { + under[..under_n].iter().find(|b| px >= b.0 && px < b.0 + b.2 && py >= b.1 && py < b.1 + b.3).map_or(0, |b| b.4) + }; + if crate::icons::rim_small(s, c.app, C, 42, 5, behind) { + crate::icons::draw_small(s, c.app, C, 42); + } else { + // any other app: its round sign, with the edge of the black circle blended into what lies under it + disc(s, C, 42, 27, BLACK, Rgb::from565(behind(C, 42))); + app_icon(s, c.app, C, 42, 22, BLACK); + } + let face = if reply_down { KEY_DOWN } else { CHIP }; + pill(s, REPLY_X - 7, REPLY_Y - 7, REPLY_W + 14, REPLY_H + 14, BLACK); + pill(s, REPLY_X, REPLY_Y, REPLY_W, REPLY_H, face); + B.draw(s, REPLY_X + 26, REPLY_Y + (REPLY_H + B.cap) / 2, "Message", GREY.rgb565(), face.rgb565()); +} + +// ---- the keyboard ---- + +pub const SEND_X: i32 = 332; +pub const BAR_Y: i32 = 87; +pub const BAR_H: i32 = 46; +const CHIPS_FROM: i32 = 78; +const CHIPS_TO: i32 = 326; + +/// The send button is on a touch. +/// While recording the red button spans the whole bar, and a tap anywhere on it stops the recording. +pub fn send_at(x: i32, y: i32, listening: bool) -> bool { + x >= if listening { WIDE_X - 6 } else { SEND_X - 8 } && y >= BAR_Y - 10 && y < BAR_Y + BAR_H + 8 +} + +/// Where the recording pill starts: it reaches from here to the right end of the usual button. +const WIDE_X: i32 = 70; + +/// A capsule: round ends, `h` high, one fill per row (two discs side by side would show their soft edges inside). +fn pill(s: &mut impl Surface, x: i32, y: i32, w: i32, h: i32, c: Rgb) { + let c = c.rgb565(); + let r2 = h * h / 4; + for i in 0..h { + let dy2 = (2 * i + 1 - h) * (2 * i + 1 - h) / 4; + let mut d = 0; + while (d + 1) * (d + 1) + dy2 <= r2 { + d += 1; + } + let inset = h / 2 - d; + s.rect(x + inset, y + i, w - 2 * inset, 1, c); + } +} + +/// The quick replies' left edges and widths, from the left; the ones that do not fit are left out. +pub fn chips(items: &[&str]) -> ([(i32, i32); proto::QUICK_MAX], usize) { + let mut w = [(0, 0); proto::QUICK_MAX]; + let mut n = 0; + let mut x = CHIPS_FROM; + for t in items { + let cw = (B.width(t) + 22).min(200); + if x + cw > CHIPS_TO { + break; + } + w[n] = (x, cw); + x += cw + 6; + n += 1; + } + (w, n) +} + +/// The quick reply under a touch. +pub fn chip_at(items: &[&str], x: i32, y: i32) -> Option { + let (w, n) = chips(items); + (0..n).find(|&i| x >= w[i].0 - 4 && x < w[i].0 + w[i].1 + 4 && y >= BAR_Y - 8 && y < BAR_Y + BAR_H + 8) +} + +const FX: i32 = 98; +const FW: i32 = 262; + +/// One copy of the measuring, shared (inlined everywhere it would take a lot of the watch's tiny memory). +#[inline(never)] +fn wd(t: &str) -> i32 { + B.width(t) +} + +/// Where the visible part of the text starts, so the caret stays in view (`vs` is where it started before). +#[inline(never)] +pub fn window(t: &str, cur: usize, vs: usize) -> usize { + let cur = cur.min(t.len()); + if wd(t) <= FW { return 0; } + let lim = if cur >= t.len() { FW } else { FW - 50 }; + let mut v = vs.min(cur); + if vs > cur { + while v > 0 && wd(&t[v..cur]) < 60 { + v -= 1; + while !t.is_char_boundary(v) { v -= 1; } + } + } + while v < cur && wd(&t[v..cur]) > lim { + v += 1; + while !t.is_char_boundary(v) { v += 1; } + } + v +} + +/// The x of the caret when it stands before byte `cur` of the text, whose visible part starts at `vs`. +#[inline(never)] +pub fn caret_x(t: &str, cur: usize, vs: usize) -> i32 { + let w = wd(&t[vs.min(cur)..cur]); + if crate::arabic::contains_rtl(t) { (FX + FW - w - 4).max(FX - 4) } else { FX + w + 3 } +} + +/// The caret place (a byte of the text) nearest to a touch at `x`. +#[inline(never)] +pub fn cursor_at(t: &str, vs: usize, x: i32) -> usize { + let (mut best, mut gap) = (vs.min(t.len()), i32::MAX); + for i in vs.min(t.len())..=t.len() { + if !t.is_char_boundary(i) { continue; } + let g = (caret_x(t, i, vs) - x).abs(); + if g < gap { (best, gap) = (i, g); } + } + best +} + +/// The text so far, as in a messaging app: a line at the top, left aligned, its end in view. +pub fn field(s: &mut impl Surface, to: &str, text: &[u8]) { + let t = core::str::from_utf8(text).unwrap_or(""); + field_cur(s, to, text, text.len(), window(t, text.len(), 0)); +} + +/// The same with the caret at byte `cur` and the visible part starting at `vs`. +#[inline(never)] +pub fn field_cur(s: &mut impl Surface, to: &str, text: &[u8], cur: usize, vs: usize) { + let (x, base) = (FX, 72); + let t = core::str::from_utf8(text).unwrap_or(""); + let cur = cur.min(t.len()); + let vs = vs.min(cur); + if t.is_empty() { + s.rect(x - 5, 48, 3, 28, BLUE_LIGHT.rgb565()); + let mut head = [0u8; 48]; + let pre = b"Reply to "; + head[..pre.len()].copy_from_slice(pre); + let name = to.as_bytes(); + let n = name.len().min(head.len() - pre.len()); + let n = (0..=n).rev().find(|&i| to.is_char_boundary(i)).unwrap_or(0); + head[pre.len()..pre.len() + n].copy_from_slice(&name[..n]); + let label = core::str::from_utf8(&head[..pre.len() + n]).unwrap_or(""); + let (label, cut) = B.fit(label, 260); + let end = put(s, &B, x, base, label, DIM, BLACK); + if cut { put(s, &B, end, base, "…", DIM, BLACK); } + return; + } + let before = &t[vs..cur]; + let wb = wd(before); + let (after, _) = B.fit(&t[cur..], (FW - wb - 6).max(0)); + if crate::arabic::contains_rtl(t) { + // Arabic reads from right to left: what comes before the caret is on its right. + let shown = &t[vs..cur + after.len()]; + let left = x + FW - wd(shown).min(FW); + put(s, &B, left, base, shown, BLUE_LIGHT, BLACK); + s.rect((x + FW - wb - 5).max(x - 5), 48, 3, 28, BLUE_LIGHT.rgb565()); + } else { + let split = before.rfind(' ').map_or(0, |i| i + 1); + let end = put(s, &B, x, base, &before[..split], WHITE, BLACK); + let end = put(s, &B, end, base, &before[split..], BLUE_LIGHT, BLACK); + s.rect(end + 2, 48, 3, 28, BLUE_LIGHT.rgb565()); + put(s, &B, end + 6, base, after, WHITE, BLACK); + } +} + +/// The quick replies (while there is no text yet) and the send button. +pub fn bar(s: &mut impl Surface, m: &Model, text: &[u8], listening: bool, voice_error: bool) { + bar_cur(s, m, text, text.len(), listening, voice_error); +} + +/// The same when the caret is at `cur`: the suggestions go with the word before it. +pub fn bar_cur(s: &mut impl Surface, m: &Model, text: &[u8], cur: usize, listening: bool, voice_error: bool) { + s.rect(60, BAR_Y - 2, SIZE - 120, BAR_H + 4, 0); + let wide = listening; // recording: the red button stretches over the quick replies (and the suggestions) + // The unused arrow tile is removed; suggestions use the reclaimed horizontal space. + if !wide { + let (items, k) = m.items(&text[..cur.min(text.len())]); + let (w, n) = chips(&items[..k]); + for (i, &(x, cw)) in w[..n].iter().enumerate() { + tile(s, x, BAR_Y, cw, BAR_H, CHIP); + centred(s, &B, x + cw / 2, BAR_Y + 31, items[i], cw - 16, WHITE, CHIP); + } + } + // One action slot inside the keyboard: microphone while empty, blue send arrow once text exists. + let on = !text.is_empty() && !listening; + let face = if listening { RED } else if on { BLUE_LIGHT } else { CHIP }; + if wide { + pill(s, WIDE_X, BAR_Y - 5, SEND_X + 84 - WIDE_X, BAR_H + 10, face); + centred(s, &B, (WIDE_X + SEND_X) / 2, BAR_Y + 31, "Recording", SEND_X - WIDE_X - 20, WHITE, face); + } else { + pill(s, SEND_X, BAR_Y - 5, 84, BAR_H + 10, face); + } + let (cx, cy) = (SEND_X + 42, BAR_Y + BAR_H / 2); + if on { + let ink = Rgb(28, 40, 76); + // outlined paper plane + let (a, b, c, d) = ((cx - 17, cy - 18), (cx + 20, cy), (cx - 17, cy + 18), (cx - 8, cy)); + for (p, q) in [(a, b), (b, c), (c, d), (d, a)] { + line(s, p.0, p.1, q.0, q.1, 3, ink, face); + } + } else { + let ink = if listening { WHITE } else if voice_error { RED } else { Rgb(218, 222, 230) }; + // A normal microphone: solid capsule, a round U-shaped holder under it, a stem and a base. + let y = cy - 2; + ring(s, cx, y + 2, 12, 15, ink, face); // the holder: a ring ... + s.rect(cx - 16, y - 14, 33, 16, face.rgb565()); // ... with its top half wiped away, leaving a U + line(s, cx, y + 17, cx, y + 22, 3, ink, face); // stem + line(s, cx - 8, y + 22, cx + 8, y + 22, 3, ink, face); // base + disc(s, cx, y - 12, 7, ink, face); // capsule: two round ends and a filled middle + s.rect(cx - 7, y - 12, 14, 12, ink.rgb565()); + disc(s, cx, y, 7, ink, face); + } +} + +/// A thin closed outline through `pts`. +fn outline(s: &mut impl Surface, pts: &[(i32, i32)], ink: Rgb, bg: Rgb) { + for i in 0..pts.len() { + let (a, b) = (pts[i], pts[(i + 1) % pts.len()]); + line(s, a.0, a.1, b.0, b.1, 2, ink, bg); + } +} + +/// A rounded tile (radius about 12): thirteen fills, cheap to draw. +fn tile(s: &mut impl Surface, x: i32, y: i32, w: i32, h: i32, c: Rgb) { + tile_with(s, x, y, w, h, c, &[9, 5, 3, 2, 1, 1]); +} + +/// A tile whose corners are cut by `steps` (how far in each row from the edge starts). +fn tile_with(s: &mut impl Surface, x: i32, y: i32, w: i32, h: i32, c: Rgb, steps: &[i32]) { + let c = c.rgb565(); + for (i, &inset) in steps.iter().enumerate() { + s.rect(x + inset, y + i as i32, w - 2 * inset, 1, c); + s.rect(x + inset, y + h - 1 - i as i32, w - 2 * inset, 1, c); + } + let n = steps.len() as i32; + s.rect(x, y + n, w, h - 2 * n, c); +} + +/// One key: a dark rounded tile (like a phone keyboard on a watch), a small gap round it. `down`: a finger is on it; +/// `shift`: the letters are capitals. +pub fn key(s: &mut impl Surface, c: &Cell, page: Page, shift: bool, down: bool) { + s.rect(c.x, c.y, c.w, c.h, 0); + let (cx, cy) = (c.x + c.w / 2, c.y + c.h / 2); + let special = !matches!(c.key, Key::Ch(_) | Key::Hi(_)); + let under = if down { KEY_DOWN } else if c.key == Key::Space { SPACE_FACE } else if special { KEY_SPECIAL } else { KEY_FACE }; + let (ix, iy) = if matches!(c.key, Key::Space | Key::Page) || c.w > 60 { (4, 5) } else { (3, 5) }; + if c.key == Key::Space { + // a big soft bar reaching down along the edge of the screen + tile_with(s, c.x + ix, c.y + iy, c.w - 2 * ix, c.h - iy - 2, under, &[14, 9, 6, 4, 3, 2, 2, 1, 1, 1]); + } else { + tile(s, c.x + ix, c.y + iy, c.w - 2 * ix, c.h - 2 * iy, under); + } + match c.key { + Key::Ch(code) => { + // Internal Arabic key codes are converted to real Unicode for their key labels too. + let code = if page == Page::Letters && shift { code.to_ascii_uppercase() } else { code }; + let ch = keys::character(code); + let mut buf = [0u8; 4]; + let t = ch.encode_utf8(&mut buf); + // Latin letters in the bigger font; the wide Arabic shapes keep the smaller one so they stay inside their keys + let f = if ch.is_ascii() { &T } else { &B }; + put(s, f, cx - f.width(t) / 2, cy + f.cap / 2, t, Rgb(232, 234, 237), under); + } + Key::Hi(i) => { + let mut buf = [0u8; 4]; + let ch = keys::hindi(i); + let t = ch.encode_utf8(&mut buf); + // a sign that sits on a letter has no width of its own: centre its ink on the key instead + match B.ink(ch) { + Some((0, x, y, w, h)) => { put(s, &B, cx - x - w / 2, cy - y - h / 2, t, Rgb(232, 234, 237), under); } + _ => { put(s, &B, cx - B.width(t) / 2, cy + B.cap / 2, t, Rgb(232, 234, 237), under); } + } + } + Key::Shift if page.is_hindi() => { + // the first letter of the page Shift goes to + let t = match page.next_hindi() { Page::HindiMore => "ल", Page::HindiVowels => "अ", _ => "क" }; + put(s, &B, cx - B.width(t) / 2, cy + B.cap / 2, t, BLUE_LIGHT, under); + } + Key::Shift => { + // an outlined up arrow + let ink = if shift { BLUE_LIGHT } else { Rgb(232, 234, 237) }; + let mut p = [(0, 0); 8]; + let n = scaled(cx, cy, 42, &[(0, -34), (34, 2), (15, 2), (15, 34), (-15, 34), (-15, 2), (-34, 2)], &mut p); + outline(s, &p[..n], ink, under); + } + Key::Back => { + // an outlined delete sign (a tag pointing left) with a cross in it + let ink = Rgb(232, 234, 237); + let mut p = [(0, 0); 8]; + let n = scaled(cx, cy, 56, &[(-40, 0), (-14, -32), (40, -32), (40, 32), (-14, 32)], &mut p); + outline(s, &p[..n], ink, under); + let x = cx + 5; + line(s, x - 6, cy - 6, x + 6, cy + 6, 3, ink, under); + line(s, x + 6, cy - 6, x - 6, cy + 6, 3, ink, under); + } + Key::Space => { + // Show the active language in that language: English, العربية or हिंदी. + let t = match page.lang() { 1 => "العربية", 2 => "हिंदी", _ => "English" }; + // Dark gray, rather than white, keeps the language hint understated. + put(s, &B, cx - B.width(t) / 2, cy + B.cap / 2, t, Rgb(105, 109, 114), under); + } + Key::Page => { + let t = match page { + Page::Letters => "?123", + Page::Numbers => "abc", + Page::ArabicLetters => "١٢٣", + Page::ArabicNumbers => "أبج", + Page::HindiNumbers => "कखग", + _ => "123", + }; + put(s, &B, cx - B.width(t) / 2, cy + B.cap / 2, t, WHITE, under); + } + } +} + +/// Every key of a page (a new page, or the letters changed case). +pub fn all_keys(s: &mut impl Surface, page: Page, shift: bool) { + let (cells, n) = keys::layout(page); + for c in &cells[..n] { + key(s, c, page, shift, false); + } +} + +/// The keyboard: the text line, the quick replies and send button, and the keys over the rest of the screen. +pub fn keyboard(s: &mut impl Surface, m: &Model, to: &str, text: &[u8], page: Page, shift: bool) { + keyboard_voice(s, m, to, text, page, shift, false, false); +} + +/// Keyboard renderer with the dictation button state. The six-argument wrapper above +/// remains for the existing framebuffer tests and older internal callers. +pub fn keyboard_voice(s: &mut impl Surface, m: &Model, to: &str, text: &[u8], page: Page, shift: bool, listening: bool, voice_error: bool) { + s.rect(0, 0, SIZE, SIZE, 0); + field(s, to, text); + bar(s, m, text, listening, voice_error); + all_keys(s, page, shift); +} + +/// Only the top part (the text changed). +/// The keyboard screen with the caret at `cur` (`vs`: where the visible text starts), the drop shown when `drop`. +pub fn keyboard_cur(s: &mut impl Surface, m: &Model, to: &str, text: &[u8], cur: usize, vs: usize, drop: bool, page: Page, shift: bool, listening: bool, voice_error: bool) { + s.rect(0, 0, SIZE, SIZE, 0); + field_cur(s, to, text, cur, vs); + bar_cur(s, m, text, cur, listening, voice_error); + all_keys(s, page, shift); +} + +/// Only the top part, with the caret at `cur`. +pub fn text_changed_cur(s: &mut impl Surface, m: &Model, to: &str, text: &[u8], cur: usize, vs: usize, drop: bool, listening: bool, voice_error: bool) { + s.rect(40, 30, SIZE - 80, keys::TOP - 34, 0); + field_cur(s, to, text, cur, vs); + bar_cur(s, m, text, cur, listening, voice_error); +} + +pub fn text_changed(s: &mut impl Surface, m: &Model, to: &str, text: &[u8]) { + text_changed_voice(s, m, to, text, false, false); +} + +/// Redraw the text field and dictation/send control while keeping the legacy test API. +pub fn text_changed_voice(s: &mut impl Surface, m: &Model, to: &str, text: &[u8], listening: bool, voice_error: bool) { + s.rect(40, 30, SIZE - 80, keys::TOP - 34, 0); + field(s, to, text); + bar(s, m, text, listening, voice_error); +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::keys::layout; + use cmf_wp2_ui::Fb; + use std::vec; + + fn model() -> Model { + let mut m = Model::new(); + for (i, (app, name, msg)) in [ + (1u8, "Jane Appleseed", "I'm on my way! Can you pick up some milk on the way home, please? Thanks a lot, see you very soon at the house."), + (2, "Bob", "ok"), + (3, "A very long contact name", "Hello there"), + (0, "Mum", "Call me when you can, it is not urgent but I would like to hear from you soon"), + ] + .into_iter() + .enumerate() + { + let mut v = vec![b'r', b'1', b'L', i as u8, app, 9, 5 + i as u8, name.len() as u8]; + v.extend_from_slice(name.as_bytes()); + v.extend_from_slice(msg.as_bytes()); + m.apply(&v); + } + m.apply(b"r1Q\x03\x02Ok\x03Yes\x07Thanks!"); + m + } + + fn lit_outside(fb: &Fb) -> Option<(i32, i32)> { + for y in 0..SIZE { + for x in 0..SIZE { + let (dx, dy) = (x - C, y - C); + if dx * dx + dy * dy > (SIZE / 2) * (SIZE / 2) && fb.at(x, y) != 0 { + return Some((x, y)); + } + } + } + None + } + + fn lit(fb: &Fb, x0: i32, y0: i32, x1: i32, y1: i32) -> usize { + let mut n = 0; + for y in y0..y1 { + for x in x0..x1 { + if fb.at(x, y) != 0 { + n += 1; + } + } + } + n + } + + /// With WP2_SHOTS=dir set, the tests leave pictures there. + fn shot(name: &str, fb: &Fb) { + let Ok(dir) = std::env::var("WP2_SHOTS") else { return }; + let mut out = std::format!("P6\n{SIZE} {SIZE}\n255\n").into_bytes(); + for y in 0..SIZE { + for x in 0..SIZE { + let c = fb.at(x, y); + let (r, g, b) = (((c >> 11) & 31) as u32, ((c >> 5) & 63) as u32, (c & 31) as u32); + out.extend_from_slice(&[(r * 255 / 31) as u8, (g * 255 / 63) as u8, (b * 255 / 31) as u8]); + } + } + std::fs::write(std::format!("{dir}/{name}.ppm"), out).unwrap(); + } + + #[test] + fn fonts_have_what_the_screens_need() { + assert!(T.covers("Jane Appleseed qwertyuiop QWERTY 1234567890 .,?!'\"-/:;()$&@#+ No messages")); + assert!(B.covers("Reply to Type a message 12:05 a.m. p.m. Waiting for the phone… 123 abc ·")); + assert!(B.covers("مرحبا")); + assert!(B.covers("أهلاً، كيف حالك؟ 123")); + } + + #[test] + fn nothing_is_drawn_outside_the_round_screen() { + let m = model(); + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + idle(&mut fb, true); + assert_eq!(lit_outside(&fb), None, "idle"); + shot("idle", &fb); + for i in 0..m.n { + page(&mut fb, &m.chats[i], i, m.n, i == 1); + assert_eq!(lit_outside(&fb), None, "page {i}"); + shot(&std::format!("page{i}"), &fb); + } + page(&mut fb, &m.chats[0], 0, 1, false); + assert_eq!(lit_outside(&fb), None, "single"); + let mut pinned = m.chats[1]; + pinned.pinned = true; + for (k, c) in [(0, &m.chats[1]), (1, &pinned)] { + page(&mut fb, c, 1, m.n, false); + assert_eq!(lit_outside(&fb), None, "pinned {k}"); + shot(&std::format!("pin{k}"), &fb); + } + for (p, shift) in [(Page::Letters, false), (Page::Letters, true), (Page::Numbers, false)] { + keyboard(&mut fb, &m, "Jane Appleseed", b"", p, shift); + assert_eq!(lit_outside(&fb), None, "{p:?}"); + shot(&std::format!("kb_{p:?}_{shift}"), &fb); + } + keyboard_voice(&mut fb, &m, "Jane Appleseed", b"", Page::Letters, false, true, false); + assert_eq!(lit_outside(&fb), None, "recording"); + shot("recording", &fb); + keyboard(&mut fb, &m, "A very long contact name", b"Hello how are you doing today my friend?", Page::Letters, false); + assert_eq!(lit_outside(&fb), None, "typed"); + shot("typed", &fb); + keyboard(&mut fb, &m, "أحمد", "مرحبا".as_bytes(), Page::ArabicLetters, false); + assert_eq!(lit_outside(&fb), None, "Arabic keyboard"); + shot("typed_arabic", &fb); + for (p, name) in [(Page::HindiLetters, "hi_a"), (Page::HindiMore, "hi_b"), (Page::HindiVowels, "hi_c"), (Page::HindiNumbers, "hi_num")] { + keyboard(&mut fb, &m, "राहुल शर्मा", "नमस्ते, आप कैसे हैं? मैं ठीक हूँ".as_bytes(), p, false); + assert_eq!(lit_outside(&fb), None, "{p:?}"); + shot(name, &fb); + } + for (k, t, sub) in [(0, "Sending…", ""), (1, "Sent", "Jane"), (2, "Not sent", "Is Watch Menu open?")] { + status(&mut fb, k, t, sub); + assert_eq!(lit_outside(&fb), None, "status {k}"); + shot(&std::format!("status{k}"), &fb); + } + } + + #[test] + fn a_page_keeps_to_its_card_and_the_message_fits() { + let m = model(); + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + page(&mut fb, &m.chats[3], 3, m.n, false); // chat 3 is the long first message + assert_eq!(lit(&fb, 0, 0, SIZE, PAGE_Y - 34), 0); + assert_eq!(lit(&fb, 0, 0, PAGE_X, SIZE), 0); + assert_eq!(lit(&fb, 0, PAGE_Y + PAGE_H, SIZE, SIZE), 0); + // five lines at most + let mut rest = m.chats[3].msg(); + for _ in 0..BODY_LINES { + let (l, more) = first_line(&B, rest, BODY_W); + assert!(B.width(l) <= BODY_W); + rest = more; + } + let _ = rest; + } + + #[test] + fn a_long_message_folds_and_the_button_opens_and_closes_it() { + let mut m = Model::new(); + let full: std::string::String = (0..32).map(|i| std::format!("word{i} ")).collect::().trim().into(); + let mut v = vec![b'r', b'1', b'L', 5, 1, 9, 5, 3]; + v.extend_from_slice(b"Sam"); + v.extend_from_slice(&full.as_bytes()[..96]); + m.apply(&v); + for (i, part) in full.as_bytes().chunks(proto::CHUNK).enumerate() { + let last = (i + 1) * proto::CHUNK >= full.len(); + let mut p = vec![b'r', b'1', b'M', 5, i as u8 | if last { 0x80 } else { 0 }]; + p.extend_from_slice(part); + m.apply(&p); + } + let c = &m.chats[0]; + let key = key_of(c.entries().next().unwrap().1); + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + // folded: the button is on screen, below the fourth line, and finds the message + let max = detail_max(c, None); + detail(&mut fb, c, None, max, false); + assert_eq!(lit_outside(&fb), None); + shot("long_folded", &fb); + let mut found = None; + for y in (VIEW_TOP..VIEW_BOTTOM).step_by(4) { + for x in (30..440).step_by(20) { + if let Some(k) = more_at(c, None, max, x, y) { found = Some((x, y, k)); } + } + } + let (x, y, k) = found.expect("the folded message has a Show more button on screen"); + assert_eq!(k, key); + // opened: taller, and its button (Show less) is found again + let open_max = detail_max(c, Some(key)); + assert!(open_max > max, "{open_max} > {max}"); + detail(&mut fb, c, Some(key), open_max, false); + assert_eq!(lit_outside(&fb), None); + shot("long_open", &fb); + let _ = (x, y); + let mut again = false; + for y in (VIEW_TOP..VIEW_BOTTOM).step_by(4) { + for x in (30..440).step_by(20) { + if more_at(c, Some(key), open_max, x, y) == Some(key) { again = true; } + } + } + assert!(again, "the opened message has a Show less button on screen"); + // a short message has no button anywhere + let mut short = Model::new(); + let mut v = vec![b'r', b'1', b'L', 6, 1, 9, 5, 3]; + v.extend_from_slice(b"Sam"); + v.extend_from_slice(b"hello there"); + short.apply(&v); + for y in VIEW_TOP..VIEW_BOTTOM { + assert_eq!(more_at(&short.chats[0], None, 0, C, y), None); + } + } + + #[test] + fn the_whole_message_scrolls_and_stays_on_the_screen() { + let m = model(); + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + for i in 0..m.n { + let max = detail_max(&m.chats[i], None); + for sc in [0, max] { + detail(&mut fb, &m.chats[i], None, sc, false); + assert_eq!(lit_outside(&fb), None, "chat {i} scroll {sc}"); + } + } + detail(&mut fb, &m.chats[0], None, 0, false); + shot("detail", &fb); + detail(&mut fb, &m.chats[0], None, detail_max(&m.chats[0], None), true); + shot("detail_end", &fb); + assert_eq!(detail_max(&m.chats[1], None), 0); + // 96 bytes of the widest letters is more than six lines: folded to four with "Show more"; opened, all of it + // shows and scrolls + let mut wide = Model::new(); + let mut v = vec![b'r', b'1', b'L', 9, 1, 9, 5, 3]; + v.extend_from_slice(b"Ann"); + v.extend_from_slice(&[b'W'; 96]); + wide.apply(&v); + let key = key_of(wide.chats[0].entries().next().unwrap().1); + detail(&mut fb, &wide.chats[0], None, 0, false); + assert_eq!(lit_outside(&fb), None, "wide folded"); + shot("detail_folded", &fb); + let max = detail_max(&wide.chats[0], Some(key)); + assert!(max > 0, "{max}"); + for sc in [0, 1, max] { + detail(&mut fb, &wide.chats[0], Some(key), sc, false); + assert_eq!(lit_outside(&fb), None, "wide {sc}"); + } + shot("detail_scroll", &fb); + // a conversation: their messages, my replies, long and short + let mut conv = Model::new(); + for (i, t) in ["Hey, are you coming tonight?", "Bring the charger please", "Also milk"].iter().enumerate() { + let mut v = vec![b'r', b'1', b'L', 4, 1, 9, 5 + i as u8, 14]; + v.extend_from_slice(b"Jane Appleseed"); + v.extend_from_slice(t.as_bytes()); + conv.apply(&v); + if i == 1 { + conv.sent(4, b"Yes, I'll be there soon."); + } + } + conv.sent(4, b"ok"); + let max = detail_max(&conv.chats[0], None); + for sc in 0..=max { + detail(&mut fb, &conv.chats[0], None, sc, false); + assert_eq!(lit_outside(&fb), None, "conv {sc}"); + if sc == max { shot("conv_end", &fb); } + if sc == 0 { shot("conv_top", &fb); } + } + assert!(reply_at(233, 390) && !reply_at(233, 200) && !reply_at(40, 390)); + } + + #[test] + fn a_touch_finds_the_place_in_the_text_and_the_caret_is_there() { + let t = "hello brave new world"; + for i in 0..=t.len() { + assert_eq!(cursor_at(t, 0, caret_x(t, i, 0)), i); + } + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + keyboard_cur(&mut fb, &model(), "Sam", t.as_bytes(), 5, 0, true, Page::Letters, false, false, false); + text_changed_cur(&mut fb, &model(), "Sam", t.as_bytes(), 11, 0, true, false, false); + let long = "word ".repeat(30); + let vs = window(&long, 20, 0); + assert!(vs <= 20 && caret_x(&long, 20, vs) < FX + FW); + } + + #[test] + fn lines_break_at_spaces() { + assert_eq!(first_line(&B, "hello", 500), ("hello", "")); + let (a, b) = first_line(&B, "one two three four five six seven", 100); + assert!(B.width(a) <= 100 && a.ends_with(|c: char| c.is_alphabetic()) && !a.contains(" "), "{a}"); + assert!(!b.is_empty() && !b.starts_with(' ')); + let (a, b) = first_line(&B, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 100); + assert!(B.width(a) <= 100 && !a.is_empty() && !b.is_empty()); + } + + #[test] + fn touches_find_the_page_chips_and_the_send_button() { + let m = model(); + assert!(page_at(C, C) && !page_at(10, C) && !page_at(C, 20)); + let (items, k) = m.items(b""); + let (w, n) = chips(&items[..k]); + assert!(n >= 2, "{n}"); + assert_eq!(chip_at(&items[..k], w[1].0 + 5, BAR_Y + 10), Some(1)); + assert_eq!(chip_at(&items[..k], 5, BAR_Y + 10), None); + assert!(send_at(SEND_X + 30, BAR_Y + 20, false) && !send_at(C, BAR_Y + 20, false)); + assert!(send_at(C, BAR_Y + 20, true), "while recording the whole bar stops it"); + for i in 1..n { + assert!(w[i].0 >= w[i - 1].0 + w[i - 1].1, "chips overlap"); + } + assert!(w[n - 1].0 + w[n - 1].1 <= SEND_X, "chips run into the send button"); + assert_eq!((max_top(0), max_top(1), max_top(4)), (0, 0, 3)); + } + + #[test] + fn a_key_press_changes_only_that_key() { + let m = model(); + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + keyboard(&mut fb, &m, "Jane", b"", Page::Letters, false); + let (cells, n) = layout(Page::Letters); + for k in [Key::Ch(b'g'), Key::Space, Key::Back, Key::Shift] { + let g = cells[..n].iter().find(|c| c.key == k).unwrap(); + let before: std::vec::Vec = (0..SIZE * SIZE).map(|i| fb.at(i % SIZE, i / SIZE)).collect(); + key(&mut fb, g, Page::Letters, false, true); + let mut changed = 0; + for i in 0..SIZE * SIZE { + let (x, y) = (i % SIZE, i / SIZE); + if fb.at(x, y) != before[i as usize] { + changed += 1; + assert!(x >= g.x && x < g.x + g.w && y >= g.y && y < g.y + g.h, "{k:?} {x},{y}"); + } + } + assert!(changed > 100, "{k:?} {changed}"); + key(&mut fb, g, Page::Letters, false, false); + let after: std::vec::Vec = (0..SIZE * SIZE).map(|i| fb.at(i % SIZE, i / SIZE)).collect(); + assert!(before == after, "{k:?} is not drawn back as it was"); + } + } + + #[test] + fn typing_updates_the_top_and_nothing_below_it() { + let m = model(); + let mut px = vec![0u16; (SIZE * SIZE) as usize]; + let mut fb = Fb::new(&mut px); + keyboard(&mut fb, &m, "Jane", b"", Page::Letters, false); + let before: std::vec::Vec = (0..SIZE * SIZE).map(|i| fb.at(i % SIZE, i / SIZE)).collect(); + text_changed(&mut fb, &m, "Jane", b"Hi"); + for i in 0..SIZE * SIZE { + let (x, y) = (i % SIZE, i / SIZE); + if fb.at(x, y) != before[i as usize] { + assert!(y < keys::TOP, "{x},{y}"); + } + } + // "Hi" offers words like "hill"... or nothing; either way the chips are what `items` says + let (items, k) = m.items(b"Hi"); + assert!(chips(&items[..k]).1 <= k); + // words that continue "Hi" are drawn in the row; after "Hi " (a space) there are none + assert!(lit(&fb, CHIPS_FROM, BAR_Y, CHIPS_TO, BAR_Y + BAR_H) > 0); + text_changed(&mut fb, &m, "Jane", b"Hi "); + assert_eq!(lit(&fb, CHIPS_FROM, BAR_Y, CHIPS_TO, BAR_Y + BAR_H), 0); + } +} diff --git a/apps/watch-replies/src/words.rs b/apps/watch-replies/src/words.rs new file mode 100644 index 0000000..3ce2781 --- /dev/null +++ b/apps/watch-replies/src/words.rs @@ -0,0 +1,457 @@ +//! Suggested words: the first few words from this list that start like the word being typed (the list is roughly +//! ordered by how common the words are, so the likeliest come first). + +const WORDS: &str = concat!( + "the\n", + "be\n", + "to\n", + "of\n", + "and\n", + "in\n", + "that\n", + "have\n", + "it\n", + "for\n", + "not\n", + "on\n", + "with\n", + "he\n", + "as\n", + "you\n", + "do\n", + "at\n", + "this\n", + "but\n", + "his\n", + "by\n", + "from\n", + "they\n", + "we\n", + "say\n", + "her\n", + "she\n", + "or\n", + "an\n", + "will\n", + "my\n", + "one\n", + "all\n", + "would\n", + "there\n", + "their\n", + "what\n", + "so\n", + "up\n", + "out\n", + "if\n", + "about\n", + "who\n", + "get\n", + "which\n", + "go\n", + "me\n", + "when\n", + "make\n", + "can\n", + "like\n", + "time\n", + "no\n", + "just\n", + "him\n", + "know\n", + "take\n", + "people\n", + "into\n", + "year\n", + "your\n", + "good\n", + "some\n", + "could\n", + "them\n", + "see\n", + "other\n", + "than\n", + "then\n", + "now\n", + "look\n", + "only\n", + "come\n", + "its\n", + "over\n", + "think\n", + "also\n", + "back\n", + "after\n", + "use\n", + "two\n", + "how\n", + "our\n", + "work\n", + "first\n", + "well\n", + "way\n", + "even\n", + "new\n", + "want\n", + "because\n", + "any\n", + "these\n", + "give\n", + "home\n", + "day\n", + "most\n", + "us\n", + "is\n", + "are\n", + "was\n", + "were\n", + "been\n", + "has\n", + "had\n", +); + +const ARABIC_WORDS: &str = concat!( + "عايز\n", + "عايزة\n", + "عايزين\n", + "دلوقتي\n", + "معلش\n", + "انا\n", + "أنا\n", + "انت\n", + "أنت\n", + "انتي\n", + "إنت\n", + "إنتي\n", + "احنا\n", + "إحنا\n", + "انتوا\n", + "انتو\n", + "ازيك\n", + "إزيك\n", + "اخبارك\n", + "أخبارك\n", + "عامل\n", + "عاملة\n", + "ايه\n", + "إيه\n", + "ازاي\n", + "إزاي\n", + "عاوز\n", + "عاوزة\n", + "عاوزين\n", + "مش\n", + "ماشي\n", + "تمام\n", + "طيب\n", + "طب\n", + "كده\n", + "كدا\n", + "دلوقت\n", + "لسه\n", + "لسة\n", + "برضه\n", + "برده\n", + "عشان\n", + "علشان\n", + "مفيش\n", + "مافيش\n", + "فيه\n", + "فاضي\n", + "فاضية\n", + "ممكن\n", + "ينفع\n", + "ينفعش\n", + "ليه\n", + "فين\n", + "امتى\n", + "إمتى\n", + "مين\n", + "كام\n", + "ازايك\n", + "إزايك\n", + "بجد\n", + "فعلا\n", + "فعلاً\n", + "اوي\n", + "أوي\n", + "قوي\n", + "جدا\n", + "جدًا\n", + "شوية\n", + "شويه\n", + "حاجة\n", + "حاجه\n", + "حاجات\n", + "حلو\n", + "حلوة\n", + "حلوين\n", + "جميل\n", + "جميلة\n", + "كويس\n", + "كويسة\n", + "تماما\n", + "خلاص\n", + "حاضر\n", + "اه\n", + "آه\n", + "ايوه\n", + "أيوه\n", + "ايوا\n", + "أيوة\n", + "لأ\n", + "لا\n", + "لازم\n", + "أكيد\n", + "اكيد\n", + "يمكن\n", + "غالبا\n", + "غالبًا\n", + "تقريبا\n", + "تقريبًا\n", + "بالظبط\n", + "بالضبط\n", + "طبعا\n", + "طبعاً\n", + "يعني\n", + "بص\n", + "بصي\n", + "بصوا\n", + "شوف\n", + "شوفي\n", + "شوفوا\n", + "استنى\n", + "استني\n", + "استنوا\n", + "ثانية\n", + "ثانيه\n", + "دقيقة\n", + "دقيقه\n", + "دقايق\n", + "ساعة\n", + "ساعه\n", + "حالاً\n", + "حالا\n", + "النهارده\n", + "النهاردة\n", + "النهاردا\n", + "امبارح\n", + "أمبارح\n", + "بكرة\n", + "بكره\n", + "بكرا\n", + "بعده\n", + "الصبح\n", + "بالليل\n", + "الليل\n", + "النهار\n", + "الجمعة\n", + "السبت\n", + "الاحد\n", + "الأحد\n", + "الاتنين\n", + "التلات\n", + "التلاتة\n", + "الاربع\n", + "الأربع\n", + "الخميس\n", + "الاسبوع\n", + "الأسبوع\n", + "الشهر\n", + "السنة\n", + "بعدين\n", + "قبل\n", + "مرحبا\n", + "شكرا\n", +); + +/// Up to 3 words that continue `frag` (the letters typed since the last space), not the word itself. +/// True for Arabic letters in the basic and commonly used extended Arabic blocks. +fn is_arabic_letter(c: char) -> bool { + matches!(c as u32, 0x0621..=0x064A | 0x066E..=0x06D3 | 0x0750..=0x077F | 0x08A0..=0x08FF) +} + +fn is_word_char(c: char) -> bool { + c.is_ascii_alphabetic() || c == '\'' || is_arabic_letter(c) +} + +fn contains_arabic(text: &str) -> bool { + text.chars().any(is_arabic_letter) +} + +/// Up to 3 words that continue the current English or Arabic word fragment. +pub fn suggest(frag: &[u8], out: &mut [&'static str; 3]) -> usize { + if frag.is_empty() || frag.len() > 40 { + return 0; + } + let Ok(fragment) = core::str::from_utf8(frag) else { return 0; }; + let dictionary = if contains_arabic(fragment) { ARABIC_WORDS } else { WORDS }; + let mut n = 0; + for w in dictionary.split('\n') { + let wb = w.as_bytes(); + if wb.len() > frag.len() && wb[..frag.len()].eq_ignore_ascii_case(frag) && !out[..n].contains(&w) { + out[n] = w; + n += 1; + if n == 3 { + break; + } + } + } + n +} + +/// The letters being typed at the end of `text` (empty after a space or a symbol). +/// Walk Unicode characters so an Arabic word is never cut in the middle of a UTF-8 sequence. +pub fn fragment(text: &[u8]) -> &[u8] { + let Ok(s) = core::str::from_utf8(text) else { return &[]; }; + let mut start = 0; + for (i, c) in s.char_indices() { + if !is_word_char(c) { + start = i + c.len_utf8(); + } + } + &text[start..] +} + +/// Small offline next-word maps. The same suggestion chips are used for both languages. +const ENGLISH_NEXT: &str = concat!( + "are=you,we,they\n", + "how=are,do,is\n", + "i=am,will,can\n", + "you=can,are,have\n", + "thank=you\n", + "see=you,soon\n", + "good=morning,night,luck\n", + "on=my,the,it\n", + "let=me,us\n", + "what=do,is,about\n", + "can=you,i,we\n", + "do=you,we,i\n", + "have=a,to,you\n", + "i'm=fine,good,sorry\n", + "no=problem,worries,thanks\n", + "my=friend,name,love\n", + "looking=forward,for,at\n", +); + +const ARABIC_NEXT: &str = concat!( + "ازيك=عامل,عاملة\n", + "إزيك=عامل,عاملة\n", + "عامل=ايه,إيه\n", + "عاملة=ايه,إيه\n", + "انا=تمام,بخير\n", + "أنا=تمام,بخير\n", + "انت=عامل,رايح\n", + "أنت=عامل,رايح\n", + "انتي=عاملة,رايحة\n", + "إنتي=عاملة,رايحة\n", + "صباح=الخير\n", + "مساء=الخير\n", + "شكرا=جدا,ليك\n", + "شكراً=جدا,ليك\n", + "الحمد=لله\n", + "ربنا=يخليك,يكرمك\n", + "مع=السلام,اكيد\n", + "ممكن=اسألك,تساعدني\n", + "ازاي=كده,يعني\n", + "إزاي=كده,يعني\n", + "ايه=رأيك,الموضوع\n", + "إيه=رأيك,الموضوع\n", + "فين=انت,انتي\n", + "بعد=كده,شوية\n", + "كل=حاجة,يوم\n", + "ماشي=تمام,خلاص\n", + "تمام=الحمدلله,كده\n", + "معلش=ولا,مفيش\n", + "مش=عارف,فاهم\n", + "عشان=كده,انا\n", + "كده=يعني,تمام\n", + "برضه=مش,كده\n", + "دلوقتي=لا,اه\n", + "بكرة=إن,الصبح\n", + "يا=حبيبي,باشا\n", + "وحشت=ني\n", +); + +/// Up to three next-word suggestions after a trailing space, based on the previous word. +pub fn predict_next(text: &[u8], out: &mut [&'static str; 3]) -> usize { + if text.last() != Some(&b' ') || text.len() < 2 { + return 0; + } + let previous = fragment(&text[..text.len() - 1]); + if previous.is_empty() { + return 0; + } + let Ok(previous_text) = core::str::from_utf8(previous) else { return 0; }; + let is_arabic = contains_arabic(previous_text); + let dictionary = if is_arabic { ARABIC_NEXT } else { ENGLISH_NEXT }; + for line in dictionary.split('\n') { + let Some((word, list)) = line.split_once('=') else { continue; }; + let matched = if is_arabic { word.as_bytes() == previous } else { word.as_bytes().eq_ignore_ascii_case(previous) }; + if matched { + let mut n = 0; + for candidate in list.split(',').take(3) { out[n] = candidate; n += 1; } + return n; + } + } + 0 +} + + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn ho_offers_home() { + let mut o = [""; 3]; + let n = suggest(b"Ho", &mut o); + assert!(n >= 1 && o[..n].contains(&"home"), "{:?}", &o[..n]); + assert_eq!(suggest(b"", &mut o), 0); + assert_eq!(fragment(b"see you at ho"), b"ho"); + assert_eq!(fragment(b"hi "), b""); + } + + #[test] + fn arabic_prefixes_offer_arabic_words() { + let mut out = [""; 3]; + let n = suggest("مر".as_bytes(), &mut out); + assert!(n > 0 && out[..n].contains(&"مرحبا"), "{:?}", &out[..n]); + + let n = suggest("شك".as_bytes(), &mut out); + assert!(n > 0 && out[..n].contains(&"شكرا"), "{:?}", &out[..n]); + } + + #[test] + fn fragment_finds_arabic_utf8_words_after_spaces_and_punctuation() { + assert_eq!(fragment("انا في البيت".as_bytes()), "البيت".as_bytes()); + assert_eq!(fragment("Hello، يا صديقي".as_bytes()), "صديقي".as_bytes()); + assert_eq!(fragment("مرحبا ".as_bytes()), b""); + assert_eq!(fragment("hello! مر".as_bytes()), "مر".as_bytes()); + } + + #[test] + fn egyptian_dictionary_prioritizes_everyday_colloquial_words() { + let mut out = [""; 3]; + let n = suggest("عا".as_bytes(), &mut out); + assert!(n > 0 && out[..n].contains(&"عايز"), "{:?}", &out[..n]); + let n = suggest("دل".as_bytes(), &mut out); + assert!(n > 0 && out[..n].contains(&"دلوقتي"), "{:?}", &out[..n]); + let n = suggest("معل".as_bytes(), &mut out); + assert!(n > 0 && out[..n].contains(&"معلش"), "{:?}", &out[..n]); + } + + #[test] + fn next_word_predictions_work_in_both_languages_without_hiding_quick_replies() { + let mut model = crate::proto::Model::new(); + model.set_defaults(); + let (quick, quick_n) = model.items(b""); + assert_eq!(quick_n, 3); + assert!(quick[..quick_n].contains(&"Ok")); + + let (english, english_n) = model.items(b"How are "); + assert!(english_n > 0 && english[..english_n].contains(&"you")); + + let (arabic, arabic_n) = model.items("ازيك ".as_bytes()); + assert!(arabic_n > 0 && arabic[..arabic_n].contains(&"عامل")); + } +} diff --git a/apps/watch-replies/store.md b/apps/watch-replies/store.md new file mode 100644 index 0000000..ea21a95 --- /dev/null +++ b/apps/watch-replies/store.md @@ -0,0 +1,24 @@ +Watch Replies requires the [Watch Menu 2 Android app](https://github.com/abdalrahmanmamdouh2004-svg/watch-menu/releases/tag/1.2.0) on your phone. It brings messages from supported chat apps to your CMF Watch Pro 2 and lets you reply from your wrist. + +Read incoming messages, open a conversation, and reply using the watch's on-screen keyboard. You can also dictate a reply with the watch's built-in microphone: your speech is sent to the phone, converted to text, and placed in the reply box so you can review it before sending. + +## Features + +- **Six supported chat apps:** WhatsApp, Messenger, Telegram, Instagram, X, and Discord. +- **Up to six recent conversations** in the watch inbox, with the newest activity shown first. +- **Pin conversations** to keep important chats in the inbox when newer messages arrive. +- **Type or dictate replies** in English, Arabic, or Hindi. +- **Conversation history:** see recent incoming messages and replies you sent from the watch. +- **Quick replies:** use saved replies. + +## Privacy and message storage + +Watch Replies sends sender details, message text, replies, and dictated audio over the watch's Bluetooth app channel. The current watch app channel does not provide reliable privacy from other compatible Bluetooth Low Energy (BLE) clients in range: another client may be able to read or send app-channel data. Do not use Watch Replies for sensitive or confidential conversations. + +Watch Replies is not a permanent message archive or a backup of your chat apps. It keeps a limited, recent inbox of up to six conversations; entries and conversation history may disappear when they are dismissed or the app session is reset. Do not rely on it to preserve messages. + +## Requirements + +- The **Watch Menu Android app** must be installed on your phone: [Download Watch Menu 1.2.0](https://github.com/abdalrahmanmamdouh2004-svg/watch-menu/releases/tag/1.2.0). +- A CMF Watch Pro 2 with the latest compatible patched firmware batch. +- The App Loader update dated **November 30, 2026, or newer**. diff --git a/apps/watch-replies/store.toml b/apps/watch-replies/store.toml new file mode 100644 index 0000000..8becd49 --- /dev/null +++ b/apps/watch-replies/store.toml @@ -0,0 +1,5 @@ +name = "Watch Replies" +summary = "Read your messages on the watch and answer them with an on-screen keyboard or with speech to text. REQUIRES Watch Menu 2 companion App" +version = "1.2.28" +author = "Abdalrahman" +screenshots = ["shots/inbox.png", "shots/keyboard.png", "shots/empty.png", "shots/keyboard-recording.png"]