Update font scale on monitor scale change for RENDERER backend (macOS) (#1650)

* Update font scale on monitor scale change for `RENDERER` backend (macOS)

* fix(renderer): check every font of a fontgroup for scale changes in `update_font_scale`

It is needed because fonts can be reused between groups and outside of them.
So if the first font of a group has already been scaled, we still need to check if the others still needs to be scaled.
This commit is contained in:
Guldoman
2024-06-23 09:02:56 +08:00
committed by takase1121
parent 2f32806426
commit 214602d17a
4 changed files with 41 additions and 11 deletions
+18
View File
@@ -54,6 +54,9 @@ typedef struct RenFont {
FT_StreamRec stream;
GlyphSet* sets[SUBPIXEL_BITMAPS_CACHED][MAX_LOADABLE_GLYPHSETS];
float size, space_advance, tab_advance;
#ifdef LITE_USE_SDL_RENDERER
int scale;
#endif
unsigned short max_height, baseline, height;
ERenFontAntialiasing antialiasing;
ERenFontHinting hinting;
@@ -62,6 +65,18 @@ typedef struct RenFont {
char path[];
} RenFont;
#ifdef LITE_USE_SDL_RENDERER
void update_font_scale(RenWindow *window_renderer, RenFont **fonts) {
const int surface_scale = renwin_get_surface(window_renderer).scale;
for (int i = 0; i < FONT_FALLBACK_MAX && fonts[i]; ++i) {
if (fonts[i]->scale != surface_scale) {
ren_font_group_set_size(window_renderer, fonts, fonts[0]->size);
return;
}
}
}
#endif
static const char* utf8_to_codepoint(const char *p, unsigned *dst) {
const unsigned char *up = (unsigned char*)p;
unsigned res, n;
@@ -336,6 +351,9 @@ void ren_font_group_set_size(RenWindow *window_renderer, RenFont **fonts, float
FT_Face face = fonts[i]->face;
FT_Set_Pixel_Sizes(face, 0, (int)(size*surface_scale));
fonts[i]->size = size;
#ifdef LITE_USE_SDL_RENDERER
fonts[i]->scale = surface_scale;
#endif
fonts[i]->height = (short)((face->height / (float)face->units_per_EM) * size);
fonts[i]->baseline = (short)((face->ascender / (float)face->units_per_EM) * size);
FT_Load_Char(face, ' ', font_set_load_options(fonts[i]));