summaryrefslogtreecommitdiff
path: root/sdext
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-06-29 16:36:16 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-06-29 22:10:27 +0200
commiteefba50f5908d535bce81b5b0d3d883715b6575e (patch)
tree68002ca8a6fd8ba80893293c0555bdba12d213d3 /sdext
parent9586d734c22e8650d0a060ec23d0bee6444d8bdb (diff)
tdf#137544 reduce work in sdext::PageElement::resolveUnderlines
when opening complex pdf Change-Id: I67146a60d016964c96a3994c5a0334287f7bab0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136654 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sdext')
-rw-r--r--sdext/source/pdfimport/tree/genericelements.cxx17
1 files changed, 12 insertions, 5 deletions
diff --git a/sdext/source/pdfimport/tree/genericelements.cxx b/sdext/source/pdfimport/tree/genericelements.cxx
index f4dee87c71cb..2eb789616b30 100644
--- a/sdext/source/pdfimport/tree/genericelements.cxx
+++ b/sdext/source/pdfimport/tree/genericelements.cxx
@@ -332,6 +332,14 @@ void PageElement::resolveUnderlines( PDFIProcessor const & rProc )
// FIXME: currently the algorithm used is quadratic
// this could be solved by some sorting beforehand
+ std::vector<Element*> textAndHypers;
+ textAndHypers.reserve(Children.size());
+ for (auto const & p : Children)
+ {
+ if (dynamic_cast< TextElement* >(p.get()) || dynamic_cast<HyperlinkElement*>(p.get()))
+ textAndHypers.push_back(p.get());
+ }
+
auto poly_it = Children.begin();
while( poly_it != Children.end() )
{
@@ -372,9 +380,8 @@ void PageElement::resolveUnderlines( PDFIProcessor const & rProc )
u_y = r_x; r_x = l_x; l_x = u_y;
}
u_y = aPoly.getB2DPoint(0).getY();
- for( const auto& rxChild : Children )
+ for( Element* pEle : textAndHypers )
{
- Element* pEle = rxChild.get();
if( pEle->y <= u_y && pEle->y + pEle->h*1.1 >= u_y )
{
// first: is the element underlined completely ?
@@ -394,13 +401,13 @@ void PageElement::resolveUnderlines( PDFIProcessor const & rProc )
pText->FontId = rProc.getFontId( aAttr );
}
}
- else if( dynamic_cast< HyperlinkElement* >(pEle) )
+ else // must be HyperlinkElement
bRemovePoly = true;
}
// second: hyperlinks may be larger than their underline
// since they are just arbitrary rectangles in the action definition
- else if( dynamic_cast< HyperlinkElement* >(pEle) != nullptr &&
- l_x >= pEle->x && r_x <= pEle->x+pEle->w )
+ else if( l_x >= pEle->x && r_x <= pEle->x+pEle->w &&
+ dynamic_cast< HyperlinkElement* >(pEle) != nullptr )
{
bRemovePoly = true;
}