summaryrefslogtreecommitdiff
path: root/sdext/source/pdfimport
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2018-12-03 00:52:17 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-12-03 08:14:15 +0100
commit056845403c387f1fe286f9df13f73fa2fc6d0014 (patch)
tree34fcb1196b3a1f863bc87915355cb24143cfa9bc /sdext/source/pdfimport
parent83a72f46d34fde7a119b00fcc0a7bf58dbe0076a (diff)
Simplify containers iterations in sdext
Use range-based loop or replace with STL functions Change-Id: I760c1aaeae9afc99effee6a2645bb77439260ddf Reviewed-on: https://gerrit.libreoffice.org/64435 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sdext/source/pdfimport')
-rw-r--r--sdext/source/pdfimport/odf/odfemitter.cxx9
-rw-r--r--sdext/source/pdfimport/sax/emitcontext.cxx6
-rw-r--r--sdext/source/pdfimport/sax/saxattrlist.cxx8
-rw-r--r--sdext/source/pdfimport/tree/drawtreevisiting.cxx23
-rw-r--r--sdext/source/pdfimport/tree/genericelements.cxx26
-rw-r--r--sdext/source/pdfimport/tree/style.cxx15
-rw-r--r--sdext/source/pdfimport/tree/style.hxx12
-rw-r--r--sdext/source/pdfimport/tree/writertreevisiting.cxx97
8 files changed, 88 insertions, 108 deletions
diff --git a/sdext/source/pdfimport/odf/odfemitter.cxx b/sdext/source/pdfimport/odf/odfemitter.cxx
index f83c7323193c..78a38e42502f 100644
--- a/sdext/source/pdfimport/odf/odfemitter.cxx
+++ b/sdext/source/pdfimport/odf/odfemitter.cxx
@@ -71,17 +71,14 @@ void OdfEmitter::beginTag( const char* pTag, const PropertyMap& rProperties )
aElement.append(" ");
std::vector<OUString> aAttributes;
- PropertyMap::const_iterator aCurr(rProperties.begin());
- const PropertyMap::const_iterator aEnd(rProperties.end());
- while( aCurr != aEnd )
+ for( const auto& rCurr : rProperties )
{
OUStringBuffer aAttribute;
- aAttribute.append(aCurr->first);
+ aAttribute.append(rCurr.first);
aAttribute.append("=\"");
- aAttribute.append(aCurr->second);
+ aAttribute.append(rCurr.second);
aAttribute.append("\" ");
aAttributes.push_back(aAttribute.makeStringAndClear());
- ++aCurr;
}
// since the hash map's sorting is undefined (and varies across
diff --git a/sdext/source/pdfimport/sax/emitcontext.cxx b/sdext/source/pdfimport/sax/emitcontext.cxx
index f21b17e60c88..8eab0e0b5ddf 100644
--- a/sdext/source/pdfimport/sax/emitcontext.cxx
+++ b/sdext/source/pdfimport/sax/emitcontext.cxx
@@ -116,12 +116,12 @@ void SaxEmitter::beginTag( const char* pTag, const PropertyMap& rProperties )
OStringBuffer aBuf( 1024 );
aBuf.append( '<' );
aBuf.append( pTag );
- for( PropertyMap::const_iterator it = rProperties.begin(); it != rProperties.end(); ++it )
+ for( const auto& rProperty : rProperties )
{
aBuf.append( ' ' );
- aBuf.append( OUStringToOString( it->first, RTL_TEXTENCODING_UTF8 ) );
+ aBuf.append( OUStringToOString( rProperty.first, RTL_TEXTENCODING_UTF8 ) );
aBuf.append( "=\"" );
- aBuf.append( OUStringToOString( it->second, RTL_TEXTENCODING_UTF8 ) );
+ aBuf.append( OUStringToOString( rProperty.second, RTL_TEXTENCODING_UTF8 ) );
aBuf.append( "\"" );
}
aBuf.append( ">\n" );
diff --git a/sdext/source/pdfimport/sax/saxattrlist.cxx b/sdext/source/pdfimport/sax/saxattrlist.cxx
index feb6b3ba9385..8efb6b4c9acc 100644
--- a/sdext/source/pdfimport/sax/saxattrlist.cxx
+++ b/sdext/source/pdfimport/sax/saxattrlist.cxx
@@ -26,12 +26,10 @@ namespace pdfi
SaxAttrList::SaxAttrList( const std::unordered_map< OUString, OUString >& rMap )
{
m_aAttributes.reserve(rMap.size());
- for( std::unordered_map< OUString,
- OUString >::const_iterator it = rMap.begin();
- it != rMap.end(); ++it )
+ for( const auto& rEntry : rMap )
{
- m_aIndexMap[ it->first ] = m_aAttributes.size();
- m_aAttributes.emplace_back( it->first, it->second );
+ m_aIndexMap[ rEntry.first ] = m_aAttributes.size();
+ m_aAttributes.emplace_back( rEntry.first, rEntry.second );
}
}
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.cxx b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
index d845d827ce5d..8182d5fd47eb 100644
--- a/sdext/source/pdfimport/tree/drawtreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
@@ -500,10 +500,9 @@ void DrawXmlOptimizer::visit( PageElement& elem, const std::list< std::unique_pt
// adjust line height and text items
fCurLineHeight = 0.0;
nCurLineElements = 0;
- for( auto it = pCurPara->Children.begin();
- it != pCurPara->Children.end(); ++it )
+ for( auto& rxChild : pCurPara->Children )
{
- TextElement* pTestText = dynamic_cast<TextElement*>(it->get());
+ TextElement* pTestText = dynamic_cast<TextElement*>(rxChild.get());
if( pTestText )
{
fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pTestText->h)/double(nCurLineElements+1);
@@ -985,16 +984,16 @@ void DrawXmlFinalizer::visit( PageElement& elem, const std::list< std::unique_pt
elem.LeftMargin = elem.w;
elem.RightMargin = 0;
- for( auto it = elem.Children.begin(); it != elem.Children.end(); ++it )
+ for( const auto& rxChild : elem.Children )
{
- if( (*it)->x < elem.LeftMargin )
- elem.LeftMargin = (*it)->x;
- if( (*it)->y < elem.TopMargin )
- elem.TopMargin = (*it)->y;
- if( (*it)->x + (*it)->w > elem.RightMargin )
- elem.RightMargin = ((*it)->x + (*it)->w);
- if( (*it)->y + (*it)->h > elem.BottomMargin )
- elem.BottomMargin = ((*it)->y + (*it)->h);
+ if( rxChild->x < elem.LeftMargin )
+ elem.LeftMargin = rxChild->x;
+ if( rxChild->y < elem.TopMargin )
+ elem.TopMargin = rxChild->y;
+ if( rxChild->x + rxChild->w > elem.RightMargin )
+ elem.RightMargin = (rxChild->x + rxChild->w);
+ if( rxChild->y + rxChild->h > elem.BottomMargin )
+ elem.BottomMargin = (rxChild->y + rxChild->h);
}
// transform margins to mm
diff --git a/sdext/source/pdfimport/tree/genericelements.cxx b/sdext/source/pdfimport/tree/genericelements.cxx
index d4eb7dcc34d8..152366d6b4bf 100644
--- a/sdext/source/pdfimport/tree/genericelements.cxx
+++ b/sdext/source/pdfimport/tree/genericelements.cxx
@@ -188,15 +188,14 @@ void ParagraphElement::visitedBy( ElementTreeVisitor& r
bool ParagraphElement::isSingleLined( PDFIProcessor const & rProc ) const
{
- auto it = Children.begin();
TextElement* pText = nullptr, *pLastText = nullptr;
- while( it != Children.end() )
+ for( auto& rxChild : Children )
{
// a paragraph containing subparagraphs cannot be single lined
- if( dynamic_cast< ParagraphElement* >(it->get()) != nullptr )
+ if( dynamic_cast< ParagraphElement* >(rxChild.get()) != nullptr )
return false;
- pText = dynamic_cast< TextElement* >(it->get());
+ pText = dynamic_cast< TextElement* >(rxChild.get());
if( pText )
{
const FontAttributes& rFont = rProc.getFont( pText->FontId );
@@ -211,7 +210,6 @@ bool ParagraphElement::isSingleLined( PDFIProcessor const & rProc ) const
else
pLastText = pText;
}
- ++it;
}
// a paragraph without a single text is not considered single lined
@@ -221,9 +219,9 @@ bool ParagraphElement::isSingleLined( PDFIProcessor const & rProc ) const
double ParagraphElement::getLineHeight( PDFIProcessor& rProc ) const
{
double line_h = 0;
- for( auto it = Children.begin(); it != Children.end(); ++it )
+ for( auto& rxChild : Children )
{
- ParagraphElement* pPara = dynamic_cast< ParagraphElement* >(it->get());
+ ParagraphElement* pPara = dynamic_cast< ParagraphElement* >(rxChild.get());
TextElement* pText = nullptr;
if( pPara )
{
@@ -231,7 +229,7 @@ double ParagraphElement::getLineHeight( PDFIProcessor& rProc ) const
if( lh > line_h )
line_h = lh;
}
- else if( (pText = dynamic_cast< TextElement* >( it->get() )) != nullptr )
+ else if( (pText = dynamic_cast< TextElement* >( rxChild.get() )) != nullptr )
{
const FontAttributes& rFont = rProc.getFont( pText->FontId );
double lh = pText->h;
@@ -247,11 +245,10 @@ double ParagraphElement::getLineHeight( PDFIProcessor& rProc ) const
TextElement* ParagraphElement::getFirstTextChild() const
{
TextElement* pText = nullptr;
- for( auto it = Children.begin();
- it != Children.end() && ! pText; ++it )
- {
+ auto it = std::find_if(Children.begin(), Children.end(),
+ [](const std::unique_ptr<Element>& rxElem) { return dynamic_cast<TextElement*>(rxElem.get()) != nullptr; });
+ if (it != Children.end())
pText = dynamic_cast<TextElement*>(it->get());
- }
return pText;
}
@@ -378,10 +375,9 @@ 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( auto it = Children.begin();
- it != Children.end(); ++it )
+ for( auto& rxChild : Children )
{
- Element* pEle = it->get();
+ Element* pEle = rxChild.get();
if( pEle->y <= u_y && pEle->y + pEle->h*1.1 >= u_y )
{
// first: is the element underlined completely ?
diff --git a/sdext/source/pdfimport/tree/style.cxx b/sdext/source/pdfimport/tree/style.cxx
index a4314fe61ab9..87d0479a564a 100644
--- a/sdext/source/pdfimport/tree/style.cxx
+++ b/sdext/source/pdfimport/tree/style.cxx
@@ -210,17 +210,16 @@ void StyleContainer::emit( EmitContext& rContext,
ElementTreeVisitor& rContainedElemVisitor )
{
std::vector< sal_Int32 > aMasterPageSection, aAutomaticStyleSection, aOfficeStyleSection;
- for( std::unordered_map< sal_Int32, RefCountedHashedStyle >::iterator it = m_aIdToStyle.begin();
- it != m_aIdToStyle.end(); ++it )
+ for( const auto& rEntry : m_aIdToStyle )
{
- if( ! it->second.style.IsSubStyle )
+ if( ! rEntry.second.style.IsSubStyle )
{
- if( it->second.style.Name == "style:master-page" )
- aMasterPageSection.push_back( it->first );
- else if( getStyleName( it->first ) == "standard" )
- aOfficeStyleSection.push_back( it->first );
+ if( rEntry.second.style.Name == "style:master-page" )
+ aMasterPageSection.push_back( rEntry.first );
+ else if( getStyleName( rEntry.first ) == "standard" )
+ aOfficeStyleSection.push_back( rEntry.first );
else
- aAutomaticStyleSection.push_back( it->first );
+ aAutomaticStyleSection.push_back( rEntry.first );
}
}
diff --git a/sdext/source/pdfimport/tree/style.hxx b/sdext/source/pdfimport/tree/style.hxx
index 332fdfb65c80..1eda41ea07a4 100644
--- a/sdext/source/pdfimport/tree/style.hxx
+++ b/sdext/source/pdfimport/tree/style.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_STYLE_HXX
#include <pdfihelper.hxx>
+#include <numeric>
#include <unordered_map>
#include <vector>
#include <rtl/ustring.hxx>
@@ -65,13 +66,10 @@ namespace pdfi
size_t hashCode() const
{
- size_t nRet = size_t(Name.hashCode());
- for( PropertyMap::const_iterator it = Properties.begin();
- it != Properties.end(); ++it )
- {
- nRet ^= size_t(it->first.hashCode());
- nRet ^= size_t(it->second.hashCode());
- }
+ size_t nRet = std::accumulate(Properties.begin(), Properties.end(), size_t(Name.hashCode()),
+ [](const size_t& sum, const PropertyMap::value_type& rEntry) {
+ return sum ^ size_t(rEntry.first.hashCode()) ^ size_t(rEntry.second.hashCode());
+ });
nRet ^= size_t(Contents.hashCode());
nRet ^= size_t(ContainedElement);
for( size_t n = 0; n < SubStyles.size(); ++n )
diff --git a/sdext/source/pdfimport/tree/writertreevisiting.cxx b/sdext/source/pdfimport/tree/writertreevisiting.cxx
index 2e83a9b30316..6e37899fbd55 100644
--- a/sdext/source/pdfimport/tree/writertreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/writertreevisiting.cxx
@@ -321,9 +321,9 @@ void WriterXmlEmitter::visit( DocumentElement& elem, const std::list< std::uniqu
m_rEmitContext.rEmitter.beginTag( "office:body", PropertyMap() );
m_rEmitContext.rEmitter.beginTag( "office:text", PropertyMap() );
- for( auto it = elem.Children.begin(); it != elem.Children.end(); ++it )
+ for( auto& rxChild : elem.Children )
{
- PageElement* pPage = dynamic_cast<PageElement*>(it->get());
+ PageElement* pPage = dynamic_cast<PageElement*>(rxChild.get());
if( pPage )
{
// emit only page anchored objects
@@ -512,10 +512,9 @@ void WriterXmlOptimizer::visit( PageElement& elem, const std::list< std::unique_
// adjust line height and text items
fCurLineHeight = 0.0;
nCurLineElements = 0;
- for( auto it = pCurPara->Children.begin();
- it != pCurPara->Children.end(); ++it )
+ for( auto& rxChild : pCurPara->Children )
{
- TextElement* pTestText = dynamic_cast<TextElement*>(it->get());
+ TextElement* pTestText = dynamic_cast<TextElement*>(rxChild.get());
if( pTestText )
{
fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pTestText->h)/double(nCurLineElements+1);
@@ -669,60 +668,54 @@ void WriterXmlOptimizer::checkHeaderAndFooter( PageElement& rElem )
* - at least lineheight below the previous paragraph
*/
+ auto isParagraphElement = [](std::unique_ptr<Element>& rxChild) -> bool {
+ return dynamic_cast<ParagraphElement*>(rxChild.get()) != nullptr;
+ };
+
// detect header
// Note: the following assumes that the pages' children have been
// sorted geometrically
- auto it = rElem.Children.begin();
- while( it != rElem.Children.end() )
+ auto it = std::find_if(rElem.Children.begin(), rElem.Children.end(), isParagraphElement);
+ if (it != rElem.Children.end())
{
ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(it->get());
- if( pPara )
+ if( pPara->y+pPara->h < rElem.h*0.15 && pPara->isSingleLined( m_rProcessor ) )
{
- if( pPara->y+pPara->h < rElem.h*0.15 && pPara->isSingleLined( m_rProcessor ) )
+ auto next_it = it;
+ ParagraphElement* pNextPara = nullptr;
+ while( ++next_it != rElem.Children.end() && pNextPara == nullptr )
{
- auto next_it = it;
- ParagraphElement* pNextPara = nullptr;
- while( ++next_it != rElem.Children.end() && pNextPara == nullptr )
- {
- pNextPara = dynamic_cast<ParagraphElement*>(next_it->get());
- }
- if( pNextPara && pNextPara->y > pPara->y+pPara->h*2 )
- {
- rElem.HeaderElement = std::move(*it);
- pPara->Parent = nullptr;
- rElem.Children.erase( it );
- }
+ pNextPara = dynamic_cast<ParagraphElement*>(next_it->get());
+ }
+ if( pNextPara && pNextPara->y > pPara->y+pPara->h*2 )
+ {
+ rElem.HeaderElement = std::move(*it);
+ pPara->Parent = nullptr;
+ rElem.Children.erase( it );
}
- break;
}
- ++it;
}
// detect footer
- std::list< std::unique_ptr<Element> >::reverse_iterator rit = rElem.Children.rbegin();
- while( rit != rElem.Children.rend() )
+ auto rit = std::find_if(rElem.Children.rbegin(), rElem.Children.rend(), isParagraphElement);
+ if (rit != rElem.Children.rend())
{
ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(rit->get());
- if( pPara )
+ if( pPara->y > rElem.h*0.85 && pPara->isSingleLined( m_rProcessor ) )
{
- if( pPara->y > rElem.h*0.85 && pPara->isSingleLined( m_rProcessor ) )
+ std::list< std::unique_ptr<Element> >::reverse_iterator next_it = rit;
+ ParagraphElement* pNextPara = nullptr;
+ while( ++next_it != rElem.Children.rend() && pNextPara == nullptr )
{
- std::list< std::unique_ptr<Element> >::reverse_iterator next_it = rit;
- ParagraphElement* pNextPara = nullptr;
- while( ++next_it != rElem.Children.rend() && pNextPara == nullptr )
- {
- pNextPara = dynamic_cast<ParagraphElement*>(next_it->get());
- }
- if( pNextPara && pNextPara->y < pPara->y-pPara->h*2 )
- {
- rElem.FooterElement = std::move(*rit);
- pPara->Parent = nullptr;
- rElem.Children.erase( std::next(rit).base() );
- }
+ pNextPara = dynamic_cast<ParagraphElement*>(next_it->get());
+ }
+ if( pNextPara && pNextPara->y < pPara->y-pPara->h*2 )
+ {
+ rElem.FooterElement = std::move(*rit);
+ pPara->Parent = nullptr;
+ rElem.Children.erase( std::next(rit).base() );
}
- break;
}
- ++rit;
}
}
@@ -1099,20 +1092,20 @@ void WriterXmlFinalizer::visit( PageElement& elem, const std::list< std::unique_
elem.RightMargin = 0;
// first element should be a paragraph
ParagraphElement* pFirstPara = nullptr;
- for( auto it = elem.Children.begin(); it != elem.Children.end(); ++it )
+ for( auto& rxChild : elem.Children )
{
- if( dynamic_cast<ParagraphElement*>( it->get() ) )
+ if( dynamic_cast<ParagraphElement*>( rxChild.get() ) )
{
- if( (*it)->x < elem.LeftMargin )
- elem.LeftMargin = (*it)->x;
- if( (*it)->y < elem.TopMargin )
- elem.TopMargin = (*it)->y;
- if( (*it)->x + (*it)->w > elem.w - elem.RightMargin )
- elem.RightMargin = elem.w - ((*it)->x + (*it)->w);
- if( (*it)->y + (*it)->h > elem.h - elem.BottomMargin )
- elem.BottomMargin = elem.h - ((*it)->y + (*it)->h);
+ if( rxChild->x < elem.LeftMargin )
+ elem.LeftMargin = rxChild->x;
+ if( rxChild->y < elem.TopMargin )
+ elem.TopMargin = rxChild->y;
+ if( rxChild->x + rxChild->w > elem.w - elem.RightMargin )
+ elem.RightMargin = elem.w - (rxChild->x + rxChild->w);
+ if( rxChild->y + rxChild->h > elem.h - elem.BottomMargin )
+ elem.BottomMargin = elem.h - (rxChild->y + rxChild->h);
if( ! pFirstPara )
- pFirstPara = dynamic_cast<ParagraphElement*>( it->get() );
+ pFirstPara = dynamic_cast<ParagraphElement*>( rxChild.get() );
}
}
if( elem.HeaderElement && elem.HeaderElement->y < elem.TopMargin )