Commits

Herbert Duerr [hdu]  committed cf07edd

#i87970# use UCS4+weight as GFB-result cache keys

  • Participants
  • Parent commits cfa07b1

Comments (0)

Files changed (2)

File vcl/inc/vcl/outfont.hxx

     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<sal_UCS4,String> UnicodeFallbackList;
+    typedef ::std::pair<sal_UCS4,FontWeight> GFBCacheKey;
+    struct GFBCacheKey_Hash{ size_t operator()( const GFBCacheKey& ) const; };
+    typedef ::std::hash_map<GFBCacheKey,String,GFBCacheKey_Hash> UnicodeFallbackList;
     UnicodeFallbackList* mpUnicodeFallbackList;
 };
 

File vcl/source/gdi/outdev3.cxx

 
 // -----------------------------------------------------------------------
 
-inline void ImplFontEntry::AddFallbackForUnicode( sal_UCS4 cChar, const String& rFontName )
+size_t ImplFontEntry::GFBCacheKey_Hash::operator()( const GFBCacheKey& rData ) const
+{
+    std::hash<sal_UCS4> a;
+    std::hash<int > 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;
-}
-
-// -----------------------------------------------------------------------
-
-inline bool ImplFontEntry::GetFallbackForUnicode( sal_UCS4 cChar, String* pFontName ) const
+    (*mpUnicodeFallbackList)[ GFBCacheKey(cChar,eWeight) ] = rFontName;
+}
+
+// -----------------------------------------------------------------------
+
+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;
 
 
 // -----------------------------------------------------------------------
 
-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;
         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;
             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;
             }
             // 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 );
                 for( nStrIndex = 0; nStrIndex < rMissingCodes.getLength(); )
                 {
                     cChar = rMissingCodes.iterateCodePoints( &nStrIndex );
-                    rFontSelData.mpFontEntry->IgnoreFallbackForUnicode( cChar, rFontSelData.maSearchName );
+                    rFontSelData.mpFontEntry->IgnoreFallbackForUnicode( cChar, rFontSelData.GetWeight(), rFontSelData.maSearchName );
                 }
             }
         }