mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 13:08:35 -07:00
Build font parameters for asset packs fonts
This commit is contained in:
@@ -112,6 +112,9 @@ uint8_t canvas_current_font_width(const Canvas* canvas) {
|
|||||||
const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font font) {
|
const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font font) {
|
||||||
furi_assert(canvas);
|
furi_assert(canvas);
|
||||||
furi_assert(font < FontTotalNumber);
|
furi_assert(font < FontTotalNumber);
|
||||||
|
if((FontSwap)font < FontSwapCount && xtreme_assets.font_params[font]) {
|
||||||
|
return xtreme_assets.font_params[font];
|
||||||
|
}
|
||||||
return &canvas_font_params[font];
|
return &canvas_font_params[font];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
XtremeAssets xtreme_assets = {
|
XtremeAssets xtreme_assets = {
|
||||||
.is_nsfw = false,
|
.is_nsfw = false,
|
||||||
.fonts = {NULL},
|
.fonts = {NULL},
|
||||||
|
.font_params = {NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
void load_icon_animated(const Icon* replace, const char* name, FuriString* path, File* file) {
|
void load_icon_animated(const Icon* replace, const char* name, FuriString* path, File* file) {
|
||||||
@@ -113,8 +114,14 @@ void load_font(FontSwap font, const char* name, FuriString* path, File* file) {
|
|||||||
uint64_t size = storage_file_size(file);
|
uint64_t size = storage_file_size(file);
|
||||||
uint8_t* swap = malloc(size);
|
uint8_t* swap = malloc(size);
|
||||||
|
|
||||||
if(storage_file_read(file, swap, size) == size) {
|
if(size > 20 && storage_file_read(file, swap, size) == size) {
|
||||||
xtreme_assets.fonts[font] = swap;
|
xtreme_assets.fonts[font] = swap;
|
||||||
|
CanvasFontParameters* params = malloc(sizeof(CanvasFontParameters));
|
||||||
|
params->leading_default = swap[10]; // max_char_height
|
||||||
|
params->leading_min = params->leading_default - 2; // good enough
|
||||||
|
params->height = swap[13]; // ascent_A
|
||||||
|
params->descender = swap[19]; // start_pos_lower_a
|
||||||
|
xtreme_assets.font_params[font] = params;
|
||||||
} else {
|
} else {
|
||||||
free(swap);
|
free(swap);
|
||||||
}
|
}
|
||||||
@@ -122,6 +129,13 @@ void load_font(FontSwap font, const char* name, FuriString* path, File* file) {
|
|||||||
storage_file_close(file);
|
storage_file_close(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_font(FontSwap font) {
|
||||||
|
free(xtreme_assets.fonts[font]);
|
||||||
|
xtreme_assets.fonts[font] = NULL;
|
||||||
|
free(xtreme_assets.font_params[font]);
|
||||||
|
xtreme_assets.font_params[font] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static const char* font_names[] = {
|
static const char* font_names[] = {
|
||||||
[FontSwapPrimary] = "Primary",
|
[FontSwapPrimary] = "Primary",
|
||||||
[FontSwapSecondary] = "Secondary",
|
[FontSwapSecondary] = "Secondary",
|
||||||
@@ -172,8 +186,7 @@ void XTREME_ASSETS_FREE() {
|
|||||||
|
|
||||||
for(FontSwap font = 0; font < FontSwapCount; font++) {
|
for(FontSwap font = 0; font < FontSwapCount; font++) {
|
||||||
if(xtreme_assets.fonts[font] != NULL) {
|
if(xtreme_assets.fonts[font] != NULL) {
|
||||||
free(xtreme_assets.fonts[font]);
|
free_font(font);
|
||||||
xtreme_assets.fonts[font] = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <furi_hal_serial_types.h>
|
#include <furi_hal_serial_types.h>
|
||||||
|
#include <gui/canvas.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -97,6 +98,7 @@ typedef enum {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
bool is_nsfw; // TODO: replace with packs text support
|
bool is_nsfw; // TODO: replace with packs text support
|
||||||
uint8_t* fonts[FontSwapCount];
|
uint8_t* fonts[FontSwapCount];
|
||||||
|
CanvasFontParameters* font_params[FontSwapCount];
|
||||||
} XtremeAssets;
|
} XtremeAssets;
|
||||||
|
|
||||||
void XTREME_SETTINGS_LOAD();
|
void XTREME_SETTINGS_LOAD();
|
||||||
|
|||||||
Reference in New Issue
Block a user