TEXTMETRIC 结构和“Cambria Math"的问题;字体 [英] Problem with the TEXTMETRIC struct and the "Cambria Math" font

查看:63
本文介绍了TEXTMETRIC 结构和“Cambria Math"的问题;字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行下面的代码,我会得到带有cambria Math"字体的 tm 和 gm 结构的以下值:

tm.tmHeight = 161tm.tmAscent = 90tm.tmDescent = 71

gm.gmBlackBoxY = 14

tm 中的值明显有误gmBlackBoxY 似乎是正确的.

现在,如果我用

运行代码

lfFaceName = "Arial"

我为 tmgm 得到以下值,它们是正确的:

tm.tmHeight = 33tm.tmAscent = 27tm.tmDescent = 6

gm.gmBlackBoxY = 15

代码:

int iLogPixelsY;iLogPixelsY = GetDeviceCaps(hdc,LOGPIXELSY);LOGFONT lf;国际知识产权;iPts = 22;memset(&lf, 0, sizeof(LOGFONT));lf.lfHeight = -iPts * iLogPixelsY/72;lf.lfWeight = FW_NORMAL;lf.lfItalic = 0;lf.lfCharSet = 0;lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;wcscpy(lf.lfFaceName, L"Cambria Math");HFONT hFont;hFont = CreateFontIndirect(&lf);hFont = (HFONT)SelectObject(hdc, hFont);TCHAR tx;tx = 'a';TEXTMETRIC tm;GetTextMetrics(hdc, &tm);字形 gm;GetGlyphOutline(hdc, tx, GGO_METRICS, &gm, 0, NULL, &gmat);

谁能解释为Cambria Math"字体获取TEXTMETRIC 结构的明显错误?

解决方案

代码中的错误不适用于获取 TEXTMETRIC 结构(不包括在同一代码中使用 TCHARs、CHARs 和 WCHARs 函数和变量).

>

tm.tmHeight == 161;tm.tmAscent == 90;tm.tmDescent == 71;tm.tmInternalLeading == 132;

以上几行没有任何错误!!!

tm.tmHeight == tm.tmAscent + tm.tmDescent;tm.tmHeight == tm.tmInternalLeading + MulDiv(22,GetDeviceCaps(hdc,LOGPIXELSY),72);

Cambria Math"就是用这些参数设计的!

转到链接 http://www.ascenderfonts.com/font/cambria-regular.aspx 将字体大小更改为 22pt(或其他),并查看字体Cambria"和字体Cambria Math"的上下边距之间的差异.

If I run the code below, I get the following values for the tm and gm structures with the "cambria Math" font:

tm.tmHeight = 161
tm.tmAscent = 90
tm.tmDescent = 71

and

gm.gmBlackBoxY = 14

The values in tm are clearly in error! The gmBlackBoxY seems to be correct.

Now, if I run the code with

lfFaceName = "Arial"

I get for tm and gm the following values, which are correct:

tm.tmHeight = 33
tm.tmAscent = 27
tm.tmDescent = 6

and

gm.gmBlackBoxY = 15

Code:

int iLogPixelsY;
iLogPixelsY = GetDeviceCaps(hdc,LOGPIXELSY);

LOGFONT lf;
int iPts;
iPts = 22;

memset(&lf, 0, sizeof(LOGFONT));

lf.lfHeight = -iPts * iLogPixelsY / 72;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = 0;
lf.lfCharSet = 0;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;

wcscpy(lf.lfFaceName, L"Cambria Math");
HFONT hFont;
hFont = CreateFontIndirect(&lf);
hFont = (HFONT)SelectObject(hdc, hFont);

TCHAR tx;
tx = 'a';

TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);

GLYPHMETRICS gm;
GetGlyphOutline(hdc, tx, GGO_METRICS, &gm, 0, NULL, &gmat);

Could anyone explain the apparent incorrectness in obtaining the TEXTMETRIC structure for a "Cambria Math" font ?

解决方案

Incorrectness in your code is does not apply to obtaining TEXTMETRIC structure (excluding, that you use TCHARs, CHARs and WCHARs functions and variables in same code).

tm.tmHeight == 161;
tm.tmAscent == 90;
tm.tmDescent == 71;
tm.tmInternalLeading == 132;

Above lines do not have any errors!!!

tm.tmHeight == tm.tmAscent + tm.tmDescent;
tm.tmHeight == tm.tmInternalLeading + MulDiv(22,GetDeviceCaps(hdc,LOGPIXELSY),72);

"Cambria Math" is designed with these parameters!

Go to the link http://www.ascenderfonts.com/font/cambria-regular.aspx Change the font size to 22pt (or whatever) and look at the difference between of top and bottom margins for the font "Cambria" and font "Cambria Math".

这篇关于TEXTMETRIC 结构和“Cambria Math"的问题;字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆