MCPcopy Create free account
hub / github.com/KDE/okular / loadSyncFile

Method loadSyncFile

core/document.cpp:2067–2168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2065};
2066
2067void DocumentPrivate::loadSyncFile(const QString &filePath)
2068{
2069 QFile f(filePath + QLatin1String("sync"));
2070 if (!f.open(QIODevice::ReadOnly)) {
2071 return;
2072 }
2073
2074 QTextStream ts(&f);
2075 // first row: core name of the pdf output
2076 const QString coreName = ts.readLine();
2077 // second row: version string, in the form 'Version %u'
2078 const QString versionstr = ts.readLine();
2079 // anchor the pattern with \A and \z to match the entire subject string
2080 // TODO: with Qt 5.12 QRegularExpression::anchoredPattern() can be used instead
2081 static QRegularExpression versionre(QStringLiteral("\\AVersion \\d+\\z"), QRegularExpression::CaseInsensitiveOption);
2082 QRegularExpressionMatch match = versionre.match(versionstr);
2083 if (!match.hasMatch()) {
2084 return;
2085 }
2086
2087 QHash<int, pdfsyncpoint> points;
2088 QStack<QString> fileStack;
2089 int currentpage = -1;
2090 const QLatin1String texStr(".tex");
2091 const QChar spaceChar = QChar::fromLatin1(' ');
2092
2093 fileStack.push(coreName + texStr);
2094
2095 const QSizeF dpi = m_generator->dpi();
2096
2097 QString line;
2098 while (!ts.atEnd()) {
2099 line = ts.readLine();
2100 const QStringList tokens = line.split(spaceChar, Qt::SkipEmptyParts);
2101 const int tokenSize = tokens.count();
2102 if (tokenSize < 1) {
2103 continue;
2104 }
2105 if (tokens.first() == QLatin1String("l") && tokenSize >= 3) {
2106 int id = tokens.at(1).toInt();
2107 QHash<int, pdfsyncpoint>::const_iterator it = points.constFind(id);
2108 if (it == points.constEnd()) {
2109 pdfsyncpoint pt;
2110 pt.x = 0;
2111 pt.y = 0;
2112 pt.row = tokens.at(2).toInt();
2113 pt.column = 0; // TODO
2114 pt.page = -1;
2115 pt.file = fileStack.top();
2116 points[id] = pt;
2117 }
2118 } else if (tokens.first() == QLatin1String("s") && tokenSize >= 2) {
2119 currentpage = tokens.at(1).toInt() - 1;
2120 } else if (tokens.first() == QLatin1String("p*") && tokenSize >= 4) {
2121 // TODO
2122 qCDebug(OkularCoreDebug) << "PdfSync: 'p*' line ignored";
2123 } else if (tokens.first() == QLatin1String("p") && tokenSize >= 4) {
2124 int id = tokens.at(1).toInt();

Callers 2

openDocumentMethod · 0.80
swapBackingFileMethod · 0.80

Calls 11

splitMethod · 0.80
isEmptyMethod · 0.80
appendMethod · 0.80
setSourceReferencesMethod · 0.80
openMethod · 0.45
dpiMethod · 0.45
countMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected