Hi: Here goes another path. Very small one. It's about the PDFRectangle proposal.
I have another questions with this one too. 1. What for are getXMin and getYMin ? I mean, they aren't used anywhere (I haven't found any place where they are used). 2. Shouldn't be better to encapsulate PDFRectangle, doing x1,x2,y1 and y2 private and implementing getters and setters ? (anyway this is an aesthetically change). Off topic: I have forgot to mention that I have been late sending back these changes because at the moment I'm unemployed and I have been searhing a new job. Sorry! Bye,
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 2e09848..6c27130 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -26,6 +26,7 @@
#include "CharCodeToUnicode.h"
#include "Form.h"
#include "Error.h"
+#include "Page.h"
#define annotFlagHidden 0x0002
#define annotFlagPrint 0x0004
@@ -104,7 +105,6 @@ void Annot::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog
double *borderDash;
int borderDashLength;
double borderR, borderG, borderB;
- double t;
ok = gTrue;
xref = xrefA;
@@ -129,34 +129,37 @@ void Annot::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog
obj1.free();
//----- 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();
- 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;
}
obj1.free();
-
+
//----- get the flags
if (dict->lookup("F", &obj1)->isInt()) {
flags = obj1.getInt();
@@ -320,6 +323,14 @@ void Annot::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog
borderR, borderG, borderB);
}
+double Annot::getXMin() {
+ return rect->x1;
+}
+
+double Annot::getYMin() {
+ return rect->y1;
+}
+
void Annot::readArrayNum(Object *pdfArray, int key, double *value) {
Object valueObject;
@@ -392,7 +403,7 @@ void Annot::generateFieldAppearance(Dict *field, Dict *annot, Dict *acroForm) {
obj1.arrayGetLength() > 0) {
setColor(obj1.getArray(), gTrue, 0);
appearBuf->appendf("0 0 {0:.2f} {1:.2f} re f\n",
- xMax - xMin, yMax - yMin);
+ rect->x2 - rect->x1, rect->y2 - rect->y1);
}
obj1.free();
}
@@ -417,8 +428,8 @@ void Annot::generateFieldAppearance(Dict *field, Dict *annot, Dict *acroForm) {
mkDict->lookup("BG", &obj1);
}
if (obj1.isArray() && obj1.arrayGetLength() > 0) {
- dx = xMax - xMin;
- dy = yMax - yMin;
+ dx = rect->x2 - rect->x1;
+ dy = rect->y2 - rect->y1;
// radio buttons with no caption have a round border
hasCaption = mkDict->lookup("CA", &obj2)->isString();
@@ -554,8 +565,8 @@ void Annot::generateFieldAppearance(Dict *field, Dict *annot, Dict *acroForm) {
if (mkDict) {
if (mkDict->lookup("BC", &obj3)->isArray() &&
obj3.arrayGetLength() > 0) {
- dx = xMax - xMin;
- dy = yMax - yMin;
+ dx = rect->x2 - rect->x1;
+ dy = rect->y2 - rect->y1;
setColor(obj3.getArray(), gTrue, 0);
drawCircle(0.5 * dx, 0.5 * dy, 0.2 * (dx < dy ? dx : dy),
gTrue);
@@ -704,8 +715,8 @@ void Annot::generateFieldAppearance(Dict *field, Dict *annot, Dict *acroForm) {
obj1.initArray(xref);
obj1.arrayAdd(obj2.initReal(0));
obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(xMax - xMin));
- obj1.arrayAdd(obj2.initReal(yMax - yMin));
+ obj1.arrayAdd(obj2.initReal(rect->x2 - rect->x1));
+ obj1.arrayAdd(obj2.initReal(rect->y2 - rect->y1));
appearDict.dictAdd(copyString("BBox"), &obj1);
// set the resource dictionary
@@ -911,12 +922,12 @@ void Annot::drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
if (multiline) {
// note: the comb flag is ignored in multiline mode
- wMax = xMax - xMin - 2 * border - 4;
+ wMax = rect->x2 - rect->x1 - 2 * border - 4;
// compute font autosize
if (fontSize == 0) {
for (fontSize = 20; fontSize > 1; --fontSize) {
- y = yMax - yMin;
+ y = rect->y2 - rect->y1;
w2 = 0;
i = 0;
while (i < text->getLength()) {
@@ -942,7 +953,7 @@ void Annot::drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
// starting y coordinate
// (note: each line of text starts with a Td operator that moves
// down a line)
- y = yMax - yMin;
+ y = rect->y2 - rect->y1;
// set the font matrix
if (tmPos >= 0) {
@@ -980,10 +991,10 @@ void Annot::drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
x = border + 2;
break;
case fieldQuadCenter:
- x = (xMax - xMin - w) / 2;
+ x = (rect->x2 - rect->x1 - w) / 2;
break;
case fieldQuadRight:
- x = xMax - xMin - border - 2 - w;
+ x = rect->x2 - rect->x1 - border - 2 - w;
break;
}
@@ -1005,11 +1016,11 @@ void Annot::drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
// comb formatting
if (comb > 0) {
// compute comb spacing
- w = (xMax - xMin - 2 * border) / comb;
+ w = (rect->x2 - rect->x1 - 2 * border) / comb;
// compute font autosize
if (fontSize == 0) {
- fontSize = yMax - yMin - 2 * border;
+ fontSize = rect->y2 - rect->y1 - 2 * border;
if (w < fontSize) {
fontSize = w;
}
@@ -1034,7 +1045,7 @@ void Annot::drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
x = border + 2 + (comb - text->getLength()) * w;
break;
}
- y = 0.5 * (yMax - yMin) - 0.4 * fontSize;
+ y = 0.5 * (rect->y2 - rect->y1) - 0.4 * fontSize;
// set the font matrix
if (tmPos >= 0) {
@@ -1086,8 +1097,8 @@ void Annot::drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
// compute font autosize
if (fontSize == 0) {
- fontSize = yMax - yMin - 2 * border;
- fontSize2 = (xMax - xMin - 4 - 2 * border) / w;
+ fontSize = rect->y2 - rect->y1 - 2 * border;
+ fontSize2 = (rect->x2 - rect->x1 - 4 - 2 * border) / w;
if (fontSize2 < fontSize) {
fontSize = fontSize2;
}
@@ -1107,13 +1118,13 @@ void Annot::drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
x = border + 2;
break;
case fieldQuadCenter:
- x = (xMax - xMin - w) / 2;
+ x = (rect->x2 - rect->x1 - w) / 2;
break;
case fieldQuadRight:
- x = xMax - xMin - border - 2 - w;
+ x = rect->x2 - rect->x1 - border - 2 - w;
break;
}
- y = 0.5 * (yMax - yMin) - 0.4 * fontSize;
+ y = 0.5 * (rect->y2 - rect->y1) - 0.4 * fontSize;
// set the font matrix
if (tmPos >= 0) {
@@ -1237,8 +1248,8 @@ void Annot::drawListBox(GooString **text, GBool *selection,
wMax = w;
}
}
- fontSize = yMax - yMin - 2 * border;
- fontSize2 = (xMax - xMin - 4 - 2 * border) / wMax;
+ fontSize = rect->y2 - rect->y1 - 2 * border;
+ fontSize2 = (rect->x2 - rect->x1 - 4 - 2 * border) / wMax;
if (fontSize2 < fontSize) {
fontSize = fontSize2;
}
@@ -1250,7 +1261,7 @@ void Annot::drawListBox(GooString **text, GBool *selection,
}
}
// draw the text
- y = yMax - yMin - 1.1 * fontSize;
+ y = rect->y2 - rect->y1 - 1.1 * fontSize;
for (i = topIdx; i < nOptions; ++i) {
// setup
appearBuf->append("q\n");
@@ -1261,7 +1272,7 @@ void Annot::drawListBox(GooString **text, GBool *selection,
appearBuf->appendf("{0:.2f} {1:.2f} {2:.2f} {3:.2f} re f\n",
border,
y - 0.2 * fontSize,
- xMax - xMin - 2 * border,
+ rect->x2 - rect->x1 - 2 * border,
1.1 * fontSize);
}
@@ -1287,10 +1298,10 @@ void Annot::drawListBox(GooString **text, GBool *selection,
x = border + 2;
break;
case fieldQuadCenter:
- x = (xMax - xMin - w) / 2;
+ x = (rect->x2 - rect->x1 - w) / 2;
break;
case fieldQuadRight:
- x = xMax - xMin - border - 2 - w;
+ x = rect->x2 - rect->x1 - border - 2 - w;
break;
}
@@ -1495,7 +1506,7 @@ void Annot::draw(Gfx *gfx, GBool printing) {
isLink = type && !type->cmp("Link");
appearance.fetch(xref, &obj);
gfx->drawAnnot(&obj, isLink ? borderStyle : (AnnotBorderStyle *)NULL,
- xMin, yMin, xMax, yMax);
+ rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 50f5bfb..5b7c2b5 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -20,6 +20,7 @@ class CharCodeToUnicode;
class GfxFont;
class GfxFontDict;
class FormWidget;
+class PDFRectangle;
//------------------------------------------------------------------------
// AnnotBorderStyle
@@ -82,13 +83,14 @@ public:
void generateFieldAppearance(Dict *field, Dict *annot, Dict *acroForm);
- double getXMin() { return xMin; }
- double getYMin() { return yMin; }
+ double getXMin();
+ double getYMin();
double getFontSize() { return fontSize; }
GooString *getType() { return type; }
-
+ PDFRectangle *getRect() { return rect; }
+
private:
void setColor(Array *a, GBool fill, int adjust);
void drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
@@ -110,6 +112,9 @@ private:
void initialize (XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog);
+ // required data
+ PDFRectangle *rect; // Rect
+
XRef *xref; // the xref table for this PDF file
Ref ref; // object ref identifying this annotation
FormWidget *widget; // FormWidget object for this annotation
@@ -118,8 +123,6 @@ private:
// for the normal appearance
GooString *appearBuf;
Guint flags;
- double xMin, yMin, // annotation rectangle
- xMax, yMax;
AnnotBorderStyle *borderStyle;
double fontSize;
GBool ok;
signature.asc
Description: Esta parte del mensaje está firmada digitalmente
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
