From a2e6a8838ebd67f6c3f25b1c49afa6bbf38cfe94 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 16 Jan 2025 18:12:40 +0000 Subject: [PATCH] PicoVector: AF: Support for 16bit point count. Somewhere in the conversion from C++ to C we lost support for 16-bit point counts. Raise the internal point count to 16-bit, and check for a flag in the font. If the flag is set, treat the point count as 16-bits, otherwise fallback to 8 for back compatibility. --- libraries/pico_vector/alright-fonts.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libraries/pico_vector/alright-fonts.h b/libraries/pico_vector/alright-fonts.h index 2e02b540..92c19bed 100644 --- a/libraries/pico_vector/alright-fonts.h +++ b/libraries/pico_vector/alright-fonts.h @@ -33,6 +33,8 @@ #include #include +#define FLAG_16BIT_POINT_COUNT 0b00000001 + #ifdef AF_MALLOC #ifndef PP_MALLOC #define PP_MALLOC(size) AF_MALLOC(size) @@ -69,7 +71,7 @@ typedef struct { pp_point_t af_point_transform(pp_point_t *p, pp_mat3_t *m); typedef struct { - uint8_t point_count; + uint16_t point_count; af_point_t *points; } af_path_t; @@ -130,6 +132,7 @@ uint8_t ru8(AF_FILE file) {return AF_FGETC(file);} int8_t rs8(AF_FILE file) {return AF_FGETC(file);} bool af_load_font_file(AF_FILE file, af_face_t *face) { + bool font16 = false; // check header magic bytes are present char marker[4]; AF_FREAD(marker, 1, 4, file); if(memcmp(marker, "af!?", 4) != 0) { @@ -138,7 +141,9 @@ bool af_load_font_file(AF_FILE file, af_face_t *face) { // extract flags and ensure none set face->flags = ru16(file); - if(face->flags != 0) { + if(face->flags == FLAG_16BIT_POINT_COUNT) { + font16 = true; + } else if(face->flags != 0) { return false; // unknown flags set } @@ -183,7 +188,7 @@ bool af_load_font_file(AF_FILE file, af_face_t *face) { af_glyph_t *glyph = &face->glyphs[i]; for(int j = 0; j < glyph->path_count; j++) { af_path_t *path = &glyph->paths[j]; - path->point_count = ru8(file); + path->point_count = font16 ? ru16(file) : ru8(file); path->points = points; points += path->point_count; }