mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
improve stb font
This commit is contained in:
parent
d9c549f282
commit
6e08872691
@ -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)
|
||||
|
@ -1,5 +1,8 @@
|
||||
# 最新动态
|
||||
|
||||
2022/05/14
|
||||
* 修复opengl模式下无法渲染缺少ascent、descent信息字体的问题,并统一agge模式下的效果(感谢雨欣提供补丁)。
|
||||
|
||||
2022/05/13
|
||||
* 完善load\_asset\_zip(感谢俊圣提供补丁)
|
||||
* 完善fps测试(感谢俊圣提供补丁)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user