Re: Searching for text in PDF files is wrong

2018-12-03 Thread Marius Gedminas
On Fri, Nov 30, 2018 at 09:56:12PM +0100, Радомир Хаџић via gtk-app-devel-list 
wrote:
> I use poppler_page_find_text() to find text in PDF files. This returns
> GList of pointers to PopplerRectangles. Then I use
> poppler_page_render_selection() to mark the found text.
> 
> What is wrong is that PopplerRectangles returned by
> poppler_page_find_text() are incompatible with those that
> poppler_page_render_selection() requests, which is why the wrong text
> is selected.
> 
> I have found that to make those two compatible, I have to do the
> following to PopplerRectangles returned by poppler_page_find_text():
> 1) SWAP(rectangle.x1, rectangle.x2);
> 2) SWAP(rectangle.y1, rectangle.y2);
> 3) rectangle.y1 = page_height - rectangle.y1;
> 4) rectangle.y2 = page_height - rectangle.y2;
> But this does not solve the problem because the marked text cycles
> between right and wrong again while resizing the window.

> is: https://pastebin.com/h3F56Yv7

You're doing in-place coordinate conversions in your drawing code.
Every expose event will change the coordinates event, which is why
you're seeing the flip-flopping.

Do the conversion only once, or use a local temporary PopplerRectangle
variable and avoid in-place conversions.

(I'm not familiar with poppler's APIs and cannot say if your conversion
code is correct.)

HTH,
Marius Gedminas
-- 
Lutetium is the heaviest and hardest of the rare earth metals, and is used in
the production of umlauts and other fraktur font features.
-- Charles Stross
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Searching for text in PDF files is wrong

2018-12-03 Thread Emmanuele Bassi via gtk-app-devel-list
Hi;

this list is for the development of applications with GTK; your question
relates to Poppler, so you should ask on a Poppler-related mailing list or
developers forum, e.g.
https://lists.freedesktop.org/mailman/listinfo/poppler

Ciao,
 Emmanuele.

On Fri, 30 Nov 2018 at 20:56, Радомир Хаџић via gtk-app-devel-list <
gtk-app-devel-list@gnome.org> wrote:

> Hi.
>
> I use poppler_page_find_text() to find text in PDF files. This returns
> GList of pointers to PopplerRectangles. Then I use
> poppler_page_render_selection() to mark the found text.
>
> What is wrong is that PopplerRectangles returned by
> poppler_page_find_text() are incompatible with those that
> poppler_page_render_selection() requests, which is why the wrong text
> is selected.
>
> I have found that to make those two compatible, I have to do the
> following to PopplerRectangles returned by poppler_page_find_text():
> 1) SWAP(rectangle.x1, rectangle.x2);
> 2) SWAP(rectangle.y1, rectangle.y2);
> 3) rectangle.y1 = page_height - rectangle.y1;
> 4) rectangle.y2 = page_height - rectangle.y2;
> But this does not solve the problem because the marked text cycles
> between right and wrong again while resizing the window.
>
> I have created a small program that illustrates the problem. Here it
> is: https://pastebin.com/h3F56Yv7 (I've also sent an attachment but
> last time you didn't get it so this paste is a fallback in case you
> don't get it again.)
> You ought to supply two arguments when running the program: the
> absolute path to a PDF file and the text you want to search for,
> respectively. Pay attention to the selected text with and without
> lines 54-57.
>
> How can I make the found text to be marked properly? This "workaround"
> does not work very well and it is an ugly solution anyway.
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>


-- 
https://www.bassi.io
[@] ebassi [@gmail.com]
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list