Skip to content

Commit

Permalink
Include some of the fixes suggested in #1270
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrm committed Dec 29, 2024
1 parent 82d807a commit ed14e38
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
5 changes: 3 additions & 2 deletions pdf_viewer/database.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "database.h";
#include "database.h"
#include <sstream>
#include <cassert>
#include <utility>
Expand Down Expand Up @@ -1876,11 +1876,12 @@ bool DatabaseManager::update_portal_change_src_position(const std::string& uuid,
});

}

std::wstring encode_variant(QVariant var) {


std::vector<QString> specials = { "CURRENT_TIMESTAMP", "datetime('now')" };
if ((var.type() == QVariant::String) || (var.type() == QVariant::Char)) {
if ((var.typeId() == QMetaType::QString) || (var.typeId() == QMetaType::Char)) {
if (std::find(specials.begin(), specials.end(), var.toString()) != specials.end()) {
return var.toString().toStdWString();
}
Expand Down
7 changes: 4 additions & 3 deletions pdf_viewer/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ std::optional<std::pair<std::wstring, std::wstring>> Document::get_generic_link_
std::pair<int,
int>* out_range) {

std::wregex regex(L"[a-zA-Z]{3,}(\.){0,1}[ \t]+[0-9]+(\.[0-9]+)*");
std::wregex regex(L"[a-zA-Z]{3,}(\\.){0,1}[ \t]+[0-9]+(\\.[0-9]+)*");
std::optional<std::wstring> match_string = get_regex_match_at_position(regex, flat_chars, position, out_range);
if (match_string) {
std::vector<std::wstring> parts = split_whitespace(match_string.value());
Expand Down Expand Up @@ -2843,7 +2843,8 @@ const std::vector<AbsoluteRect>& Document::get_page_lines(
}
else {
fz_pixmap* pixmap = get_small_pixmap(page);
if (pixmap == nullptr) return {};
static const std::vector<AbsoluteRect> empty = {};
if (pixmap == nullptr) return empty;
std::vector<unsigned int> hist = get_max_width_histogram_from_pixmap(pixmap);
std::vector<unsigned int> line_locations;
std::vector<unsigned int> line_locations_begins;
Expand Down Expand Up @@ -4040,7 +4041,7 @@ std::optional<DocumentPos> Document::find_abbreviation(std::wstring abbr, std::v

int Document::find_reference_page_with_reference_text(std::wstring ref) {

QStringList parts = QString::fromStdWString(ref).split(QRegularExpression("[ \w\(\);,]"));
QStringList parts = QString::fromStdWString(ref).split(QRegularExpression("[ \\w\\(\\);,]"));
QString largest_part = "";
for (int i = 0; i < parts.size(); i++) {
if (parts.at(i).size() > largest_part.size() ) {
Expand Down
3 changes: 2 additions & 1 deletion pdf_viewer/document_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ NormalizedWindowPos DocumentView::document_to_window_pos(DocumentPos doc_pos) {
float window_y = static_cast<float>((window_pos.y - halfheight) / halfheight);
return { window_x, -window_y };
}
return { -10, -10 };
}

WindowPos DocumentView::absolute_to_window_pos_in_pixels(AbsoluteDocumentPos abspos) {
Expand Down Expand Up @@ -1337,7 +1338,7 @@ std::vector<SmartViewCandidate> DocumentView::find_line_definitions() {
return result;
}

std::wstring item_regex(L"[a-zA-Z]{2,}\\.?[ \t]+[0-9]+(\.[0-9]+)*");
std::wstring item_regex(L"[a-zA-Z]{2,}\\.?[ \t]+[0-9]+(\\.[0-9]+)*");
std::wstring reference_regex(L"\\[[a-zA-Z0-9, ]+\\]");
std::wstring equation_regex(L"\\([0-9]+(\\.[0-9]+)*\\)");

Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ struct ParseState {
}
return arg;
}
return {};
}

bool is_valid_command_name_char(QChar c) {
Expand Down
2 changes: 0 additions & 2 deletions pdf_viewer/main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3794,8 +3794,6 @@ void MainWidget::execute_command(std::wstring command, std::wstring text, bool w

QString qtext = QString::fromStdWString(command);

qtext.arg(qfile_path);

#ifdef SIOYEK_QT6
QStringList command_parts_ = qtext.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
#else
Expand Down
6 changes: 3 additions & 3 deletions pdf_viewer/pdf_view_opengl_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2232,13 +2232,13 @@ float PdfViewOpenGLWidget::get_overview_side_pos(int index) {
if (index == OverviewSide::bottom) {
return overview_offset_y - overview_half_height;
}
if (index == OverviewSide::top) {
else if (index == OverviewSide::top) {
return overview_offset_y + overview_half_height;
}
if (index == OverviewSide::left) {
else if (index == OverviewSide::left) {
return overview_offset_x - overview_half_width;
}
if (index == OverviewSide::right) {
else {
return overview_offset_x + overview_half_width;
}
}
Expand Down
6 changes: 3 additions & 3 deletions pdf_viewer/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ void index_generic(const std::vector<fz_stext_char*>& flat_chars, int page_numbe
}
}

std::wregex index_dst_regex(L"(^|\n)[A-Z][a-zA-Z]{2,}\.?[ \t]+[0-9]+(\.[0-9]+)*");
std::wregex index_dst_regex(L"(^|\n)[A-Z][a-zA-Z]{2,}\\.?[ \t]+[0-9]+(\\.[0-9]+)*");
//std::wregex index_dst_regex(L"(^|\n)[A-Z][a-zA-Z]{2,}[ \t]+[0-9]+(\-[0-9]+)*");
//std::wregex index_src_regex(L"[a-zA-Z]{3,}[ \t]+[0-9]+(\.[0-9]+)*");
std::wsmatch match;
Expand Down Expand Up @@ -3651,7 +3651,7 @@ std::wstring get_paper_name_from_reference_text(std::wstring reference_text) {

QString str = QString::fromStdWString(reference_text);
//QRegularExpression reference_ending_dot_regex = QRegularExpression("(\.\w*In )|(\.\w*[aA]r[xX]iv )|(\.\w*[aA]r[X]iv )");
QRegularExpression reference_ending_dot_regex = QRegularExpression("(\.\w*In )|(\.\w*[aA]r[xX]iv )");
QRegularExpression reference_ending_dot_regex = QRegularExpression("(\\.\\w*In )|(\\.\w*[aA]r[xX]iv )");

int ending_index = str.lastIndexOf(reference_ending_dot_regex);
if (ending_index == -1) {
Expand Down Expand Up @@ -3830,7 +3830,7 @@ bool is_text_refernce_rather_than_paper_name(std::wstring text) {
return true;
}

QStringList parts = QString::fromStdWString(text).split(QRegularExpression("[ \(\)]"));
QStringList parts = QString::fromStdWString(text).split(QRegularExpression("[ \\(\\)]"));
for (int i = 0; i < parts.size(); i++) {
if (is_year(parts[i])) {
return true;
Expand Down

0 comments on commit ed14e38

Please sign in to comment.