| 580 | } |
| 581 | |
| 582 | void PDFDocumentWindow::syncRange(const size_type pageIndex, const QPointF & start, const QPointF & end, const TWSynchronizer::Resolution resolution) |
| 583 | { |
| 584 | if (!_synchronizer) |
| 585 | return; |
| 586 | |
| 587 | clearSyncHighlight(); |
| 588 | |
| 589 | // NOTE: "start" and "end" are in PDF coordinates, which are upside down |
| 590 | // (i.e., (0,0) is in the lower left), whereas SyncTeX expects TeX |
| 591 | // coordinates (i.e., (0,0) in the upper left). Hence we need to convert the |
| 592 | // coordinates. |
| 593 | QSharedPointer<QtPDF::Backend::Document> doc = pdfWidget->document().toStrongRef(); |
| 594 | if (!doc) |
| 595 | return; |
| 596 | QSharedPointer<QtPDF::Backend::Page> page = doc->page(pageIndex).toStrongRef(); |
| 597 | if (!page) |
| 598 | return; |
| 599 | |
| 600 | // Synchronize the point "start" |
| 601 | TWSynchronizer::PDFSyncPoint srcStart; |
| 602 | srcStart.filename = curFile; |
| 603 | srcStart.page = pageIndex + 1; |
| 604 | srcStart.rects.append(QRectF(start.x(), page->pageSizeF().height() - start.y(), 0, 0)); |
| 605 | TWSynchronizer::TeXSyncPoint destStart = _synchronizer->syncFromPDF(srcStart, resolution); |
| 606 | |
| 607 | // Syncronize the point "end" |
| 608 | TWSynchronizer::TeXSyncPoint destEnd; |
| 609 | if (end.isNull() || end == start) |
| 610 | // If "end" was not provided or was the same as "start", just copy the |
| 611 | // result |
| 612 | destEnd = destStart; |
| 613 | else { |
| 614 | // Otherwise, perform the synchronization |
| 615 | TWSynchronizer::PDFSyncPoint srcEnd; |
| 616 | srcEnd.filename = curFile; |
| 617 | srcEnd.page = pageIndex + 1; |
| 618 | srcEnd.rects.append(QRectF(end.x(), page->pageSizeF().height() - end.y(), 0, 0)); |
| 619 | destEnd = _synchronizer->syncFromPDF(srcEnd, resolution); |
| 620 | } |
| 621 | |
| 622 | // Check if (at least) "start" was properly synchronized; if not: bail out |
| 623 | if (destStart.filename.isEmpty() || destStart.line < 0) |
| 624 | return; |
| 625 | |
| 626 | // Open the destination document (for the point "start"), and put the cursor |
| 627 | // on the right line (though not necessarily on the right column or with the |
| 628 | // the right selection, yet, as that requires additional handling below) |
| 629 | QDir curDir(QFileInfo(curFile).canonicalPath()); |
| 630 | TeXDocumentWindow * texDoc = TeXDocumentWindow::openDocument(QFileInfo(curDir, destStart.filename).canonicalFilePath(), true, true, destStart.line); |
| 631 | if (!texDoc) |
| 632 | return; |
| 633 | |
| 634 | // Get a text cursor in the correct position for "start" (if no valid column |
| 635 | // was found, place it at the beginning of the correct line) |
| 636 | QTextCursor curStart = texDoc->textCursor(); |
| 637 | using pos_type = decltype(curStart.position()); |
| 638 | curStart.setPosition(0); |
| 639 | curStart.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, destStart.line - 1); |
nothing calls this directly
no test coverage detected