From 4fe8bdce536b37a006b68e419cd6807ef0d23e74 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Fri, 29 Dec 2006 18:18:07 +0000 Subject: [PATCH] Fixed free text selection for rotated pages svn path=/trunk/playground/graphics/okular/; revision=617621 --- core/area.h | 22 ++++++++++++++++++---- core/page.cpp | 10 ++++------ generators/poppler/generator_pdf.cpp | 16 ++++++++++------ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/core/area.h b/core/area.h index ad12c7218..12463689b 100644 --- a/core/area.h +++ b/core/area.h @@ -331,13 +331,14 @@ template class RegularArea : public QList< ~RegularArea(); bool contains( double x, double y ) const; bool contains( const NormalizedShape& shape ) const; - bool intersects (const RegularArea * area) const; - bool intersects (const NormalizedShape& shape) const; - void appendArea (const RegularArea *area); + bool intersects( const RegularArea *area ) const; + bool intersects( const NormalizedShape& shape ) const; + void appendArea( const RegularArea *area ); void appendShape( const NormalizedShape& shape ); - void simplify (); + void simplify(); bool isNull() const; QList geometry( int xScale, int yScale, int dx=0,int dy=0 ) const; + void transform( const QMatrix &matrix ); }; template @@ -513,6 +514,19 @@ QList RegularArea::geometry( int xScale, int ySca return ret; } +template +void RegularArea::transform( const QMatrix &matrix ) +{ + if ( !this ) + return; + + if ( this->isEmpty() ) + return; + + for ( int i = 0; i < this->count(); ++i ) + givePtr( (*this)[i] )->transform( matrix ); +} + typedef RegularArea RegularAreaRect; class HighlightAreaRect : public RegularAreaRect diff --git a/core/page.cpp b/core/page.cpp index fa8b1379f..5a8112658 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -256,7 +256,10 @@ QString Page::text( const RegularAreaRect * area ) const if ( !d->m_text ) return ret; - ret = d->m_text->text( area ); + RegularAreaRect rotatedArea = *area; + rotatedArea.transform( d->rotationMatrix().inverted() ); + + ret = d->m_text->text( &rotatedArea ); return ret; } @@ -270,9 +273,6 @@ void Page::rotateAt( int orientation ) deleteHighlights(); deleteTextSelections(); - 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 ); @@ -374,8 +374,6 @@ void Page::setTextPage( TextPage * textPage ) { delete d->m_text; - textPage->transform( d->rotationMatrix() ); - d->m_text = textPage; } diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index 2fcf9e83e..3f757b158 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -623,8 +623,8 @@ void PDFGenerator::generatePixmap( Okular::PixmapRequest * request ) docLock.unlock(); if ( genTextPage ) { - QList textList = p->textList((Poppler::Page::Rotation)request->page()->rotation()); - page->setTextPage( abstractTextPage(textList, page->height(), page->width(), request->page()->totalOrientation()) ); + QList textList = p->textList((Poppler::Page::Rotation)request->page()->orientation()); + page->setTextPage( abstractTextPage(textList, page->height(), page->width(), request->page()->orientation()) ); qDeleteAll(textList); } delete p; @@ -647,11 +647,15 @@ void PDFGenerator::generateSyncTextPage( Okular::Page * page ) // build a TextList... Poppler::Page *pp = pdfdoc->page( page->number() ); docLock.lock(); - QList textList = pp->textList((Poppler::Page::Rotation)page->rotation()); + QList textList = pp->textList((Poppler::Page::Rotation)page->orientation()); docLock.unlock(); delete pp; // ..and attach it to the page - page->setTextPage( abstractTextPage(textList, page->height(), page->width(), page->totalOrientation()) ); + + const double pageWidth = ( page->rotation() % 2 ? page->height() : page->width() ); + const double pageHeight = ( page->rotation() % 2 ? page->width() : page->height() ); + + page->setTextPage( abstractTextPage(textList, pageHeight, pageWidth, (Poppler::Page::Rotation)page->orientation())); qDeleteAll(textList); } @@ -1291,7 +1295,7 @@ void PDFGenerator::threadFinished() if ( !outText.isEmpty() ) { request->page()->setTextPage( abstractTextPage( outText , - request->page()->height(), request->page()->width(),request->page()->totalOrientation())); + request->page()->height(), request->page()->width(),request->page()->orientation())); qDeleteAll(outText); } bool genObjectRects = request->id() & (PAGEVIEW_ID | PRESENTATION_ID); @@ -1471,7 +1475,7 @@ void PDFPixmapGeneratorThread::run() if ( genTextPage ) { - d->m_textList = pp->textList((Poppler::Page::Rotation)d->currentRequest->page()->rotation()); + d->m_textList = pp->textList((Poppler::Page::Rotation)d->currentRequest->page()->orientation()); } delete pp;