summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-06-05 14:16:23 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2019-05-13 19:51:03 +0200
commit934c23c0bafe6d828a6fa3a4f28e3eb9ea33f633 (patch)
tree9215346cd0e56fffb7002ba03aa13fabbbc554a3
parent2be06a9a06e797929d32f4b30083b98ab1cb268a (diff)
hold LogicalFontInstance with rtl::Reference
instead of manual reference counting. Also the releasing of not-currently-in-use LogicalFontInstance objects from the cache is made less aggressive - we now only flush entries until we have less than CACHE_SIZE instances, instead of flushing the whole cache. Reviewed-on: https://gerrit.libreoffice.org/55384 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> (cherry picked from commit c4c56de1b0e62ec866b519b2b24c5e805f0a86d3) Change-Id: Ib235b132776b5f09ae8ae93a933c2eebe5fa9610
-rw-r--r--include/vcl/outdev.hxx2
-rw-r--r--vcl/inc/PhysicalFontFace.hxx2
-rw-r--r--vcl/inc/fontinstance.hxx9
-rw-r--r--vcl/inc/fontselect.hxx3
-rw-r--r--vcl/inc/impfontcache.hxx20
-rw-r--r--vcl/inc/quartz/salgdi.h6
-rw-r--r--vcl/inc/sallayout.hxx2
-rw-r--r--vcl/inc/salwtype.hxx3
-rw-r--r--vcl/inc/unx/freetype_glyphcache.hxx4
-rw-r--r--vcl/inc/unx/glyphcache.hxx5
-rw-r--r--vcl/inc/win/salgdi.h7
-rw-r--r--vcl/inc/win/winlayout.hxx2
-rw-r--r--vcl/quartz/ctfonts.cxx2
-rw-r--r--vcl/quartz/salgdi.cxx10
-rw-r--r--vcl/source/font/PhysicalFontFace.cxx2
-rw-r--r--vcl/source/font/fontcache.cxx148
-rw-r--r--vcl/source/font/fontinstance.cxx22
-rw-r--r--vcl/source/font/fontselect.cxx1
-rw-r--r--vcl/source/gdi/CommonSalLayout.cxx2
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx12
-rw-r--r--vcl/source/gdi/print.cxx25
-rw-r--r--vcl/source/gdi/virdev.cxx6
-rw-r--r--vcl/source/outdev/font.cxx26
-rw-r--r--vcl/source/outdev/outdev.cxx3
-rw-r--r--vcl/source/outdev/outdevstate.cxx7
-rw-r--r--vcl/source/outdev/textline.cxx8
-rw-r--r--vcl/source/window/window.cxx5
-rw-r--r--vcl/unx/generic/glyphs/freetype_glyphcache.cxx9
-rw-r--r--vcl/win/gdi/salfont.cxx25
-rw-r--r--vcl/win/gdi/salgdi.cxx1
-rw-r--r--vcl/win/gdi/winlayout.cxx5
31 files changed, 103 insertions, 281 deletions
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 174987e51757..93a3ce610c32 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -332,7 +332,7 @@ private:
mutable VclPtr<OutputDevice> mpPrevGraphics; ///< Previous output device in list
mutable VclPtr<OutputDevice> mpNextGraphics; ///< Next output device in list
GDIMetaFile* mpMetaFile;
- mutable LogicalFontInstance* mpFontInstance;
+ mutable rtl::Reference<LogicalFontInstance> mpFontInstance;
mutable ImplFontCache* mpFontCache;
mutable PhysicalFontCollection* mpFontCollection;
mutable std::unique_ptr<ImplDeviceFontList> mpDeviceFontList;
diff --git a/vcl/inc/PhysicalFontFace.hxx b/vcl/inc/PhysicalFontFace.hxx
index 2406b6cf41da..e289345716ca 100644
--- a/vcl/inc/PhysicalFontFace.hxx
+++ b/vcl/inc/PhysicalFontFace.hxx
@@ -54,7 +54,7 @@ public:
class VCL_PLUGIN_PUBLIC PhysicalFontFace : public FontAttributes, public salhelper::SimpleReferenceObject
{
public:
- virtual LogicalFontInstance* CreateFontInstance(const FontSelectPattern&) const;
+ virtual rtl::Reference<LogicalFontInstance> CreateFontInstance(const FontSelectPattern&) const;
virtual rtl::Reference<PhysicalFontFace> Clone() const = 0;
int GetHeight() const { return mnHeight; }
diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx
index 317b7181198d..149bb553c3eb 100644
--- a/vcl/inc/fontinstance.hxx
+++ b/vcl/inc/fontinstance.hxx
@@ -24,6 +24,7 @@
#include "impfontmetricdata.hxx"
#include <rtl/ref.hxx>
+#include <salhelper/simplereferenceobject.hxx>
#include <unordered_map>
#include <memory>
@@ -35,7 +36,7 @@ class PhysicalFontFace;
// TODO: allow sharing of metrics for related fonts
-class VCL_PLUGIN_PUBLIC LogicalFontInstance
+class VCL_PLUGIN_PUBLIC LogicalFontInstance : public salhelper::SimpleReferenceObject
{
// just declaring the factory function doesn't work AKA
// friend LogicalFontInstance* PhysicalFontFace::CreateFontInstance(const FontSelectPattern&) const;
@@ -43,7 +44,7 @@ class VCL_PLUGIN_PUBLIC LogicalFontInstance
friend class ImplFontCache;
public: // TODO: make data members private
- virtual ~LogicalFontInstance();
+ virtual ~LogicalFontInstance() override;
ImplFontMetricDataRef mxFontMetric; // Font attributes
const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
@@ -57,9 +58,6 @@ public: // TODO: make data members private
bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, OUString* pFontName ) const;
void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const OUString& rFontName );
- void Acquire();
- void Release();
-
inline hb_font_t* GetHbFont();
void SetAverageWidthFactor(double nFactor) { m_nAveWidthFactor = nFactor; }
double GetAverageWidthFactor() const { return m_nAveWidthFactor; }
@@ -88,7 +86,6 @@ private:
typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList;
std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList;
ImplFontCache * mpFontCache;
- sal_uInt32 mnRefCount;
const FontSelectPattern m_aFontSelData;
hb_font_t* m_pHbFont;
double m_nAveWidthFactor;
diff --git a/vcl/inc/fontselect.hxx b/vcl/inc/fontselect.hxx
index 389077270758..efb88ad74ae1 100644
--- a/vcl/inc/fontselect.hxx
+++ b/vcl/inc/fontselect.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_VCL_INC_FONTSELECT_HXX
#include <i18nlangtag/lang.h>
+#include <rtl/ref.hxx>
#include "fontattributes.hxx"
@@ -80,7 +81,7 @@ public:
#endif
public: // TODO: change to private
- LogicalFontInstance* mpFontInstance; // pointer to the resulting FontCache entry
+ rtl::Reference<LogicalFontInstance> mpFontInstance; // pointer to the resulting FontCache entry
void copyAttributes(const FontSelectPatternAttributes &rAttributes);
};
diff --git a/vcl/inc/impfontcache.hxx b/vcl/inc/impfontcache.hxx
index a99283fb300e..6cb05b39d9b3 100644
--- a/vcl/inc/impfontcache.hxx
+++ b/vcl/inc/impfontcache.hxx
@@ -33,36 +33,24 @@ class PhysicalFontCollection;
class ImplFontCache
{
- // For access to Acquire and Release
- friend class LogicalFontInstance;
-
private:
LogicalFontInstance* mpLastHitCacheEntry; ///< keeps the last hit cache entry
- int mnRef0Count; ///< number of unreferenced LogicalFontInstances
// cache of recently used font instances
struct IFSD_Equal { bool operator()( const FontSelectPattern&, const FontSelectPattern& ) const; };
struct IFSD_Hash { size_t operator()( const FontSelectPattern& ) const; };
- typedef std::unordered_map<FontSelectPattern,LogicalFontInstance*,IFSD_Hash,IFSD_Equal > FontInstanceList;
+ typedef std::unordered_map<FontSelectPattern, rtl::Reference<LogicalFontInstance>, IFSD_Hash, IFSD_Equal> FontInstanceList;
FontInstanceList maFontInstanceList;
- int CountUnreferencedEntries() const;
- bool IsFontInList(const LogicalFontInstance* pFont) const;
-
- /// Increase the refcount of the given LogicalFontInstance.
- void Acquire(LogicalFontInstance*);
- /// Decrease the refcount and potentially cleanup the entries with zero refcount from the cache.
- void Release(LogicalFontInstance*);
-
- LogicalFontInstance* GetFontInstance(PhysicalFontCollection const*, FontSelectPattern&);
+ rtl::Reference<LogicalFontInstance> GetFontInstance(PhysicalFontCollection const*, FontSelectPattern&);
public:
ImplFontCache();
~ImplFontCache();
- LogicalFontInstance* GetFontInstance( PhysicalFontCollection const *,
+ rtl::Reference<LogicalFontInstance> GetFontInstance( PhysicalFontCollection const *,
const vcl::Font&, const Size& rPixelSize, float fExactHeight);
- LogicalFontInstance* GetGlyphFallbackFont( PhysicalFontCollection const *, FontSelectPattern&,
+ rtl::Reference<LogicalFontInstance> GetGlyphFallbackFont( PhysicalFontCollection const *, FontSelectPattern&,
int nFallbackLevel, OUString& rMissingCodes );
void Invalidate();
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index 2f53a44d694e..1dd896058890 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -71,7 +71,7 @@ public:
bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const;
bool HasChar( sal_uInt32 cChar ) const;
- LogicalFontInstance* CreateFontInstance(const FontSelectPattern&) const override;
+ rtl::Reference<LogicalFontInstance> CreateFontInstance(const FontSelectPattern&) const override;
protected:
CoreTextFontFace( const CoreTextFontFace& );
@@ -85,7 +85,7 @@ private:
class CoreTextStyle : public LogicalFontInstance
{
- friend LogicalFontInstance* CoreTextFontFace::CreateFontInstance(const FontSelectPattern&) const;
+ friend rtl::Reference<LogicalFontInstance> CoreTextFontFace::CreateFontInstance(const FontSelectPattern&) const;
public:
~CoreTextStyle();
@@ -159,7 +159,7 @@ class AquaSalGraphics : public SalGraphics
RGBAColor maFillColor;
// Device Font settings
- CoreTextStyle* mpTextStyle[MAX_FALLBACK];
+ rtl::Reference<CoreTextStyle> mpTextStyle[MAX_FALLBACK];
RGBAColor maTextColor;
/// allows text to be rendered without antialiasing
bool mbNonAntialiasedText;
diff --git a/vcl/inc/sallayout.hxx b/vcl/inc/sallayout.hxx
index 62cda5832906..8daed9a01d09 100644
--- a/vcl/inc/sallayout.hxx
+++ b/vcl/inc/sallayout.hxx
@@ -352,7 +352,7 @@ private:
void ParseFeatures(const OUString& name);
- LogicalFontInstance* const mpFont;
+ rtl::Reference<LogicalFontInstance> const mpFont;
css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
std::vector<GlyphItem> m_GlyphItems;
diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx
index 34ca43664a25..29cbaf00c3a6 100644
--- a/vcl/inc/salwtype.hxx
+++ b/vcl/inc/salwtype.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_VCL_INC_SALWTYPE_HXX
#include <i18nlangtag/lang.h>
+#include <rtl/ref.hxx>
#include <rtl/ustring.hxx>
#include <tools/solar.h>
@@ -238,7 +239,7 @@ struct SalFrameState
struct SalInputContext
{
- LogicalFontInstance* mpFont;
+ rtl::Reference<LogicalFontInstance> mpFont;
LanguageType meLanguage;
InputContextFlags mnOptions;
};
diff --git a/vcl/inc/unx/freetype_glyphcache.hxx b/vcl/inc/unx/freetype_glyphcache.hxx
index d6b87b7ab7a9..bf00935b15a1 100644
--- a/vcl/inc/unx/freetype_glyphcache.hxx
+++ b/vcl/inc/unx/freetype_glyphcache.hxx
@@ -114,7 +114,7 @@ private:
public:
FreetypeFontFace( FreetypeFontInfo*, const FontAttributes& );
- virtual LogicalFontInstance* CreateFontInstance( const FontSelectPattern& ) const override;
+ virtual rtl::Reference<LogicalFontInstance> CreateFontInstance( const FontSelectPattern& ) const override;
virtual rtl::Reference<PhysicalFontFace> Clone() const override { return new FreetypeFontFace( *this ); }
virtual sal_IntPtr GetFontId() const override { return mpFreetypeFontInfo->GetFontId(); }
};
@@ -122,7 +122,7 @@ public:
// a class for cache entries for physical font instances that are based on serverfonts
class VCL_DLLPUBLIC FreetypeFontInstance : public LogicalFontInstance
{
- friend LogicalFontInstance* FreetypeFontFace::CreateFontInstance(const FontSelectPattern&) const;
+ friend rtl::Reference<LogicalFontInstance> FreetypeFontFace::CreateFontInstance(const FontSelectPattern&) const;
FreetypeFont* mpFreetypeFont;
diff --git a/vcl/inc/unx/glyphcache.hxx b/vcl/inc/unx/glyphcache.hxx
index 5e515db564b5..50d1f071d44f 100644
--- a/vcl/inc/unx/glyphcache.hxx
+++ b/vcl/inc/unx/glyphcache.hxx
@@ -39,6 +39,7 @@
#include <unordered_map>
class FreetypeManager;
+class FreetypeFontInstance;
class FreetypeFontInfo;
class GlyphData;
class FontConfigFontOptions;
@@ -139,7 +140,7 @@ public:
bool GetGlyphOutline(const GlyphItem& rGlyph, basegfx::B2DPolyPolygon&) const;
bool GetAntialiasAdvice() const;
- LogicalFontInstance* GetFontInstance() const { return mpFontInstance; }
+ FreetypeFontInstance* GetFontInstance() const { return mpFontInstance.get(); }
private:
friend class GlyphCache;
@@ -161,7 +162,7 @@ private:
typedef std::unordered_map<int,GlyphData> GlyphList;
mutable GlyphList maGlyphList;
- LogicalFontInstance* const mpFontInstance;
+ rtl::Reference<FreetypeFontInstance> mpFontInstance;
// used by GlyphCache for cache LRU algorithm
mutable long mnRefCount;
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index dc7bc7510229..0f175ebe75c2 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -64,7 +64,7 @@ public:
virtual ~WinFontFace() override;
virtual rtl::Reference<PhysicalFontFace> Clone() const override;
- virtual LogicalFontInstance* CreateFontInstance( const FontSelectPattern& ) const override;
+ virtual rtl::Reference<LogicalFontInstance> CreateFontInstance( const FontSelectPattern& ) const override;
virtual sal_IntPtr GetFontId() const override;
void SetFontId( sal_IntPtr nId ) { mnId = nId; }
void UpdateFromHDC( HDC ) const;
@@ -170,7 +170,8 @@ private:
**/
HFONT mhFonts[ MAX_FALLBACK ]; // Font + Fallbacks
- WinFontInstance* mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance
+ rtl::Reference<WinFontInstance>
+ mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance
float mfFontScale[ MAX_FALLBACK ]; // allows metrics emulation of huge font sizes
HRGN mhRegion; // vcl::Region Handle
HPEN mhDefPen; // DefaultPen
@@ -182,8 +183,6 @@ private:
RGNDATA* mpStdClipRgnData; // Cache Standard-ClipRegion-Data
int mnPenWidth; // line width
- LogicalFontInstance* GetWinFontEntry(int nFallbackLevel);
-
bool CacheGlyphs(const GenericSalLayout& rLayout);
bool DrawCachedGlyphs(const GenericSalLayout& rLayout);
HFONT ImplDoSetFont(FontSelectPattern const * i_pFont, const PhysicalFontFace * i_pFontFace, float& o_rFontScale, HFONT& o_rOldFont);
diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index 0c447153c800..07ae1a7d03c1 100644
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -145,7 +145,7 @@ public:
// win32 specific physical font instance
class WinFontInstance : public LogicalFontInstance
{
- friend LogicalFontInstance* WinFontFace::CreateFontInstance(const FontSelectPattern&) const;
+ friend rtl::Reference<LogicalFontInstance> WinFontFace::CreateFontInstance(const FontSelectPattern&) const;
public:
virtual ~WinFontInstance() override;
diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx
index 1d72f601eafa..dc372325e9e8 100644
--- a/vcl/quartz/ctfonts.cxx
+++ b/vcl/quartz/ctfonts.cxx
@@ -288,7 +288,7 @@ rtl::Reference<PhysicalFontFace> CoreTextFontFace::Clone() const
return new CoreTextFontFace( *this);
}
-LogicalFontInstance* CoreTextFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
+rtl::Reference<LogicalFontInstance> CoreTextFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
{
return new CoreTextStyle(*this, rFSD);
}
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 7154bd672e0f..48e40f3d0895 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -66,7 +66,7 @@ bool CoreTextGlyphFallbackSubstititution::FindFontSubstitute(FontSelectPattern&
OUString& rMissingChars) const
{
bool bFound = false;
- CoreTextStyle* pStyle = static_cast<CoreTextStyle*>(rPattern.mpFontInstance);
+ CoreTextStyle* pStyle = static_cast<CoreTextStyle*>(rPattern.mpFontInstance.get());
CTFontRef pFont = static_cast<CTFontRef>(CFDictionaryGetValue(pStyle->GetStyleDict(), kCTFontAttributeName));
CFStringRef pStr = CreateCFString(rMissingChars);
if (pStr)
@@ -243,7 +243,7 @@ AquaSalGraphics::~AquaSalGraphics()
{
if (!mpTextStyle[i])
break;
- mpTextStyle[i]->Release();
+ mpTextStyle[i].clear();
}
if( mpXorEmulation )
@@ -488,8 +488,7 @@ void AquaSalGraphics::SetFont(const FontSelectPattern* pReqFont, int nFallbackLe
{
if (!mpTextStyle[i])
break;
- mpTextStyle[i]->Release();
- mpTextStyle[i] = nullptr;
+ mpTextStyle[i].clear();
}
if (!pReqFont)
@@ -499,8 +498,7 @@ void AquaSalGraphics::SetFont(const FontSelectPattern* pReqFont, int nFallbackLe
return;
// update the text style
- mpTextStyle[nFallbackLevel] = static_cast<CoreTextStyle*>(pReqFont->mpFontInstance);
- mpTextStyle[nFallbackLevel]->Acquire();
+ mpTextStyle[nFallbackLevel] = static_cast<CoreTextStyle*>(pReqFont->mpFontInstance.get());
SAL_INFO("vcl.ct",
"SetFont"
diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx
index 690fd1fdc401..d356438e43a1 100644
--- a/vcl/source/font/PhysicalFontFace.cxx
+++ b/vcl/source/font/PhysicalFontFace.cxx
@@ -45,7 +45,7 @@ PhysicalFontFace::PhysicalFontFace( const PhysicalFontFace& other )
{
}
-LogicalFontInstance* PhysicalFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
+rtl::Reference<LogicalFontInstance> PhysicalFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
{
return new LogicalFontInstance(*this, rFSD);
}
diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx
index 205b49ada4e0..a58d9b6931f2 100644
--- a/vcl/source/font/fontcache.cxx
+++ b/vcl/source/font/fontcache.cxx
@@ -83,23 +83,14 @@ bool ImplFontCache::IFSD_Equal::operator()(const FontSelectPattern& rA, const Fo
}
ImplFontCache::ImplFontCache()
-: mpLastHitCacheEntry( nullptr ),
- mnRef0Count( 0 )
+: mpLastHitCacheEntry( nullptr )
{}
ImplFontCache::~ImplFontCache()
{
- for (auto const& fontInstance : maFontInstanceList)
- {
- LogicalFontInstance* pFontInstance = fontInstance.second;
- if (pFontInstance->mnRefCount)
- pFontInstance->mpFontCache = nullptr;
- else
- delete pFontInstance;
- }
}
-LogicalFontInstance* ImplFontCache::GetFontInstance( PhysicalFontCollection const * pFontList,
+rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( PhysicalFontCollection const * pFontList,
const vcl::Font& rFont, const Size& rSize, float fExactHeight )
{
// initialize internal font request object
@@ -107,10 +98,10 @@ LogicalFontInstance* ImplFontCache::GetFontInstance( PhysicalFontCollection cons
return GetFontInstance( pFontList, aFontSelData );
}
-LogicalFontInstance* ImplFontCache::GetFontInstance( PhysicalFontCollection const * pFontList,
+rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( PhysicalFontCollection const * pFontList,
FontSelectPattern& aFontSelData )
{
- LogicalFontInstance *pFontInstance = nullptr;
+ rtl::Reference<LogicalFontInstance> pFontInstance;
PhysicalFontFamily* pFontFamily = nullptr;
// check if a directly matching logical font instance is already cached,
@@ -140,12 +131,7 @@ LogicalFontInstance* ImplFontCache::GetFontInstance( PhysicalFontCollection cons
}
}
- if( pFontInstance ) // cache hit => use existing font instance
- {
- // increase the font instance's reference count
- pFontInstance->Acquire();
- }
- else if (pFontFamily) // still no cache hit => create a new font instance
+ if( !pFontInstance && pFontFamily) // still no cache hit => create a new font instance
{
PhysicalFontFace* pFontData = pFontFamily->FindBestFontFace(aFontSelData);
@@ -173,19 +159,38 @@ LogicalFontInstance* ImplFontCache::GetFontInstance( PhysicalFontCollection cons
}
#endif
+ static const size_t FONTCACHE_MAX = getenv("LO_TESTNAME") ? 1 : 50;
+
+ if (maFontInstanceList.size() >= FONTCACHE_MAX)
+ {
+ // remove entries from font instance cache that are only referenced by the cache
+ FontInstanceList::iterator it_next = maFontInstanceList.begin();
+ while( it_next != maFontInstanceList.end() )
+ {
+ LogicalFontInstance* pFontEntry = (*it_next).second.get();
+ if( pFontEntry->m_nCount > 1 )
+ {
+ ++it_next;
+ continue;
+ }
+ maFontInstanceList.erase(it_next);
+ if (mpLastHitCacheEntry == pFontEntry)
+ mpLastHitCacheEntry = nullptr;
+ // just remove one entry, which will bring us back under FONTCACHE_MAX size again
+ break;
+ }
+ }
+
+ assert(pFontInstance);
// add the new entry to the cache
-#ifndef NDEBUG
- auto aResult =
-#endif
- maFontInstanceList.insert({aFontSelData, pFontInstance});
- assert(aResult.second);
+ maFontInstanceList.insert({aFontSelData, pFontInstance.get()});
}
- mpLastHitCacheEntry = pFontInstance;
+ mpLastHitCacheEntry = pFontInstance.get();
return pFontInstance;
}
-LogicalFontInstance* ImplFontCache::GetGlyphFallbackFont( PhysicalFontCollection const * pFontCollection,
+rtl::Reference<LogicalFontInstance> ImplFontCache::GetGlyphFallbackFont( PhysicalFontCollection const * pFontCollection,
FontSelectPattern& rFontSelData, int nFallbackLevel, OUString& rMissingCodes )
{
// get a candidate font for glyph fallback
@@ -216,102 +221,17 @@ LogicalFontInstance* ImplFontCache::GetGlyphFallbackFont( PhysicalFontCollection
rFontSelData.maSearchName.clear();
}
- LogicalFontInstance* pFallbackFont = GetFontInstance( pFontCollection, rFontSelData );
+ rtl::Reference<LogicalFontInstance> pFallbackFont = GetFontInstance( pFontCollection, rFontSelData );
return pFallbackFont;
}
-void ImplFontCache::Acquire(LogicalFontInstance* pFontInstance)
-{
- assert(pFontInstance->mpFontCache == this);
- assert(IsFontInList(pFontInstance) && "ImplFontCache::Acquire() - font absent in the cache");
-
- if (0 == pFontInstance->mnRefCount++)
- --mnRef0Count;
-}
-
-void ImplFontCache::Release(LogicalFontInstance* pFontInstance)
-{
- static const int FONTCACHE_MAX = getenv("LO_TESTNAME") ? 1 : 50;
-
- assert(pFontInstance->mpFontCache == this);
- assert(IsFontInList(pFontInstance) && "ImplFontCache::Release() - font absent in the cache");
- assert(pFontInstance->mnRefCount > 0 && "ImplFontCache::Release() - font refcount underflow");
- if( --pFontInstance->mnRefCount > 0 )
- return;
-
- if (++mnRef0Count < FONTCACHE_MAX)
- return;
-
- assert(CountUnreferencedEntries() == mnRef0Count);
-
- // remove unused entries from font instance cache
- FontInstanceList::iterator it_next = maFontInstanceList.begin();
- while( it_next != maFontInstanceList.end() )
- {
- LogicalFontInstance* pFontEntry = (*it_next).second;
- if( pFontEntry->mnRefCount > 0 )
- {
- ++it_next;
- continue;
- }
-
- it_next = maFontInstanceList.erase(it_next);
- delete pFontEntry;
- --mnRef0Count;
- assert(mnRef0Count>=0 && "ImplFontCache::Release() - refcount0 underflow");
-
- if (mpLastHitCacheEntry == pFontEntry)
- mpLastHitCacheEntry = nullptr;
- }
-
- assert(mnRef0Count==0 && "ImplFontCache::Release() - refcount0 mismatch");
-}
-
-bool ImplFontCache::IsFontInList(const LogicalFontInstance* pFont) const
-{
- auto Pred = [pFont](const FontInstanceList::value_type& el) -> bool { return el.second == pFont; };
- return std::find_if(maFontInstanceList.begin(), maFontInstanceList.end(), Pred) != maFontInstanceList.end();
-}
-
-int ImplFontCache::CountUnreferencedEntries() const
-{
- size_t nCount = 0;
- // count unreferenced entries
- for (auto const& fontInstance : maFontInstanceList)
- {
- const LogicalFontInstance* pFontEntry = fontInstance.second;
- if (pFontEntry->mnRefCount > 0)
- continue;
- ++nCount;
- }
- return nCount;
-}
-
void ImplFontCache::Invalidate()
{
- assert(CountUnreferencedEntries() == mnRef0Count);
-
- // delete unreferenced entries
- for (auto const& fontInstance : maFontInstanceList)
- {
- LogicalFontInstance* pFontEntry = fontInstance.second;
- if( pFontEntry->mnRefCount > 0 )
- {
- // These fonts will become orphans after clearing the list below;
- // allow them to control their life from now on and wish good luck :)
- pFontEntry->mpFontCache = nullptr;
- continue;
- }
-
- delete pFontEntry;
- --mnRef0Count;
- }
-
// #112304# make sure the font cache is really clean
mpLastHitCacheEntry = nullptr;
+ for (auto const & pair : maFontInstanceList)
+ pair.second->mpFontCache = nullptr;
maFontInstanceList.clear();
-
- assert(mnRef0Count==0 && "ImplFontCache::Invalidate() - mnRef0Count non-zero");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/font/fontinstance.cxx b/vcl/source/font/fontinstance.cxx
index fca20fd03ca3..e5fac6c6a67b 100644
--- a/vcl/source/font/fontinstance.cxx
+++ b/vcl/source/font/fontinstance.cxx
@@ -48,7 +48,6 @@ LogicalFontInstance::LogicalFontInstance(const PhysicalFontFace& rFontFace, cons
, mnOrientation( 0 )
, mbInit( false )
, mpFontCache( nullptr )
- , mnRefCount( 1 )
, m_aFontSelData(rFontSelData)
, m_pHbFont(nullptr)
, m_nAveWidthFactor(1.0f)
@@ -115,27 +114,6 @@ void LogicalFontInstance::GetScale(double* nXScale, double* nYScale)
*nXScale = nWidth / nUPEM;
}
-void LogicalFontInstance::Acquire()
-{
- assert(mnRefCount < std::numeric_limits<decltype(mnRefCount)>::max()
- && "LogicalFontInstance::Release() - refcount overflow");
- if (mpFontCache)
- mpFontCache->Acquire(this);
- else
- ++mnRefCount;
-}
-
-void LogicalFontInstance::Release()
-{
- assert(mnRefCount > 0 && "LogicalFontInstance::Release() - refcount underflow");
-
- if (mpFontCache)
- mpFontCache->Release(this);
- else
- if (--mnRefCount == 0)
- delete this;
-}
-
void LogicalFontInstance::AddFallbackForUnicode( sal_UCS4 cChar, FontWeight eWeight, const OUString& rFontName )
{
if( !mpUnicodeFallbackList )
diff --git a/vcl/source/font/fontselect.cxx b/vcl/source/font/fontselect.cxx
index 80b9ba78ce6b..563c6ebcbc54 100644
--- a/vcl/source/font/fontselect.cxx
+++ b/vcl/source/font/fontselect.cxx
@@ -21,6 +21,7 @@
#include <o3tl/safeint.hxx>
#include <fontselect.hxx>
+#include <fontinstance.hxx>
#include <PhysicalFontFace.hxx>
#include <svdata.hxx>
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index 8dcdc06a1ce8..22b5ea460d8e 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -58,12 +58,10 @@ GenericSalLayout::GenericSalLayout(LogicalFontInstance &rFont)
, mpVertGlyphs(nullptr)
, mbFuzzing(utl::ConfigManager::IsFuzzing())
{
- mpFont->Acquire();
}
GenericSalLayout::~GenericSalLayout()
{
- mpFont->Release();
}
void GenericSalLayout::ParseFeatures(const OUString& aName)
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index d9411779fb34..181d2003f3e4 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -6779,7 +6779,7 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool
// This includes ascent / descent.
aRectangle.setHeight(aRefDevFontMetric.GetLineHeight());
- LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance;
+ LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance.get();
if (pFontInstance->mnOrientation)
{
// Adapt rectangle for rotated text.
@@ -7269,7 +7269,7 @@ void PDFWriterImpl::drawLine( const Point& rStart, const Point& rStop, const Lin
void PDFWriterImpl::drawWaveTextLine( OStringBuffer& aLine, long nWidth, FontLineStyle eTextLine, Color aColor, bool bIsAbove )
{
// note: units in pFontInstance are ref device pixel
- LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance;
+ LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance.get();
long nLineHeight = 0;
long nLinePos = 0;
@@ -7339,7 +7339,7 @@ void PDFWriterImpl::drawWaveTextLine( OStringBuffer& aLine, long nWidth, FontLin
void PDFWriterImpl::drawStraightTextLine( OStringBuffer& aLine, long nWidth, FontLineStyle eTextLine, Color aColor, bool bIsAbove )
{
// note: units in pFontInstance are ref device pixel
- LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance;
+ LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance.get();
long nLineHeight = 0;
long nLinePos = 0;
long nLinePos2 = 0;
@@ -7510,7 +7510,7 @@ void PDFWriterImpl::drawStraightTextLine( OStringBuffer& aLine, long nWidth, Fon
void PDFWriterImpl::drawStrikeoutLine( OStringBuffer& aLine, long nWidth, FontStrikeout eStrikeout, Color aColor )
{
// note: units in pFontInstance are ref device pixel
- LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance;
+ LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance.get();
long nLineHeight = 0;
long nLinePos = 0;
long nLinePos2 = 0;
@@ -7607,7 +7607,7 @@ void PDFWriterImpl::drawStrikeoutChar( const Point& rPos, long nWidth, FontStrik
aRect.SetBottom( rPos.Y()+aRefDevFontMetric.GetDescent() );
aRect.SetTop( rPos.Y()-aRefDevFontMetric.GetAscent() );
- LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance;
+ LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance.get();
if (pFontInstance->mnOrientation)
{
tools::Polygon aPoly( aRect );
@@ -7642,7 +7642,7 @@ void PDFWriterImpl::drawTextLine( const Point& rPos, long nWidth, FontStrikeout
updateGraphicsState();
// note: units in pFontInstance are ref device pixel
- LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance;
+ LogicalFontInstance* pFontInstance = m_pReferenceDevice->mpFontInstance.get();
Color aUnderlineColor = m_aCurrentPDFState.m_aTextLineColor;
Color aOverlineColor = m_aCurrentPDFState.m_aOverlineColor;
Color aStrikeoutColor = m_aCurrentPDFState.m_aFont.GetColor();
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index a5fe96a76db0..ac44dcbbaf18 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -580,12 +580,7 @@ void Printer::ImplReleaseFonts()
mbNewFont = true;
mbInitFont = true;
- if ( mpFontInstance )
- {
- mpFontInstance->Release();
- mpFontInstance = nullptr;
- }
-
+ mpFontInstance.clear();
mpDeviceFontList.reset();
mpDeviceFontSizeList.reset();
}
@@ -946,11 +941,7 @@ void Printer::dispose()
// OutputDevice Dtor is trying the same thing; that why we need to set
// the FontEntry to NULL here
// TODO: consolidate duplicate cleanup by Printer and OutputDevice
- if ( mpFontInstance )
- {
- mpFontInstance->Release();
- mpFontInstance = nullptr;
- }
+ mpFontInstance.clear();
mpDeviceFontList.reset();
mpDeviceFontSizeList.reset();
delete mpFontCache;
@@ -1087,11 +1078,7 @@ bool Printer::SetPrinterProps( const Printer* pPrinter )
{
ReleaseGraphics();
pSVData->mpDefInst->DestroyInfoPrinter( mpInfoPrinter );
- if ( mpFontInstance )
- {
- mpFontInstance->Release();
- mpFontInstance = nullptr;
- }
+ mpFontInstance.clear();
mpDeviceFontList.reset();
mpDeviceFontSizeList.reset();
// clean up font list
@@ -1122,11 +1109,7 @@ bool Printer::SetPrinterProps( const Printer* pPrinter )
{
pSVData->mpDefInst->DestroyInfoPrinter( mpInfoPrinter );
- if ( mpFontInstance )
- {
- mpFontInstance->Release();
- mpFontInstance = nullptr;
- }
+ mpFontInstance.clear();
mpDeviceFontList.reset();
mpDeviceFontSizeList.reset();
delete mpFontCache;
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
index 8972d83c23c8..dad14458705c 100644
--- a/vcl/source/gdi/virdev.cxx
+++ b/vcl/source/gdi/virdev.cxx
@@ -487,11 +487,7 @@ void VirtualDevice::ImplSetReferenceDevice( RefDevMode i_eRefDevMode, sal_Int32
// the reference device should have only scalable fonts
// => clean up the original font lists before getting new ones
- if ( mpFontInstance )
- {
- mpFontInstance->Release();
- mpFontInstance = nullptr;
- }
+ mpFontInstance.clear();
mpDeviceFontList.reset();
mpDeviceFontSizeList.reset();
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index c65dd0d5cce9..439a3df75c5b 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -168,7 +168,7 @@ FontMetric OutputDevice::GetFontMetric() const
if( mbNewFont && !ImplNewFont() )
return aMetric;
- LogicalFontInstance* pFontInstance = mpFontInstance;
+ LogicalFontInstance* pFontInstance = mpFontInstance.get();
ImplFontMetricDataRef xFontMetric = pFontInstance->mxFontMetric;
// prepare metric
@@ -475,11 +475,7 @@ long OutputDevice::GetFontExtLeading() const
void OutputDevice::ImplClearFontData( const bool bNewFontLists )
{
// the currently selected logical font is no longer needed
- if ( mpFontInstance )
- {
- mpFontInstance->Release();
- mpFontInstance = nullptr;
- }
+ mpFontInstance.clear();
mbInitFont = true;
mbNewFont = true;
@@ -884,12 +880,11 @@ vcl::Font OutputDevice::GetDefaultFont( DefaultFontType nType, LanguageType eLan
// get the name of the first available font
float fExactHeight = static_cast<float>(aSize.Height());
- LogicalFontInstance* pFontInstance = pOutDev->mpFontCache->GetFontInstance( pOutDev->mpFontCollection, aFont, aSize, fExactHeight );
+ rtl::Reference<LogicalFontInstance> pFontInstance = pOutDev->mpFontCache->GetFontInstance( pOutDev->mpFontCollection, aFont, aSize, fExactHeight );
if (pFontInstance)
{
assert(pFontInstance->GetFontFace());
aFont.SetFamilyName(pFontInstance->GetFontFace()->GetFamilyName());
- pFontInstance->Release();
}
}
}
@@ -1034,12 +1029,12 @@ bool OutputDevice::ImplNewFont() const
aSize.setWidth( 1 );
// get font entry
- LogicalFontInstance* pOldFontInstance = mpFontInstance;
+ rtl::Reference<LogicalFontInstance> pOldFontInstance = mpFontInstance;
mpFontInstance = mpFontCache->GetFontInstance( mpFontCollection, maFont, aSize, fExactHeight );
- if( pOldFontInstance )
- pOldFontInstance->Release();
+ bool bNewFontInstance = pOldFontInstance.get() != mpFontInstance.get();
+ pOldFontInstance.clear();
- LogicalFontInstance* pFontInstance = mpFontInstance;
+ LogicalFontInstance* pFontInstance = mpFontInstance.get();
if (!pFontInstance)
{
@@ -1049,7 +1044,7 @@ bool OutputDevice::ImplNewFont() const
// mark when lower layers need to get involved
mbNewFont = false;
- if( pFontInstance != pOldFontInstance )
+ if( bNewFontInstance )
mbInitFont = true;
// select font when it has not been initialized yet
@@ -1350,7 +1345,7 @@ std::unique_ptr<SalLayout> OutputDevice::ImplGlyphFallbackLayout( std::unique_pt
// if the system-specific glyph fallback is active
aFontSelData.mpFontInstance = mpFontInstance; // reset the fontinstance to base-level
- LogicalFontInstance* pFallbackFont = mpFontCache->GetGlyphFallbackFont( mpFontCollection,
+ rtl::Reference<LogicalFontInstance> pFallbackFont = mpFontCache->GetGlyphFallbackFont( mpFontCollection,
aFontSelData, nFallbackLevel, aMissingCodes );
if( !pFallbackFont )
break;
@@ -1364,7 +1359,6 @@ std::unique_ptr<SalLayout> OutputDevice::ImplGlyphFallbackLayout( std::unique_pt
if( mpFontInstance->GetFontFace() == pFallbackFont->GetFontFace() &&
aMissingCodes.indexOf(0x202F) == -1 )
{
- pFallbackFont->Release();
continue;
}
}
@@ -1382,8 +1376,6 @@ std::unique_ptr<SalLayout> OutputDevice::ImplGlyphFallbackLayout( std::unique_pt
pMultiSalLayout->SetIncomplete(true);
}
- pFallbackFont->Release();
-
// break when this fallback was sufficient
if( !rLayoutArgs.PrepareFallback() )
break;
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index 82833c72d819..1ecdcca86411 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -172,8 +172,7 @@ void OutputDevice::dispose()
mpOutDevStateStack.reset();
// release the active font instance
- if( mpFontInstance )
- mpFontInstance->Release();
+ mpFontInstance.clear();
// remove cached results of GetDevFontList/GetDevSizeList
mpDeviceFontList.reset();
diff --git a/vcl/source/outdev/outdevstate.cxx b/vcl/source/outdev/outdevstate.cxx
index 6713f6481369..24e0b75e3c3e 100644
--- a/vcl/source/outdev/outdevstate.cxx
+++ b/vcl/source/outdev/outdevstate.cxx
@@ -615,12 +615,7 @@ void OutputDevice::ImplReleaseFonts()
mbNewFont = true;
mbInitFont = true;
- if ( mpFontInstance )
- {
- mpFontInstance->Release();
- mpFontInstance = nullptr;
- }
-
+ mpFontInstance.clear();
mpDeviceFontList.reset();
mpDeviceFontSizeList.reset();
}
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index 22e7db6230a1..2034a54beb8a 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -211,7 +211,7 @@ void OutputDevice::ImplDrawWaveTextLine( long nBaseX, long nBaseY,
Color aColor,
bool bIsAbove )
{
- LogicalFontInstance* pFontInstance = mpFontInstance;
+ LogicalFontInstance* pFontInstance = mpFontInstance.get();
long nLineHeight;
long nLinePos;
@@ -279,7 +279,7 @@ void OutputDevice::ImplDrawStraightTextLine( long nBaseX, long nBaseY,
Color aColor,
bool bIsAbove )
{
- LogicalFontInstance* pFontInstance = mpFontInstance;
+ LogicalFontInstance* pFontInstance = mpFontInstance.get();
long nLineHeight = 0;
long nLinePos = 0;
long nLinePos2 = 0;
@@ -521,7 +521,7 @@ void OutputDevice::ImplDrawStrikeoutLine( long nBaseX, long nBaseY,
FontStrikeout eStrikeout,
Color aColor )
{
- LogicalFontInstance* pFontInstance = mpFontInstance;
+ LogicalFontInstance* pFontInstance = mpFontInstance.get();
long nLineHeight = 0;
long nLinePos = 0;
long nLinePos2 = 0;
@@ -1030,7 +1030,7 @@ void OutputDevice::DrawWaveLine( const Point& rStartPos, const Point& rEndPos )
}
// #109280# make sure the waveline does not exceed the descent to avoid paint problems
- LogicalFontInstance* pFontInstance = mpFontInstance;
+ LogicalFontInstance* pFontInstance = mpFontInstance.get();
if( nWaveHeight > pFontInstance->mxFontMetric->GetWavelineUnderlineSize() )
{
nWaveHeight = pFontInstance->mxFontMetric->GetWavelineUnderlineSize();
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index ce0be303d2e8..12182b2c3f1f 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -1738,7 +1738,7 @@ void Window::ImplNewInputContext()
SalInputContext aNewContext;
const vcl::Font& rFont = rInputContext.GetFont();
const OUString& rFontName = rFont.GetFamilyName();
- LogicalFontInstance* pFontInstance = nullptr;
+ rtl::Reference<LogicalFontInstance> pFontInstance;
aNewContext.mpFont = nullptr;
if (!rFontName.isEmpty())
{
@@ -1761,9 +1761,6 @@ void Window::ImplNewInputContext()
aNewContext.meLanguage = rFont.GetLanguage();
aNewContext.mnOptions = rInputContext.GetOptions();
pFocusWin->ImplGetFrame()->SetInputContext( &aNewContext );
-
- if ( pFontInstance )
- pFontInstance->Release();
}
void Window::doLazyDelete()
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index 5d7b9ff064ac..d17f02db69ff 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -357,7 +357,7 @@ FreetypeFontFace::FreetypeFontFace( FreetypeFontInfo* pFI, const FontAttributes&
{
}
-LogicalFontInstance* FreetypeFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
+rtl::Reference<LogicalFontInstance> FreetypeFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
{
return new FreetypeFontInstance(*this, rFSD);
}
@@ -366,7 +366,7 @@ LogicalFontInstance* FreetypeFontFace::CreateFontInstance(const FontSelectPatter
FreetypeFont::FreetypeFont( const FontSelectPattern& rFSD, FreetypeFontInfo* pFI )
: maGlyphList( 0),
- mpFontInstance(rFSD.mpFontInstance),
+ mpFontInstance(static_cast<FreetypeFontInstance*>(rFSD.mpFontInstance.get())),
mnRefCount(1),
mnBytesUsed( sizeof(FreetypeFont) ),
mpPrevGCFont( nullptr ),
@@ -385,8 +385,7 @@ FreetypeFont::FreetypeFont( const FontSelectPattern& rFSD, FreetypeFontInfo* pFI
int nPrioEmbedded = nDefaultPrioEmbedded;
// TODO: move update of mpFontInstance into FontEntry class when
// it becomes responsible for the FreetypeFont instantiation
- static_cast<FreetypeFontInstance*>(mpFontInstance)->SetFreetypeFont( this );
- mpFontInstance->Acquire();
+ mpFontInstance->SetFreetypeFont( this );
maFaceFT = pFI->GetFaceFT();
@@ -485,7 +484,7 @@ FreetypeFont::~FreetypeFont()
mpFontInfo->ReleaseFaceFT();
- mpFontInstance->Release();
+ mpFontInstance.clear();
ReleaseFromGarbageCollect();
}
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 11957c7043dc..b0158f9154d5 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -658,7 +658,7 @@ rtl::Reference<PhysicalFontFace> WinFontFace::Clone() const
return new WinFontFace(*this);
}
-LogicalFontInstance* WinFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
+rtl::Reference<LogicalFontInstance> WinFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
{
return new WinFontInstance(*this, rFSD);
}
@@ -922,33 +922,16 @@ void WinSalGraphics::SetFont( const FontSelectPattern* pFont, int nFallbackLevel
for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
{
if( mhFonts[i] )
- {
::DeleteFont( mhFonts[i] );
- mhFonts[ i ] = nullptr;
- }
- if (mpWinFontEntry[i])
- {
- GetWinFontEntry(i)->Release();
- mpWinFontEntry[i] = nullptr;
- }
- mfFontScale[i] = 1.0;
+ mhFonts[ i ] = nullptr;
+ mpWinFontEntry[i] = nullptr;
}
return;
}
- if (mpWinFontEntry[nFallbackLevel])
- {
- GetWinFontEntry(nFallbackLevel)->Release();
- }
// WinSalGraphics::GetEmbedFontData does not set mpFontInstance
// since it is interested in font file data only.
- if (pFont->mpFontInstance)
- {
- pFont->mpFontInstance->Acquire();
- }
-
- WinFontInstance *pFontInstance = static_cast<WinFontInstance*>(pFont->mpFontInstance);
- mpWinFontEntry[ nFallbackLevel ] = pFontInstance;
+ mpWinFontEntry[ nFallbackLevel ] = reinterpret_cast<WinFontInstance*>( pFont->mpFontInstance.get() );
HFONT hOldFont = nullptr;
HFONT hNewFont = pFontInstance ? pFontInstance->GetHFONT() : nullptr;
diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx
index aba0d6e6589e..57dd4ed37efd 100644
--- a/vcl/win/gdi/salgdi.cxx
+++ b/vcl/win/gdi/salgdi.cxx
@@ -29,6 +29,7 @@
#include <win/salgdi.h>
#include <win/salframe.h>
#include <win/salvd.h>
+#include <win/winlayout.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <salgdiimpl.hxx>
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 392a6abef02a..fa0c2b683387 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -310,11 +310,6 @@ std::unique_ptr<SalLayout> WinSalGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs
return std::unique_ptr<SalLayout>(aLayout);
}
-LogicalFontInstance * WinSalGraphics::GetWinFontEntry(int const nFallbackLevel)
-{
- return mpWinFontEntry[nFallbackLevel];
-}
-
WinFontInstance::WinFontInstance(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP)
: LogicalFontInstance(rPFF, rFSP)
, m_hFont(nullptr)