From 6d36d7185b025c77db9dcccea1861d37dd6bcc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Wed, 27 Apr 2022 11:57:29 +0200 Subject: [PATCH] provide explicit function for hashing vcl::Font MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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(-) 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 #include #include +#include #include #include @@ -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( maColor )); + o3tl::hash_combine( hash, static_cast( 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(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);