[Libreoffice-commits] core.git: sw/inc sw/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Oct 31 08:54:02 PDT 2014


 sw/inc/textboxhelper.hxx               |    8 ++++++++
 sw/source/core/doc/textboxhelper.cxx   |   33 +++++++++++++++++++++++++++++++++
 sw/source/core/unocore/unoportenum.cxx |    2 +-
 3 files changed, 42 insertions(+), 1 deletion(-)

New commits:
commit 6606313d6e69fbab7841f60de8bc152ce605e46b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Oct 31 16:31:11 2014 +0100

    Add a SwTextBoxHelper::findTextBoxes() variant that takes an SwNode
    
    This method is called by the ODF export for each paragraph, so limiting
    the result for TextBoxes anchored to a single paragraph helps to avoid
    iterating over all the frames for each paragraph.
    
    For a test document of 2000 mail merge records and 16 frames, the times for
    css::text::MailMerge::execute() are 8m18.811s -> 7m53.575s.
    
    Change-Id: I7a9cd7b23a3e903059ec0ae3a6a8f8309681bb2e

diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index 1a59df5..5473979 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -29,6 +29,7 @@ class SwFmtCntnt;
 class SwDoc;
 class Rectangle;
 class _ZSortFly;
+class SwNode;
 
 /**
  * A TextBox is a TextFrame, that is tied to a drawinglayer shape.
@@ -68,6 +69,13 @@ public:
 
     /// Look up TextFrames in a document, which are in fact TextBoxes.
     static std::set<const SwFrmFmt*> findTextBoxes(const SwDoc* pDoc);
+    /**
+     * Look up TextFrames in a document, which are in fact TextBoxes.
+     *
+     * If rNode has a matching SwCntntFrm, then only TextBoxes of rNode are
+     * returned.
+     */
+    static std::set<const SwFrmFmt*> findTextBoxes(const SwNode& rNode);
     /// Build a textbox -> shape format map.
     static std::map<SwFrmFmt*, SwFrmFmt*> findShapes(const SwDoc* pDoc);
     /// Count number of shapes in the document, excluding TextBoxes.
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 6554588..122b3b3 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -29,6 +29,9 @@
 #include <unoprnms.hxx>
 #include <dflyobj.hxx>
 #include <mvsave.hxx>
+#include <sortedobjs.hxx>
+#include <anchoredobject.hxx>
+#include <cntfrm.hxx>
 
 #include <editeng/unoprnms.hxx>
 #include <editeng/charrotateitem.hxx>
@@ -132,6 +135,36 @@ std::set<const SwFrmFmt*> SwTextBoxHelper::findTextBoxes(const SwDoc* pDoc)
     return aRet;
 }
 
+std::set<const SwFrmFmt*> SwTextBoxHelper::findTextBoxes(const SwNode& rNode)
+{
+    const SwDoc* pDoc = rNode.GetDoc();
+    const SwCntntNode* pCntntNode = 0;
+    const SwCntntFrm* pCntntFrm = 0;
+    if (pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() &&
+        (pCntntNode = rNode.GetCntntNode()) &&
+        (pCntntFrm = pCntntNode->getLayoutFrm(pDoc->getIDocumentLayoutAccess().GetCurrentLayout())))
+    {
+        // We can use the layout information to iterate over only the frames which are anchored to us.
+        std::set<const SwFrmFmt*> aRet;
+        const SwSortedObjs* pSortedObjs = pCntntFrm->GetDrawObjs();
+        if (pSortedObjs)
+        {
+            for (size_t i = 0; i < pSortedObjs->size(); ++i)
+            {
+                SwAnchoredObject* pAnchoredObject = (*pSortedObjs)[i];
+                SwFrmFmt* pTextBox = findTextBox(&pAnchoredObject->GetFrmFmt());
+                if (pTextBox)
+                    aRet.insert(pTextBox);
+            }
+        }
+        return aRet;
+    }
+    else
+        // If necessary, here we could manually limit the returned set to the
+        // ones which are anchored to rNode, but currently no need to do so.
+        return findTextBoxes(pDoc);
+}
+
 std::map<SwFrmFmt*, SwFrmFmt*> SwTextBoxHelper::findShapes(const SwDoc* pDoc)
 {
     std::map<SwFrmFmt*, SwFrmFmt*> aRet;
diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx
index 35e074a..1aa2bd5 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -1281,7 +1281,7 @@ static void lcl_CreatePortions(
     PortionStack_t PortionStack;
     PortionStack.push( PortionList_t(&i_rPortions, (const SwTxtAttr *)0) );
 
-    std::set<const SwFrmFmt*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc);
+    std::set<const SwFrmFmt*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pUnoCrsr->GetNode());
 
     bool bAtEnd( false );
     while (!bAtEnd) // every iteration consumes at least current character!


More information about the Libreoffice-commits mailing list