[poppler] Annot Improving (II)

Iñigo Martínez inigomartinez at gmail.com
Tue Nov 6 00:53:44 PST 2007


2007/11/6, Jeff Muizelaar <jeff at infidigm.net>:
> On Tue, Nov 06, 2007 at 12:33:20AM +0100, Iñigo Martínez wrote:
> > Here goes another patch related to Annot improvement. It's a simple
> > cleaning. I have used PDFRectangle structure for Annotation rectangle.
> >
> > The changes in yesterdays patch are along with these changes too.
> >
> > Maybe I should split both changes too ?
>
> Definitely. It makes it much easier to review. I'd suggest looking at
> stgit for managing patch sets.

Thank you for reviewing my code Jeff. I'm just now searching
information about stgit.
>
> A bit of review follows.
>
> -Jeff
>
> >    //----- parse the rectangle
> > +  rect = new PDFRectangle();
> > +  if (dict->lookup("Rect", &obj1)->isArray() && obj1.arrayGetLength() == 4) {
> > +    Object obj2;
> > +    (obj1.arrayGet(0, &obj2)->isNum() ? rect->x1 = obj2.getNum() : rect->x1 = 0);
> > +    obj2.free();
> > +    (obj1.arrayGet(1, &obj2)->isNum() ? rect->y1 = obj2.getNum() : rect->y1 = 0);
> > +    obj2.free();
> > +    (obj1.arrayGet(2, &obj2)->isNum() ? rect->x2 = obj2.getNum() : rect->x2 = 1);
> > +    obj2.free();
> > +    (obj1.arrayGet(3, &obj2)->isNum() ? rect->y2 = obj2.getNum() : rect->y2 = 1);
> > +    obj2.free();
>
> The old code defaults to xMax and yMax of 0. Why the change to 1?

Umm, the old code defaults both xMax and yMax to 0 in the case of the
object not being a number in the readArrayNum method. But in those
cases readArrayNum sets 'ok' to false, so once it returns, the code
checks 'ok' in the condition and sets their values to 1 for both. In
the new code, it does check every object without caring about the
rest. If any of them is wrong, the object isn't a number object, it
does reset the value to its default value.

Sincerely, I don't know what should be the correct behaviour. The
'Rect' entry is a required field, so if something is wrong there you
can't ignore the object, it must be filled with something.

This is a question (one of many :p) I had some time ago. What should
be done where the data is wrong on an object ? In some entries default
values are specified, but not in others. Do you use any policy to
handle this cases ?

>
> >
> > -  if (dict->lookup("Rect", &obj1)->isArray() &&
> > -      obj1.arrayGetLength() == 4) {
> > -    readArrayNum(&obj1, 0, &xMin);
> > -    readArrayNum(&obj1, 1, &yMin);
> > -    readArrayNum(&obj1, 2, &xMax);
> > -    readArrayNum(&obj1, 3, &yMax);
> > -    if (ok) {
> > -      if (xMin > xMax) {
> > -        t = xMin; xMin = xMax; xMax = t;
> > -      }
> > -      if (yMin > yMax) {
> > -        t = yMin; yMin = yMax; yMax = t;
> > -      }
> > -    } else {
> > -      xMin = yMin = 0;
> > -      xMax = yMax = 1;
> > -      error(-1, "Bad bounding box for annotation");
> > -      ok = gFalse;
> > +    if (rect->x1 > rect->x2) {
> > +      double t = rect->x1;
> > +      rect->x1 = rect->x2;
> > +      rect->x2 = t;
> > +    }
> > +
> > +    if (rect->y1 > rect->y2) {
> > +      double t = rect->y1;
> > +      rect->y1 = rect->y2;
> > +      rect->y2 = t;
> >      }
> >    } else {
> > -    xMin = yMin = 0;
> > -    xMax = yMax = 1;
> > +    rect->x1 = rect->y1 = 0;
> > +    rect->x2 = rect->y2 = 1;
> >      error(-1, "Bad bounding box for annotation");
> >      ok = gFalse;
> >    }


More information about the poppler mailing list