Kaydet (Commit) 32ec7666 authored tarafından Thomas Arnhold's avatar Thomas Arnhold Kaydeden (comit) Thorsten Behrens

fdo#62525: use cow_wrapper for FontAttribute

Change-Id: Ic07da7c7cf225a910e6f0fa4f6d20c4700e7ec7a
üst 0bca4ccd
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_FONTATTRIBUTE_HXX #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_FONTATTRIBUTE_HXX
#include <drawinglayer/drawinglayerdllapi.h> #include <drawinglayer/drawinglayerdllapi.h>
#include <o3tl/cow_wrapper.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// predefines // predefines
...@@ -44,8 +45,11 @@ namespace drawinglayer ...@@ -44,8 +45,11 @@ namespace drawinglayer
*/ */
class DRAWINGLAYER_DLLPUBLIC FontAttribute class DRAWINGLAYER_DLLPUBLIC FontAttribute
{ {
public:
typedef o3tl::cow_wrapper< ImpFontAttribute > ImplType;
private: private:
ImpFontAttribute* mpFontAttribute; ImplType mpFontAttribute;
public: public:
/// constructors/assignmentoperator/destructor /// constructors/assignmentoperator/destructor
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include <drawinglayer/attribute/fontattribute.hxx> #include <drawinglayer/attribute/fontattribute.hxx>
#include <rtl/instance.hxx>
#include <tools/string.hxx> #include <tools/string.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -29,9 +30,6 @@ namespace drawinglayer ...@@ -29,9 +30,6 @@ namespace drawinglayer
class ImpFontAttribute class ImpFontAttribute
{ {
public: public:
// refcounter
sal_uInt32 mnRefCount;
/// core data /// core data
String maFamilyName; // Font Family Name String maFamilyName; // Font Family Name
String maStyleName; // Font Style Name String maStyleName; // Font Style Name
...@@ -57,8 +55,7 @@ namespace drawinglayer ...@@ -57,8 +55,7 @@ namespace drawinglayer
bool bOutline, bool bOutline,
bool bRTL, bool bRTL,
bool bBiDiStrong) bool bBiDiStrong)
: mnRefCount(0), : maFamilyName(rFamilyName),
maFamilyName(rFamilyName),
maStyleName(rStyleName), maStyleName(rStyleName),
mnWeight(nWeight), mnWeight(nWeight),
mbSymbol(bSymbol), mbSymbol(bSymbol),
...@@ -71,6 +68,20 @@ namespace drawinglayer ...@@ -71,6 +68,20 @@ namespace drawinglayer
{ {
} }
ImpFontAttribute()
: maFamilyName(),
maStyleName(),
mnWeight(0),
mbSymbol(false),
mbVertical(false),
mbItalic(false),
mbOutline(false),
mbRTL(false),
mbBiDiStrong(false),
mbMonospaced(false)
{
}
// data read access // data read access
const String& getFamilyName() const { return maFamilyName; } const String& getFamilyName() const { return maFamilyName; }
const String& getStyleName() const { return maStyleName; } const String& getStyleName() const { return maStyleName; }
...@@ -96,26 +107,14 @@ namespace drawinglayer ...@@ -96,26 +107,14 @@ namespace drawinglayer
&& getBiDiStrong() == rCompare.getBiDiStrong() && getBiDiStrong() == rCompare.getBiDiStrong()
&& getMonospaced() == rCompare.getMonospaced()); && getMonospaced() == rCompare.getMonospaced());
} }
static ImpFontAttribute* get_global_default()
{
static ImpFontAttribute* pDefault = 0;
if(!pDefault)
{
pDefault = new ImpFontAttribute(
String(), String(),
0,
false, false, false, false, false, false, false);
// never delete; start with RefCount 1, not 0
pDefault->mnRefCount++;
}
return pDefault;
}
}; };
namespace
{
struct theGlobalDefault :
public rtl::Static< FontAttribute::ImplType, theGlobalDefault > {};
}
FontAttribute::FontAttribute( FontAttribute::FontAttribute(
const String& rFamilyName, const String& rFamilyName,
const String& rStyleName, const String& rStyleName,
...@@ -127,73 +126,39 @@ namespace drawinglayer ...@@ -127,73 +126,39 @@ namespace drawinglayer
bool bOutline, bool bOutline,
bool bRTL, bool bRTL,
bool bBiDiStrong) bool bBiDiStrong)
: mpFontAttribute(new ImpFontAttribute( : mpFontAttribute(ImpFontAttribute(
rFamilyName, rStyleName, nWeight, bSymbol, bVertical, bItalic, bMonospaced, bOutline, bRTL, bBiDiStrong)) rFamilyName, rStyleName, nWeight, bSymbol, bVertical, bItalic, bMonospaced, bOutline, bRTL, bBiDiStrong))
{ {
} }
FontAttribute::FontAttribute() FontAttribute::FontAttribute()
: mpFontAttribute(ImpFontAttribute::get_global_default()) : mpFontAttribute(theGlobalDefault::get())
{ {
mpFontAttribute->mnRefCount++;
} }
FontAttribute::FontAttribute(const FontAttribute& rCandidate) FontAttribute::FontAttribute(const FontAttribute& rCandidate)
: mpFontAttribute(rCandidate.mpFontAttribute) : mpFontAttribute(rCandidate.mpFontAttribute)
{ {
mpFontAttribute->mnRefCount++;
} }
FontAttribute::~FontAttribute() FontAttribute::~FontAttribute()
{ {
if(mpFontAttribute->mnRefCount)
{
mpFontAttribute->mnRefCount--;
}
else
{
delete mpFontAttribute;
}
} }
bool FontAttribute::isDefault() const bool FontAttribute::isDefault() const
{ {
return mpFontAttribute == ImpFontAttribute::get_global_default(); return mpFontAttribute.same_object(theGlobalDefault::get());
} }
FontAttribute& FontAttribute::operator=(const FontAttribute& rCandidate) FontAttribute& FontAttribute::operator=(const FontAttribute& rCandidate)
{ {
if(rCandidate.mpFontAttribute != mpFontAttribute) mpFontAttribute = rCandidate.mpFontAttribute;
{
if(mpFontAttribute->mnRefCount)
{
mpFontAttribute->mnRefCount--;
}
else
{
delete mpFontAttribute;
}
mpFontAttribute = rCandidate.mpFontAttribute;
mpFontAttribute->mnRefCount++;
}
return *this; return *this;
} }
bool FontAttribute::operator==(const FontAttribute& rCandidate) const bool FontAttribute::operator==(const FontAttribute& rCandidate) const
{ {
if(rCandidate.mpFontAttribute == mpFontAttribute) return rCandidate.mpFontAttribute == mpFontAttribute;
{
return true;
}
if(rCandidate.isDefault() != isDefault())
{
return false;
}
return (*rCandidate.mpFontAttribute == *mpFontAttribute);
} }
const String& FontAttribute::getFamilyName() const const String& FontAttribute::getFamilyName() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment