diff --git a/core/page.cpp b/core/page.cpp index 59c792f1a..611b5ec9c 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -274,8 +274,9 @@ void Page::rotateAt( int orientation ) deleteHighlights(); deleteTextSelections(); - delete d->m_text; - d->m_text = 0; + + if ( d->m_text ) + d->m_text->transform( d->rotationMatrix() ); if ( ( d->m_orientation + d->m_rotation ) % 2 != ( d->m_orientation + neworientation ) % 2 ) qSwap( d->m_width, d->m_height ); @@ -377,6 +378,9 @@ void Page::setPixmap( int id, QPixmap *pixmap ) void Page::setTextPage( TextPage * textPage ) { delete d->m_text; + + textPage->transform( d->rotationMatrix() ); + d->m_text = textPage; } diff --git a/core/textpage.cpp b/core/textpage.cpp index 097a0347c..92700bd77 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -29,13 +29,15 @@ class SearchPoint }; TextEntity::TextEntity( const QString &text, NormalizedRect *area ) - : m_text( text ), m_area( area ), d( 0 ) + : m_text( text ), m_area( area ), m_transformed_area( 0 ), d( 0 ) { + m_transformed_area = new NormalizedRect( *m_area ); } TextEntity::~TextEntity() { delete m_area; + delete m_transformed_area; } QString TextEntity::text() const @@ -48,6 +50,17 @@ NormalizedRect* TextEntity::area() const return m_area; } +NormalizedRect* TextEntity::transformedArea() const +{ + return m_transformed_area; +} + +void TextEntity::transform( const QMatrix &matrix ) +{ + *m_transformed_area = *m_area; + m_transformed_area->transform( matrix ); +} + class TextPage::Private { public: @@ -125,7 +138,7 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const #endif for (it=0;itm_words.count();it++) { - tmp=d->m_words[it]->area(); + tmp=d->m_words[it]->transformedArea(); if (tmp->contains(startCx,startCy) || ( tmp->top <= startCy && tmp->bottom >= startCy && tmp->left >= startCx ) || ( tmp->top >= startCy)) @@ -153,7 +166,7 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const #endif for (it=d->m_words.count()-1; it>=itB;it--) { - tmp=d->m_words[it]->area(); + tmp=d->m_words[it]->transformedArea(); if (tmp->contains(endCx,endCy) || ( tmp->top <= endCy && tmp->bottom >= endCy && tmp->right <= endCx ) || ( tmp->bottom <= endCy)) @@ -178,8 +191,8 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const if (sel->itB()!=-1 && sel->itE()!=-1) { - start=d->m_words[sel->itB()]->area(); - end=d->m_words[sel->itE()]->area(); + start=d->m_words[sel->itB()]->transformedArea(); + end=d->m_words[sel->itE()]->transformedArea(); NormalizedRect first,second,third;/* first.right=1; @@ -214,7 +227,7 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const int selMax = qMax( sel->itB(), sel->itE() ); for ( it = qMin( sel->itB(), sel->itE() ); it <= selMax; ++it ) { - tmp=d->m_words[it]->area(); + tmp=d->m_words[it]->transformedArea(); if (tmp->intersects(&first) || tmp->intersects(&second) || tmp->intersects(&third)) ret->append(new NormalizedRect(*tmp)); } @@ -373,7 +386,7 @@ RegularAreaRect* TextPage::Private::findTextInternalForward( int searchID, const kDebug(1223) << "\tmatched" << endl; #endif haveMatch=true; - ret->append( curEntity->area() ); + ret->append( curEntity->transformedArea() ); j+=min; queryLeft-=min; } @@ -417,7 +430,7 @@ QString TextPage::text(const RegularAreaRect *area) const for ( it = d->m_words.begin(); it != end; ++it ) { // provide the string FIXME?: newline handling - if (area->intersects((*it)->area())) + if (area->intersects((*it)->transformedArea())) { // kDebug()<< "[" << (*it)->area->left << "," << (*it)->area->top << "]x["<< (*it)->area->right << "," << (*it)->area->bottom << "]\n"; ret += (*it)->text(); @@ -427,3 +440,8 @@ QString TextPage::text(const RegularAreaRect *area) const return ret; } +void TextPage::transform( const QMatrix &matrix ) +{ + for ( int i = 0; i < d->m_words.count(); ++i ) + d->m_words[ i ]->transform( matrix ); +} diff --git a/core/textpage.h b/core/textpage.h index 672d5cb47..bdcb3caea 100644 --- a/core/textpage.h +++ b/core/textpage.h @@ -78,9 +78,20 @@ class TextEntity */ NormalizedRect* area() const; + /** + * Returns the transformed area of the text entity. + */ + NormalizedRect* transformedArea() const; + + /** + * Transforms the area coordinates of the text entity. + */ + void transform( const QMatrix &matrix ); + private: QString m_text; NormalizedRect* m_area; + NormalizedRect* m_transformed_area; class Private; Private *d; @@ -142,6 +153,11 @@ class TextPage */ RegularAreaRect *textArea( TextSelection *selection ) const; + /** + * Transforms the area coordinates of the text entities. + */ + void transform( const QMatrix &matrix ); + private: class Private; Private* const d;