From 591c1f8cc5e538f935c82d6dd1c31a48e3e4d822 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 15 Mar 2024 16:15:33 +0000 Subject: [PATCH] Support for international fonts, and rendering UTF8 characters that come from iOS direct in the messages app --- README.md | 40 ++++++++++++--- apps/.eslintrc.js | 4 +- apps/fontall/ChangeLog | 1 + apps/fontall/README.md | 22 ++++++++ apps/fontall/app.png | Bin 0 -> 1629 bytes apps/fontall/boot.js | 1 + apps/fontall/font.pbf | Bin 0 -> 2039413 bytes apps/fontall/lib.js | 3 ++ apps/fontall/metadata.json | 16 ++++++ apps/fontext/ChangeLog | 1 + apps/fontext/README.md | 25 +++++++++ apps/fontext/app.png | Bin 0 -> 1629 bytes apps/fontext/boot.js | 1 + apps/fontext/font.pbf | Bin 0 -> 21305 bytes apps/fontext/lib.js | 3 ++ apps/fontext/metadata.json | 16 ++++++ apps/ios/ChangeLog | 3 +- apps/ios/README.md | 12 +++-- apps/ios/boot.js | 93 ++++++++++++++++++---------------- apps/ios/metadata.json | 2 +- apps/ios/settings.js | 7 +++ apps/lint_exemptions.js | 12 ----- apps/messagegui/ChangeLog | 2 +- apps/messagegui/app.js | 19 ++++++- apps/messagegui/metadata.json | 2 +- bin/README.md | 1 + bin/font_creator.js | 50 ++++++++++++++++++ webtools | 2 +- 28 files changed, 264 insertions(+), 74 deletions(-) create mode 100644 apps/fontall/ChangeLog create mode 100644 apps/fontall/README.md create mode 100644 apps/fontall/app.png create mode 100644 apps/fontall/boot.js create mode 100644 apps/fontall/font.pbf create mode 100644 apps/fontall/lib.js create mode 100644 apps/fontall/metadata.json create mode 100644 apps/fontext/ChangeLog create mode 100644 apps/fontext/README.md create mode 100644 apps/fontext/app.png create mode 100644 apps/fontext/boot.js create mode 100644 apps/fontext/font.pbf create mode 100644 apps/fontext/lib.js create mode 100644 apps/fontext/metadata.json create mode 100755 bin/font_creator.js diff --git a/README.md b/README.md index ed6a501ef..ee1c22061 100644 --- a/README.md +++ b/README.md @@ -251,7 +251,7 @@ and which gives information about the app for the Launcher. "description": "...", // long description (can contain markdown) "icon": "icon.png", // icon in apps/ "screenshots" : [ { "url":"screenshot.png" } ], // optional screenshot for app - "type":"...", // optional(if app) - + "type":"...", // optional(if app) - // 'app' - an application // 'clock' - a clock - required for clocks to automatically start // 'widget' - a widget @@ -300,7 +300,7 @@ and which gives information about the app for the Launcher. "customConnect": true, // if supplied, ensure we are connected to a device // before the "custom.html" iframe is loaded. An // onInit function in "custom.html" is then called - // with info on the currently connected device. + // with info on the currently connected device. "interface": "interface.html", // if supplied, apps/interface.html is loaded in an // iframe, and it may interact with the connected Bangle @@ -328,9 +328,9 @@ and which gives information about the app for the Launcher. {"name":"appid.data.json", // filename used in storage "storageFile":true // if supplied, file is treated as storageFile "url":"", // if supplied URL of file to load (currently relative to apps/) - "content":"...", // if supplied, this content is loaded directly + "content":"...", // if supplied, this content is loaded directly "evaluate":true, // if supplied, data isn't quoted into a String before upload - // (eg it's evaluated as JS) + // (eg it's evaluated as JS) }, {"wildcard":"appid.data.*" // wildcard of filenames used in storage }, // this is mutually exclusive with using "name" @@ -424,9 +424,9 @@ See [apps/gpsrec/interface.html](the GPS Recorder) for a full example. ### Adding configuration to the "Settings" menu -Apps (or widgets) can add their own settings to the "Settings" menu under "App/widget settings". +Apps (or widgets) can add their own settings to the "Settings" menu under "App/widget settings". To do so, the app needs to include a `settings.js` file, containing a single function -that handles configuring the app. +that handles configuring the app. When the app settings are opened, this function is called with one argument, `back`: a callback to return to the settings menu. @@ -449,12 +449,12 @@ Example `settings.js` 'Monkeys': { value: settings.monkeys, onchange: (m) => {save('monkeys', m)} - } + } }; E.showMenu(appMenu) }) ``` -In this example the app needs to add `myappid.settings.js` to `storage` in `metadata.json`. +In this example the app needs to add `myappid.settings.js` to `storage` in `metadata.json`. It should also add `myappid.json` to `data`, to make sure it is cleaned up when the app is uninstalled. ```json { "id": "myappid", @@ -554,6 +554,30 @@ You can use `g.setColor(r,g,b)` OR `g.setColor(16bitnumber)` - some common 16 bi | GreenYellow | 0xAFE5 | | Pink | 0xF81F | +## Fonts + +A recent addition to Bangle.js is the ability to use extra fonts with support for more characters. +For example [all regions](https://banglejs.com/apps/?id=fontall) or [extended](https://banglejs.com/apps/?id=fontext) fonts. + +Once installed, these apps cause a new font, `Intl` to be added to `Graphics`, which can be used with just `g.setFont("Intl")`. + +There is also a `font` library - this is not implemented yet, but more information about the planned implementation +is available at https://github.com/espruino/BangleApps/issues/3109 + +For now, to make your app work with the international font, you can check if `Graphics.prototype.setFontIntl` exists, +and if so you can change the font you plan on using: + +```JS +myFont = "6x8:2"; +if (Graphics.prototype.setFontIntl) + myFont = "Intl"; +``` + +Any new Font library must contain the metadata `"icon": "app.png", "tags": "font", "type": "module", "provides_modules" : ["fonts"],` +and should provide a `font` library, as well as a `boot.js` that adds `Graphics.prototype.setFontIntl`. If you plan on +making a new library it's best to just copy one of the existing ones for now. + + ## API Reference [Reference](http://www.espruino.com/Reference#software) diff --git a/apps/.eslintrc.js b/apps/.eslintrc.js index 9bff7882e..4c86b8174 100644 --- a/apps/.eslintrc.js +++ b/apps/.eslintrc.js @@ -164,7 +164,9 @@ module.exports = { "D28": "readonly", "D29": "readonly", "D30": "readonly", - "D31": "readonly" + "D31": "readonly", + + "bleServiceOptions": "writable", // available in boot.js code that's called ad part of bootupdate }, "parserOptions": { "ecmaVersion": 11 diff --git a/apps/fontall/ChangeLog b/apps/fontall/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/fontall/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/fontall/README.md b/apps/fontall/README.md new file mode 100644 index 000000000..9b53058d9 --- /dev/null +++ b/apps/fontall/README.md @@ -0,0 +1,22 @@ +# Fonts (all languages) + +This library provides an international font that can be used to display messages. + +The font is the 16px high [GNU Unifont](https://unifoundry.com/unifont/index.html). +All characters from Unicode codepoint 32 up until codepoint 65535 (U+FFFF) are included here, +which should be enough for most languages. + +**The font is 2MB and takes a while to upload** - if you don't require all the languages +it provides, consider installing another Font library like [extended fonts](https://banglejs.com/apps/?id=fontsext) +that contains just the characters you need instead. + +## Usage + +See [the BangleApps README file](https://github.com/espruino/BangleApps/blob/master/README.md#api-reference) +for more information on fonts. + + +## Recreating font.pbf + +* Go to `bin` directory +* Run `./font_creator.js "All" ../apps/fontall/font.pbf` \ No newline at end of file diff --git a/apps/fontall/app.png b/apps/fontall/app.png new file mode 100644 index 0000000000000000000000000000000000000000..e029647b7add152ab4a4a45c85123d7c26d4f751 GIT binary patch literal 1629 zcmV-j2BP_iP)u5>P;O94EHpWhPF>vC|d~r6BcC zi4%*2kjeo#v=WCR))r_$WV4;kj_q_}J6k16gT&G%P8`Rv6US@DjuRKEQVu=P3aLn? zs1;3V^3a>f*t11;5E2&hC;b#fe)Hz{{_mSNgCON9SGmenu5$g~>r4H`-NTL9E5pVt z;4@@g21CZBF{G4h*pU5fm=awELk2cWU~nA|o~=hpu>b<@8#FBa%$6N&V90=hbv*h- z3sQLfO{^|WZczV~!o(s>9?8&}4Y|Oqt z(s<#+VZ-u~A>+~^!a(la)MS12ixNUd-h+}n(J1`=RBhr26h4(BLD7fBy_-4VP8+fZ zMvU2xA!GKE;QhinvIh;B)q#f0_XBvkv8c%j-NMIoqBM*sQJZ)d{_d)cJ$b4&zS>ut z05owLEdG}rO*~c1J%)_g6ZDHv3k8|3QYp%M~iyKbtz>?485~WiGP}G6O7P#Z$ z?>W#IaG+5x+UP=23uwp?ym!fMw>}kd(a)o9;TNm&r>&wB zJFz&yPZf&V(a1;aaeeAol^u-&yEY<17%Q{@H=ZWkcxu&MpZeN^r{RP8pkRzXCF`#v zQ-Ws^wlkJIESPjq7To60#%}Oag`!UNyqZ70S2LgK)y{)n4Hugx++1h@9z2Z_wWOxd zI0B15$2lyRmd4_z1%rDvkyq`gFwtI3BqKJtO*7YI(}bZgu&Ej5K#ywnN)rO^NB)KC zRnPC{w=>lhSo8;x1{t_ZKVKxi7lisf+J( zV$rvpSgf@Vjh}H~v6usm{>pA+PFH9nHv}uSY3A?c5@n^@T@%u7bn~8?&?P8L69PRo zAvhj%DMS5*#0g!r!GXrlI?(9t4Mlm+SuX`0EN3#CYVHHL{hUPCQ_Tyqp+&g_DY}#t zzjszdw{Ilx#A2T~(8wxRme;z%PT&N~OLA`6x>?b@>^d``lTG!^OJeeN?fg-JC`;C= z3IA!+gnzWE!so53uyvzA^YW@tBYXS#vSOkfSp_6O(ZRwZ4}2?V8w0t+rVjtcNmLUC zR(1GZk7~}`r43{30|0(<70+J_p@gpNMcrI@)c*!}{d0$I5q3Ij8TDPWfSk8*@mv&Tf+QxQBM zwtx<0;3(UN?LrNJeJU!d2mrHux~T7(QDk(Bsmga93Y)6f_#hGX*shw;iCk+cSv#!= z2;Qvia{o??V)~jeFgh%Hh4R2Tu|&=CsWnSgK!y}qrYhe66mEyeAd@*vlBt^94k!a} zi0-gFaMhylA7J|4tnfc=uJ)7MU7ey}0zxcu-xKC)|6Q@|H&ywP#mZ9)sGNKO%C<37 zPO$KvWX7450fj{|y(X6E`n_+Ps;6#ocaz#lK{$x1+W!u-D*pDj%Y4T-vjD5oyR}U^ zakI5@0<>0oX{0nQ((%hMRc5TE+W(Dss=mBzUewht5(>NzVv`bC{Ltc8 zt91NK3oV?dg64C{*j{E_i_*KxB=cR)-!tECY|++A?^Kg4xQ!b|etx7)HhEQWv1}4v zcy_b$lvsuL*=EVu&E|?Rz(F#$+AKN8d8u_)Og`Esn{>BHCstU(G!^65TBYO1;o(5d zD;ZC~5ZH5mvHN@sDTOjU_T3{b((!}M((%_@D!nhaO2+m!A;Aa!Yp-&Zt6b$OSGmfC b6sW%e(Yx=Nk5cJ}00000NkvXXu0mjfuzni* literal 0 HcmV?d00001 diff --git a/apps/fontall/boot.js b/apps/fontall/boot.js new file mode 100644 index 000000000..07b99570e --- /dev/null +++ b/apps/fontall/boot.js @@ -0,0 +1 @@ +Graphics.prototype.setFontIntl = function() { return this.setFontPBF(require("Storage").read("fontall.pbf")); }; \ No newline at end of file diff --git a/apps/fontall/font.pbf b/apps/fontall/font.pbf new file mode 100644 index 0000000000000000000000000000000000000000..2f5374987c4075169e46902d61d55643a2965e81 GIT binary patch literal 2039413 zcmWjLXIM^+AHeZ*kEUH#f3inLW>JzdqM=d>p-8Au(NLsGg{G2*Qc6atB%_d|LP7}H znkr;J51Ie(^X7hW&i(4X&h@#zzw%!K;Qi-r1A z%Y;`SZH1R(9fX&5PQvq87vaSPci}~wxA45LpYU>4u<*(~On7xNLa2YePiPpGAT(@B z5gJY(7Mi{v6