From 641b9cb1d0934b3f8b4a80279cb3f3f81ecc4707 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 30 Oct 2016 22:09:10 +0200 Subject: tdf#103588: Draw with the right font on Windows Apparently without implementing InitFont(), we might end up drawing with the wrong font, thanks to the arcane ways GDI API. Change-Id: I224de138446d4a536e13992efa98b0f04609576a --- vcl/inc/CommonSalLayout.hxx | 8 ++++++-- vcl/source/gdi/CommonSalLayout.cxx | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/CommonSalLayout.hxx b/vcl/inc/CommonSalLayout.hxx index 298c4c5d990d..eb2e3cd98870 100644 --- a/vcl/inc/CommonSalLayout.hxx +++ b/vcl/inc/CommonSalLayout.hxx @@ -42,9 +42,12 @@ class CommonSalLayout : public GenericSalLayout hb_font_t* mpHbFont; const FontSelectPattern& mrFontSelData; css::uno::Reference mxBreak; -#if defined(MACOSX) || defined(IOS) +#ifdef _WIN32 + HDC mhDC; + HFONT mhFont; +#elif defined(MACOSX) || defined(IOS) const CoreTextStyle& mrCoreTextStyle; -#elif !defined(_WIN32) +#else FreetypeFont& mrFreetypeFont; #endif @@ -57,6 +60,7 @@ class CommonSalLayout : public GenericSalLayout public: #if defined(_WIN32) explicit CommonSalLayout(HDC, WinFontInstance&, const WinFontFace&); + void InitFont() const override { SelectObject(mhDC, mhFont); }; const FontSelectPattern& getFontSelData() const { return mrFontSelData; }; #elif defined(MACOSX) || defined(IOS) explicit CommonSalLayout(const CoreTextStyle&); diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx index dc6ca2cc745d..e7f282627ee7 100644 --- a/vcl/source/gdi/CommonSalLayout.cxx +++ b/vcl/source/gdi/CommonSalLayout.cxx @@ -172,12 +172,13 @@ void CommonSalLayout::ParseFeatures(const OUString& name) #if defined(_WIN32) CommonSalLayout::CommonSalLayout(HDC hDC, WinFontInstance& rWinFontInstance, const WinFontFace& rWinFontFace) : mrFontSelData(rWinFontInstance.maFontSelData) +, mhDC(hDC) +, mhFont(static_cast(GetCurrentObject(hDC, OBJ_FONT))) { mpHbFont = rWinFontFace.GetHbFont(); if (!mpHbFont) { - HFONT hFont = static_cast(GetCurrentObject(hDC, OBJ_FONT)); - hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, hFont, nullptr); + hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, mhFont, nullptr); mpHbFont = createHbFont(pHbFace); rWinFontFace.SetHbFont(mpHbFont); -- cgit