tdf#103725: Fix horizontal scaling on Windows
* Restore the hack for adjusting font width on Windows, for the life of me I can’t find where we change font width or why I get different values on Windows than Linux. * Create IDWriteFont from LOGFONT instead of HDC, as it seems the later will discard the font width. Change-Id: I74d6685b8c2a6f5d8087f439fbb02f0343f13691
This commit is contained in:
@@ -95,7 +95,13 @@ void CommonSalLayout::getScale(double* nXScale, double* nYScale)
|
|||||||
unsigned int nUPEM = hb_face_get_upem(pHbFace);
|
unsigned int nUPEM = hb_face_get_upem(pHbFace);
|
||||||
|
|
||||||
double nHeight(mrFontSelData.mnHeight);
|
double nHeight(mrFontSelData.mnHeight);
|
||||||
|
#if _WIN32
|
||||||
|
// FIXME: we get very weird font width on Windows, the number below is
|
||||||
|
// “reverse engineered” so that I get the width I’m expecting.
|
||||||
|
double nWidth(mrFontSelData.mnWidth ? mrFontSelData.mnWidth * 1.8285 : nHeight);
|
||||||
|
#else
|
||||||
double nWidth(mrFontSelData.mnWidth ? mrFontSelData.mnWidth : nHeight);
|
double nWidth(mrFontSelData.mnWidth ? mrFontSelData.mnWidth : nHeight);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (nYScale)
|
if (nYScale)
|
||||||
*nYScale = nHeight / nUPEM;
|
*nYScale = nHeight / nUPEM;
|
||||||
|
@@ -1106,24 +1106,27 @@ HFONT WinSalGraphics::ImplDoSetFont( FontSelectPattern* i_pFont, float& o_rFontS
|
|||||||
LOGFONTW aLogFont;
|
LOGFONTW aLogFont;
|
||||||
ImplGetLogFontFromFontSelect( getHDC(), i_pFont, aLogFont, true );
|
ImplGetLogFontFromFontSelect( getHDC(), i_pFont, aLogFont, true );
|
||||||
|
|
||||||
// #i47675# limit font requests to MAXFONTHEIGHT
|
if (!SalLayout::UseCommonLayout())
|
||||||
// TODO: share MAXFONTHEIGHT font instance
|
|
||||||
if( (-aLogFont.lfHeight <= MAXFONTHEIGHT)
|
|
||||||
&& (+aLogFont.lfWidth <= MAXFONTHEIGHT) )
|
|
||||||
{
|
{
|
||||||
o_rFontScale = 1.0;
|
// #i47675# limit font requests to MAXFONTHEIGHT
|
||||||
}
|
// TODO: share MAXFONTHEIGHT font instance
|
||||||
else if( -aLogFont.lfHeight >= +aLogFont.lfWidth )
|
if( (-aLogFont.lfHeight <= MAXFONTHEIGHT)
|
||||||
{
|
&& (+aLogFont.lfWidth <= MAXFONTHEIGHT) )
|
||||||
o_rFontScale = -aLogFont.lfHeight / (float)MAXFONTHEIGHT;
|
{
|
||||||
aLogFont.lfHeight = -MAXFONTHEIGHT;
|
o_rFontScale = 1.0;
|
||||||
aLogFont.lfWidth = FRound( aLogFont.lfWidth / o_rFontScale );
|
}
|
||||||
}
|
else if( -aLogFont.lfHeight >= +aLogFont.lfWidth )
|
||||||
else // #i95867# also limit font widths
|
{
|
||||||
{
|
o_rFontScale = -aLogFont.lfHeight / (float)MAXFONTHEIGHT;
|
||||||
o_rFontScale = +aLogFont.lfWidth / (float)MAXFONTHEIGHT;
|
aLogFont.lfHeight = -MAXFONTHEIGHT;
|
||||||
aLogFont.lfWidth = +MAXFONTHEIGHT;
|
aLogFont.lfWidth = FRound( aLogFont.lfWidth / o_rFontScale );
|
||||||
aLogFont.lfHeight = FRound( aLogFont.lfHeight / o_rFontScale );
|
}
|
||||||
|
else // #i95867# also limit font widths
|
||||||
|
{
|
||||||
|
o_rFontScale = +aLogFont.lfWidth / (float)MAXFONTHEIGHT;
|
||||||
|
aLogFont.lfWidth = +MAXFONTHEIGHT;
|
||||||
|
aLogFont.lfHeight = FRound( aLogFont.lfHeight / o_rFontScale );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hNewFont = ::CreateFontIndirectW( &aLogFont );
|
hNewFont = ::CreateFontIndirectW( &aLogFont );
|
||||||
|
@@ -3599,9 +3599,19 @@ std::vector<Rectangle> D2DWriteTextOutRenderer::GetGlyphInkBoxes(uint16_t * pGid
|
|||||||
bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** ppFontFace, float * lfSize) const
|
bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** ppFontFace, float * lfSize) const
|
||||||
{
|
{
|
||||||
bool succeeded = false;
|
bool succeeded = false;
|
||||||
|
IDWriteFont* pFont;
|
||||||
|
|
||||||
|
LOGFONTW aLogFont;
|
||||||
|
HFONT hFont = static_cast<HFONT>(::GetCurrentObject(hDC, OBJ_FONT));
|
||||||
|
GetObjectW(hFont, sizeof(LOGFONTW), &aLogFont);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
succeeded = SUCCEEDED(mpGdiInterop->CreateFontFaceFromHdc(hDC, ppFontFace));
|
succeeded = SUCCEEDED(mpGdiInterop->CreateFontFromLOGFONT(&aLogFont, &pFont));
|
||||||
|
if (succeeded)
|
||||||
|
{
|
||||||
|
succeeded = SUCCEEDED(pFont->CreateFontFace(ppFontFace));
|
||||||
|
pFont->Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
@@ -3611,10 +3621,6 @@ bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** p
|
|||||||
|
|
||||||
if (succeeded)
|
if (succeeded)
|
||||||
{
|
{
|
||||||
LOGFONTW aLogFont;
|
|
||||||
HFONT hFont = static_cast<HFONT>(::GetCurrentObject(hDC, OBJ_FONT));
|
|
||||||
|
|
||||||
GetObjectW(hFont, sizeof(LOGFONTW), &aLogFont);
|
|
||||||
float dpix, dpiy;
|
float dpix, dpiy;
|
||||||
mpRT->GetDpi(&dpix, &dpiy);
|
mpRT->GetDpi(&dpix, &dpiy);
|
||||||
*lfSize = aLogFont.lfHeight * 96.0f / dpiy;
|
*lfSize = aLogFont.lfHeight * 96.0f / dpiy;
|
||||||
|
Reference in New Issue
Block a user