Ayrosa
Ayrosa

Reputation: 3513

Problem with the TEXTMETRIC struct and the "Cambria Math" font

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 ?

Upvotes: 2

Views: 1303

Answers (1)

Andrew D.
Andrew D.

Reputation: 8230

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".

Upvotes: 1

Related Questions