diff options
author | Dmitriy Shilin <dshil@fastmail.com> | 2019-01-08 04:20:29 -0800 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-01-18 15:20:43 +0100 |
commit | f00fc7ee17153ff70fa4fb2052a5b555af0c054c (patch) | |
tree | a49f2b853a072303b43b04b49b9e93f75224003d /vcl/win | |
parent | 8e50e218d26dfab1038570476e11d616f91d3768 (diff) |
tdf#107792 vcl/win: introduce ScopedSelectedHFONT
Change-Id: If06ef869fc68976ee3ac6e671edd1bb4f992e716
Reviewed-on: https://gerrit.libreoffice.org/65964
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'vcl/win')
-rw-r--r-- | vcl/win/gdi/winlayout.cxx | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx index ebaf2f1be2d6..120f6bb65e22 100644 --- a/vcl/win/gdi/winlayout.cxx +++ b/vcl/win/gdi/winlayout.cxx @@ -235,7 +235,7 @@ bool ExTextOutRenderer::operator ()(GenericSalLayout const &rLayout, HDC hDC) { HFONT hFont = static_cast<HFONT>(GetCurrentObject( hDC, OBJ_FONT )); - HFONT hAltFont = nullptr; + ScopedHFONT hAltFont; bool bUseAltFont = false; bool bShift = false; if (rLayout.GetFont().GetFontSelectPattern().mbVertical) @@ -246,14 +246,14 @@ bool ExTextOutRenderer::operator ()(GenericSalLayout const &rLayout, { memmove(&aLogFont.lfFaceName[0], &aLogFont.lfFaceName[1], sizeof(aLogFont.lfFaceName)-sizeof(aLogFont.lfFaceName[0])); - hAltFont = CreateFontIndirectW(&aLogFont); + hAltFont.reset(CreateFontIndirectW(&aLogFont)); } else { bShift = true; aLogFont.lfEscapement += 2700; aLogFont.lfOrientation = aLogFont.lfEscapement; - hAltFont = CreateFontIndirectW(&aLogFont); + hAltFont.reset(CreateFontIndirectW(&aLogFont)); } } @@ -267,7 +267,7 @@ bool ExTextOutRenderer::operator ()(GenericSalLayout const &rLayout, if (hAltFont && pGlyph->IsVertical() == bUseAltFont) { bUseAltFont = !bUseAltFont; - SelectFont(hDC, bUseAltFont ? hAltFont : hFont); + SelectFont(hDC, bUseAltFont ? hAltFont.get() : hFont); } if (bShift && pGlyph->IsVertical()) SetTextAlign(hDC, TA_TOP|TA_LEFT); @@ -281,7 +281,6 @@ bool ExTextOutRenderer::operator ()(GenericSalLayout const &rLayout, { if (bUseAltFont) SelectFont(hDC, hFont); - DeleteObject(hAltFont); } return true; @@ -364,14 +363,13 @@ hb_font_t* WinFontInstance::ImplInitHbFont() // Set width to the default to get the original value in the metrics. aLogFont.lfWidth = 0; - // Get the font metrics. - HDC hDC = m_pGraphics->getHDC(); - HFONT hNewFont = CreateFontIndirectW(&aLogFont); - HGDIOBJ hOrigFont = SelectObject(hDC, hNewFont); TEXTMETRICW aFontMetric; - GetTextMetricsW(hDC, &aFontMetric); - SelectObject(hDC, hOrigFont); - DeleteObject(hNewFont); + { + // Get the font metrics. + HDC hDC = m_pGraphics->getHDC(); + ScopedSelectedHFONT(hDC, CreateFontIndirectW(&aLogFont)); + GetTextMetricsW(hDC, &aFontMetric); + } SetAverageWidthFactor(nUPEM / aFontMetric.tmAveCharWidth); } |