[Libreoffice-commits] core.git: editeng/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jul 22 10:22:08 UTC 2021
editeng/source/editeng/editobj.cxx | 81 +++++++++---------------------------
editeng/source/editeng/editobj2.hxx | 8 ---
editeng/source/editeng/impedit4.cxx | 13 +----
3 files changed, 27 insertions(+), 75 deletions(-)
New commits:
commit a9bba3827888b290c435a3b0e5cdf50846d08bd2
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Jul 22 11:02:30 2021 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Jul 22 12:21:32 2021 +0200
Simplify EditTextObject's pool initialization
Old scheme (ever since commit fd069bee7e57ad529c3c0974559fd2d84ec3151a
"initial import") was that when source EditTextObject was owner of the
pool, the copy created a new pool; and when source was not owner, the
copy just re-used existing pool.
It made no sense since commit 1545949690c750d7b512000723b564e69cf3c3a6
where pools were made ref-counted using rtl::Reference.
This also simplifies the only place which used the EditTextObject ctor
taking pool by making the related ctor to take all necessary arguments
instead of calling setters after constructing the object, which allows
to drop a couple of setters.
Change-Id: I843e154dd57f33f7c037063b4a0fcc0ac5a33cd2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119358
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx
index 9f8cc2cb76df..5f14386c4ccb 100644
--- a/editeng/source/editeng/editobj.cxx
+++ b/editeng/source/editeng/editobj.cxx
@@ -254,51 +254,36 @@ void EditTextObjectImpl::Dump() const
}
#endif
-static EditEngineItemPool* getEditEngineItemPool(SfxItemPool* pPool)
+static rtl::Reference<SfxItemPool> getEditEngineItemPool(SfxItemPool* pPool, MapUnit eDefaultMetric)
{
- EditEngineItemPool* pRetval = dynamic_cast< EditEngineItemPool* >(pPool);
-
- while(!pRetval && pPool && pPool->GetSecondaryPool())
- {
- pPool = pPool->GetSecondaryPool();
-
- if(pPool)
- {
- pRetval = dynamic_cast< EditEngineItemPool* >(pPool);
- }
- }
-
- return pRetval;
-}
-
-EditTextObjectImpl::EditTextObjectImpl( SfxItemPool* pP )
- : meUserType(OutlinerMode::DontKnow)
- , meScriptType(SvtScriptType::NONE)
- , meRotation(TextRotation::NONE)
- , meMetric(MapUnit::LASTENUMDUMMY)
- , mbVertical(false)
-{
- // #i101239# ensure target is an EditEngineItemPool, else
- // fallback to pool ownership. This is needed to ensure that at
+ // #i101239# ensure target is an EditEngineItemPool, so that at
// pool destruction time of an alien pool, the pool is still alive.
// When registering would happen at an alien pool which just uses an
// EditEngineItemPool as some sub-pool, that pool could already
// be decoupled and deleted which would lead to crashes.
- mpPool = getEditEngineItemPool(pP);
+ for (; pPool; pPool = pPool->GetSecondaryPool())
+ if (dynamic_cast<EditEngineItemPool*>(pPool))
+ return pPool;
- if ( mpPool )
- {
- mbOwnerOfPool = false;
- }
- else
- {
- mpPool = EditEngine::CreatePool();
- mbOwnerOfPool = true;
- }
+ auto pRetval = EditEngine::CreatePool();
+ pRetval->SetDefaultMetric(eDefaultMetric);
+ return pRetval;
+}
+
+EditTextObjectImpl::EditTextObjectImpl(SfxItemPool* pP, MapUnit eDefaultMetric, bool bVertical,
+ TextRotation eRotation, SvtScriptType eScriptType)
+ : mpPool(getEditEngineItemPool(pP, eDefaultMetric))
+ , meUserType(OutlinerMode::DontKnow)
+ , meScriptType(eScriptType)
+ , meRotation(eRotation)
+ , meMetric(eDefaultMetric)
+ , mbVertical(bVertical)
+{
}
EditTextObjectImpl::EditTextObjectImpl( const EditTextObjectImpl& r )
- : meUserType(r.meUserType)
+ : mpPool(r.mpPool)
+ , meUserType(r.meUserType)
, meScriptType(r.meScriptType)
, meRotation(r.meRotation)
, meMetric(r.meMetric)
@@ -306,24 +291,6 @@ EditTextObjectImpl::EditTextObjectImpl( const EditTextObjectImpl& r )
{
// Do not copy PortionInfo
- if ( !r.mbOwnerOfPool )
- {
- // reuse alien pool; this must be an EditEngineItemPool
- // since there is no other way to construct an EditTextObject
- // than it's regular constructor where that is ensured
- mpPool = r.mpPool;
- mbOwnerOfPool = false;
- }
- else
- {
- mpPool = EditEngine::CreatePool();
- mbOwnerOfPool = true;
-
- }
-
- if (mbOwnerOfPool && r.mpPool)
- mpPool->SetDefaultMetric( r.mpPool->GetMetric( DEF_METRIC ) );
-
maContents.reserve(r.maContents.size());
for (auto const& content : r.maContents)
maContents.push_back(std::unique_ptr<ContentInfo>(new ContentInfo(*content, *mpPool)));
@@ -405,12 +372,6 @@ TextRotation EditTextObjectImpl::GetRotation() const
return meRotation;
}
-
-void EditTextObjectImpl::SetScriptType( SvtScriptType nType )
-{
- meScriptType = nType;
-}
-
XEditAttribute EditTextObjectImpl::CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd )
{
return MakeXEditAttribute( *mpPool, rItem, nStart, nEnd );
diff --git a/editeng/source/editeng/editobj2.hxx b/editeng/source/editeng/editobj2.hxx
index a6f2b1be0d6d..818ea0fbaf75 100644
--- a/editeng/source/editeng/editobj2.hxx
+++ b/editeng/source/editeng/editobj2.hxx
@@ -180,14 +180,14 @@ private:
TextRotation meRotation;
MapUnit meMetric;
- bool mbOwnerOfPool;
bool mbVertical;
bool ImpChangeStyleSheets( std::u16string_view rOldName, SfxStyleFamily eOldFamily,
const OUString& rNewName, SfxStyleFamily eNewFamily );
public:
- EditTextObjectImpl( SfxItemPool* pPool );
+ EditTextObjectImpl(SfxItemPool* pPool, MapUnit eDefaultMetric, bool bVertical,
+ TextRotation eRotation, SvtScriptType eScriptType);
EditTextObjectImpl( const EditTextObjectImpl& r );
virtual ~EditTextObjectImpl() override;
@@ -207,7 +207,6 @@ public:
virtual TextRotation GetRotation() const override;
virtual SvtScriptType GetScriptType() const override { return meScriptType;}
- void SetScriptType( SvtScriptType nType );
virtual std::unique_ptr<EditTextObject> Clone() const override;
@@ -254,9 +253,6 @@ public:
bool HasMetric() const { return meMetric != MapUnit::LASTENUMDUMMY; }
MapUnit GetMetric() const { return meMetric; }
- void SetMetric( MapUnit n ) { meMetric = n; }
-
- bool IsOwnerOfPool() const { return mbOwnerOfPool; }
virtual bool operator==( const EditTextObject& rCompare ) const override;
bool Equals( const EditTextObjectImpl& rCompare, bool bComparePool ) const;
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index 1786b3215d88..de36a316de83 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -989,14 +989,6 @@ std::unique_ptr<EditTextObject> ImpEditEngine::CreateTextObject(const EditSelect
std::unique_ptr<EditTextObject> ImpEditEngine::CreateTextObject( EditSelection aSel, SfxItemPool* pPool, bool bAllowBigObjects, sal_Int32 nBigObjectStart )
{
- std::unique_ptr<EditTextObjectImpl> pTxtObj(std::make_unique<EditTextObjectImpl>(pPool));
- pTxtObj->SetVertical( GetVertical() );
- pTxtObj->SetRotation( GetRotation() );
- MapUnit eMapUnit = aEditDoc.GetItemPool().GetMetric( DEF_METRIC );
- pTxtObj->SetMetric( eMapUnit );
- if ( pTxtObj->IsOwnerOfPool() )
- pTxtObj->GetPool()->SetDefaultMetric( eMapUnit );
-
sal_Int32 nStartNode, nEndNode;
sal_Int32 nTextPortions = 0;
@@ -1009,7 +1001,10 @@ std::unique_ptr<EditTextObject> ImpEditEngine::CreateTextObject( EditSelection a
// Templates are not saved!
// (Only the name and family, template itself must be in App!)
- pTxtObj->SetScriptType(GetItemScriptType(aSel));
+
+ const MapUnit eMapUnit = aEditDoc.GetItemPool().GetMetric(DEF_METRIC);
+ auto pTxtObj(std::make_unique<EditTextObjectImpl>(pPool, eMapUnit, GetVertical(), GetRotation(),
+ GetItemScriptType(aSel)));
// iterate over the paragraphs ...
sal_Int32 nNode;
More information about the Libreoffice-commits
mailing list