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 <l.lunak@collabora.com>
This commit is contained in:
Luboš Luňák
2022-04-27 11:57:29 +02:00
parent 8de60b9049
commit 6d36d7185b
4 changed files with 62 additions and 3 deletions

View File

@@ -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& );

View File

@@ -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& );

View File

@@ -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 )

View File

@@ -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);