From c98d05242ad28e2081db3dae99d5bc506630d289 Mon Sep 17 00:00:00 2001 From: "Herbert Duerr [hdu]" Date: Fri, 26 Feb 2010 17:22:21 +0100 Subject: [PATCH] #i87970# use UCS4+weight as GFB-result cache keys --- vcl/inc/vcl/outfont.hxx | 10 ++++++---- vcl/source/gdi/outdev3.cxx | 29 ++++++++++++++++++----------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/vcl/inc/vcl/outfont.hxx b/vcl/inc/vcl/outfont.hxx index 86fc0dbc09a0..f0eed5345692 100644 --- a/vcl/inc/vcl/outfont.hxx +++ b/vcl/inc/vcl/outfont.hxx @@ -335,15 +335,17 @@ public: // TODO: make data members private short mnOrientation; // text angle in 3600 system bool mbInit; // true if maMetric member is valid - void AddFallbackForUnicode( sal_UCS4, const String& rFontName ); - bool GetFallbackForUnicode( sal_UCS4, String* pFontName ) const; - void IgnoreFallbackForUnicode( sal_UCS4, const String& rFontName ); + void AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName ); + bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, String* pFontName ) const; + void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const String& rFontName ); private: // cache of Unicode characters and replacement font names // TODO: a fallback map can be shared with many other ImplFontEntries // TODO: at least the ones which just differ in orientation, stretching or height - typedef ::std::hash_map UnicodeFallbackList; + typedef ::std::pair GFBCacheKey; + struct GFBCacheKey_Hash{ size_t operator()( const GFBCacheKey& ) const; }; + typedef ::std::hash_map UnicodeFallbackList; UnicodeFallbackList* mpUnicodeFallbackList; }; diff --git a/vcl/source/gdi/outdev3.cxx b/vcl/source/gdi/outdev3.cxx index 3eef39c32345..b69ce6f662ff 100644 --- a/vcl/source/gdi/outdev3.cxx +++ b/vcl/source/gdi/outdev3.cxx @@ -998,21 +998,28 @@ ImplFontEntry::~ImplFontEntry() // ----------------------------------------------------------------------- -inline void ImplFontEntry::AddFallbackForUnicode( sal_UCS4 cChar, const String& rFontName ) +size_t ImplFontEntry::GFBCacheKey_Hash::operator()( const GFBCacheKey& rData ) const +{ + std::hash a; + std::hash b; + return a(rData.first) ^ b(rData.second); +} + +inline void ImplFontEntry::AddFallbackForUnicode( sal_UCS4 cChar, FontWeight eWeight, const String& rFontName ) { if( !mpUnicodeFallbackList ) mpUnicodeFallbackList = new UnicodeFallbackList; - (*mpUnicodeFallbackList)[cChar] = rFontName; + (*mpUnicodeFallbackList)[ GFBCacheKey(cChar,eWeight) ] = rFontName; } // ----------------------------------------------------------------------- -inline bool ImplFontEntry::GetFallbackForUnicode( sal_UCS4 cChar, String* pFontName ) const +inline bool ImplFontEntry::GetFallbackForUnicode( sal_UCS4 cChar, FontWeight eWeight, String* pFontName ) const { if( !mpUnicodeFallbackList ) return false; - UnicodeFallbackList::const_iterator it = mpUnicodeFallbackList->find( cChar ); + UnicodeFallbackList::const_iterator it = mpUnicodeFallbackList->find( GFBCacheKey(cChar,eWeight) ); if( it == mpUnicodeFallbackList->end() ) return false; @@ -1022,10 +1029,10 @@ inline bool ImplFontEntry::GetFallbackForUnicode( sal_UCS4 cChar, String* pFontN // ----------------------------------------------------------------------- -inline void ImplFontEntry::IgnoreFallbackForUnicode( sal_UCS4 cChar, const String& rFontName ) +inline void ImplFontEntry::IgnoreFallbackForUnicode( sal_UCS4 cChar, FontWeight eWeight, const String& rFontName ) { // DBG_ASSERT( mpUnicodeFallbackList, "ImplFontEntry::IgnoreFallbackForUnicode no list" ); - UnicodeFallbackList::iterator it = mpUnicodeFallbackList->find( cChar ); + UnicodeFallbackList::iterator it = mpUnicodeFallbackList->find( GFBCacheKey(cChar,eWeight) ); // DBG_ASSERT( it != mpUnicodeFallbackList->end(), "ImplFontEntry::IgnoreFallbackForUnicode no match" ); if( it == mpUnicodeFallbackList->end() ) return; @@ -1420,7 +1427,7 @@ ImplDevFontListData* ImplDevFontList::GetGlyphFallbackFont( ImplFontSelectData& while( nStrIndex < rMissingCodes.getLength() ) { cChar = rMissingCodes.iterateCodePoints( &nStrIndex ); - bCached = rFontSelData.mpFontEntry->GetFallbackForUnicode( cChar, &rFontSelData.maSearchName ); + bCached = rFontSelData.mpFontEntry->GetFallbackForUnicode( cChar, rFontSelData.GetWeight(), &rFontSelData.maSearchName ); // ignore entries which don't have a fallback if( !bCached || (rFontSelData.maSearchName.Len() != 0) ) break; @@ -1436,7 +1443,7 @@ ImplDevFontListData* ImplDevFontList::GetGlyphFallbackFont( ImplFontSelectData& while( nStrIndex < rMissingCodes.getLength() ) { cChar = rMissingCodes.iterateCodePoints( &nStrIndex ); - bCached = rFontSelData.mpFontEntry->GetFallbackForUnicode( cChar, &aFontName ); + bCached = rFontSelData.mpFontEntry->GetFallbackForUnicode( cChar, rFontSelData.GetWeight(), &aFontName ); if( !bCached || (rFontSelData.maSearchName != aFontName) ) pRemainingCodes[ nRemainingLength++ ] = cChar; } @@ -1455,8 +1462,8 @@ ImplDevFontListData* ImplDevFontList::GetGlyphFallbackFont( ImplFontSelectData& // cache the result even if there was no match for(;;) { - if( !rFontSelData.mpFontEntry->GetFallbackForUnicode( cChar, &rFontSelData.maSearchName ) ) - rFontSelData.mpFontEntry->AddFallbackForUnicode( cChar, rFontSelData.maSearchName ); + if( !rFontSelData.mpFontEntry->GetFallbackForUnicode( cChar, rFontSelData.GetWeight(), &rFontSelData.maSearchName ) ) + rFontSelData.mpFontEntry->AddFallbackForUnicode( cChar, rFontSelData.GetWeight(), rFontSelData.maSearchName ); if( nStrIndex >= aOldMissingCodes.getLength() ) break; cChar = aOldMissingCodes.iterateCodePoints( &nStrIndex ); @@ -1467,7 +1474,7 @@ ImplDevFontListData* ImplDevFontList::GetGlyphFallbackFont( ImplFontSelectData& for( nStrIndex = 0; nStrIndex < rMissingCodes.getLength(); ) { cChar = rMissingCodes.iterateCodePoints( &nStrIndex ); - rFontSelData.mpFontEntry->IgnoreFallbackForUnicode( cChar, rFontSelData.maSearchName ); + rFontSelData.mpFontEntry->IgnoreFallbackForUnicode( cChar, rFontSelData.GetWeight(), rFontSelData.maSearchName ); } } }