Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Left-side equations are indexed as well and can be smart-jumped to #783

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pdf_viewer/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ std::vector<std::unique_ptr<Command>> InputHandler::handle_key(QKeyEvent* key_ev

int key = 0;
if (!USE_LEGACY_KEYBINDS){
std::vector<QString> special_texts = {"\b", "\t", " ", "\r", "\n"};
std::vector<QString> special_texts = {"\b", "\u007F", "\t", " ", "\r", "\n"};
if (((key_event->key() >= 'A') && (key_event->key() <= 'Z')) || ((key_event->text().size() > 0) &&
(std::find(special_texts.begin(), special_texts.end(), key_event->text()) == special_texts.end()))) {
if (!control_pressed && !alt_pressed) {
Expand Down
14 changes: 8 additions & 6 deletions pdf_viewer/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,14 @@ void find_regex_matches_in_stext_page(const std::vector<fz_stext_char*>& flat_ch
}
}

bool are_stext_chars_far_enough_for_equation(fz_stext_char* first, fz_stext_char* second) {
bool are_stext_chars_far_enough_for_equation(fz_stext_char* first, fz_stext_char* second, fz_stext_char* eqn_end, fz_stext_char* eqn_end_next) {
float second_width = second->quad.lr.x - second->quad.ll.x;

if (second_width < 0) {
return false;
}

return (second->origin.x - first->origin.x) > (5 * second_width);
return (second->origin.x - first->origin.x) > (5 * second_width) || (eqn_end_next->origin.x - eqn_end->origin.x) > (5 * second_width);
}

bool is_whitespace(int chr) {
Expand Down Expand Up @@ -1114,9 +1114,11 @@ void index_equations(const std::vector<fz_stext_char*> &flat_chars, int page_num
break;
}


// we expect the equation reference to be sufficiently separated from the rest of the text
if (((start_index > 0) && are_stext_chars_far_enough_for_equation(flat_chars[start_index-1], flat_chars[start_index]))) {
// we expect the equation reference to be sufficiently separated from the rest of the text.
// When equations are on the left-hand side, for whatever reason for non-optimal OCR, the
// equation is trailed by some character, so that we have to compare distance of the last
// character in the equation with the character 2 afterward, rather than the next.
if (((start_index > 0 && end_index < flat_chars.size() - 2) && are_stext_chars_far_enough_for_equation(flat_chars[start_index-1], flat_chars[start_index], flat_chars[end_index], flat_chars[end_index+2]))) {

std::wstring match_text = match_texts[i].substr(1, match_texts[i].size() - 2);
IndexedData indexed_equation;
Expand Down