108 lines
4.2 KiB
Diff
108 lines
4.2 KiB
Diff
From 310c7c65cf85d1eee4515ef67b9a89c939ae9492 Mon Sep 17 00:00:00 2001
|
|
From: hrdl <31923882+lennonhill@users.noreply.github.com>
|
|
Date: Mon, 29 Aug 2022 12:43:31 +0200
|
|
Subject: [PATCH] Parse mupdf 1.20 links
|
|
|
|
---
|
|
pdf_viewer/document_view.cpp | 2 +-
|
|
pdf_viewer/main_widget.cpp | 6 +++---
|
|
pdf_viewer/utils.cpp | 20 +++++---------------
|
|
pdf_viewer/utils.h | 2 +-
|
|
4 files changed, 10 insertions(+), 20 deletions(-)
|
|
|
|
diff --git a/pdf_viewer/document_view.cpp b/pdf_viewer/document_view.cpp
|
|
index ace3f161d..1362ee4b5 100644
|
|
--- a/pdf_viewer/document_view.cpp
|
|
+++ b/pdf_viewer/document_view.cpp
|
|
@@ -1077,7 +1077,7 @@ std::vector<DocumentPos> DocumentView::find_line_definitions() {
|
|
|
|
std::optional<PdfLink> pdf_link = current_document->get_link_in_page_rect(get_center_page_number(), line_rects[line_index]);
|
|
if (pdf_link.has_value()) {
|
|
- auto parsed_uri = parse_uri(pdf_link.value().uri);
|
|
+ auto parsed_uri = parse_uri(mupdf_context, pdf_link.value().uri);
|
|
result.push_back({ parsed_uri.page - 1, parsed_uri.x, parsed_uri.y });
|
|
return result;
|
|
}
|
|
diff --git a/pdf_viewer/main_widget.cpp b/pdf_viewer/main_widget.cpp
|
|
index 5265398d2..707d11b30 100644
|
|
--- a/pdf_viewer/main_widget.cpp
|
|
+++ b/pdf_viewer/main_widget.cpp
|
|
@@ -153,7 +153,7 @@ void MainWidget::set_overview_position(int page, float offset) {
|
|
|
|
void MainWidget::set_overview_link(PdfLink link) {
|
|
|
|
- auto [page, offset_x, offset_y] = parse_uri(link.uri);
|
|
+ auto [page, offset_x, offset_y] = parse_uri(mupdf_context, link.uri);
|
|
if (page >= 1) {
|
|
set_overview_position(page - 1, offset_y);
|
|
}
|
|
@@ -2861,7 +2861,7 @@ void MainWidget::handle_pending_text_command(std::wstring text) {
|
|
open_web_url(utf8_decode(selected_link->uri));
|
|
}
|
|
else{
|
|
- auto [page, offset_x, offset_y] = parse_uri(selected_link->uri);
|
|
+ auto [page, offset_x, offset_y] = parse_uri(mupdf_context, selected_link->uri);
|
|
long_jump_to_destination(page-1, offset_y);
|
|
}
|
|
}
|
|
@@ -3472,7 +3472,7 @@ void MainWidget::handle_link_click(const PdfLink& link) {
|
|
return;
|
|
}
|
|
|
|
- auto [page, offset_x, offset_y] = parse_uri(link.uri);
|
|
+ auto [page, offset_x, offset_y] = parse_uri(mupdf_context, link.uri);
|
|
|
|
// convert one indexed page to zero indexed page
|
|
page--;
|
|
diff --git a/pdf_viewer/utils.cpp b/pdf_viewer/utils.cpp
|
|
index a25d18f10..e416737ba 100644
|
|
--- a/pdf_viewer/utils.cpp
|
|
+++ b/pdf_viewer/utils.cpp
|
|
@@ -24,6 +24,8 @@
|
|
#include <qnetworkreply.h>
|
|
#include <qscreen.h>
|
|
|
|
+#include <mupdf/pdf.h>
|
|
+
|
|
extern std::wstring LIBGEN_ADDRESS;
|
|
extern std::wstring GOOGLE_SCHOLAR_ADDRESS;
|
|
extern std::ofstream LOG_FILE;
|
|
@@ -106,21 +108,9 @@ bool rects_intersect(fz_rect rect1, fz_rect rect2) {
|
|
return range_intersects(rect1.x0, rect1.x1, rect2.x0, rect2.x1) && range_intersects(rect1.y0, rect1.y1, rect2.y0, rect2.y1);
|
|
}
|
|
|
|
-ParsedUri parse_uri(std::string uri) {
|
|
- int comma_index = -1;
|
|
-
|
|
- uri = uri.substr(1, uri.size() - 1);
|
|
- comma_index = static_cast<int>(uri.find(","));
|
|
- int page = atoi(uri.substr(0, comma_index ).c_str());
|
|
-
|
|
- uri = uri.substr(comma_index+1, uri.size() - comma_index-1);
|
|
- comma_index = static_cast<int>(uri.find(","));
|
|
- float offset_x = atof(uri.substr(0, comma_index ).c_str());
|
|
-
|
|
- uri = uri.substr(comma_index+1, uri.size() - comma_index-1);
|
|
- float offset_y = atof(uri.c_str());
|
|
-
|
|
- return { page, offset_x, offset_y };
|
|
+ParsedUri parse_uri(fz_context* mupdf_context, std::string uri) {
|
|
+ fz_link_dest dest = pdf_parse_link_uri(mupdf_context, uri.c_str());
|
|
+ return { dest.loc.page + 1, dest.x, dest.y };
|
|
}
|
|
|
|
char get_symbol(int key, bool is_shift_pressed, const std::vector<char>& special_symbols) {
|
|
diff --git a/pdf_viewer/utils.h b/pdf_viewer/utils.h
|
|
index 4d551c35a..aa0d0d61b 100644
|
|
--- a/pdf_viewer/utils.h
|
|
+++ b/pdf_viewer/utils.h
|
|
@@ -33,7 +33,7 @@ void get_flat_toc(const std::vector<TocNode*>& roots, std::vector<std::wstring>&
|
|
int mod(int a, int b);
|
|
bool range_intersects(float range1_start, float range1_end, float range2_start, float range2_end);
|
|
bool rects_intersect(fz_rect rect1, fz_rect rect2);
|
|
-ParsedUri parse_uri(std::string uri);
|
|
+ParsedUri parse_uri(fz_context* mupdf_context, std::string uri);
|
|
char get_symbol(int key, bool is_shift_pressed, const std::vector<char>&special_symbols);
|
|
|
|
template<typename T>
|