From 334df91c6e464fe6434500f63e2fb12438722845 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Thu, 6 Sep 2018 14:00:29 +0200 Subject: WIN drop mhFonts[MAX_FALLBACK] Everything now uses the HFONT from WinFontInstance, so there is no need for the additional fallback array. Change-Id: I15a197b262633569cb95c37689561db5323e1115 Reviewed-on: https://gerrit.libreoffice.org/60092 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski --- vcl/inc/win/salgdi.h | 13 ------------ vcl/win/gdi/salfont.cxx | 55 +++++++++++++++---------------------------------- vcl/win/gdi/salgdi.cxx | 6 ------ 3 files changed, 17 insertions(+), 57 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h index 32a104bef88e..243d2cdc8fc5 100644 --- a/vcl/inc/win/salgdi.h +++ b/vcl/inc/win/salgdi.h @@ -156,19 +156,6 @@ private: bool mbScreen : 1; // is Screen compatible HWND mhWnd; // Window-Handle, when Window-Graphics - /** HFONT lifecycle - * - * The HFONT has to be shared between mhFonts and mpWinFontEntry. - * As mpWinFontEntry is reference counted and just freed in SetFont, the HFONT is - * transferred from mhFonts to the mpWinFontEntry. - * - * We need the mhFonts list, as embedded fonts don't have a corresponding WinFontInstance - * so for these there is just the mhFonts entry. - * - * The HFONT object can just be assigned to mhFonts _or_ mpWinFontEntry! - **/ - - HFONT mhFonts[ MAX_FALLBACK ]; // Font + Fallbacks rtl::Reference mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance HRGN mhRegion; // vcl::Region Handle diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index bed9c7a22376..e2734052c9c0 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -913,22 +913,17 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, int nFallbackLevel) // return early if there is no new font if( !pFont ) { - // deselect still active font - if (mhDefFont) - { - ::SelectFont(getHDC(), mhDefFont); - mhDefFont = nullptr; - } + if (!mpWinFontEntry[nFallbackLevel].is()) + return; + + // select original DC font + assert(mhDefFont); + ::SelectFont(getHDC(), mhDefFont); + mhDefFont = nullptr; + // release no longer referenced font handles for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i ) - { - if( mhFonts[i] ) - { - ::DeleteFont( mhFonts[i] ); - mhFonts[ i ] = nullptr; - } mpWinFontEntry[i] = nullptr; - } return; } @@ -953,16 +948,8 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, int nFallbackLevel) else { // release no longer referenced font handles - for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i ) - { - if( mhFonts[i] ) - { - ::DeleteFont( mhFonts[i] ); - mhFonts[i] = nullptr; - } - if (i > nFallbackLevel) - mpWinFontEntry[i] = nullptr; - } + for( int i = nFallbackLevel + 1; mpWinFontEntry[i].is() && i < MAX_FALLBACK; ++i ) + mpWinFontEntry[i] = nullptr; } // now the font is live => update font face @@ -973,8 +960,8 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, int nFallbackLevel) void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int nFallbackLevel ) { // temporarily change the HDC to the font in the fallback level - assert(!mhFonts[nFallbackLevel] && mpWinFontEntry[nFallbackLevel]); - const HFONT hOldFont = SelectFont(getHDC(), mpWinFontEntry[nFallbackLevel]->GetHFONT()); + rtl::Reference pFontInstance = mpWinFontEntry[nFallbackLevel]; + const HFONT hOldFont = SelectFont(getHDC(), pFontInstance->GetHFONT()); wchar_t aFaceName[LF_FACESIZE+60]; if( GetTextFaceW( getHDC(), SAL_N_ELEMENTS(aFaceName), aFaceName ) ) @@ -985,7 +972,7 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int nFa const RawFontData aHheaRawData(getHDC(), nHheaTag); const RawFontData aOS2RawData(getHDC(), nOS2Tag); - rxFontMetric->SetMinKashida(mpWinFontEntry[nFallbackLevel]->GetKashidaWidth()); + rxFontMetric->SetMinKashida(pFontInstance->GetKashidaWidth()); // get the font metric OUTLINETEXTMETRICW aOutlineMetric; @@ -1006,7 +993,7 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int nFa rxFontMetric->SetSlant( 0 ); // transformation dependent font metrics - rxFontMetric->SetWidth(static_cast(mpWinFontEntry[nFallbackLevel]->GetScale() * aWinMetric.tmAveCharWidth)); + rxFontMetric->SetWidth(static_cast(pFontInstance->GetScale() * aWinMetric.tmAveCharWidth)); const std::vector rHhea(aHheaRawData.get(), aHheaRawData.get() + aHheaRawData.size()); const std::vector rOS2(aOS2RawData.get(), aOS2RawData.get() + aOS2RawData.size()); @@ -1596,18 +1583,13 @@ private: HFONT m_hOrigFont; }; -ScopedFont::ScopedFont(WinSalGraphics & rData): m_rData(rData) +ScopedFont::ScopedFont(WinSalGraphics & rData): m_rData(rData), m_hOrigFont(nullptr) { if (m_rData.mpWinFontEntry[0]) { m_hOrigFont = m_rData.mpWinFontEntry[0]->GetHFONT(); m_rData.mpWinFontEntry[0]->UnsetHFONT(); } - else - { - m_hOrigFont = m_rData.mhFonts[0]; - m_rData.mhFonts[0] = nullptr; // avoid deletion of current font - } } ScopedFont::~ScopedFont() @@ -1615,11 +1597,8 @@ ScopedFont::~ScopedFont() if( m_hOrigFont ) { // restore original font, destroy temporary font - HFONT hTempFont = m_rData.mhFonts[0]; - if (m_rData.mpWinFontEntry[0]) - m_rData.mpWinFontEntry[0]->SetHFONT(m_hOrigFont); - else - m_rData.mhFonts[0] = m_hOrigFont; + HFONT hTempFont = m_rData.mpWinFontEntry[0]->GetHFONT(); + m_rData.mpWinFontEntry[0]->SetHFONT(m_hOrigFont); SelectObject( m_rData.getHDC(), m_hOrigFont ); DeleteObject( hTempFont ); } diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx index 46155bbef3dc..24188e42517d 100644 --- a/vcl/win/gdi/salgdi.cxx +++ b/vcl/win/gdi/salgdi.cxx @@ -620,12 +620,6 @@ WinSalGraphics::WinSalGraphics(WinSalGraphics::Type eType, bool bScreen, HWND hW mpImpl.reset(new WinOpenGLSalGraphicsImpl(*this, pProvider)); else mpImpl.reset(new WinSalGraphicsImpl(*this)); - - for( int i = 0; i < MAX_FALLBACK; ++i ) - { - mhFonts[ i ] = nullptr; - mpWinFontEntry[ i ] = nullptr; - } } WinSalGraphics::~WinSalGraphics() -- cgit