From fec13a036e7123389d79e431a51a007bc4418322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=94=BF?= Date: Tue, 10 Jul 2018 17:41:45 +0800 Subject: [PATCH] set extra glyph scale factor from freetype font metrics --- src/fontstash.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/fontstash.h b/src/fontstash.h index 1ca75bb6..73b443c2 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -378,6 +378,7 @@ struct FONSfont float ascender; float descender; float lineh; + float scaleFactor; FONSglyph* glyphs; int cglyphs; int nglyphs; @@ -938,6 +939,11 @@ int fonsAddFontMem(FONScontext* stash, const char* name, unsigned char* data, in font->ascender = (float)ascent / (float)fh; font->descender = (float)descent / (float)fh; font->lineh = (float)(fh + lineGap) / (float)fh; +#ifdef FONS_USE_FREETYPE + font->scaleFactor = (float)(font->font.font->height) / (float)(font->font.font->units_per_EM); +#else + font->scaleFactor = 1.0f; +#endif return idx; @@ -1042,7 +1048,7 @@ static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned in float scale; FONSglyph* glyph = NULL; unsigned int h; - float size = isize/10.0f; + float size = isize/10.0f * font->scaleFactor; int pad, added; unsigned char* bdst; unsigned char* dst;