[Libreoffice-commits] core.git: 2 commits - vcl/inc vcl/source vcl/win
Khaled Hosny
khaledhosny at eglug.org
Fri Nov 11 12:06:50 UTC 2016
vcl/inc/win/winlayout.hxx | 1 -
vcl/source/gdi/CommonSalLayout.cxx | 6 ++++++
vcl/win/gdi/salfont.cxx | 37 ++++++++++++++++++++-----------------
vcl/win/gdi/winlayout.cxx | 34 +++++++++++-----------------------
4 files changed, 37 insertions(+), 41 deletions(-)
New commits:
commit 30fefcf71417f8c8644f5c0d3cb28c8c7f92a6c7
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Fri Nov 11 13:58:21 2016 +0200
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
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index ae5e442..52721e1 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -95,7 +95,13 @@ void CommonSalLayout::getScale(double* nXScale, double* nYScale)
unsigned int nUPEM = hb_face_get_upem(pHbFace);
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);
+#endif
if (nYScale)
*nYScale = nHeight / nUPEM;
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index f290bdd..7f41fdd 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -1106,24 +1106,27 @@ HFONT WinSalGraphics::ImplDoSetFont( FontSelectPattern* i_pFont, float& o_rFontS
LOGFONTW aLogFont;
ImplGetLogFontFromFontSelect( getHDC(), i_pFont, aLogFont, true );
- // #i47675# limit font requests to MAXFONTHEIGHT
- // TODO: share MAXFONTHEIGHT font instance
- if( (-aLogFont.lfHeight <= MAXFONTHEIGHT)
- && (+aLogFont.lfWidth <= MAXFONTHEIGHT) )
+ if (!SalLayout::UseCommonLayout())
{
- o_rFontScale = 1.0;
- }
- else if( -aLogFont.lfHeight >= +aLogFont.lfWidth )
- {
- o_rFontScale = -aLogFont.lfHeight / (float)MAXFONTHEIGHT;
- aLogFont.lfHeight = -MAXFONTHEIGHT;
- aLogFont.lfWidth = FRound( aLogFont.lfWidth / o_rFontScale );
- }
- else // #i95867# also limit font widths
- {
- o_rFontScale = +aLogFont.lfWidth / (float)MAXFONTHEIGHT;
- aLogFont.lfWidth = +MAXFONTHEIGHT;
- aLogFont.lfHeight = FRound( aLogFont.lfHeight / o_rFontScale );
+ // #i47675# limit font requests to MAXFONTHEIGHT
+ // TODO: share MAXFONTHEIGHT font instance
+ if( (-aLogFont.lfHeight <= MAXFONTHEIGHT)
+ && (+aLogFont.lfWidth <= MAXFONTHEIGHT) )
+ {
+ o_rFontScale = 1.0;
+ }
+ else if( -aLogFont.lfHeight >= +aLogFont.lfWidth )
+ {
+ o_rFontScale = -aLogFont.lfHeight / (float)MAXFONTHEIGHT;
+ aLogFont.lfHeight = -MAXFONTHEIGHT;
+ aLogFont.lfWidth = FRound( aLogFont.lfWidth / 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 );
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index b7882e3..335bb8c 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -3599,9 +3599,19 @@ std::vector<Rectangle> D2DWriteTextOutRenderer::GetGlyphInkBoxes(uint16_t * pGid
bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** ppFontFace, float * lfSize) const
{
bool succeeded = false;
+ IDWriteFont* pFont;
+
+ LOGFONTW aLogFont;
+ HFONT hFont = static_cast<HFONT>(::GetCurrentObject(hDC, OBJ_FONT));
+ GetObjectW(hFont, sizeof(LOGFONTW), &aLogFont);
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)
{
@@ -3611,10 +3621,6 @@ bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** p
if (succeeded)
{
- LOGFONTW aLogFont;
- HFONT hFont = static_cast<HFONT>(::GetCurrentObject(hDC, OBJ_FONT));
-
- GetObjectW(hFont, sizeof(LOGFONTW), &aLogFont);
float dpix, dpiy;
mpRT->GetDpi(&dpix, &dpiy);
*lfSize = aLogFont.lfHeight * 96.0f / dpiy;
commit b9ed8e553eb8515051dbdcabfe4aa0227f0d3023
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Fri Nov 11 11:33:37 2016 +0200
Unused code
Change-Id: Ie2e4b5881a783441d32010408c05b3c9f1e5641c
diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index 84b27d5..64e78d4 100755
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -480,7 +480,6 @@ public:
std::vector<Rectangle> GetGlyphInkBoxes(uint16_t * pGid, uint16_t * pGidEnd) const /*override*/;
ID2D1RenderTarget * GetRenderTarget() const { return mpRT; }
- IDWriteFontFace * GetDWriteFontFace(HDC) const;
IDWriteFontFace * GetFontFace() const { return mpFontFace; }
float GetEmHeight() const { return mlfEmHeight; }
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 468bc1c..b7882e3 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -3531,24 +3531,6 @@ bool D2DWriteTextOutRenderer::operator ()(SalLayout const &rLayout, HDC hDC,
return (succeeded && nGlyphs >= 1 && pRectToErase);
}
-IDWriteFontFace* D2DWriteTextOutRenderer::GetDWriteFontFace(HDC hDC) const
-{
- IDWriteFontFace* pFontFace;
- bool succeeded = false;
- try
- {
- succeeded = SUCCEEDED(mpGdiInterop->CreateFontFaceFromHdc(hDC, &pFontFace));
- }
- catch (const std::exception& e)
- {
- SAL_WARN("vcl.gdi", "Error in dwrite while creating font face: " << e.what());
- return nullptr;
- }
- if(succeeded)
- return pFontFace;
- else return nullptr;
-}
-
bool D2DWriteTextOutRenderer::BindFont(HDC hDC)
{
// A TextOutRender can only be bound to one font at a time, so the
More information about the Libreoffice-commits
mailing list