Fixed free text selection for rotated pages

svn path=/trunk/playground/graphics/okular/; revision=617621
remotes/origin/KDE/4.0
Tobias Koenig 19 years ago
parent 486095425b
commit 4fe8bdce53
  1. 22
      core/area.h
  2. 10
      core/page.cpp
  3. 16
      generators/poppler/generator_pdf.cpp

@ -331,13 +331,14 @@ template <class NormalizedShape, class Shape> class RegularArea : public QList<
~RegularArea(); ~RegularArea();
bool contains( double x, double y ) const; bool contains( double x, double y ) const;
bool contains( const NormalizedShape& shape ) const; bool contains( const NormalizedShape& shape ) const;
bool intersects (const RegularArea<NormalizedShape,Shape> * area) const; bool intersects( const RegularArea<NormalizedShape,Shape> *area ) const;
bool intersects (const NormalizedShape& shape) const; bool intersects( const NormalizedShape& shape ) const;
void appendArea (const RegularArea<NormalizedShape,Shape> *area); void appendArea( const RegularArea<NormalizedShape,Shape> *area );
void appendShape( const NormalizedShape& shape ); void appendShape( const NormalizedShape& shape );
void simplify (); void simplify();
bool isNull() const; bool isNull() const;
QList<Shape> geometry( int xScale, int yScale, int dx=0,int dy=0 ) const; QList<Shape> geometry( int xScale, int yScale, int dx=0,int dy=0 ) const;
void transform( const QMatrix &matrix );
}; };
template <class NormalizedShape, class Shape> template <class NormalizedShape, class Shape>
@ -513,6 +514,19 @@ QList<Shape> RegularArea<NormalizedShape, Shape>::geometry( int xScale, int ySca
return ret; return ret;
} }
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::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<NormalizedRect,QRect> RegularAreaRect; typedef RegularArea<NormalizedRect,QRect> RegularAreaRect;
class HighlightAreaRect : public RegularAreaRect class HighlightAreaRect : public RegularAreaRect

@ -256,7 +256,10 @@ QString Page::text( const RegularAreaRect * area ) const
if ( !d->m_text ) if ( !d->m_text )
return ret; return ret;
ret = d->m_text->text( area ); RegularAreaRect rotatedArea = *area;
rotatedArea.transform( d->rotationMatrix().inverted() );
ret = d->m_text->text( &rotatedArea );
return ret; return ret;
} }
@ -270,9 +273,6 @@ void Page::rotateAt( int orientation )
deleteHighlights(); deleteHighlights();
deleteTextSelections(); deleteTextSelections();
if ( d->m_text )
d->m_text->transform( d->rotationMatrix() );
if ( ( d->m_orientation + d->m_rotation ) % 2 != ( d->m_orientation + neworientation ) % 2 ) if ( ( d->m_orientation + d->m_rotation ) % 2 != ( d->m_orientation + neworientation ) % 2 )
qSwap( d->m_width, d->m_height ); qSwap( d->m_width, d->m_height );
@ -374,8 +374,6 @@ void Page::setTextPage( TextPage * textPage )
{ {
delete d->m_text; delete d->m_text;
textPage->transform( d->rotationMatrix() );
d->m_text = textPage; d->m_text = textPage;
} }

@ -623,8 +623,8 @@ void PDFGenerator::generatePixmap( Okular::PixmapRequest * request )
docLock.unlock(); docLock.unlock();
if ( genTextPage ) if ( genTextPage )
{ {
QList<Poppler::TextBox*> textList = p->textList((Poppler::Page::Rotation)request->page()->rotation()); QList<Poppler::TextBox*> textList = p->textList((Poppler::Page::Rotation)request->page()->orientation());
page->setTextPage( abstractTextPage(textList, page->height(), page->width(), request->page()->totalOrientation()) ); page->setTextPage( abstractTextPage(textList, page->height(), page->width(), request->page()->orientation()) );
qDeleteAll(textList); qDeleteAll(textList);
} }
delete p; delete p;
@ -647,11 +647,15 @@ void PDFGenerator::generateSyncTextPage( Okular::Page * page )
// build a TextList... // build a TextList...
Poppler::Page *pp = pdfdoc->page( page->number() ); Poppler::Page *pp = pdfdoc->page( page->number() );
docLock.lock(); docLock.lock();
QList<Poppler::TextBox*> textList = pp->textList((Poppler::Page::Rotation)page->rotation()); QList<Poppler::TextBox*> textList = pp->textList((Poppler::Page::Rotation)page->orientation());
docLock.unlock(); docLock.unlock();
delete pp; delete pp;
// ..and attach it to the page // ..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); qDeleteAll(textList);
} }
@ -1291,7 +1295,7 @@ void PDFGenerator::threadFinished()
if ( !outText.isEmpty() ) if ( !outText.isEmpty() )
{ {
request->page()->setTextPage( abstractTextPage( outText , 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); qDeleteAll(outText);
} }
bool genObjectRects = request->id() & (PAGEVIEW_ID | PRESENTATION_ID); bool genObjectRects = request->id() & (PAGEVIEW_ID | PRESENTATION_ID);
@ -1471,7 +1475,7 @@ void PDFPixmapGeneratorThread::run()
if ( genTextPage ) 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; delete pp;

Loading…
Cancel
Save