Skip to content

Commit cdb3024

Browse files
committed
add commented out char swapping code which might be handy for espruino/BangleApps#3312
1 parent 5e5e9f7 commit cdb3024

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

libs/graphics/jswrap_graphics.c

+33
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,39 @@ static int _jswrap_graphics_getCharWidth(JsGraphicsFontInfo *info, int ch) {
21822182
return 0;
21832183
}
21842184

2185+
/*
2186+
static int _jswrap_graphics_fontInfoMaxChar(JsGraphicsFontInfo *info) {
2187+
if (info->font == JSGRAPHICS_FONTSIZE_4X6) return 132;
2188+
if (info->widths) return info->customFirstChar + jsvGetLength(info->widths) - 1;
2189+
return 255;
2190+
}
2191+
2192+
// Map the character to a version that's displayable in this font
2193+
// potentially usable for https://github.com/espruino/BangleApps/issues/3312
2194+
static int _jswrap_graphics_fontMapCharacter(JsGraphicsFontInfo *info, int ch) {
2195+
#ifdef ESPR_PBF_FONTS
2196+
// if we have a PBF font then keep the character if we know it exists in the font
2197+
if ((info->font & JSGRAPHICS_FONTSIZE_FONT_MASK)==JSGRAPHICS_FONTSIZE_CUSTOM_PBF) {
2198+
// do we want to do this? this could make things very slow having to look up the char each time
2199+
PbfFontLoaderGlyph result;
2200+
if (jspbfFontFindGlyph(&info->pbfInfo, ch, &result)) {
2201+
return ch;
2202+
}
2203+
}
2204+
#endif
2205+
int maxChar = _jswrap_graphics_fontInfoMaxChar(info);
2206+
if (ch<=maxChar) return ch;
2207+
// from 0xC0: "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
2208+
const char *map = "AAAAAAACEEEEIIIIDNOOOOOx0UUUUYpBaaaaaaaceeeeiiiionooooo%ouuuuypy";
2209+
if (ch>255) return 0;
2210+
if (ch>=0xC0) ch = map[ch-0xC0];
2211+
if (maxChar<0x7A) { // if no lowercase chars
2212+
if (ch>='a' && ch<='z') ch -= 'a'-'A'; // convert from lower to uppercase
2213+
}
2214+
return ch;
2215+
}
2216+
*/
2217+
21852218
/*JSON{
21862219
"type" : "method",
21872220
"class" : "Graphics",

0 commit comments

Comments
 (0)