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

Method parseReference

generators/dvi/dviRenderer.cpp:527–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525}
526
527Anchor dviRenderer::parseReference(const QString &reference)
528{
529 QMutexLocker locker(&mutex);
530
531#ifdef DEBUG_DVIRENDERER
532 qCCritical(OkularDviDebug) << "dviRenderer::parseReference( " << reference << " ) called";
533#endif
534
535 if (dviFile == nullptr) {
536 return Anchor();
537 }
538
539 // case 1: The reference is a number, which we'll interpret as a
540 // page number.
541 bool ok;
542 int page = reference.toInt(&ok);
543 if (ok == true) {
544 if (page < 0) {
545 page = 0;
546 }
547 if (page > dviFile->total_pages) {
548 page = dviFile->total_pages;
549 }
550
551 return Anchor(page, Length());
552 }
553
554 // case 2: The reference is of form "src:1111Filename", where "1111"
555 // points to line number 1111 in the file "Filename". KDVI then
556 // looks for source specials of the form "src:xxxxFilename", and
557 // tries to find the special with the biggest xxxx
558 if (reference.indexOf(QStringLiteral("src:"), 0, Qt::CaseInsensitive) == 0) {
559 // Extract the file name and the numeral part from the reference string
560 DVI_SourceFileSplitter splitter(reference, dviFile->filename);
561 quint32 refLineNumber = splitter.line();
562 QString refFileName = splitter.filePath();
563
564 if (sourceHyperLinkAnchors.isEmpty()) {
565 Q_EMIT warning(i18n("You have asked Okular to locate the place in the DVI file which corresponds to "
566 "line %1 in the TeX-file %2. It seems, however, that the DVI file "
567 "does not contain the necessary source file information. ",
568 refLineNumber,
569 refFileName),
570 -1);
571 return Anchor();
572 }
573
574 // Go through the list of source file anchors, and find the anchor
575 // whose line number is the biggest among those that are smaller
576 // than the refLineNumber. That way, the position in the DVI file
577 // which is highlighted is always a little further up than the
578 // position in the editor, e.g. if the DVI file contains
579 // positional information at the beginning of every paragraph,
580 // KDVI jumps to the beginning of the paragraph that the cursor is
581 // in, and never to the next paragraph. If source file anchors for
582 // the refFileName can be found, but none of their line numbers is
583 // smaller than the refLineNumber, the reason is most likely, that
584 // the cursor in the editor stands somewhere in the preamble of

Callers 1

metaDataMethod · 0.80

Calls 6

LengthClass · 0.85
lineMethod · 0.80
filePathMethod · 0.80
isEmptyMethod · 0.80
AnchorClass · 0.70
endMethod · 0.45

Tested by

no test coverage detected