diff --git a/core/area.h b/core/area.h index 18a11874e..1a164ae46 100644 --- a/core/area.h +++ b/core/area.h @@ -275,24 +275,34 @@ struct HighlightRect : public NormalizedRect /** @internal */ template -class okularDeleter +class okularPtrUtils { public: static void doDelete( T& t ) { (void)t; } + + static T* givePtr( T& t ) + { + return &t; + } }; /** @internal */ template -class okularDeleter +class okularPtrUtils { public: static void doDelete( T* t ) { delete t; } + + static T* givePtr( T* t ) + { + return t; + } }; /** @@ -315,6 +325,7 @@ template class RegularArea : public QList< bool intersects (const RegularArea * area) const; bool intersects (const NormalizedShape& shape) const; void appendArea (const RegularArea *area); + void appendShape( const NormalizedShape& shape ); void simplify (); bool isNull() const; QList* geometry( int xScale, int yScale, int dx=0,int dy=0 ) const; @@ -325,7 +336,7 @@ RegularArea::~RegularArea() { int size = this->count(); for ( int i = 0; i < size; ++i ) - okularDeleter::doDelete( (*this)[i] ); + okularPtrUtils::doDelete( (*this)[i] ); } template @@ -342,7 +353,7 @@ void RegularArea::simplify() *((*this)[x]) |= *((*this)[i+1]); NormalizedShape tobedeleted = (*this)[i+1]; this->removeAt( i + 1 ); - okularDeleter::doDelete( tobedeleted ); + okularPtrUtils::doDelete( tobedeleted ); --end; --i; } @@ -420,6 +431,33 @@ void RegularArea::appendArea( const RegularArea +void RegularArea::appendShape( const NormalizedShape& shape ) +{ + if ( !this ) + return; + + int size = this->count(); + // if the list is empty, adds the shape normally + if ( size == 0 ) + { + this->append( shape ); + } + else + { + // if the new shape intersects with the last shape in the list, then + // merge it with that and delete the shape + if ( (*this)[size - 1]->intersects( shape ) ) + { + *((*this)[size - 1]) |= *okularPtrUtils::givePtr( shape ); + okularPtrUtils::doDelete( shape ); + } + else + this->append( shape ); + } +} + + template bool RegularArea::contains( double x, double y ) const { diff --git a/core/textpage.cpp b/core/textpage.cpp index 5a3b58206..8b0425c90 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -215,7 +215,7 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const { tmp=d->m_words[it]->area(); if (tmp->intersects(&first)) - ret->append(tmp); + ret->appendShape(tmp); } } else*/ @@ -234,13 +234,12 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const { tmp=d->m_words[it]->transformedArea(); if (tmp->intersects(&first) || tmp->intersects(&second) || tmp->intersects(&third)) - ret->append(new NormalizedRect(*tmp)); + ret->appendShape(new NormalizedRect(*tmp)); } // } } - ret->simplify(); return ret; }