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
This commit is contained in:
Khaled Hosny
2016-10-30 22:09:10 +02:00
parent ffed74ee54
commit 641b9cb1d0
2 changed files with 9 additions and 4 deletions

View File

@@ -42,9 +42,12 @@ class CommonSalLayout : public GenericSalLayout
hb_font_t* mpHbFont;
const FontSelectPattern& mrFontSelData;
css::uno::Reference<css::i18n::XBreakIterator> 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&);

View File

@@ -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<HFONT>(GetCurrentObject(hDC, OBJ_FONT)))
{
mpHbFont = rWinFontFace.GetHbFont();
if (!mpHbFont)
{
HFONT hFont = static_cast<HFONT>(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);