Selecting text from annotation rect selects the wrong text
Preface:
Using the latest code in the master branch. I have searched the issues and didn't find anything related, apologies if this is known. Also apologies if this is expected behavior. If it's not expected behavior, I'd gladly submit a PR to fix the issue.
Problem:
For highlight annotations, it's useful to extract the highlighted text. Annotations have their coordinates start (point 0,0) at the bottom left of the page, but it seems text selection starts at the top left of the page. At least for the glib api this is the case. Note that the annotation was done in Okular which uses the QT5 api of Poppler.
As such the following does not work:
char *text = poppler_page_get_text_for_area(demo->page, &amapping->area);
Nor does this (same results as the screenshots above):
PopplerRectangle rect;
poppler_annot_get_rectangle(amapping->annot, &rect);
char *text = poppler_page_get_text_for_area(demo->page, &rect);
This does get the correct text (792 is the page height):
PopplerRectangle rect;
poppler_annot_get_rectangle(amapping->annot, &rect);
rect.y1 = 792 - rect.y1;
rect.y2 = 792 - rect.y2;
char *text = poppler_page_get_text_for_area(demo->page, &rect);
Test files
Debug info