[poppler] problem with rectangles of links in a pdf

Carlos Garcia Campos carlosgc at gnome.org
Tue Oct 12 02:39:04 PDT 2010


Excerpts from Vincent Torri's message of mar oct 12 11:01:12 +0200 2010:
> 
> On Tue, 12 Oct 2010, Carlos Garcia Campos wrote:
> 
> > Excerpts from Vincent Torri's message of lun oct 11 09:13:11 +0200 2010:
> >>
> >> Hey,
> >>
> >> I am trying to display the rectangles of the links of a pdf. Here is what
> >> i do (basically, it's what the glib frontend does):
> >>
> >> /* I loop over the links */
> >> link = links.getLink(i);
> >> link->getRect (&x1, &y1, &x2, &y2);
> >> x1 -= ebp->page.page->getCropBox()->x1;
> >> x2 -= ebp->page.page->getCropBox()->x1;
> >> y1 -= ebp->page.page->getCropBox()->y1;
> >> y2 -= ebp->page.page->getCropBox()->y1;
> >>
> >> link_item->rect.x = round(x1);
> >> link_item->rect.y = round(y1);
> >> link_item->rect.w = round(x2 - x1);
> >> link_item->rect.h = round(y2 - y1);
> >>
> >> I display these rectangles on the pdf. I have attached the result
> >> (rectangles are blue) and the pdf.
> >>
> >> Does someone see if what I did is wrong ?
> >
> > You need to invert the y axis, in the PDF coordinate system the origin
> > (0, 0) is at the lower-left corner, while in X is at the upper-left
> > corner. So, you need something like:
> >
> > screen_rectangle.y = height - pdf_link_rectangle.y1;
> 
> It's better but no perfect yet (see attachment). The vertical alignement 
> is still not good, and some rectangles are overlapping (because i'm 
> rounding values ?)

Without looking at the code it's difficult to know what's wrong.

> Note that the glib frontend has certainly the same bug:
> 
>      default:
>        mapping->area.x1 = rect.x1;
>        mapping->area.y1 = rect.y1;
>        mapping->area.x2 = rect.x2;
>        mapping->area.y2 = rect.y2;
> 
> in poppler-page.cc (poppler 0.15)

This is not a bug, we expose coords in PDF user space, so that
depending on your device space you will need to transform or not.

> Vincent Torri

Regards, 
-- 
Carlos Garcia Campos
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/poppler/attachments/20101012/ebc6c687/attachment.pgp>


More information about the poppler mailing list