From 7d85157c3c454a445d5bd1450791cb22e5815fe2 Mon Sep 17 00:00:00 2001 From: en-ot Date: Thu, 1 Jul 2021 11:58:11 +0300 Subject: [PATCH] FAST_UNICODE_INDEX - faster binary search for index from unicode code point, for ordered by code point fonts only --- Extensions/Smooth_font.cpp | 33 +++++++++++++++++++++++++++++++++ User_Setup.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/Extensions/Smooth_font.cpp b/Extensions/Smooth_font.cpp index fa94c59..ed66033 100644 --- a/Extensions/Smooth_font.cpp +++ b/Extensions/Smooth_font.cpp @@ -338,6 +338,37 @@ uint32_t TFT_eSPI::readInt32(void) ** Function name: getUnicodeIndex ** Description: Get the font file index of a Unicode character *************************************************************************************x*/ + +#ifdef FAST_UNICODE_INDEX +bool TFT_eSPI::getUnicodeIndex(uint16_t unicode, uint16_t *index) +{ + int above = gFont.gCount; + int bottom = 0; + int i = above / 2; + do + { + uint16_t code = gUnicode[i]; + if (code == unicode) + { + *index = i; + return true; + } + if (code > unicode) + { + above = i; + } + else + { + bottom = i+1; + } + i = (above+bottom)/2; + } while (above > bottom); + + return false; +} + +#else + bool TFT_eSPI::getUnicodeIndex(uint16_t unicode, uint16_t *index) { for (uint16_t i = 0; i < gFont.gCount; i++) @@ -351,6 +382,8 @@ bool TFT_eSPI::getUnicodeIndex(uint16_t unicode, uint16_t *index) return false; } +#endif + /*************************************************************************************** ** Function name: drawGlyph diff --git a/User_Setup.h b/User_Setup.h index a5cadeb..e47499b 100644 --- a/User_Setup.h +++ b/User_Setup.h @@ -304,6 +304,8 @@ // this will save ~20kbytes of FLASH #define SMOOTH_FONT +// Smooth font improvements +#define FAST_UNICODE_INDEX // ################################################################################## //