[Poppler-bugs] [Bug 51487] [PATCH] Add support for TextMarkup Annotations in glib frontend

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Thu Jan 30 14:49:55 PST 2014


https://bugs.freedesktop.org/show_bug.cgi?id=51487

--- Comment #46 from Germán Poo-Caamaño <gpoo at gnome.org> ---
Created attachment 93092
  --> https://bugs.freedesktop.org/attachment.cgi?id=93092&action=edit
glib-demo: Fix performance in text markup annotations

The performance issue is in the following snippet:

     if (ABS(r->y2 - rects[i].y2) > 0.0001) {
        if (i > 0)
             l_rects = g_list_append (l_rects, r);
         r = g_slice_new (PopplerRectangle);
         r->x1 = rects[i].x1;
         r->y1 = height - rects[i].y1;
         r->x2 = rects[i].x2;
         r->y2 = height - rects[i].y2;
         lines++;
     } else {
         r->x1 = MIN(r->x1, rects[i].x1);
         r->y1 = height - MIN(r->y1, rects[i].y1);
         r->x2 = MAX(r->x2, rects[i].x2);
         r->y2 = height - MAX(r->y2, rects[i].y2);
     }

The condition is never FALSE, r->y2 is never close to
rects[i].y2 because r->y2 is now relative to the height.
Therefore, this makes the text markup slow because it
creates a rectangle per glyph (in my test 199 glyphs in
3 lines).

To make it work, we would need something like:

    if (ABS(r->y2 - (height - rects[i].y2)) > 0.0001) {
        if (i > 0)
            l_rects = g_list_append (l_rects, r);
        r = g_slice_new (PopplerRectangle);
        r->x1 = rects[i].x1;
        r->y1 = height - rects[i].y1;
        r->x2 = rects[i].x2;
        r->y2 = height - rects[i].y2;
        lines++;
    } else {
        r->x1 = MIN(r->x1, rects[i].x1);
        r->y1 = MIN(r->y1, height - rects[i].y1 + 14);
        r->x2 = MAX(r->x2, rects[i].x2);
        r->y2 = MAX(r->y2, height - rects[i].y2);
    }

Do you notice the magic 14?  I suspect that that number is
the line height.  Without that number, the quadrilaterals
ends with something that resembles rectangle coordinates
instead of quadrilateral ones, for example:

P1: 114.0, 114.0    P2: 292.0, 553.0
P3: 114.0, 559.0    P4: 292.0, 559.0

instead of the correct one:

P1: 114.0, 114.0    P2: 292.0, 567.0 **
P3: 114.0, 559.0    P4: 292.0, 559.0

The difference between 567 and 553 is 14, the line height
(font size?) in my test.

If there were such API (which I don't know) we could even
set an extra pixel on both top and bottom, that would make
the highlight looks nicer (IMHO). However, the use of API
would become even more complicated than it should be.

I still think that a solution in the line of what
poppler_page_get_selection_region provided would be better.
Because it would make its use simpler, and we could leave
poppler_page_get_text_layout_for_area for special situations.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/poppler-bugs/attachments/20140130/889d9f7e/attachment.html>


More information about the Poppler-bugs mailing list