1
0
forked from me/IronOS

Unify more of the font generation logic between both paths and coalesce all fonts

This commit is contained in:
Ben V. Brown
2022-12-05 22:21:10 +11:00
parent 79eee9fc6c
commit e9a28c3671
5 changed files with 92 additions and 171 deletions

View File

@@ -179,7 +179,7 @@ void OLED::drawChar(const uint16_t charCode, const FontStyle fontStyle) {
break;
}
currentFont = fontStyle == FontStyle::SMALL ? FontSectionsData.font06_start_ptr : FontSectionsData.font12_start_ptr;
currentFont = fontStyle == FontStyle::SMALL ? FontSectionInfo.font06_start_ptr : FontSectionInfo.font12_start_ptr;
index = charCode - 2;
break;
}

View File

@@ -149,9 +149,13 @@ struct TranslationData {
struct FontSection {
const uint8_t *font12_start_ptr;
const uint8_t *font06_start_ptr;
uint16_t font12_decompressed_size;
uint16_t font06_decompressed_size;
const uint8_t *font12_compressed_source; // Pointer to compressed data or null
const uint8_t *font06_compressed_source; // Pointer to compressed data or null
};
extern const struct FontSection FontSectionsData;
extern const FontSection FontSectionInfo;
constexpr uint8_t settings_item_index(const SettingsItemIndex i) { return static_cast<uint8_t>(i); }
// Use a constexpr function for type-checking.

View File

@@ -2,7 +2,7 @@
#define TRANSLATION_MULTI_H_
#include "Translation.h"
#include <stdbool.h>
// The compressed translation data will be decompressed to this buffer. These
// data may include:
// - TranslationData (translation index table and translation strings)
@@ -14,21 +14,6 @@
extern uint8_t translation_data_out_buffer[];
extern const uint16_t translation_data_out_buffer_size;
struct FontSectionDataInfo {
uint16_t symbol_start;
uint16_t symbol_count;
uint16_t data_size : 15;
bool data_is_compressed : 1;
// Font12x16 data followed by font6x8 data
const uint8_t *data_ptr;
};
extern const FontSectionDataInfo FontSectionDataInfos[];
extern const uint8_t FontSectionDataCount;
extern FontSection DynamicFontSections[];
struct LanguageMeta {
uint16_t uniqueID;
const uint8_t *translation_data;

View File

@@ -51,30 +51,16 @@ void prepareTranslations() {
}
Tr = &translationData->indices;
TranslationStrings = translationData->strings;
// Font 12 can be compressed; if it is then we want to decompress it to ram
memset(DynamicFontSections, 0, FontSectionsCount * sizeof(DynamicFontSections[0]));
for (int i = 0; i < FontSectionDataCount; i++) {
const auto &fontSectionDataInfo = FontSectionDataInfos[i];
auto &fontSection = DynamicFontSections[i];
fontSection.symbol_start = fontSectionDataInfo.symbol_start;
fontSection.symbol_end = fontSection.symbol_start + fontSectionDataInfo.symbol_count;
const uint16_t font12_size = fontSectionDataInfo.symbol_count * (12 * 16 / 8);
uint16_t dataSize;
if (fontSectionDataInfo.data_is_compressed) {
unsigned int outsize;
outsize = blz_depack_srcsize(fontSectionDataInfo.data_ptr, buffer_next_ptr, fontSectionDataInfo.data_size);
if (FontSectionInfo.font12_compressed_source != NULL) {
unsigned int outsize;
outsize = blz_depack(FontSectionInfo.font06_compressed_source, (uint8_t *)FontSectionInfo.font12_start_ptr, FontSectionInfo.font12_decompressed_size);
}
fontSection.font12_start_ptr = buffer_next_ptr;
dataSize = outsize;
buffer_remaining_size -= outsize;
buffer_next_ptr += outsize;
} else {
fontSection.font12_start_ptr = fontSectionDataInfo.data_ptr;
dataSize = fontSectionDataInfo.data_size;
}
if (dataSize > font12_size) {
fontSection.font06_start_ptr = fontSection.font12_start_ptr + font12_size;
}
if (FontSectionInfo.font06_compressed_source != NULL) {
unsigned int outsize;
outsize = blz_depack(FontSectionInfo.font06_compressed_source, (uint8_t *)FontSectionInfo.font06_start_ptr, FontSectionInfo.font06_decompressed_size);
}
}