Kaydet (Commit) 6606313d authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst 2ec4c8b0
...@@ -29,6 +29,7 @@ class SwFmtCntnt; ...@@ -29,6 +29,7 @@ class SwFmtCntnt;
class SwDoc; class SwDoc;
class Rectangle; class Rectangle;
class _ZSortFly; class _ZSortFly;
class SwNode;
/** /**
* A TextBox is a TextFrame, that is tied to a drawinglayer shape. * A TextBox is a TextFrame, that is tied to a drawinglayer shape.
...@@ -68,6 +69,13 @@ public: ...@@ -68,6 +69,13 @@ public:
/// Look up TextFrames in a document, which are in fact TextBoxes. /// Look up TextFrames in a document, which are in fact TextBoxes.
static std::set<const SwFrmFmt*> findTextBoxes(const SwDoc* pDoc); 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. /// Build a textbox -> shape format map.
static std::map<SwFrmFmt*, SwFrmFmt*> findShapes(const SwDoc* pDoc); static std::map<SwFrmFmt*, SwFrmFmt*> findShapes(const SwDoc* pDoc);
/// Count number of shapes in the document, excluding TextBoxes. /// Count number of shapes in the document, excluding TextBoxes.
......
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
#include <unoprnms.hxx> #include <unoprnms.hxx>
#include <dflyobj.hxx> #include <dflyobj.hxx>
#include <mvsave.hxx> #include <mvsave.hxx>
#include <sortedobjs.hxx>
#include <anchoredobject.hxx>
#include <cntfrm.hxx>
#include <editeng/unoprnms.hxx> #include <editeng/unoprnms.hxx>
#include <editeng/charrotateitem.hxx> #include <editeng/charrotateitem.hxx>
...@@ -132,6 +135,36 @@ std::set<const SwFrmFmt*> SwTextBoxHelper::findTextBoxes(const SwDoc* pDoc) ...@@ -132,6 +135,36 @@ std::set<const SwFrmFmt*> SwTextBoxHelper::findTextBoxes(const SwDoc* pDoc)
return aRet; 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*> SwTextBoxHelper::findShapes(const SwDoc* pDoc)
{ {
std::map<SwFrmFmt*, SwFrmFmt*> aRet; std::map<SwFrmFmt*, SwFrmFmt*> aRet;
......
...@@ -1281,7 +1281,7 @@ static void lcl_CreatePortions( ...@@ -1281,7 +1281,7 @@ static void lcl_CreatePortions(
PortionStack_t PortionStack; PortionStack_t PortionStack;
PortionStack.push( PortionList_t(&i_rPortions, (const SwTxtAttr *)0) ); 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 ); bool bAtEnd( false );
while (!bAtEnd) // every iteration consumes at least current character! while (!bAtEnd) // every iteration consumes at least current character!
......
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