Characters / fonts boundary checks

This commit is contained in:
Raphael Coeffic
2021-05-08 08:38:23 +02:00
parent 3a9da6d8b9
commit 3f64afaa5c
3 changed files with 19 additions and 4 deletions
+14 -2
View File
@@ -122,8 +122,20 @@ const unsigned char font_xxl[] = {
const uint16_t * const fontspecsTable[FONTS_COUNT] = { font_std_en_specs };
const uint8_t * fontsTable[FONTS_COUNT] = { font_std_en };
#else
const uint16_t * const fontspecsTable[FONTS_COUNT] = { font_std_specs, font_bold_specs, font_xxs_specs, font_xs_specs, font_l_specs, font_xl_specs, font_xxl_specs };
const uint8_t * fontsTable[FONTS_COUNT] = { font_std, font_bold, font_xxs, font_xs, font_l, font_xl, font_xxl };
// -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,
sizeof(font_xs_specs)/2-2, sizeof(font_l_specs)/2-2, sizeof(font_xl_specs)/2-2,
sizeof(font_xxl_specs)/2-2
};
const uint16_t *const fontspecsTable[FONTS_COUNT] = {
font_std_specs, font_bold_specs, font_xxs_specs, font_xs_specs,
font_l_specs, font_xl_specs, font_xxl_specs
};
const uint8_t *fontsTable[FONTS_COUNT] = {
font_std, font_bold, font_xxs, font_xs, font_l, font_xl, font_xxl
};
#endif
uint8_t * decompressFont(const uint8_t * font)
+4 -1
View File
@@ -66,9 +66,12 @@ int getTextWidth(const char * s, int len, LcdFlags flags)
c += CJK_FIRST_LETTER_INDEX;
result += getFontPatternWidth(specs, c) + 1;
}
else if ((c >= 0x20) && (c < CJK_FIRST_LETTER_INDEX + 0x20)) { // debug
else if ((c >= 0x20) && (c < fontCharactersTable[FONT_INDEX(flags)] + 0x20)) { // debug
result += getCharWidth(c, specs);
}
else {
TRACE("char out-of bound: 0x%X", c);
}
++s;
}