Commit e984ef40 authored by Pino Toscano's avatar Pino Toscano

Patch by Luigi Toscano <luigi.toscano@tiscali.it> to:

- simplify the handling of the pages wrt rotation
- make internal anchors hyperlinks work again

Thanks!

CCMAIL: luigi.toscano@tiscali.it

svn path=/trunk/KDE/kdegraphics/okular/; revision=753485
parent 03e0154f
...@@ -65,7 +65,7 @@ bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page ...@@ -65,7 +65,7 @@ bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page
kDebug() << "# of pages: " << m_dviRenderer->dviFile->total_pages; kDebug() << "# of pages: " << m_dviRenderer->dviFile->total_pages;
m_resolution = Okular::Utils::dpiY(); m_resolution = Okular::Utils::dpiY();
loadPages( pagesVector, 0 ); loadPages( pagesVector );
ready = true; ready = true;
return true; return true;
...@@ -90,88 +90,43 @@ bool DviGenerator::canGeneratePixmap () const ...@@ -90,88 +90,43 @@ bool DviGenerator::canGeneratePixmap () const
return ready; return ready;
} }
static void rotateCoordinates( const int iWidth, const int iHeight,
int &fWidth, int &fHeight, const int orientation)
{
if ( orientation % 2 == 0 )
{
/* portrait */
fWidth = iWidth;
fHeight = iHeight;
}
else
{
/* landscape */
fWidth = iHeight;
fHeight = iWidth;
}
}
static void rotateCoordinates( const double iWidth, const double iHeight,
double &fWidth, double &fHeight, const int orientation)
{
if ( orientation % 2 == 0 )
{
/* portrait */
fWidth = iWidth;
fHeight = iHeight;
}
else
{
/* landscape */
fWidth = iHeight;
fHeight = iWidth;
}
}
void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp, void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp,
const Anchor &anch, int pW, int pH, const Anchor &anch, int pW, int pH )
int orientation )
{ {
vp.pageNumber = anch.page - 1; vp.pageNumber = anch.page - 1;
double vp_x = 0.0, vp_y = 0.0;
SimplePageSize ps = m_dviRenderer->sizeOfPage( vp.pageNumber ); SimplePageSize ps = m_dviRenderer->sizeOfPage( vp.pageNumber );
double resolution = 0; double resolution = 0;
if ( orientation % 2 == 0 ) resolution = (double)(pW)/ps.width().getLength_in_inch();
resolution = (double)(pW)/ps.width().getLength_in_inch();
else
resolution = (double)(pH)/ps.height().getLength_in_inch();
double py = (double)anch.distance_from_top.getLength_in_inch()*resolution + 0.5; double py = (double)anch.distance_from_top.getLength_in_inch()*resolution + 0.5;
rotateCoordinates( 0.5, py / (double)pH, vp.rePos.normalizedX = 0.5;
vp_x, vp_y, orientation ); vp.rePos.normalizedY = py/(double)pH;
vp.rePos.normalizedX = vp_x;
vp.rePos.normalizedY = vp_y;
vp.rePos.enabled = true; vp.rePos.enabled = true;
vp.rePos.pos = Okular::DocumentViewport::Center; vp.rePos.pos = Okular::DocumentViewport::Center;
} }
QLinkedList<Okular::ObjectRect*> DviGenerator::generateDviLinks( const dviPageInfo *pageInfo, QLinkedList<Okular::ObjectRect*> DviGenerator::generateDviLinks( const dviPageInfo *pageInfo )
int orientation )
{ {
QLinkedList<Okular::ObjectRect*> dviLinks; QLinkedList<Okular::ObjectRect*> dviLinks;
int pageWidth = 0, pageHeight = 0; int pageWidth = pageInfo->width, pageHeight = pageInfo->height;
rotateCoordinates( pageInfo->width, pageInfo->height,
pageWidth, pageHeight, orientation );
foreach( const Hyperlink dviLink, pageInfo->hyperLinkList ) foreach( const Hyperlink dviLink, pageInfo->hyperLinkList )
{ {
QRect boxArea = Okular::Utils::rotateRect( dviLink.box, pageWidth, pageHeight, QRect boxArea = dviLink.box;
orientation );
double nl = (double)boxArea.left() / pageWidth, double nl = (double)boxArea.left() / pageWidth,
nt = (double)boxArea.top() / pageHeight, nt = (double)boxArea.top() / pageHeight,
nr = (double)boxArea.right() / pageWidth, nr = (double)boxArea.right() / pageWidth,
nb = (double)boxArea.bottom() / pageHeight; nb = (double)boxArea.bottom() / pageHeight;
Anchor anch = m_dviRenderer->findAnchor(dviLink.linkText); QString linkText = dviLink.linkText;
if ( linkText.startsWith("#") )
linkText = linkText.mid( 1 );
Anchor anch = m_dviRenderer->findAnchor( linkText );
Okular::Action *okuLink = 0; Okular::Action *okuLink = 0;
...@@ -180,8 +135,8 @@ QLinkedList<Okular::ObjectRect*> DviGenerator::generateDviLinks( const dviPageIn ...@@ -180,8 +135,8 @@ QLinkedList<Okular::ObjectRect*> DviGenerator::generateDviLinks( const dviPageIn
{ {
/* internal link */ /* internal link */
Okular::DocumentViewport vp; Okular::DocumentViewport vp;
fillViewportFromAnchor( vp, anch, pageWidth, pageHeight, fillViewportFromAnchor( vp, anch, pageWidth, pageHeight );
orientation );
okuLink = new Okular::GotoAction( "", vp ); okuLink = new Okular::GotoAction( "", vp );
} }
else else
...@@ -190,11 +145,11 @@ QLinkedList<Okular::ObjectRect*> DviGenerator::generateDviLinks( const dviPageIn ...@@ -190,11 +145,11 @@ QLinkedList<Okular::ObjectRect*> DviGenerator::generateDviLinks( const dviPageIn
} }
if ( okuLink ) if ( okuLink )
{ {
Okular::ObjectRect *orlink = new Okular::ObjectRect( nl, nt, nr, nb, false, Okular::ObjectRect::Action, Okular::ObjectRect *orlink = new Okular::ObjectRect( nl, nt, nr, nb,
okuLink ); false, Okular::ObjectRect::Action, okuLink );
dviLinks.push_front( orlink ); dviLinks.push_front( orlink );
} }
} }
return dviLinks; return dviLinks;
} }
...@@ -205,8 +160,8 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request ) ...@@ -205,8 +160,8 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
dviPageInfo *pageInfo = new dviPageInfo(); dviPageInfo *pageInfo = new dviPageInfo();
pageSize ps; pageSize ps;
rotateCoordinates( request->width(), request->height(), pageInfo->width = request->width();
pageInfo->width, pageInfo->height, request->page()->rotation() ); pageInfo->height = request->height();
pageInfo->pageNumber = request->pageNumber() + 1; pageInfo->pageNumber = request->pageNumber() + 1;
...@@ -242,8 +197,7 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request ) ...@@ -242,8 +197,7 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( pageInfo->img ) ) ); request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( pageInfo->img ) ) );
request->page()->setObjectRects( request->page()->setObjectRects( generateDviLinks( pageInfo ) );
generateDviLinks( pageInfo, 0 ) );
} }
} }
...@@ -259,9 +213,9 @@ Okular::TextPage* DviGenerator::textPage( Okular::Page *page ) ...@@ -259,9 +213,9 @@ Okular::TextPage* DviGenerator::textPage( Okular::Page *page )
kDebug() << "DviGenerator::textPage( Okular::Page * page )"; kDebug() << "DviGenerator::textPage( Okular::Page * page )";
dviPageInfo *pageInfo = new dviPageInfo(); dviPageInfo *pageInfo = new dviPageInfo();
pageSize ps; pageSize ps;
rotateCoordinates( (int)(page->width()), (int)(page->height()), pageInfo->width=page->width();
pageInfo->width, pageInfo->height, page->totalOrientation() ); pageInfo->height=page->height();
pageInfo->pageNumber = page->number() + 1; pageInfo->pageNumber = page->number() + 1;
...@@ -275,13 +229,13 @@ Okular::TextPage* DviGenerator::textPage( Okular::Page *page ) ...@@ -275,13 +229,13 @@ Okular::TextPage* DviGenerator::textPage( Okular::Page *page )
{ {
m_dviRenderer->getText( pageInfo ); m_dviRenderer->getText( pageInfo );
ktp = extractTextFromPage( pageInfo, page->totalOrientation() ); ktp = extractTextFromPage( pageInfo );
} }
delete pageInfo; delete pageInfo;
return ktp; return ktp;
} }
Okular::TextPage *DviGenerator::extractTextFromPage( dviPageInfo *pageInfo, int orientation ) Okular::TextPage *DviGenerator::extractTextFromPage( dviPageInfo *pageInfo )
{ {
QList<Okular::TextEntity*> textOfThePage; QList<Okular::TextEntity*> textOfThePage;
...@@ -289,17 +243,12 @@ Okular::TextPage *DviGenerator::extractTextFromPage( dviPageInfo *pageInfo, int ...@@ -289,17 +243,12 @@ Okular::TextPage *DviGenerator::extractTextFromPage( dviPageInfo *pageInfo, int
QVector<TextBox>::ConstIterator itEnd = pageInfo->textBoxList.constEnd(); QVector<TextBox>::ConstIterator itEnd = pageInfo->textBoxList.constEnd();
QRect tmpRect; QRect tmpRect;
int pageWidth = 0, pageHeight = 0; int pageWidth = pageInfo->width, pageHeight = pageInfo->height;
rotateCoordinates( pageInfo->width, pageInfo->height,
pageWidth, pageHeight, orientation );
for ( ; it != itEnd ; ++it ) for ( ; it != itEnd ; ++it )
{ {
TextBox curTB = *it; TextBox curTB = *it;
tmpRect = Okular::Utils::rotateRect( curTB.box, pageWidth, pageHeight, orientation );
#if 0 #if 0
kDebug() << "orientation: " << orientation kDebug() << "orientation: " << orientation
<< ", curTB.box: " << curTB.box << ", curTB.box: " << curTB.box
...@@ -308,7 +257,7 @@ Okular::TextPage *DviGenerator::extractTextFromPage( dviPageInfo *pageInfo, int ...@@ -308,7 +257,7 @@ Okular::TextPage *DviGenerator::extractTextFromPage( dviPageInfo *pageInfo, int
<<endl; <<endl;
#endif #endif
textOfThePage.push_back( new Okular::TextEntity( curTB.text, textOfThePage.push_back( new Okular::TextEntity( curTB.text,
new Okular::NormalizedRect( tmpRect, pageWidth, pageHeight ) ) ); new Okular::NormalizedRect( curTB.box, pageWidth, pageHeight ) ) );
} }
Okular::TextPage* ktp = new Okular::TextPage( textOfThePage ); Okular::TextPage* ktp = new Okular::TextPage( textOfThePage );
...@@ -357,15 +306,14 @@ const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis() ...@@ -357,15 +306,14 @@ const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
for( ; it != itEnd; ++it ) for( ; it != itEnd; ++it )
{ {
QDomElement domel = m_docSynopsis->createElement( (*it).title ); QDomElement domel = m_docSynopsis->createElement( (*it).title );
Anchor a = m_dviRenderer->findAnchor((*it).anchorName); Anchor a = m_dviRenderer->findAnchor((*it).anchorName);
if ( a.isValid() ) if ( a.isValid() )
{ {
Okular::DocumentViewport vp; Okular::DocumentViewport vp;
const Okular::Page *p = document()->page( a.page - 1 ); const Okular::Page *p = document()->page( a.page - 1 );
/* Don't care about rotations... */
fillViewportFromAnchor( vp, a, (int)p->width(), (int)p->height(), 0 ); fillViewportFromAnchor( vp, a, (int)p->width(), (int)p->height() );
domel.setAttribute( "Viewport", vp.toString() ); domel.setAttribute( "Viewport", vp.toString() );
} }
if ( stack.isEmpty() ) if ( stack.isEmpty() )
...@@ -382,7 +330,7 @@ const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis() ...@@ -382,7 +330,7 @@ const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
return m_docSynopsis; return m_docSynopsis;
} }
void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector, int orientation ) void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector )
{ {
QSize pageRequiredSize; QSize pageRequiredSize;
...@@ -403,14 +351,6 @@ void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector, int orient ...@@ -403,14 +351,6 @@ void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector, int orient
pageRequiredSize = ps.sizeInPixel( m_resolution ); pageRequiredSize = ps.sizeInPixel( m_resolution );
} }
if ( orientation % 2 != 0 )
{
/* landscape */
pageRequiredSize = QSize ( pageRequiredSize.height(),
pageRequiredSize.width() );
}
for ( int i = 0; i < numofpages; ++i ) for ( int i = 0; i < numofpages; ++i )
{ {
//kDebug() << "getting status of page " << i << ":"; //kDebug() << "getting status of page " << i << ":";
...@@ -423,7 +363,8 @@ void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector, int orient ...@@ -423,7 +363,8 @@ void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector, int orient
Okular::Page * page = new Okular::Page( i, Okular::Page * page = new Okular::Page( i,
pageRequiredSize.width(), pageRequiredSize.width(),
pageRequiredSize.height(), pageRequiredSize.height(),
(Okular::Rotation)orientation ); Okular::Rotation0 );
pagesVector[i] = page; pagesVector[i] = page;
} }
kDebug() << "pagesVector successfully inizialized ! "; kDebug() << "pagesVector successfully inizialized ! ";
......
...@@ -50,12 +50,11 @@ class DviGenerator : public Okular::Generator ...@@ -50,12 +50,11 @@ class DviGenerator : public Okular::Generator
bool ready; bool ready;
dviRenderer *m_dviRenderer; dviRenderer *m_dviRenderer;
void loadPages( QVector< Okular::Page * > & pagesVector, int orientation ); void loadPages( QVector< Okular::Page * > & pagesVector );
Okular::TextPage *extractTextFromPage( dviPageInfo *pageInfo, int orientation ); Okular::TextPage *extractTextFromPage( dviPageInfo *pageInfo );
void fillViewportFromAnchor( Okular::DocumentViewport &vp, const Anchor &anch, void fillViewportFromAnchor( Okular::DocumentViewport &vp, const Anchor &anch,
int pW, int pH, int orientation ); int pW, int pH );
QLinkedList<Okular::ObjectRect*> generateDviLinks( const dviPageInfo *pageInfo, QLinkedList<Okular::ObjectRect*> generateDviLinks( const dviPageInfo *pageInfo );
int orientation );
}; };
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment