[Libreoffice-commits] core.git: 2 commits - include/vcl vcl/inc vcl/source
Chris Sherlock
chris.sherlock79 at gmail.com
Wed Jan 13 18:57:24 PST 2016
include/vcl/metric.hxx | 3 +-
vcl/inc/impfontmetric.hxx | 22 +++++++++++++++++++--
vcl/source/gdi/metric.cxx | 29 +++++-----------------------
vcl/source/outdev/font.cxx | 46 ++++++++++++++++++++++-----------------------
4 files changed, 51 insertions(+), 49 deletions(-)
New commits:
commit 27c4cf76a189b546daf14797773517655f24c81d
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Thu Jan 14 13:54:55 2016 +1100
vcl: change from pFontAttributes to pFontMetric
Change-Id: I777fd9ee93402c9af026f1ebef6fe960bd8c7c8c
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index a38af4a..f85fcc8 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -189,40 +189,40 @@ FontMetric OutputDevice::GetFontMetric() const
return aMetric;
LogicalFontInstance* pFontInstance = mpFontInstance;
- ImplFontMetricData* pFontAttributes = &(pFontInstance->maFontMetric);
+ ImplFontMetricData* pFontMetric = &(pFontInstance->maFontMetric);
// prepare metric
aMetric.Font::operator=( maFont );
// set aMetric with info from font
aMetric.SetName( maFont.GetName() );
- aMetric.SetStyleName( pFontAttributes->GetStyleName() );
- aMetric.SetSize( PixelToLogic( Size( pFontAttributes->GetWidth(), pFontAttributes->GetAscent() + pFontAttributes->GetDescent() - pFontAttributes->GetInternalLeading() ) ) );
- aMetric.SetCharSet( pFontAttributes->IsSymbolFont() ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
- aMetric.SetFamily( pFontAttributes->GetFamilyType() );
- aMetric.SetPitch( pFontAttributes->GetPitch() );
- aMetric.SetWeight( pFontAttributes->GetWeight() );
- aMetric.SetItalic( pFontAttributes->GetSlantType() );
- aMetric.SetWidthType( pFontAttributes->GetWidthType() );
+ aMetric.SetStyleName( pFontMetric->GetStyleName() );
+ aMetric.SetSize( PixelToLogic( Size( pFontMetric->GetWidth(), pFontMetric->GetAscent() + pFontMetric->GetDescent() - pFontMetric->GetInternalLeading() ) ) );
+ aMetric.SetCharSet( pFontMetric->IsSymbolFont() ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
+ aMetric.SetFamily( pFontMetric->GetFamilyType() );
+ aMetric.SetPitch( pFontMetric->GetPitch() );
+ aMetric.SetWeight( pFontMetric->GetWeight() );
+ aMetric.SetItalic( pFontMetric->GetSlantType() );
+ aMetric.SetWidthType( pFontMetric->GetWidthType() );
if ( pFontInstance->mnOwnOrientation )
aMetric.SetOrientation( pFontInstance->mnOwnOrientation );
else
- aMetric.SetOrientation( pFontAttributes->GetOrientation() );
+ aMetric.SetOrientation( pFontMetric->GetOrientation() );
if( !pFontInstance->maFontMetric.IsKernable() )
aMetric.SetKerning( maFont.GetKerning() & ~FontKerning::FontSpecific );
// set remaining metric fields
- aMetric.SetBuiltInFontFlag( pFontAttributes->IsBuiltInFont() );
- aMetric.SetScalableFlag( pFontAttributes->IsScalable() );
- aMetric.SetFullstopCenteredFlag( pFontAttributes->IsFullstopCentered() );
- aMetric.SetBulletOffset( pFontAttributes->GetBulletOffset() );
- aMetric.SetAscent( ImplDevicePixelToLogicHeight( pFontAttributes->GetAscent() + mnEmphasisAscent ) );
- aMetric.SetDescent( ImplDevicePixelToLogicHeight( pFontAttributes->GetDescent() + mnEmphasisDescent ) );
- aMetric.SetInternalLeading( ImplDevicePixelToLogicHeight( pFontAttributes->GetInternalLeading() + mnEmphasisAscent ) );
+ aMetric.SetBuiltInFontFlag( pFontMetric->IsBuiltInFont() );
+ aMetric.SetScalableFlag( pFontMetric->IsScalable() );
+ aMetric.SetFullstopCenteredFlag( pFontMetric->IsFullstopCentered() );
+ aMetric.SetBulletOffset( pFontMetric->GetBulletOffset() );
+ aMetric.SetAscent( ImplDevicePixelToLogicHeight( pFontMetric->GetAscent() + mnEmphasisAscent ) );
+ aMetric.SetDescent( ImplDevicePixelToLogicHeight( pFontMetric->GetDescent() + mnEmphasisDescent ) );
+ aMetric.SetInternalLeading( ImplDevicePixelToLogicHeight( pFontMetric->GetInternalLeading() + mnEmphasisAscent ) );
// OutputDevice has its own external leading function due to #i60945#
aMetric.SetExternalLeading( ImplDevicePixelToLogicHeight( GetFontExtLeading() ) );
- aMetric.SetLineHeight( ImplDevicePixelToLogicHeight( pFontAttributes->GetAscent() + pFontAttributes->GetDescent() + mnEmphasisAscent + mnEmphasisDescent ) );
- aMetric.SetSlant( ImplDevicePixelToLogicHeight( pFontAttributes->GetSlant() ) );
+ aMetric.SetLineHeight( ImplDevicePixelToLogicHeight( pFontMetric->GetAscent() + pFontMetric->GetDescent() + mnEmphasisAscent + mnEmphasisDescent ) );
+ aMetric.SetSlant( ImplDevicePixelToLogicHeight( pFontMetric->GetSlant() ) );
SAL_INFO("vcl.gdi.fontmetric", "OutputDevice::GetFontMetric:" << aMetric);
@@ -482,9 +482,9 @@ FontEmphasisMark OutputDevice::ImplGetEmphasisMarkStyle( const vcl::Font& rFont
long OutputDevice::GetFontExtLeading() const
{
LogicalFontInstance* pFontInstance = mpFontInstance;
- ImplFontMetricData* pFontAttributes = &(pFontInstance->maFontMetric);
+ ImplFontMetricData* pFontMetric = &(pFontInstance->maFontMetric);
- return pFontAttributes->GetExternalLeading();
+ return pFontMetric->GetExternalLeading();
}
void OutputDevice::ImplClearFontData( const bool bNewFontLists )
@@ -1461,8 +1461,8 @@ long OutputDevice::GetMinKashida() const
return 0;
LogicalFontInstance* pFontInstance = mpFontInstance;
- ImplFontMetricData* pFontAttributes = &(pFontInstance->maFontMetric);
- return ImplDevicePixelToLogicWidth( pFontAttributes->GetMinKashida() );
+ ImplFontMetricData* pFontMetric = &(pFontInstance->maFontMetric);
+ return ImplDevicePixelToLogicWidth( pFontMetric->GetMinKashida() );
}
sal_Int32 OutputDevice::ValidateKashidas ( const OUString& rTxt,
commit 43488d9de74d785445f5f7cbb80163bfb2e36c1b
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Thu Jan 14 11:46:24 2016 +1100
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
diff --git a/include/vcl/metric.hxx b/include/vcl/metric.hxx
index 0cd14b1..e37b91f 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 226be2e..7b9413f 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 eb7271d4..adbb454 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
More information about the Libreoffice-commits
mailing list