From 90f59cace59e91511a3b99b1c05b8f95ed082db9 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Wed, 23 Oct 2024 14:54:55 +0800 Subject: [PATCH] improve font_stb_get_vmetrics for mingw --- docs/changes.md | 3 +++ src/font_loader/font_loader_stb.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index aa1a6ddaf..a1a9ce9e6 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,8 @@ # 最新动态 +2024/10/23 + * 修复mingw编译下font_stb_get_vmetrics异常问题(感谢颖健提供补丁) + 2024/10/21 * 完善AWTK字号转成标准字号的功能(感谢颖健提供补丁) * 打开对话框失去焦点时Ctrl状态未恢复的问题(感谢颖健提供补丁) diff --git a/src/font_loader/font_loader_stb.c b/src/font_loader/font_loader_stb.c index 223fd24bb..0e9bb7fcb 100644 --- a/src/font_loader/font_loader_stb.c +++ b/src/font_loader/font_loader_stb.c @@ -85,12 +85,15 @@ static bool_t font_stb_match(font_t* f, const char* name, font_size_t font_size) } static font_vmetrics_t font_stb_get_vmetrics(font_t* f, font_size_t font_size) { - int16_t ascender = 0; - int16_t descender = 0; - font_vmetrics_t vmetrics; + int ascender = 0; + int descender = 0; + float scale = 0.0f; font_stb_t* font = (font_stb_t*)f; - stbtt_fontinfo* sf = &(font->stb_font); - float scale = stbtt_ScaleForPixelHeight(sf, font_size); + const stbtt_fontinfo* sf = &(font->stb_font); + font_vmetrics_t vmetrics = {font_size, 0, 0, 0, 0, 0}; + + return_value_if_fail(sf != NULL, vmetrics); + scale = stbtt_ScaleForPixelHeight(sf, font_size); if (scale == INFINITY) { scale = stbtt_ScaleForMappingEmToPixels(sf, font_size); }