|
|
|
|
@ -1621,130 +1621,6 @@ void PDFGenerator::addFormFields( Poppler::Page * popplerPage, Okular::Page * pa |
|
|
|
|
page->setFormFields( okularFormFields ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct pdfsyncpoint |
|
|
|
|
{ |
|
|
|
|
QString file; |
|
|
|
|
qlonglong x; |
|
|
|
|
qlonglong y; |
|
|
|
|
int row; |
|
|
|
|
int column; |
|
|
|
|
int page; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void PDFGenerator::loadPdfSync( const QString & filePath, QVector<Okular::Page*> & pagesVector ) |
|
|
|
|
{ |
|
|
|
|
QFile f( filePath + QLatin1String( "sync" ) ); |
|
|
|
|
if ( !f.open( QIODevice::ReadOnly ) ) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
QTextStream ts( &f ); |
|
|
|
|
// first row: core name of the pdf output
|
|
|
|
|
const QString coreName = ts.readLine(); |
|
|
|
|
// second row: version string, in the form 'Version %u'
|
|
|
|
|
QString versionstr = ts.readLine(); |
|
|
|
|
QRegExp versionre( QStringLiteral("Version (\\d+)") ); |
|
|
|
|
versionre.setCaseSensitivity( Qt::CaseInsensitive ); |
|
|
|
|
if ( !versionre.exactMatch( versionstr ) ) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
QHash<int, pdfsyncpoint> points; |
|
|
|
|
QStack<QString> fileStack; |
|
|
|
|
int currentpage = -1; |
|
|
|
|
const QLatin1String texStr( ".tex" ); |
|
|
|
|
const QChar spaceChar = QChar::fromLatin1( ' ' ); |
|
|
|
|
|
|
|
|
|
fileStack.push( coreName + texStr ); |
|
|
|
|
|
|
|
|
|
QString line; |
|
|
|
|
while ( !ts.atEnd() ) |
|
|
|
|
{ |
|
|
|
|
line = ts.readLine(); |
|
|
|
|
const QStringList tokens = line.split( spaceChar, QString::SkipEmptyParts ); |
|
|
|
|
const int tokenSize = tokens.count(); |
|
|
|
|
if ( tokenSize < 1 ) |
|
|
|
|
continue; |
|
|
|
|
if ( tokens.first() == QLatin1String( "l" ) && tokenSize >= 3 ) |
|
|
|
|
{ |
|
|
|
|
int id = tokens.at( 1 ).toInt(); |
|
|
|
|
QHash<int, pdfsyncpoint>::const_iterator it = points.constFind( id ); |
|
|
|
|
if ( it == points.constEnd() ) |
|
|
|
|
{ |
|
|
|
|
pdfsyncpoint pt; |
|
|
|
|
pt.x = 0; |
|
|
|
|
pt.y = 0; |
|
|
|
|
pt.row = tokens.at( 2 ).toInt(); |
|
|
|
|
pt.column = 0; // TODO
|
|
|
|
|
pt.page = -1; |
|
|
|
|
pt.file = fileStack.top(); |
|
|
|
|
points[ id ] = pt; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if ( tokens.first() == QLatin1String( "s" ) && tokenSize >= 2 ) |
|
|
|
|
{ |
|
|
|
|
currentpage = tokens.at( 1 ).toInt() - 1; |
|
|
|
|
} |
|
|
|
|
else if ( tokens.first() == QLatin1String( "p*" ) && tokenSize >= 4 ) |
|
|
|
|
{ |
|
|
|
|
// TODO
|
|
|
|
|
qCDebug(OkularPdfDebug) << "PdfSync: 'p*' line ignored"; |
|
|
|
|
} |
|
|
|
|
else if ( tokens.first() == QLatin1String( "p" ) && tokenSize >= 4 ) |
|
|
|
|
{ |
|
|
|
|
int id = tokens.at( 1 ).toInt(); |
|
|
|
|
QHash<int, pdfsyncpoint>::iterator it = points.find( id ); |
|
|
|
|
if ( it != points.end() ) |
|
|
|
|
{ |
|
|
|
|
it->x = tokens.at( 2 ).toInt(); |
|
|
|
|
it->y = tokens.at( 3 ).toInt(); |
|
|
|
|
it->page = currentpage; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if ( line.startsWith( QLatin1Char( '(' ) ) && tokenSize == 1 ) |
|
|
|
|
{ |
|
|
|
|
QString newfile = line; |
|
|
|
|
// chop the leading '('
|
|
|
|
|
newfile.remove( 0, 1 ); |
|
|
|
|
if ( !newfile.endsWith( texStr ) ) |
|
|
|
|
{ |
|
|
|
|
newfile += texStr; |
|
|
|
|
} |
|
|
|
|
fileStack.push( newfile ); |
|
|
|
|
} |
|
|
|
|
else if ( line == QLatin1String( ")" ) ) |
|
|
|
|
{ |
|
|
|
|
if ( !fileStack.isEmpty() ) |
|
|
|
|
{ |
|
|
|
|
fileStack.pop(); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
qCDebug(OkularPdfDebug) << "PdfSync: going one level down too much"; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
qCDebug(OkularPdfDebug).nospace() << "PdfSync: unknown line format: '" << line << "'"; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QVector< QLinkedList< Okular::SourceRefObjectRect * > > refRects( pagesVector.size() ); |
|
|
|
|
foreach ( const pdfsyncpoint& pt, points ) |
|
|
|
|
{ |
|
|
|
|
// drop pdfsync points not completely valid
|
|
|
|
|
if ( pt.page < 0 || pt.page >= pagesVector.size() ) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
// magic numbers for TeX's RSU's (Ridiculously Small Units) conversion to pixels
|
|
|
|
|
Okular::NormalizedPoint p( |
|
|
|
|
( pt.x * dpi().width() ) / ( 72.27 * 65536.0 * pagesVector[pt.page]->width() ), |
|
|
|
|
( pt.y * dpi().height() ) / ( 72.27 * 65536.0 * pagesVector[pt.page]->height() ) |
|
|
|
|
); |
|
|
|
|
QString file = pt.file; |
|
|
|
|
Okular::SourceReference * sourceRef = new Okular::SourceReference( file, pt.row, pt.column ); |
|
|
|
|
refRects[ pt.page ].append( new Okular::SourceRefObjectRect( p, sourceRef ) ); |
|
|
|
|
} |
|
|
|
|
for ( int i = 0; i < refRects.size(); ++i ) |
|
|
|
|
if ( !refRects.at(i).isEmpty() ) |
|
|
|
|
pagesVector[i]->setSourceReferences( refRects.at(i) ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PDFGenerator::PrintError PDFGenerator::printError() const |
|
|
|
|
{ |
|
|
|
|
return lastPrintError; |
|
|
|
|
|