include/vcl/font.hxx            |    4 ++
 vcl/inc/impfont.hxx             |    3 ++
 vcl/source/font/font.cxx        |   54 ++++++++++++++++++++++++++++++++++++++++
 vcl/source/gdi/impglyphitem.cxx |    4 --
 4 files changed, 62 insertions(+), 3 deletions(-)

New commits:
commit 6d36d7185b025c77db9dcccea1861d37dd6bcc1b
Author:     Luboš Luňák <[email protected]>
AuthorDate: Wed Apr 27 11:57:29 2022 +0200
Commit:     Luboš Luňák <[email protected]>
CommitDate: Wed Apr 27 22:45:33 2022 +0200

    provide explicit function for hashing vcl::Font
    
    It's cleaner than streaming the font and then hashing the result,
    and it's also faster.
    
    Change-Id: I6262e45362d386c21482f1e71be51912f123ee45
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133500
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <[email protected]>

diff --git a/include/vcl/font.hxx b/include/vcl/font.hxx
index 0f641100eecb..9f910688de1a 100644
--- a/include/vcl/font.hxx
+++ b/include/vcl/font.hxx
@@ -161,6 +161,10 @@ public:
     bool                IsSameInstance( const Font& ) const;
     bool                EqualIgnoreColor( const Font& ) const;
 
+    // Compute value usable as hash.
+    size_t              GetHashValue() const;
+    size_t              GetHashValueIgnoreColor() const;
+
     friend VCL_DLLPUBLIC SvStream&  ::ReadFont( SvStream& rIStm, vcl::Font& );
     friend VCL_DLLPUBLIC SvStream&  ::WriteFont( SvStream& rOStm, const 
vcl::Font& );
 
diff --git a/vcl/inc/impfont.hxx b/vcl/inc/impfont.hxx
index 2c8ce660ea91..a63e2a27d1c2 100644
--- a/vcl/inc/impfont.hxx
+++ b/vcl/inc/impfont.hxx
@@ -94,6 +94,9 @@ public:
     bool                operator==( const ImplFont& ) const;
     bool                EqualIgnoreColor( const ImplFont& ) const;
 
+    size_t              GetHashValue() const;
+    size_t              GetHashValueIgnoreColor() const;
+
 private:
     friend class vcl::Font;
     friend SvStream&    ReadImplFont( SvStream& rIStm, ImplFont&, tools::Long& 
);
diff --git a/vcl/source/font/font.cxx b/vcl/source/font/font.cxx
index 3387dd196f1f..fe610aac576a 100644
--- a/vcl/source/font/font.cxx
+++ b/vcl/source/font/font.cxx
@@ -22,6 +22,7 @@
 #include <tools/gen.hxx>
 #include <unotools/fontcfg.hxx>
 #include <unotools/fontdefs.hxx>
+#include <o3tl/hash_combine.hxx>
 
 #include <vcl/font.hxx>
 #include <vcl/svapp.hxx>
@@ -332,6 +333,16 @@ bool Font::EqualIgnoreColor( const vcl::Font& rFont ) const
     return mpImplFont->EqualIgnoreColor( *rFont.mpImplFont );
 }
 
+size_t Font::GetHashValue() const
+{
+    return mpImplFont->GetHashValue();
+}
+
+size_t Font::GetHashValueIgnoreColor() const
+{
+    return mpImplFont->GetHashValueIgnoreColor();
+}
+
 void Font::Merge( const vcl::Font& rFont )
 {
     if ( !rFont.GetFamilyName().isEmpty() )
@@ -1015,6 +1026,49 @@ bool ImplFont::EqualIgnoreColor( const ImplFont& rOther 
) const
     return true;
 }
 
+size_t ImplFont::GetHashValue() const
+{
+    size_t hash = GetHashValueIgnoreColor();
+    o3tl::hash_combine( hash, static_cast<sal_uInt32>( maColor ));
+    o3tl::hash_combine( hash, static_cast<sal_uInt32>( maFillColor ));
+    return hash;
+}
+
+size_t ImplFont::GetHashValueIgnoreColor() const
+{
+    size_t hash = 0;
+
+    o3tl::hash_combine( hash, meWeight );
+    o3tl::hash_combine( hash, meItalic );
+    o3tl::hash_combine( hash, meFamily );
+    o3tl::hash_combine( hash, mePitch );
+
+    o3tl::hash_combine( hash, meCharSet );
+    o3tl::hash_combine( hash, maLanguageTag.getLanguageType( false ).get());
+    o3tl::hash_combine( hash, maCJKLanguageTag.getLanguageType( false ).get());
+    o3tl::hash_combine( hash, meAlign );
+
+    o3tl::hash_combine( hash, maAverageFontSize.GetHashValue());
+    o3tl::hash_combine( hash, mnOrientation.get());
+    o3tl::hash_combine( hash, mbVertical );
+
+    o3tl::hash_combine( hash, maFamilyName );
+    o3tl::hash_combine( hash, maStyleName );
+
+    o3tl::hash_combine( hash, meUnderline );
+    o3tl::hash_combine( hash, meOverline );
+    o3tl::hash_combine( hash, meStrikeout );
+    o3tl::hash_combine( hash, meRelief );
+    o3tl::hash_combine( hash, meEmphasisMark );
+    o3tl::hash_combine( hash, mbWordLine );
+    o3tl::hash_combine( hash, mbOutline );
+    o3tl::hash_combine( hash, mbShadow );
+    o3tl::hash_combine( hash, meKerning );
+    o3tl::hash_combine( hash, mbTransparent );
+
+    return hash;
+}
+
 void ImplFont::AskConfig()
 {
     if( mbConfigLookup )
diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx
index 0268eb3861c0..83c044ce176c 100644
--- a/vcl/source/gdi/impglyphitem.cxx
+++ b/vcl/source/gdi/impglyphitem.cxx
@@ -310,9 +310,7 @@ 
SalLayoutGlyphsCache::CachedGlyphsKey::CachedGlyphsKey(const VclPtr<const Output
     o3tl::hash_combine(hashValue, logicWidth);
 
     o3tl::hash_combine(hashValue, outputDevice.get());
-    SvMemoryStream stream;
-    WriteFont(stream, font);
-    o3tl::hash_combine(hashValue, static_cast<const char*>(stream.GetData()), 
stream.GetSize());
+    o3tl::hash_combine(hashValue, font.GetHashValueIgnoreColor());
     o3tl::hash_combine(hashValue, mapMode.GetHashValue());
     o3tl::hash_combine(hashValue, rtl);
     o3tl::hash_combine(hashValue, layoutMode);

Reply via email to