improve stb font

This commit is contained in:
lixianjing 2022-05-14 16:17:40 +08:00
parent d9c549f282
commit 6e08872691
3 changed files with 24 additions and 1 deletions

View File

@ -293,11 +293,21 @@ int fons__tt_loadFont(FONScontext *context, FONSttFontImpl *font, unsigned char
void fons__tt_getFontVMetrics(FONSttFontImpl *font, int *ascent, int *descent, int *lineGap)
{
stbtt_GetFontVMetrics(&font->font, ascent, descent, lineGap);
if(*ascent == 0 && *descent == 0) {
float scale = stbtt_ScaleForMappingEmToPixels(&font->font, 18);
*ascent = (int)(18 / scale);
*descent = 0;
*lineGap = 0;
}
}
float fons__tt_getPixelHeightScale(FONSttFontImpl *font, float size)
{
return stbtt_ScaleForPixelHeight(&font->font, size);
float scale = stbtt_ScaleForPixelHeight(&font->font, size);
if (scale == INFINITY) {
scale = stbtt_ScaleForMappingEmToPixels(&font->font, size);
}
return scale;
}
int fons__tt_getGlyphIndex(FONSttFontImpl *font, int codepoint)

View File

@ -1,5 +1,8 @@
# 最新动态
2022/05/14
* 修复opengl模式下无法渲染缺少ascent、descent信息字体的问题并统一agge模式下的效果感谢雨欣提供补丁
2022/05/13
* 完善load\_asset\_zip(感谢俊圣提供补丁)
* 完善fps测试(感谢俊圣提供补丁)

View File

@ -89,6 +89,9 @@ static font_vmetrics_t font_stb_get_vmetrics(font_t* f, font_size_t font_size) {
font_stb_t* font = (font_stb_t*)f;
stbtt_fontinfo* sf = &(font->stb_font);
float scale = stbtt_ScaleForPixelHeight(sf, font_size);
if (scale == INFINITY) {
scale = stbtt_ScaleForMappingEmToPixels(sf, font_size);
}
vmetrics.ascent = scale * font->ascent;
vmetrics.descent = scale * font->descent;
@ -210,6 +213,13 @@ static font_t* font_stb_create_ex(const char* name, const uint8_t* buff, uint32_
stbtt_InitFont(&(f->stb_font), buff, stbtt_GetFontOffsetForIndex(buff, 0));
stbtt_GetFontVMetrics(&(f->stb_font), &(f->ascent), &(f->descent), &(f->line_gap));
if (f->ascent == 0 && f->descent == 0) {
float scale = stbtt_ScaleForMappingEmToPixels(&(f->stb_font), 18);
f->ascent = (int)(18 / scale);
f->descent = 0;
f->line_gap = 0;
}
return &(f->base);
}