From a33b114ae4168f58fa8cb4b1d9069aadbd1b46b8 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 21 May 2021 21:59:45 +0200 Subject: [PATCH] Shrink fonts --- CMakeLists.txt | 1 + cmake/Bitmaps.cmake | 2 +- radio/src/gui/colorlcd/fonts.cpp | 43 ++++++++++++++++++++++++-------- radio/src/thirdparty/libopenui | 2 +- tools/build-font-bitmap.py | 1 + 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ccd04d375..80c365e64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ set(RADIO_SRC_DIR ${RADIO_DIRECTORY}/src) set(COMPANION_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/companion/src) set(SIMU_SRC_DIRECTORY ${COMPANION_SRC_DIRECTORY}/simulation) set(TOOLS_DIR ${PROJECT_SOURCE_DIR}/tools) +set(UTILS_DIR ${PROJECT_SOURCE_DIR}/radio/util) set(LIBOPENUI_TOOLS_DIR ${RADIO_SRC_DIR}/thirdparty/libopenui/tools) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) diff --git a/cmake/Bitmaps.cmake b/cmake/Bitmaps.cmake index 39ec10a9e..48b16f5a9 100644 --- a/cmake/Bitmaps.cmake +++ b/cmake/Bitmaps.cmake @@ -40,7 +40,7 @@ macro(add_truetype_font_target name size subset effect args) add_custom_command( OUTPUT ${target}.png ${target}.specs ${target}.lbm COMMAND ${PYTHON_EXECUTABLE} ${TOOLS_DIR}/build-font-bitmap.py --subset ${subset} --size ${size} --font ${font} --output ${target} - COMMAND ${PYTHON_EXECUTABLE} ${LIBOPENUI_TOOLS_DIR}/encode-bitmap.py --format 8bits --rle --size-format 2 ${args} ${target}.png ${target}.lbm + COMMAND ${PYTHON_EXECUTABLE} ${UTILS_DIR}/bin2lbm.py ${target}.png ${target}.lbm DEPENDS ${TOOLS_DIR}/build-font-bitmap.py ${TOOLS_DIR}/charset.py ${LIBOPENUI_TOOLS_DIR}/encode-bitmap.py ${RADIO_SRC_DIR}/translations/cn.h.txt ${RADIO_SRC_DIR}/fonts/extra_${size}px.png ) add_custom_target(truetype_font_${name} DEPENDS ${target}.png ${target}.specs) diff --git a/radio/src/gui/colorlcd/fonts.cpp b/radio/src/gui/colorlcd/fonts.cpp index 8468a74aa..54cf25236 100644 --- a/radio/src/gui/colorlcd/fonts.cpp +++ b/radio/src/gui/colorlcd/fonts.cpp @@ -131,8 +131,8 @@ const unsigned char font_xxl[] = { const uint16_t fontCharactersTable[FONTS_COUNT] = { sizeof(font_std_en_specs)/2-2 }; const uint16_t * const fontspecsTable[FONTS_COUNT] = { font_std_en_specs }; const uint8_t * fontsTable[FONTS_COUNT] = { font_std_en }; +const int fontsSizeTable[FONTS_COUNT] = { sizeof(font_std_en) }; #else - // -2 for: overall length and last boundary const uint16_t fontCharactersTable[FONTS_COUNT] = { sizeof(font_std_specs)/2-2, sizeof(font_bold_specs)/2-2, sizeof(font_xxs_specs)/2-2, @@ -146,21 +146,42 @@ const uint16_t *const fontspecsTable[FONTS_COUNT] = { const uint8_t *fontsTable[FONTS_COUNT] = { font_std, font_bold, font_xxs, font_xs, font_l, font_xl, font_xxl }; +const int fontsSizeTable[FONTS_COUNT] = { + sizeof(font_std), sizeof(font_bold), sizeof(font_xxs), + sizeof(font_xs), sizeof(font_l), sizeof(font_xl), + sizeof(font_xxl) +}; #endif -uint8_t * decompressFont(const uint8_t * font) +uint8_t * decompressFont(const uint8_t * font, unsigned len) { - uint16_t width = *((uint16_t *)font); - uint16_t height = *(((uint16_t *)font)+1); + int width = 0; + int height = 0; + + uint8_t* raw_font = BitmapBuffer::loadFont(font, len, width, height); + if (!raw_font) { + return nullptr; + } size_t font_size = width * height; - uint8_t * dec_buf = (uint8_t *)malloc(font_size + 4); + uint8_t * buf = (uint8_t *)malloc(font_size + 4); - // copy width / height - memcpy(dec_buf, font, 4); + ((uint16_t*)buf)[0] = (uint16_t)width; + ((uint16_t*)buf)[1] = (uint16_t)height; - RLEBitmap::decode(dec_buf+4, font_size, font+4); - return dec_buf; +#if defined(LCD_VERTICAL_INVERT) + uint8_t* src = raw_font + font_size - 1; + for(uint8_t* dst = buf + 4; src >= raw_font; --src, ++dst) { + *dst = 0xFF - *src; + } +#else + uint8_t* src = raw_font; + for(uint8_t* dst = buf + 4; src != raw_font + font_size; ++src, ++dst) { + *dst = 0xFF - *src; + } +#endif + + return buf; } void loadFonts() @@ -170,10 +191,10 @@ void loadFonts() return; #if defined(BOOT) - fontsTable[0] = decompressFont(fontsTable[0]); + fontsTable[0] = decompressFont(fontsTable[0], fontsSizeTable[0]); #else for (int i = 0; i < FONTS_COUNT; i++) { - fontsTable[i] = decompressFont(fontsTable[i]); + fontsTable[i] = decompressFont(fontsTable[i], fontsSizeTable[i]); } #endif diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index 1bc7de6c4..5fa5a379e 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit 1bc7de6c42c0a9e2284b55ae551a4d1245241bdb +Subproject commit 5fa5a379eeba432ea4aa5f154293552ebddfa3ea diff --git a/tools/build-font-bitmap.py b/tools/build-font-bitmap.py index d3176834e..336445dc7 100755 --- a/tools/build-font-bitmap.py +++ b/tools/build-font-bitmap.py @@ -123,6 +123,7 @@ class FontBitmap: image = image.crop((0, top, width - 1, bottom)) coords.insert(0, bottom - top + 1) + image = image.convert("L") image.save(filename + ".png") if generate_coords_file: with open(filename + ".specs", "w") as f: