gpt4 book ai didi

windows - TEXTMETRIC 结构和 "Cambria Math"字体有问题

转载 作者:可可西里 更新时间:2023-11-01 10:39:53 25 4
gpt4 key购买 nike

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

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

gm.gmBlackBoxY = 14

tm 中的值显然有误! gmBlackBoxY 似乎是正确的。

现在,如果我用

运行代码
lfFaceName = "Arial"

我为 tmgm 得到了以下正确的值:

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

gm.gmBlackBoxY = 15

代码:

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);

谁能解释在获取“Cambria Math”字体的 TEXTMETRIC 结构时明显的错误?

最佳答案

您代码中的错误不适用于获取 TEXTMETRIC 结构(不包括您在同一代码中使用 TCHAR、CHAR 和 WCHAR 函数和变量)。

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”的上下边距之间的差异。

关于windows - TEXTMETRIC 结构和 "Cambria Math"字体有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5554438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com