From 0c19010ca279da1685e1d442bf7567082780cb43 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 3 Jun 2024 15:58:05 +0100 Subject: [PATCH] Bangle.js: when converting text to bitmaps, try and split up emoji so we can render just those in color. Rendering text as well uses more memory but means text is rendered white, which doesn't work on some backgrounds --- .../banglejs/BangleJSDeviceSupport.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java index 6ef224d0f..530477e89 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java @@ -1236,6 +1236,21 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { return renderUnicodeWordPartAsImage(word); } + /* is the given character code an emoji? Note that `char` is only 0..65535, so many emoji will + actually be made of 2 surrogate chars. To work around this, we just assume that anything with a surrogate + is an emoji, which will be true in most cases */ + public boolean isCharCodeEmoji(char ch) { + if (ch>=0x2190 && ch<=0x21FF) return true; + if (ch>=0x2600 && ch<=0x26FF) return true; + if (ch>=0x2700 && ch<=0x27BF) return true; + if (ch>=0x3000 && ch<=0x303F) return true; + if (ch>=0xD800 && ch<=0xDFFF) return true; // high/low surrogate + if (ch>=0xFE00 && ch<=0xFE0F) return true; // variation selector 1 (2 is U+E0100 so is in a surrogate) + //if (ch>=0x1F300 && ch<=0x1F64F) return true; // needs a surrogate + //if (ch>=0x1F680 && ch<=0x1F6FF) return true; // needs a surrogate + return false; + } + public String renderUnicodeAsImage(String txt) { // FIXME: it looks like we could implement this as customStringFilter now so it happens automatically if (txt==null) return null; @@ -1250,6 +1265,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { String word = ""; StringBuilder result = new StringBuilder(); boolean needsTranslate = false; + boolean wordIsAllEmoji = true; for (int i=0;i=0xFE00; + } // chars which break words up if (" -_/:.,?!'\"&*()[]".indexOf(ch)>=0) { // word split @@ -1272,6 +1314,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { } word = ""; needsTranslate = false; + wordIsAllEmoji = true; } else { // TODO: better check? if (ch>255) needsTranslate = true;