Open tailangjun opened 7 years ago
Can you post the values of fonsVertMetrics()
for both fonts?
1.use PingFang Regular.ttf
2.use 华文黑体.ttf
Looks like there's two ways to calculate the ascender and descender, one used by OSX and another one by Windows (of course!): https://stackoverflow.com/questions/19856094/computing-font-truetype-hhea-values-ascender-descender
stb_truetype
(font rasterizer used by nanovg) is using the OSX variant. Can you try to change the following functions in stb_truetype.h, to use the windows variant.
STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)
{
if (info->os2 != 0 && ttSHORT(info->data+info->os2 + 0) > 0) { // version > 0
if (ascent ) *ascent = ttSHORT(info->data+info->os2 + 68); // sTypoAscender
if (descent) *descent = ttSHORT(info->data+info->os2 + 70); // sTypoDescender
if (lineGap) *lineGap = ttSHORT(info->data+info->os2 + 72); // sTypoLineGap
} else {
if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4);
if (descent) *descent = ttSHORT(info->data+info->hhea + 6);
if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8);
}
}
STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)
{
int fheight, ascent = 0, descent = 0;
stbtt_GetFontVMetrics(info, &ascent, &descent, NULL);
fheight = ascent - descent;
return (float) height / fheight;
}
In order to show Simplified Chinese, I tried several different ttf files. I found that set the same size, use different ttf file, the text size of the display difference. Should we need to read out some parameters from ttf file and set to fontstash? 华文黑体.ttf is bigger than UILabel, use the same fontsize. PingFang Regular.ttf is smaller than UILabel, use the same fontsize.
1.use PingFang Regular.ttf![usepingfang](https://user-images.githubusercontent.com/12316965/27180156-8b0ff10c-5204-11e7-8c4f-3383991aaac0.jpeg)
2.华文黑体.ttf![usehuawen](https://user-images.githubusercontent.com/12316965/27180181-b239e512-5204-11e7-93d8-8849bbbc9397.jpeg)