From 93f970ce7b086a31eb6e8faf1e17a5b2982c922f Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Thu, 22 Apr 2010 11:25:54 +0100 Subject: [PATCH] wineps.drv: Calculate the font size directly from the logfont. --- dlls/wineps.drv/download.c | 45 +++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/dlls/wineps.drv/download.c b/dlls/wineps.drv/download.c index a6ab9d076fe..5a873e19f62 100644 --- a/dlls/wineps.drv/download.c +++ b/dlls/wineps.drv/download.c @@ -202,6 +202,37 @@ BOOL PSDRV_SelectDownloadFont(PSDRV_PDEVICE *physDev) return TRUE; } +static UINT calc_ppem_for_height(HDC hdc, LONG height) +{ + BYTE os2[78]; /* size of version 0 table */ + BYTE hhea[8]; /* just enough to get the ascender and descender */ + LONG ascent = 0, descent = 0; + UINT emsize; + + if(height < 0) return -height; + + if(GetFontData(hdc, MS_MAKE_TAG('O','S','/','2'), 0, os2, sizeof(os2)) == sizeof(os2)) + { + ascent = GET_BE_WORD(os2 + 74); /* usWinAscent */ + descent = GET_BE_WORD(os2 + 76); /* usWinDescent */ + } + + if(ascent + descent == 0) + { + if(GetFontData(hdc, MS_MAKE_TAG('h','h','e','a'), 0, hhea, sizeof(hhea)) == sizeof(hhea)) + { + ascent = (signed short)GET_BE_WORD(hhea + 4); /* Ascender */ + descent = -(signed short)GET_BE_WORD(hhea + 6); /* Descender */ + } + } + + if(ascent + descent == 0) return height; + + get_bbox(hdc, NULL, &emsize); + + return MulDiv(emsize, height, ascent + descent); +} + /**************************************************************************** * PSDRV_WriteSetDownloadFont * @@ -214,6 +245,8 @@ BOOL PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE *physDev) LPOUTLINETEXTMETRICA potm; DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL); DOWNLOAD *pdl; + LOGFONTW lf; + UINT ppem; assert(physDev->font.fontloc == Download); @@ -223,16 +256,18 @@ BOOL PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE *physDev) get_download_name(physDev, potm, &ps_name); physDev->font.fontinfo.Download = is_font_downloaded(physDev, ps_name); - physDev->font.size = abs(PSDRV_YWStoDS(physDev, /* ppem */ - potm->otmTextMetrics.tmAscent + - potm->otmTextMetrics.tmDescent - - potm->otmTextMetrics.tmInternalLeading)); + if (!GetObjectW( GetCurrentObject(physDev->hdc, OBJ_FONT), sizeof(lf), &lf )) + return FALSE; + + ppem = calc_ppem_for_height(physDev->hdc, lf.lfHeight); + + physDev->font.size = abs(PSDRV_YWStoDS(physDev, ppem)); + physDev->font.underlineThickness = potm->otmsUnderscoreSize; physDev->font.underlinePosition = potm->otmsUnderscorePosition; physDev->font.strikeoutThickness = potm->otmsStrikeoutSize; physDev->font.strikeoutPosition = potm->otmsStrikeoutPosition; - if(physDev->font.fontinfo.Download == NULL) { RECT bbox; UINT emsize;