summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2016-01-14 11:46:24 +1100
committerChris Sherlock <chris.sherlock79@gmail.com>2016-01-14 11:46:28 +1100
commit43488d9de74d785445f5f7cbb80163bfb2e36c1b (patch)
tree4c511b24643c443dc0d33684936651dc6da5dbe2
parent2496c497b6ffe9c69370ccc12bb103099c877165 (diff)
vcl: FontMetric now has ImplFontMetricPtr objects
ImplFontMetricPtr is a typedef to an intrusive_ptr<ImplFontMetric>. I have ditched the manual reference counting to use Boost's smart pointer. Change-Id: I5e93f45d19d43c8b7253f4342c1b9ef4a4301527
-rw-r--r--include/vcl/metric.hxx3
-rw-r--r--vcl/inc/impfontmetric.hxx22
-rw-r--r--vcl/source/gdi/metric.cxx29
3 files changed, 28 insertions, 26 deletions
diff --git a/include/vcl/metric.hxx b/include/vcl/metric.hxx
index 0cd14b1c20f8..e37b91ffac75 100644
--- a/include/vcl/metric.hxx
+++ b/include/vcl/metric.hxx
@@ -33,6 +33,7 @@ class CmapResult;
typedef sal_uInt32 sal_UCS4;
typedef boost::intrusive_ptr< ImplFontCharMap > ImplFontCharMapPtr;
typedef boost::intrusive_ptr< FontCharMap > FontCharMapPtr;
+typedef boost::intrusive_ptr< ImplFontMetric > ImplFontMetricPtr;
class VCL_DLLPUBLIC FontMetric : public vcl::Font
{
@@ -72,7 +73,7 @@ public:
bool operator!=( const FontMetric& rMetric ) const
{ return !operator==( rMetric ); }
protected:
- ImplFontMetric* mpImplMetric; // Implementation
+ ImplFontMetricPtr mpImplMetric; // Implementation
};
template< typename charT, typename traits >
diff --git a/vcl/inc/impfontmetric.hxx b/vcl/inc/impfontmetric.hxx
index 226be2edfac5..7b9413f9fe4f 100644
--- a/vcl/inc/impfontmetric.hxx
+++ b/vcl/inc/impfontmetric.hxx
@@ -20,8 +20,17 @@
#ifndef INCLUDED_VCL_INC_IMPFONTMETRIC_HXX
#define INCLUDED_VCL_INC_IMPFONTMETRIC_HXX
+#include <boost/intrusive_ptr.hpp>
+
+class ImplFontCharMap;
+typedef boost::intrusive_ptr< ImplFontCharMap > ImplFontCharMapPtr;
+
class ImplFontMetric
{
+ friend class FontMetric;
+ friend void intrusive_ptr_add_ref(ImplFontMetric* pImplFontMetric);
+ friend void intrusive_ptr_release(ImplFontMetric* pImplFontMetric);
+
private:
long mnAscent; // Ascent
long mnDescent; // Descent
@@ -41,8 +50,6 @@ public:
bool operator==( const ImplFontMetric& ) const;
ImplFontMetric();
- void AddReference();
- void DeReference();
long GetAscent() const { return mnAscent; }
long GetDescent() const { return mnDescent; }
@@ -70,6 +77,17 @@ public:
};
+inline void intrusive_ptr_add_ref(ImplFontMetric* pImplFontMetric)
+{
+ ++pImplFontMetric->mnRefCount;
+}
+
+inline void intrusive_ptr_release(ImplFontMetric* pImplFontMetric)
+{
+ if (--pImplFontMetric->mnRefCount == 0)
+ delete pImplFontMetric;
+}
+
#endif // INCLUDED_VCL_INC_IMPFONTMETRIC_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/metric.cxx b/vcl/source/gdi/metric.cxx
index eb7271d4a82e..adbb45420af0 100644
--- a/vcl/source/gdi/metric.cxx
+++ b/vcl/source/gdi/metric.cxx
@@ -26,19 +26,17 @@
#include <cstdio>
FontMetric::FontMetric()
-: mpImplMetric( new ImplFontMetric )
+: mpImplMetric( new ImplFontMetric() )
{}
FontMetric::FontMetric( const FontMetric& rFontMetric )
-: Font( rFontMetric )
-{
- mpImplMetric = rFontMetric.mpImplMetric;
- mpImplMetric->AddReference();
-}
+ : Font( rFontMetric )
+ , mpImplMetric( rFontMetric.mpImplMetric )
+{}
FontMetric::~FontMetric()
{
- mpImplMetric->DeReference();
+ mpImplMetric = nullptr;
}
FontMetric& FontMetric::operator=( const FontMetric& rFontMetric )
@@ -47,9 +45,7 @@ FontMetric& FontMetric::operator=( const FontMetric& rFontMetric )
if( mpImplMetric != rFontMetric.mpImplMetric )
{
- mpImplMetric->DeReference();
mpImplMetric = rFontMetric.mpImplMetric;
- mpImplMetric->AddReference();
}
return *this;
@@ -181,25 +177,12 @@ ImplFontMetric::ImplFontMetric()
mnLineHeight( 0 ),
mnSlant( 0 ),
mnBulletOffset( 0 ),
- mnRefCount( 1 ),
+ mnRefCount( 0 ),
mbScalableFont( false ),
mbFullstopCentered( false ),
mbDevice( false )
{}
-inline void ImplFontMetric::AddReference()
-{
- // TODO: disable refcounting on the default maps?
- ++mnRefCount;
-}
-
-inline void ImplFontMetric::DeReference()
-{
- // TODO: disable refcounting on the default maps?
- if( --mnRefCount <= 0 )
- delete this;
-}
-
bool ImplFontMetric::operator==( const ImplFontMetric& r ) const
{
if( mbScalableFont != r.mbScalableFont