Problem with TEXTMETRIC structure and Cambria Math font

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

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

and

 gm.gmBlackBoxY = 14 

The values ​​in tm clearly wrong ! gmBlackBoxY seems correct.

Now, if I run the code using

 lfFaceName = "Arial" 

I get for tm and gm following values ​​that are correct:

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

and

 gm.gmBlackBoxY = 15 

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

Can someone explain the apparent incorrectness in obtaining the TEXTMETRIC structure for the Cambria Math font?

+2
source share
1 answer

Invalid code does not apply to getting a TEXTMETRIC structure (except that you use the TCHAR, CHARs, and WCHARs functions and variables in the same code).

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

There are no errors above the lines !!!

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

"Cambria Math" is designed with these parameters!

Follow the link http://www.ascenderfonts.com/font/cambria-regular.aspx Change the font size to 22pt (or something else) and look at the difference between the upper and lower margins for the Cambria font and the Cambria font Math. "

+1
source

Source: https://habr.com/ru/post/904430/


All Articles