[0.4.12][WIN32SS][NTGDI] usWinAscent and usWinDescent must be treated as signed (#1670)

TT_OS2.usWinAscent and TT_OS2.usWinDescent must be treated as FT_Short.
These values affect font metrics.
This PR will fix CORE-14994 that regressed by 0.4.10-dev-466-g
35f62fc5ba

cherry picked from commit 0.4.13-dev-483-g
641a0ea99b
This commit is contained in:
Katayama Hirofumi MZ 2019-06-20 18:58:45 +09:00 committed by Joachim Henze
parent 8c717d09ae
commit d5c85cd522

View file

@ -1846,21 +1846,17 @@ FillTMEx(TEXTMETRICW *TM, PFONTGDI FontGDI,
return;
}
if (pOS2->usWinAscent + pOS2->usWinDescent == 0)
if ((FT_Short)pOS2->usWinAscent + (FT_Short)pOS2->usWinDescent == 0)
{
Ascent = pHori->Ascender;
Descent = -pHori->Descender;
}
else
{
Ascent = pOS2->usWinAscent;
Descent = pOS2->usWinDescent;
Ascent = (FT_Short)pOS2->usWinAscent;
Descent = (FT_Short)pOS2->usWinDescent;
}
if (FontGDI->Magic != FONTGDI_MAGIC)
{
IntRequestFontSize(NULL, FontGDI, 0, 0);
}
TM->tmAscent = FontGDI->tmAscent;
TM->tmDescent = FontGDI->tmDescent;
TM->tmHeight = TM->tmAscent + TM->tmDescent;
@ -2627,7 +2623,7 @@ FontFamilyFillInfo(PFONTFAMILYINFO Info, LPCWSTR FaceName,
}
Ntm->ntmSizeEM = Otm->otmEMSquare;
Ntm->ntmCellHeight = pOS2->usWinAscent + pOS2->usWinDescent;
Ntm->ntmCellHeight = (FT_Short)pOS2->usWinAscent + (FT_Short)pOS2->usWinDescent;
Ntm->ntmAvgWidth = 0;
ExFreePoolWithTag(Otm, GDITAG_TEXT);
@ -3270,12 +3266,20 @@ IntRequestFontSize(PDC dc, PFONTGDI FontGDI, LONG lfWidth, LONG lfHeight)
return FT_Request_Size(face, &req);
}
/* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection */
/*
* NOTE: We cast TT_OS2.usWinAscent and TT_OS2.usWinDescent to signed FT_Short.
* Why? See: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswindescent
*
* > usWinDescent is "usually" a positive value ...
*
* We can read it as "not always". See CORE-14994.
* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection
*/
#define FM_SEL_USE_TYPO_METRICS 0x80
if (lfHeight > 0)
{
/* case (A): lfHeight is positive */
Sum = pOS2->usWinAscent + pOS2->usWinDescent;
Sum = (FT_Short)pOS2->usWinAscent + (FT_Short)pOS2->usWinDescent;
if (Sum == 0 || (pOS2->fsSelection & FM_SEL_USE_TYPO_METRICS))
{
Ascent = pHori->Ascender;
@ -3284,8 +3288,8 @@ IntRequestFontSize(PDC dc, PFONTGDI FontGDI, LONG lfWidth, LONG lfHeight)
}
else
{
Ascent = pOS2->usWinAscent;
Descent = pOS2->usWinDescent;
Ascent = (FT_Short)pOS2->usWinAscent;
Descent = (FT_Short)pOS2->usWinDescent;
}
FontGDI->tmAscent = FT_MulDiv(lfHeight, Ascent, Sum);
@ -3303,8 +3307,8 @@ IntRequestFontSize(PDC dc, PFONTGDI FontGDI, LONG lfWidth, LONG lfHeight)
}
else
{
FontGDI->tmAscent = FT_MulDiv(-lfHeight, pOS2->usWinAscent, face->units_per_EM);
FontGDI->tmDescent = FT_MulDiv(-lfHeight, pOS2->usWinDescent, face->units_per_EM);
FontGDI->tmAscent = FT_MulDiv(-lfHeight, (FT_Short)pOS2->usWinAscent, face->units_per_EM);
FontGDI->tmDescent = FT_MulDiv(-lfHeight, (FT_Short)pOS2->usWinDescent, face->units_per_EM);
}
FontGDI->tmHeight = FontGDI->tmAscent + FontGDI->tmDescent;
FontGDI->tmInternalLeading = FontGDI->tmHeight + lfHeight;