From e8fd56f3ba4d030af41d77fc7ce8010c9351697c Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 9 Oct 2014 00:53:54 +0200 Subject: [PATCH] Fixup last commit Somehow i ended up commiting a partial patch and not what was in reviewboard, this amends the previous commit to be what i really wanted to commit Sorry for the mess :/ --- core/document.cpp | 84 ++++++++++++++++++++++++---- core/document_p.h | 4 +- generators/poppler/generator_pdf.cpp | 81 +++------------------------ generators/poppler/generator_pdf.h | 2 - ui/pageview.cpp | 2 - 5 files changed, 83 insertions(+), 90 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 80695d9b6..bdb380f98 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1028,7 +1028,7 @@ DocumentViewport DocumentPrivate::nextDocumentViewport() const DocumentViewport ret = m_nextDocumentViewport; if ( !m_nextDocumentDestination.isEmpty() && m_generator ) { - DocumentViewport vp( m_generator->metaData( "NamedViewport", m_nextDocumentDestination ).toString() ); + DocumentViewport vp( m_parent->metaData( "NamedViewport", m_nextDocumentDestination ).toString() ); if ( vp.isValid() ) { ret = vp; @@ -2374,8 +2374,8 @@ Document::OpenResult Document::openDocument( const QString & docFile, const KUrl // no need to check for the existence of a synctex file, no parser will be // created if none exists - d->synctex_scanner = synctex_scanner_new_with_output_file( QFile::encodeName( docFile ), 0, 1); - if ( !d->synctex_scanner && QFile::exists(docFile + QLatin1String( "sync" ) ) ) + d->m_synctex_scanner = synctex_scanner_new_with_output_file( QFile::encodeName( docFile ), 0, 1); + if ( !d->m_synctex_scanner && QFile::exists(docFile + QLatin1String( "sync" ) ) ) { d->loadSyncFile(docFile); } @@ -2534,10 +2534,10 @@ void Document::closeDocument() d->m_generator->closeDocument(); } - if ( d->synctex_scanner ) + if ( d->m_synctex_scanner ) { - synctex_scanner_free( d->synctex_scanner ); - d->synctex_scanner = 0; + synctex_scanner_free( d->m_synctex_scanner ); + d->m_synctex_scanner = 0; } // stop timers @@ -2951,6 +2951,69 @@ bool Document::historyAtEnd() const QVariant Document::metaData( const QString & key, const QVariant & option ) const { + // if option starts with "src:" assume that we are handling a + // source reference + if ( key == "NamedViewport" + && option.toString().startsWith( "src:", Qt::CaseInsensitive ) + && d->m_synctex_scanner) + { + const QString reference = option.toString(); + + // The reference is of form "src:1111Filename", where "1111" + // points to line number 1111 in the file "Filename". + // Extract the file name and the numeral part from the reference string. + // This will fail if Filename starts with a digit. + QString name, lineString; + // Remove "src:". Presence of substring has been checked before this + // function is called. + name = reference.mid( 4 ); + // split + int nameLength = name.length(); + int i = 0; + for( i = 0; i < nameLength; ++i ) + { + if ( !name[i].isDigit() ) break; + } + lineString = name.left( i ); + name = name.mid( i ); + // Remove spaces. + name = name.trimmed(); + lineString = lineString.trimmed(); + // Convert line to integer. + bool ok; + int line = lineString.toInt( &ok ); + if (!ok) line = -1; + + // Use column == -1 for now. + if( synctex_display_query( d->m_synctex_scanner, QFile::encodeName(name), line, -1 ) > 0 ) + { + synctex_node_t node; + // For now use the first hit. Could possibly be made smarter + // in case there are multiple hits. + while( ( node = synctex_next_result( d->m_synctex_scanner ) ) ) + { + Okular::DocumentViewport viewport; + + // TeX pages start at 1. + viewport.pageNumber = synctex_node_page( node ) - 1; + + if ( viewport.pageNumber >= 0 ) + { + const QSizeF dpi = d->m_generator->dpi(); + + // TeX small points ... + double px = (synctex_node_visible_h( node ) * dpi.width()) / 72.27; + double py = (synctex_node_visible_v( node ) * dpi.height()) / 72.27; + viewport.rePos.normalizedX = px / page(viewport.pageNumber)->width(); + viewport.rePos.normalizedY = ( py + 0.5 ) / page(viewport.pageNumber)->height(); + viewport.rePos.enabled = true; + viewport.rePos.pos = Okular::DocumentViewport::Center; + + return viewport.toString(); + } + } + } + } return d->m_generator ? d->m_generator->metaData( key, option ) : QVariant(); } @@ -3997,17 +4060,16 @@ void Document::processSourceReference( const SourceReference * ref ) const SourceReference * Document::dynamicSourceReference( int pageNr, double absX, double absY ) { - if ( !d->synctex_scanner ) + if ( !d->m_synctex_scanner ) return 0; const QSizeF dpi = d->m_generator->dpi(); - qDebug() << absX << absY << dpi; - if (synctex_edit_query(d->synctex_scanner, pageNr + 1, absX * 72. / dpi.width(), absY * 72. / dpi.height()) > 0) + if (synctex_edit_query(d->m_synctex_scanner, pageNr + 1, absX * 72. / dpi.width(), absY * 72. / dpi.height()) > 0) { synctex_node_t node; // TODO what should we do if there is really more than one node? - while (( node = synctex_next_result( d->synctex_scanner ) )) + while (( node = synctex_next_result( d->m_synctex_scanner ) )) { int line = synctex_node_line(node); int col = synctex_node_column(node); @@ -4016,7 +4078,7 @@ const SourceReference * Document::dynamicSourceReference( int pageNr, double abs { col = 0; } - const char *name = synctex_scanner_get_name( d->synctex_scanner, synctex_node_tag( node ) ); + const char *name = synctex_scanner_get_name( d->m_synctex_scanner, synctex_node_tag( node ) ); return new Okular::SourceReference( QFile::decodeName( name ), line, col ); } diff --git a/core/document_p.h b/core/document_p.h index 8f66e7934..0f5c6b263 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -100,7 +100,7 @@ class DocumentPrivate m_fontsCached( false ), m_annotationEditingEnabled ( true ), m_annotationBeingMoved( false ), - synctex_scanner( 0 ) + m_synctex_scanner( 0 ) { calculateMaxTextPages(); } @@ -277,7 +277,7 @@ class DocumentPrivate QUndoStack *m_undoStack; QDomNode m_prevPropsOfAnnotBeingModified; - synctex_scanner_t synctex_scanner; + synctex_scanner_t m_synctex_scanner; }; class DocumentInfoPrivate diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index d68464438..07abf75c2 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -1126,25 +1126,16 @@ QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) Okular::DocumentViewport viewport; QString optionString = option.toString(); - // if option starts with "src:" assume that we are handling a - // source reference - if ( optionString.startsWith( "src:", Qt::CaseInsensitive ) ) - { - fillViewportFromSourceReference( viewport, optionString ); - } - else + // asking for the page related to a 'named link destination'. the + // option is the link name. @see addSynopsisChildren. + userMutex()->lock(); + Poppler::LinkDestination *ld = pdfdoc->linkDestination( optionString ); + userMutex()->unlock(); + if ( ld ) { - // asking for the page related to a 'named link destination'. the - // option is the link name. @see addSynopsisChildren. - userMutex()->lock(); - Poppler::LinkDestination *ld = pdfdoc->linkDestination( optionString ); - userMutex()->unlock(); - if ( ld ) - { - fillViewportFromLinkDestination( viewport, *ld ); - } - delete ld; + fillViewportFromLinkDestination( viewport, *ld ); } + delete ld; if ( viewport.pageNumber >= 0 ) return viewport.toString(); } @@ -1577,62 +1568,6 @@ PDFGenerator::PrintError PDFGenerator::printError() const return lastPrintError; } -void PDFGenerator::fillViewportFromSourceReference( Okular::DocumentViewport & viewport, const QString & reference ) const -{ -// if ( !synctex_scanner ) -// return; -// -// // The reference is of form "src:1111Filename", where "1111" -// // points to line number 1111 in the file "Filename". -// // Extract the file name and the numeral part from the reference string. -// // This will fail if Filename starts with a digit. -// QString name, lineString; -// // Remove "src:". Presence of substring has been checked before this -// // function is called. -// name = reference.mid( 4 ); -// // split -// int nameLength = name.length(); -// int i = 0; -// for( i = 0; i < nameLength; ++i ) -// { -// if ( !name[i].isDigit() ) break; -// } -// lineString = name.left( i ); -// name = name.mid( i ); -// // Remove spaces. -// name = name.trimmed(); -// lineString = lineString.trimmed(); -// // Convert line to integer. -// bool ok; -// int line = lineString.toInt( &ok ); -// if (!ok) line = -1; -// -// // Use column == -1 for now. -// if( synctex_display_query( synctex_scanner, QFile::encodeName(name), line, -1 ) > 0 ) -// { -// synctex_node_t node; -// // For now use the first hit. Could possibly be made smarter -// // in case there are multiple hits. -// while( ( node = synctex_next_result( synctex_scanner ) ) ) -// { -// // TeX pages start at 1. -// viewport.pageNumber = synctex_node_page( node ) - 1; -// -// if ( !viewport.isValid() ) return; -// -// // TeX small points ... -// double px = (synctex_node_visible_h( node ) * dpi().width()) / 72.27; -// double py = (synctex_node_visible_v( node ) * dpi().height()) / 72.27; -// viewport.rePos.normalizedX = px / document()->page(viewport.pageNumber)->width(); -// viewport.rePos.normalizedY = ( py + 0.5 ) / document()->page(viewport.pageNumber)->height(); -// viewport.rePos.enabled = true; -// viewport.rePos.pos = Okular::DocumentViewport::Center; -// -// return; -// } -// } -} - QWidget* PDFGenerator::printConfigurationWidget() const { if ( !pdfOptionsPage ) diff --git a/generators/poppler/generator_pdf.h b/generators/poppler/generator_pdf.h index deddc4e28..89afe18d0 100644 --- a/generators/poppler/generator_pdf.h +++ b/generators/poppler/generator_pdf.h @@ -117,8 +117,6 @@ class PDFGenerator : public Okular::Generator, public Okular::ConfigInterface, p void addFormFields( Poppler::Page * popplerPage, Okular::Page * page ); // load the source references from a pdfsync file void loadPdfSync( const QString & fileName, QVector & pagesVector ); - // search document for source reference - void fillViewportFromSourceReference( Okular::DocumentViewport & viewport, const QString & reference ) const; Okular::TextPage * abstractTextPage(const QList &text, double height, double width, int rot); diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 4120dd97c..17e66f4a3 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -2355,7 +2355,6 @@ void PageView::mouseReleaseEvent( QMouseEvent * e ) if ( rect && ( distance > s_minDistance ) ) rect = 0; } - qDebug() << "C" << rect; if ( rect ) { const Okular::SourceReference * ref = static_cast< const Okular::SourceReference * >( rect->object() ); @@ -2364,7 +2363,6 @@ void PageView::mouseReleaseEvent( QMouseEvent * e ) else { const Okular::SourceReference * ref = d->document->dynamicSourceReference( pageItem-> pageNumber(), nX * pageItem->page()->width(), nY * pageItem->page()->height() ); - qDebug() << "D" << ref; if ( ref ) { d->document->processSourceReference( ref );