[Libreoffice-commits] core.git: 2 commits - include/svx svx/qa svx/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sun Jun 27 01:53:33 UTC 2021


 include/svx/svdmodel.hxx       |    7 -
 svx/qa/unit/svdraw.cxx         |   89 +++++++++++++++++++++-
 svx/source/svdraw/svdmodel.cxx |  162 ++++++++++++++++++-----------------------
 3 files changed, 161 insertions(+), 97 deletions(-)

New commits:
commit b8b02686c8900ef9cab344480e0b0904e573c936
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Jun 24 17:56:50 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Jun 27 03:53:11 2021 +0200

    svx: adds a test for SdrRectObj rendering into primitives
    
    This adds a new test that checks how a model with a rectangle
    object is being rendered / transformed into drawinglayer
    primitives.
    
    Change-Id: I81851e122f182ebe5ed8486fdab8d04bb8c9e68a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117886
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx
index fa344d80acb4..b0e8ed70de9b 100644
--- a/svx/qa/unit/svdraw.cxx
+++ b/svx/qa/unit/svdraw.cxx
@@ -23,16 +23,20 @@
 
 #include <drawinglayer/tools/primitive2dxmldump.hxx>
 #include <rtl/ustring.hxx>
+#include <vcl/virdev.hxx>
 #include <svx/sdr/contact/displayinfo.hxx>
 #include <svx/sdr/contact/viewcontact.hxx>
 #include <svx/sdr/contact/viewobjectcontact.hxx>
 #include <svx/svdpage.hxx>
+#include <svx/svdorect.hxx>
 #include <svx/unopage.hxx>
-#include <vcl/virdev.hxx>
+#include <svx/unoapi.hxx>
+#include <svx/svdview.hxx>
+#include <svx/xlineit0.hxx>
+#include <svx/xlnstwit.hxx>
 #include <comphelper/propertyvalue.hxx>
 #include <sfx2/viewsh.hxx>
-#include <svx/svdview.hxx>
-#include <svx/unoapi.hxx>
+#include <svl/itempool.hxx>
 
 #include <sdr/contact/objectcontactofobjlistpainter.hxx>
 
@@ -241,6 +245,85 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testTextEditEmptyGrabBag)
     // old text.
     CPPUNIT_ASSERT(!aGrabBag.hasElements());
 }
+
+CPPUNIT_TEST_FIXTURE(SvdrawTest, testRectangleObject)
+{
+    std::unique_ptr<SdrModel> pModel(new SdrModel(nullptr, nullptr, true));
+    pModel->GetItemPool().FreezeIdRanges();
+
+    rtl::Reference<SdrPage> pPage(new SdrPage(*pModel, false));
+    pPage->SetSize(Size(1000, 1000));
+    pModel->InsertPage(pPage.get(), 0);
+
+    tools::Rectangle aSize(Point(), Size(100, 100));
+    auto* pRectangle = new SdrRectObj(*pModel, aSize);
+    pPage->NbcInsertObject(pRectangle);
+    pRectangle->SetMergedItem(XLineStyleItem(drawing::LineStyle_SOLID));
+    pRectangle->SetMergedItem(XLineStartWidthItem(200));
+
+    ScopedVclPtrInstance<VirtualDevice> aVirtualDevice;
+    aVirtualDevice->SetOutputSize(Size(2000, 2000));
+
+    SdrView aView(*pModel, aVirtualDevice);
+    aView.hideMarkHandles();
+    aView.ShowSdrPage(pPage.get());
+
+    sdr::contact::ObjectContactOfObjListPainter aObjectContact(*aVirtualDevice,
+                                                               { pPage->GetObj(0) }, nullptr);
+    const sdr::contact::ViewObjectContact& rDrawPageVOContact
+        = pPage->GetViewContact().GetViewObjectContact(aObjectContact);
+
+    sdr::contact::DisplayInfo aDisplayInfo;
+    drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
+        = rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo);
+
+    drawinglayer::Primitive2dXmlDump aDumper;
+    xmlDocUniquePtr pXmlDoc = aDumper.dumpAndParse(xPrimitiveSequence);
+
+    assertXPath(pXmlDoc, "/primitive2D", 1);
+
+    OString aBasePath("/primitive2D/sdrrectangle/polypolygoncolor");
+    assertXPath(pXmlDoc, aBasePath, "color", "#729fcf");
+
+    assertXPath(pXmlDoc, aBasePath + "/polypolygon", "height",
+                "99"); // weird Rectangle is created with size 100
+    assertXPath(pXmlDoc, aBasePath + "/polypolygon", "width", "99");
+    assertXPath(pXmlDoc, aBasePath + "/polypolygon", "minx", "0");
+    assertXPath(pXmlDoc, aBasePath + "/polypolygon", "miny", "0");
+    assertXPath(pXmlDoc, aBasePath + "/polypolygon", "maxx", "99");
+    assertXPath(pXmlDoc, aBasePath + "/polypolygon", "maxy", "99");
+
+    aBasePath = "/primitive2D/sdrrectangle/polypolygoncolor/polypolygon/polygon";
+
+    assertXPath(pXmlDoc, aBasePath + "/point", 5);
+    assertXPath(pXmlDoc, aBasePath + "/point[1]", "x", "49.5"); // hmm, weird, why?
+    assertXPath(pXmlDoc, aBasePath + "/point[1]", "y", "99");
+    assertXPath(pXmlDoc, aBasePath + "/point[2]", "x", "0");
+    assertXPath(pXmlDoc, aBasePath + "/point[2]", "y", "99");
+    assertXPath(pXmlDoc, aBasePath + "/point[3]", "x", "0");
+    assertXPath(pXmlDoc, aBasePath + "/point[3]", "y", "0");
+    assertXPath(pXmlDoc, aBasePath + "/point[4]", "x", "99");
+    assertXPath(pXmlDoc, aBasePath + "/point[4]", "y", "0");
+    assertXPath(pXmlDoc, aBasePath + "/point[5]", "x", "99");
+    assertXPath(pXmlDoc, aBasePath + "/point[5]", "y", "99");
+
+    aBasePath = "/primitive2D/sdrrectangle/polygonstroke";
+    assertXPath(pXmlDoc, aBasePath, 1);
+
+    assertXPath(pXmlDoc, aBasePath + "/line", "color", "#3465a4");
+    assertXPath(pXmlDoc, aBasePath + "/line", "width", "0");
+    assertXPath(pXmlDoc, aBasePath + "/line", "linejoin", "Round");
+    assertXPath(pXmlDoc, aBasePath + "/line", "linecap", "BUTT");
+
+    assertXPathContent(pXmlDoc, aBasePath + "/polygon", "49.5,99 0,99 0,0 99,0 99,99");
+
+    assertXPath(pXmlDoc, aBasePath + "/stroke", "fulldotdashlen", "0");
+
+    pPage->RemoveObject(0);
+
+    SdrObject* pObject(pRectangle);
+    SdrObject::Free(pObject);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit f15d50b5ff6f0c8ed1a647a4efa92f5c67077326
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri Jun 25 21:06:27 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Jun 27 03:52:58 2021 +0200

    svx: clean-up, init in constructor, rename master pages variable
    
    - maMaPag to maMasterPages
    - cleanup the constructor variable initialization
    - change degree chart from define to const variable
    
    Change-Id: Idc607b8b386855b90001ed389df2c7849969ee86
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117887
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/svx/svdmodel.hxx b/include/svx/svdmodel.hxx
index 5a7aadd7b65a..c681c4878a42 100644
--- a/include/svx/svdmodel.hxx
+++ b/include/svx/svdmodel.hxx
@@ -48,7 +48,7 @@ class OutputDevice;
 #include <unordered_set>
 #endif
 
-#define DEGREE_CHAR u'\x00B0'   /* U+00B0 DEGREE SIGN */
+constexpr const sal_Unicode DEGREE_CHAR = u'\x00B0'; /* U+00B0 DEGREE SIGN */
 
 class SdrOutliner;
 class SdrLayerAdmin;
@@ -162,7 +162,7 @@ private:
     std::unordered_set< const SdrObject* >  maAllIncarnatedObjects;
 #endif
 protected:
-    std::vector<rtl::Reference<SdrPage>> maMaPag;     // master pages
+    std::vector<rtl::Reference<SdrPage>> maMasterPages;
     std::vector<rtl::Reference<SdrPage>> maPages;
     std::function<void(std::unique_ptr<SdrUndoAction>)> m_aUndoLink;  // link to a NotifyUndo-Handler
     Size           m_aMaxObjSize; // e.g. for auto-growing text
@@ -176,8 +176,7 @@ protected:
 
     std::unique_ptr<SdrLayerAdmin> m_pLayerAdmin;
     rtl::Reference<SfxItemPool> m_pItemPool;
-    comphelper::IEmbeddedHelper*
-                    m_pEmbeddedHelper; // helper for embedded objects to get rid of the SfxObjectShell
+    comphelper::IEmbeddedHelper* m_pEmbeddedHelper; // helper for embedded objects to get rid of the SfxObjectShell
     std::unique_ptr<SdrOutliner> m_pDrawOutliner;  // an Outliner for outputting text
     std::unique_ptr<SdrOutliner> m_pHitTestOutliner;// an Outliner for the HitTest
     std::unique_ptr<SdrOutliner> m_pChainingOutliner; // an Outliner for chaining overflowing text
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index e8044ec2fda2..f46a34eaf6ec 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -82,95 +82,80 @@ struct SdrModelImpl
 {
     SfxUndoManager* mpUndoManager;
     SdrUndoFactory* mpUndoFactory;
-
     bool mbAnchoredTextOverflowLegacy; // tdf#99729 compatibility flag
-};
 
+    SdrModelImpl()
+        : mpUndoManager(nullptr)
+        , mpUndoFactory(nullptr)
+        , mbAnchoredTextOverflowLegacy(false)
+    {}
+};
 
-SdrModel::SdrModel(
-    SfxItemPool* pPool,
-    ::comphelper::IEmbeddedHelper* _pEmbeddedHelper,
-    bool bDisablePropertyFiles)
-:
-#ifdef DBG_UTIL
-    // SdrObjectLifetimeWatchDog:
-    maAllIncarnatedObjects(),
-#endif
-    maMaPag(),
-    maPages()
-{
-    mpImpl.reset(new SdrModelImpl);
-    mpImpl->mpUndoManager=nullptr;
-    mpImpl->mpUndoFactory=nullptr;
-    mpImpl->mbAnchoredTextOverflowLegacy = false;
-    mbInDestruction = false;
-    m_aObjUnit=SdrEngineDefaults::GetMapFraction();
-    m_eObjUnit=SdrEngineDefaults::GetMapUnit();
-    m_eUIUnit=FieldUnit::MM;
-    m_aUIScale=Fraction(1,1);
-    m_nUIUnitDecimalMark=0;
-    m_pLayerAdmin=nullptr;
-    m_pItemPool=pPool;
-    m_bIsWriter=true;
-    m_pEmbeddedHelper=_pEmbeddedHelper;
-    m_pDrawOutliner=nullptr;
-    m_pHitTestOutliner=nullptr;
-    m_pRefOutDev=nullptr;
-    m_pDefaultStyleSheet=nullptr;
-    mpDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj = nullptr;
-    m_pLinkManager=nullptr;
-    m_nMaxUndoCount=16;
-    m_pCurrentUndoGroup=nullptr;
-    m_nUndoLevel=0;
-    mbUndoEnabled=true;
-    mbChanged = false;
-    m_bPagNumsDirty=false;
-    m_bMPgNumsDirty=false;
-    m_bTransportContainer = false;
-    m_bSwapGraphics=false;
-    m_bPasteResize=false;
-    m_bReadOnly=false;
-    m_nDefaultTabulator=0;
-    m_bTransparentTextFrames=false;
-    m_bStarDrawPreviewMode = false;
-    mpForbiddenCharactersTable = nullptr;
-    mbModelLocked = false;
-    mpOutlinerCache = nullptr;
-    mbKernAsianPunctuation = false;
-    mbAddExtLeading = false;
-    mnHandoutPageCount = 0;
-
-    mbDisableTextEditUsesCommonUndoManager = false;
 
+SdrModel::SdrModel(SfxItemPool* pPool, comphelper::IEmbeddedHelper* pEmbeddedHelper, bool bDisablePropertyFiles)
+    : m_aObjUnit(SdrEngineDefaults::GetMapFraction())
+    , m_eObjUnit(SdrEngineDefaults::GetMapUnit())
+    , m_eUIUnit(FieldUnit::MM)
+    , m_aUIScale(Fraction(1,1))
+    , m_nUIUnitDecimalMark(0)
+    , m_pLayerAdmin(new SdrLayerAdmin)
+    , m_pItemPool(pPool)
+    , m_pEmbeddedHelper(pEmbeddedHelper)
+    , mnDefTextHgt(SdrEngineDefaults::GetFontHeight())
+    , m_pRefOutDev(nullptr)
+    , m_pDefaultStyleSheet(nullptr)
+    , mpDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(nullptr)
+    , m_pLinkManager(nullptr)
+    , m_nUndoLevel(0)
+    , m_bIsWriter(true)
+    , mbUndoEnabled(true)
+    , mbChanged(false)
+    , m_bPagNumsDirty(false)
+    , m_bMPgNumsDirty(false)
+    , m_bTransportContainer(false)
+    , m_bReadOnly(false)
+    , m_bTransparentTextFrames(false)
+    , m_bSwapGraphics(false)
+    , m_bPasteResize(false)
+    , m_bStarDrawPreviewMode(false)
+    , mbDisableTextEditUsesCommonUndoManager(false)
+    , m_nDefaultTabulator(0)
+    , m_nMaxUndoCount(16)
+    , m_pTextChain(new TextChain)
+    , mpImpl(new SdrModelImpl)
+    , mnCharCompressType(CharCompressType::NONE)
+    , mnHandoutPageCount(0)
+    , mbModelLocked(false)
+    , mbKernAsianPunctuation(false)
+    , mbAddExtLeading(false)
+    , mbInDestruction(false)
+{
     if (!utl::ConfigManager::IsFuzzing())
-        mnCharCompressType = static_cast<CharCompressType>(officecfg::Office::Common::AsianLayout::CompressCharacterDistance::
-            get());
-    else
-        mnCharCompressType = CharCompressType::NONE;
+    {
+        mnCharCompressType = static_cast<CharCompressType>(
+            officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get());
+    }
 
-    if ( pPool == nullptr )
+    if (m_pItemPool == nullptr)
     {
-        m_pItemPool=new SdrItemPool(nullptr);
+        m_pItemPool = new SdrItemPool(nullptr);
         // Outliner doesn't have its own Pool, so use the EditEngine's
         rtl::Reference<SfxItemPool> pOutlPool=EditEngine::CreatePool();
         // OutlinerPool as SecondaryPool of SdrPool
         m_pItemPool->SetSecondaryPool(pOutlPool.get());
         // remember that I created both pools myself
-        m_bIsWriter=false;
+        m_bIsWriter = false;
     }
     m_pItemPool->SetDefaultMetric(m_eObjUnit);
 
 // using static SdrEngineDefaults only if default SvxFontHeight item is not available
     const SfxPoolItem* pPoolItem = m_pItemPool->GetPoolDefaultItem( EE_CHAR_FONTHEIGHT );
-    if ( pPoolItem )
+    if (pPoolItem)
         mnDefTextHgt = static_cast<const SvxFontHeightItem*>(pPoolItem)->GetHeight();
-    else
-        mnDefTextHgt = SdrEngineDefaults::GetFontHeight();
 
     m_pItemPool->SetPoolDefaultItem( makeSdrTextWordWrapItem( false ) );
 
     SetTextDefaults();
-    m_pLayerAdmin.reset(new SdrLayerAdmin);
     m_pLayerAdmin->SetModel(this);
     ImpSetUIUnit();
 
@@ -187,16 +172,11 @@ SdrModel::SdrModel(
     m_pChainingOutliner = SdrMakeOutliner( OutlinerMode::TextObject, *this );
     ImpSetOutlinerDefaults(m_pChainingOutliner.get(), true);
 
-    // Make a TextChain
-    m_pTextChain.reset(new TextChain);
-    /* End Text Chaining related code */
-
     ImpCreateTables(bDisablePropertyFiles || utl::ConfigManager::IsFuzzing());
 }
 
 SdrModel::~SdrModel()
 {
-
     mbInDestruction = true;
 
     Broadcast(SdrHint(SdrHintKind::ModelCleared));
@@ -591,7 +571,7 @@ void SdrModel::ClearModel(bool bCalledFromDestructor)
     {
         DeleteMasterPage( static_cast<sal_uInt16>(i) );
     }
-    maMaPag.clear();
+    maMasterPages.clear();
     MasterPageListChanged();
 
     m_pLayerAdmin->ClearLayers();
@@ -1175,10 +1155,10 @@ void SdrModel::RecalcPageNums(bool bMaster)
 {
     if(bMaster)
     {
-        sal_uInt16 nCount=sal_uInt16(maMaPag.size());
+        sal_uInt16 nCount=sal_uInt16(maMasterPages.size());
         sal_uInt16 i;
         for (i=0; i<nCount; i++) {
-            SdrPage* pPg = maMaPag[i].get();
+            SdrPage* pPg = maMasterPages[i].get();
             pPg->SetPageNum(i);
         }
         m_bMPgNumsDirty=false;
@@ -1197,9 +1177,11 @@ void SdrModel::RecalcPageNums(bool bMaster)
 
 void SdrModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
 {
-    sal_uInt16 nCount=GetPageCount();
-    if (nPos>nCount) nPos=nCount;
-    maPages.insert(maPages.begin()+nPos,pPage);
+    sal_uInt16 nCount = GetPageCount();
+    if (nPos > nCount)
+        nPos = nCount;
+
+    maPages.insert(maPages.begin() + nPos, pPage);
     PageListChanged();
     pPage->SetInserted();
     pPage->SetPageNum(nPos);
@@ -1250,7 +1232,7 @@ void SdrModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
 {
     sal_uInt16 nCount=GetMasterPageCount();
     if (nPos>nCount) nPos=nCount;
-    maMaPag.insert(maMaPag.begin()+nPos,pPage);
+    maMasterPages.insert(maMasterPages.begin()+nPos,pPage);
     MasterPageListChanged();
     pPage->SetInserted();
     pPage->SetPageNum(nPos);
@@ -1271,8 +1253,8 @@ void SdrModel::DeleteMasterPage(sal_uInt16 nPgNum)
 
 rtl::Reference<SdrPage> SdrModel::RemoveMasterPage(sal_uInt16 nPgNum)
 {
-    rtl::Reference<SdrPage> pRetPg = std::move(maMaPag[nPgNum]);
-    maMaPag.erase(maMaPag.begin()+nPgNum);
+    rtl::Reference<SdrPage> pRetPg = std::move(maMasterPages[nPgNum]);
+    maMasterPages.erase(maMasterPages.begin()+nPgNum);
     MasterPageListChanged();
 
     if(pRetPg)
@@ -1297,12 +1279,12 @@ rtl::Reference<SdrPage> SdrModel::RemoveMasterPage(sal_uInt16 nPgNum)
 
 void SdrModel::MoveMasterPage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
 {
-    rtl::Reference<SdrPage> pPg = std::move(maMaPag[nPgNum]);
-    maMaPag.erase(maMaPag.begin()+nPgNum);
+    rtl::Reference<SdrPage> pPg = std::move(maMasterPages[nPgNum]);
+    maMasterPages.erase(maMasterPages.begin()+nPgNum);
     MasterPageListChanged();
     if (pPg) {
         pPg->SetInserted(false);
-        maMaPag.insert(maMaPag.begin()+nNewPos,pPg);
+        maMasterPages.insert(maMasterPages.begin()+nNewPos,pPg);
         MasterPageListChanged();
     }
     m_bMPgNumsDirty=true;
@@ -1478,7 +1460,7 @@ void SdrModel::Merge(SdrModel& rSourceModel,
                     // Now append all of them to the end of the DstModel.
                     // Don't use InsertMasterPage(), because everything is
                     // inconsistent until all are in.
-                    maMaPag.insert(maMaPag.begin()+nDstMasterPageCnt, pPg);
+                    maMasterPages.insert(maMasterPages.begin()+nDstMasterPageCnt, pPg);
                     MasterPageListChanged();
                     pPg->SetInserted();
                     m_bMPgNumsDirty=true;
@@ -1833,19 +1815,19 @@ TextChain *SdrModel::GetTextChain() const
 
 const SdrPage* SdrModel::GetMasterPage(sal_uInt16 nPgNum) const
 {
-    DBG_ASSERT(nPgNum < maMaPag.size(), "SdrModel::GetMasterPage: Access out of range (!)");
-    return maMaPag[nPgNum].get();
+    DBG_ASSERT(nPgNum < maMasterPages.size(), "SdrModel::GetMasterPage: Access out of range (!)");
+    return maMasterPages[nPgNum].get();
 }
 
 SdrPage* SdrModel::GetMasterPage(sal_uInt16 nPgNum)
 {
-    DBG_ASSERT(nPgNum < maMaPag.size(), "SdrModel::GetMasterPage: Access out of range (!)");
-    return maMaPag[nPgNum].get();
+    DBG_ASSERT(nPgNum < maMasterPages.size(), "SdrModel::GetMasterPage: Access out of range (!)");
+    return maMasterPages[nPgNum].get();
 }
 
 sal_uInt16 SdrModel::GetMasterPageCount() const
 {
-    return sal_uInt16(maMaPag.size());
+    return sal_uInt16(maMasterPages.size());
 }
 
 void SdrModel::MasterPageListChanged()


More information about the Libreoffice-commits mailing list