summaryrefslogtreecommitdiff
path: root/vcl/win/gdi/winlayout.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/win/gdi/winlayout.cxx')
-rw-r--r--vcl/win/gdi/winlayout.cxx24
1 files changed, 21 insertions, 3 deletions
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 0cd916952b3e..fa0c2b683387 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -55,10 +55,24 @@ GlobalGlyphCache * GlobalGlyphCache::get() {
return data->m_pGlobalGlyphCache.get();
}
-bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, int nGlyphIndex, SalGraphics& rGraphics)
+bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, SalGraphics& rGraphics)
{
OpenGLGlyphDrawElement aElement;
+ ScopedHDC aHDC(CreateCompatibleDC(hDC));
+
+ if (!aHDC)
+ {
+ SAL_WARN("vcl.gdi", "CreateCompatibleDC failed: " << WindowsErrorString(GetLastError()));
+ return false;
+ }
+ HFONT hOrigFont = static_cast<HFONT>(SelectObject(aHDC.get(), hFont));
+ if (hOrigFont == nullptr)
+ {
+ SAL_WARN("vcl.gdi", "SelectObject failed: " << WindowsErrorString(GetLastError()));
+ return false;
+ }
+
// For now we assume DWrite is present and we won't bother with fallback paths.
D2DWriteTextOutRenderer * pTxt = dynamic_cast<D2DWriteTextOutRenderer *>(&TextOutRenderer::get(true));
if (!pTxt)
@@ -66,7 +80,7 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, int nGlyphIndex, SalGraphics& r
pTxt->changeTextAntiAliasMode(D2DTextAntiAliasMode::AntiAliased);
- if (!pTxt->BindFont(hDC))
+ if (!pTxt->BindFont(aHDC.get()))
{
SAL_WARN("vcl.gdi", "Binding of font failed. The font might not be supported by DirectWrite.");
return false;
@@ -179,6 +193,7 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, int nGlyphIndex, SalGraphics& r
break;
default:
SAL_WARN("vcl.gdi", "DrawGlyphRun-EndDraw failed: " << WindowsErrorString(GetLastError()));
+ SelectFont(aDC.getCompatibleHDC(), hOrigFont);
return false;
}
@@ -191,6 +206,8 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, int nGlyphIndex, SalGraphics& r
maGlyphCache.PutDrawElementInCache(aElement, nGlyphIndex);
+ SelectFont(aDC.getCompatibleHDC(), hOrigFont);
+
return true;
}
@@ -386,6 +403,7 @@ bool WinSalGraphics::CacheGlyphs(const GenericSalLayout& rLayout)
HDC hDC = getHDC();
WinFontInstance& rFont = *static_cast<WinFontInstance*>(&rLayout.GetFont());
+ HFONT hFONT = rFont.GetHFONT();
int nStart = 0;
Point aPos(0, 0);
@@ -394,7 +412,7 @@ bool WinSalGraphics::CacheGlyphs(const GenericSalLayout& rLayout)
{
if (!rFont.GetGlyphCache().IsGlyphCached(pGlyph->maGlyphId))
{
- if (!rFont.CacheGlyphToAtlas(hDC, pGlyph->maGlyphId, *this))
+ if (!rFont.CacheGlyphToAtlas(hDC, hFONT, pGlyph->maGlyphId, *this))
return false;
}
}