diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-10-19 11:56:15 +0200 |
---|---|---|
committer | Adolfo Jayme Barrientos <fitojb@ubuntu.com> | 2021-10-20 07:33:31 +0200 |
commit | c9f688d64ae8e33f46e35f185b9a402f489bf911 (patch) | |
tree | 50eaafb631096aab7c0e289ae9aca556c1a792fc /sc | |
parent | 41619d287874b0a69bace26ab73378fd19e8db4f (diff) |
consider font when caching SalLayoutGlyphs in calc (tdf#143978)
d62ad3efe3c8778cfd added the caching, but did not consider that
the used OutputDevice (its font) may change.
Backport to 7.2 includes o3tl::hash_combine() from bb5425ed3d8cc04.
Change-Id: I291999d3613b7ba161e3d82348f621aa84a93067
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123809
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
(cherry picked from commit 6ee4ce119b55d6e415696b23432fe65eabc94c17)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123783
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/view/output2.cxx | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index 2d45fa62eaa7..2685cfe10fb6 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -56,6 +56,7 @@ #include <sal/log.hxx> #include <unotools/charclass.hxx> #include <osl/diagnose.h> +#include <tools/stream.hxx> #include <output.hxx> #include <document.hxx> @@ -77,6 +78,7 @@ #include <memory> #include <vector> #include <o3tl/lru_map.hxx> +#include <o3tl/hash_combine.hxx> #include <math.h> @@ -116,7 +118,19 @@ class ScDrawStringsVars tools::Long nExpWidth; ScRefCellValue maLastCell; - mutable o3tl::lru_map<OUString, SalLayoutGlyphs> mCachedGlyphs; + struct CachedGlyphsKey + { + OUString text; + VclPtr<OutputDevice> outputDevice; + size_t hashValue; + CachedGlyphsKey( const OUString& t, const VclPtr<OutputDevice>& dev ); + bool operator==( const CachedGlyphsKey& other ) const; + }; + struct CachedGlyphsHash + { + size_t operator()( const CachedGlyphsKey& key ) const { return key.hashValue; } + }; + mutable o3tl::lru_map<CachedGlyphsKey, SalLayoutGlyphs, CachedGlyphsHash> mCachedGlyphs; sal_uLong nValueFormat; bool bLineBreak; bool bRepeat; @@ -772,17 +786,35 @@ tools::Long ScDrawStringsVars::GetExpWidth() return nExpWidth; } +inline ScDrawStringsVars::CachedGlyphsKey::CachedGlyphsKey( const OUString& t, const VclPtr<OutputDevice>& d ) + : text( t ) + , outputDevice( d ) +{ + hashValue = 0; + o3tl::hash_combine( hashValue, outputDevice.get()); + SvMemoryStream stream; + WriteFont( stream, outputDevice->GetFont()); + o3tl::hash_combine( hashValue, static_cast<const char*>(stream.GetData()), stream.GetSize()); + o3tl::hash_combine( hashValue, text ); +} + +inline bool ScDrawStringsVars::CachedGlyphsKey::operator==( const CachedGlyphsKey& other ) const +{ + return hashValue == other.hashValue && outputDevice == other.outputDevice && text == other.text; +} + const SalLayoutGlyphs* ScDrawStringsVars::GetLayoutGlyphs(const OUString& rString) const { - auto it = mCachedGlyphs.find( rString ); + const CachedGlyphsKey key( rString, pOutput->pFmtDevice ); + auto it = mCachedGlyphs.find( key ); if( it != mCachedGlyphs.end() && it->second.IsValid()) return &it->second; std::unique_ptr<SalLayout> layout = pOutput->pFmtDevice->ImplLayout( rString, 0, rString.getLength(), Point( 0, 0 ), 0, nullptr, SalLayoutFlags::GlyphItemsOnly ); if( layout ) { - mCachedGlyphs.insert( std::make_pair( rString, layout->GetGlyphs())); - assert(mCachedGlyphs.find( rString ) == mCachedGlyphs.begin()); // newly inserted item is first + mCachedGlyphs.insert( std::make_pair( key, layout->GetGlyphs())); + assert(mCachedGlyphs.find( key ) == mCachedGlyphs.begin()); // newly inserted item is first return &mCachedGlyphs.begin()->second; } return nullptr; |