Shrink fonts
This commit is contained in:
committed by
Raphael Coeffic
parent
c0198a19a3
commit
a33b114ae4
@@ -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})
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Vendored
+1
-1
Submodule radio/src/thirdparty/libopenui updated: 1bc7de6c42...5fa5a379ee
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user