Commit 905e6da9 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos

Move forms specific draw methods from Annot to AnnotWidget class

parent 78afbc4d
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -19,6 +19,7 @@ class Catalog;
class CharCodeToUnicode;
class GfxFont;
class GfxFontDict;
class Form;
class FormWidget;
class PDFRectangle;
......@@ -437,21 +438,18 @@ public:
type3D // 3D 25
};
Annot(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog* catalog);
Annot(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
Annot(XRef *xrefA, Dict *dict, Catalog* catalog);
Annot(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
virtual ~Annot();
GBool isOk() { return ok; }
void draw(Gfx *gfx, GBool printing);
virtual void draw(Gfx *gfx, GBool printing);
// Get appearance object.
Object *getAppearance(Object *obj) { return appearance.fetch(xref, obj); }
GBool textField() { return isTextField; }
GBool match(Ref *refA)
{ return ref.num == refA->num && ref.gen == refA->gen; }
void generateFieldAppearance(Dict *field, Dict *annot, Dict *acroForm);
double getXMin();
double getYMin();
......@@ -473,27 +471,17 @@ public:
Dict *getOptionalContent() const { return optionalContent; }
private:
void setColor(Array *a, GBool fill, int adjust);
void drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
GBool multiline, int comb, int quadding,
GBool txField, GBool forceZapfDingbats,
GBool password=false);
void drawListBox(GooString **text, GBool *selection,
int nOptions, int topIdx,
GooString *da, GfxFontDict *fontDict, GBool quadding);
void getNextLine(GooString *text, int start,
GfxFont *font, double fontSize, double wMax,
int *end, double *width, int *next);
void drawCircle(double cx, double cy, double r, GBool fill);
void drawCircleTopLeft(double cx, double cy, double r);
void drawCircleBottomRight(double cx, double cy, double r);
void readArrayNum(Object *pdfArray, int key, double *value);
// write vStr[i:j[ in appearBuf
void writeTextString (GooString *text, GooString *appearBuf, int *i, int j, CharCodeToUnicode *ccToUnicode, GBool password);
void initialize (XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog);
void initialize (XRef *xrefA, Dict *dict, Catalog *catalog);
protected:
void setColor(Array *a, GBool fill, int adjust);
void drawCircle(double cx, double cy, double r, GBool fill);
void drawCircleTopLeft(double cx, double cy, double r);
void drawCircleBottomRight(double cx, double cy, double r);
// required data
AnnotSubtype type; // Annotation type
PDFRectangle *rect; // Rect
......@@ -514,14 +502,11 @@ protected:
XRef *xref; // the xref table for this PDF file
Ref ref; // object ref identifying this annotation
FormWidget *widget; // FormWidget object for this annotation
GooString *appearBuf;
AnnotBorder *border; // Border, BS
AnnotColor *color; // C
double fontSize;
GBool ok;
GBool regen, isTextField;
GBool isMultiline, isListbox;
bool hasRef;
};
......@@ -532,14 +517,14 @@ protected:
class AnnotPopup: public Annot {
public:
AnnotPopup(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
virtual ~AnnotPopup();
Dict *getParent() const { return parent; }
GBool getOpen() const { return open; }
protected:
void initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog);
void initialize(XRef *xrefA, Dict *dict, Catalog *catalog);
Dict *parent; // Parent
GBool open; // Open
......@@ -556,7 +541,7 @@ public:
replyTypeGroup // Group
};
AnnotMarkup(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
AnnotMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
virtual ~AnnotMarkup();
// getters
......@@ -585,7 +570,7 @@ protected:
AnnotExternalDataType exData; // ExData
private:
void initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
void initialize(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
};
//------------------------------------------------------------------------
......@@ -617,7 +602,7 @@ public:
stateNone // None
};
AnnotText(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
AnnotText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
// getters
GBool getOpen() const { return open; }
......@@ -652,9 +637,11 @@ public:
effectPush // P
};
AnnotLink(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
AnnotLink(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
virtual ~AnnotLink();
virtual void draw(Gfx *gfx, GBool printing);
// getters
Dict *getActionDict() const { return actionDict; }
// getDest
......@@ -693,7 +680,7 @@ public:
intentFreeTextTypeWriter // FreeTextTypeWriter
};
AnnotFreeText(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
AnnotFreeText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
virtual ~AnnotFreeText();
// getters
......@@ -744,7 +731,7 @@ public:
captionPosTop // Top
};
AnnotLine(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
AnnotLine(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
virtual ~AnnotLine();
// getters
......@@ -818,19 +805,38 @@ public:
highlightModePush // P,T
};
AnnotWidget(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
AnnotWidget(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
virtual ~AnnotWidget();
virtual void draw(Gfx *gfx, GBool printing);
void generateFieldAppearance ();
AnnotWidgetHighlightMode getMode() { return mode; }
AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs; }
Dict *getAction() { return action; }
Dict *getAdditionActions() { return additionActions; }
Dict *getParent() { return parent; }
protected:
private:
void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
void drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
GBool multiline, int comb, int quadding,
GBool txField, GBool forceZapfDingbats,
GBool password=false);
void drawListBox(GooString **text, GBool *selection,
int nOptions, int topIdx,
GooString *da, GfxFontDict *fontDict, GBool quadding);
void getNextLine(GooString *text, int start,
GfxFont *font, double fontSize, double wMax,
int *end, double *width, int *next);
void writeTextString (GooString *text, GooString *appearBuf, int *i, int j,
CharCodeToUnicode *ccToUnicode, GBool password);
Form *form;
FormWidget *widget; // FormWidget object for this annotation
AnnotWidgetHighlightMode mode; // H (Default I)
AnnotAppearanceCharacs *appearCharacs; // MK
Dict *action; // A
......@@ -838,6 +844,7 @@ protected:
// inherited from Annot
// AnnotBorderBS border; // BS
Dict *parent; // Parent
GBool regen;
};
//------------------------------------------------------------------------
......@@ -856,14 +863,8 @@ public:
int getNumAnnots() { return nAnnots; }
Annot *getAnnot(int i) { return annots[i]; }
// (Re)generate the appearance streams for all annotations belonging
// to a form field.
void generateAppearances(Dict *acroForm);
private:
Annot* createAnnot(XRef *xref, Dict *acroForm, Dict* dict, Catalog *catalog, Object *obj);
void scanFieldAppearances(Dict *node, Ref *ref, Dict *parent,
Dict *acroForm);
Annot* createAnnot(XRef *xref, Dict* dict, Catalog *catalog, Object *obj);
Annot *findAnnot(Ref *ref);
Annot **annots;
......
......@@ -1089,34 +1089,38 @@ FormFieldSignature::~FormFieldSignature()
Form::Form(XRef *xrefA, Object* acroFormA)
{
Array *array = NULL;
Object obj1;
xref = xrefA;
acroForm = acroFormA;
acroForm->dictLookup("Fields",&obj1);
if (obj1.isArray()) array = obj1.getArray();
obj1.free();
if(!array) {
error(-1, "Can't get Fields array\n");
}
size = 0;
numFields = 0;
rootFields = NULL;
if (array) {
acroForm->dictLookup("NeedAppearances", &obj1);
needAppearances = (obj1.isBool() && obj1.getBool());
obj1.free();
acroForm->dictLookup("Fields", &obj1);
if (obj1.isArray()) {
Array *array = obj1.getArray();
Object obj2;
for(int i=0; i<array->getLength(); i++) {
Object oref;
array->get(i, &obj1);
array->get(i, &obj2);
array->getNF(i, &oref);
if (!oref.isRef()) {
error(-1, "Direct object in rootFields");
obj1.free();
obj2.free();
oref.free();
continue;
}
if (!obj1.isDict()) {
if (!obj2.isDict()) {
error(-1, "Reference in Fields array to an invalid or non existant object");
obj1.free();
obj2.free();
oref.free();
continue;
}
......@@ -1126,21 +1130,24 @@ Form::Form(XRef *xrefA, Object* acroFormA)
rootFields = (FormField**)greallocn(rootFields,size,sizeof(FormField*));
}
rootFields[numFields++] = createFieldFromDict (&obj1, xrefA, oref.getRef());
rootFields[numFields++] = createFieldFromDict (&obj2, xrefA, oref.getRef());
//Mark readonly field
Object obj3;
if (Form::fieldLookup(obj1.getDict (), "Ff", &obj3)->isInt()) {
if (Form::fieldLookup(obj2.getDict (), "Ff", &obj3)->isInt()) {
int flags = obj3.getInt();
if (flags & 0x1)
rootFields[numFields-1]->setReadOnly(true);
}
obj3.free();
obj1.free();
obj2.free();
oref.free();
}
} else {
error(-1, "Can't get Fields array\n");
}
obj1.free ();
}
Form::~Form() {
......@@ -1246,7 +1253,7 @@ FormPageWidgets::FormPageWidgets (XRef *xrefA, Object* annots, unsigned int page
if (annots->arrayGet(i, &obj2)->isDict()) {
Annot *ann;
ann = new Annot(xref, NULL ,obj2.getDict(), NULL);
ann = new Annot(xref, obj2.getDict(), NULL);
tmp->setFontSize(ann->getFontSize());
delete ann;
}
......
......@@ -435,6 +435,7 @@ public:
static FormField *createFieldFromDict (Object* obj, XRef *xref, const Ref& aref);
Object *getObj () const { return acroForm; }
GBool getNeedAppearances () const { return needAppearances; }
int getNumFields() const { return numFields; }
FormField* getRootField(int i) const { return rootFields[i]; }
......@@ -447,6 +448,7 @@ private:
int size;
XRef* xref;
Object *acroForm;
GBool needAppearances;
};
//------------------------------------------------------------------------
......
......@@ -393,7 +393,6 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
Gfx *gfx;
Object obj;
Annots *annotList;
Dict *acroForm;
int i;
if (!out->checkPageSlice(this, hDPI, vDPI, rotate, useMediaBox, crop,
......@@ -417,15 +416,9 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
}
obj.free();
// draw annotations
annotList = new Annots(xref, catalog, getAnnots(&obj));
obj.free();
acroForm = catalog->getAcroForm()->isDict() ?
catalog->getAcroForm()->getDict() : NULL;
if (acroForm) {
annotList->generateAppearances(acroForm);
}
if (annotList->getNumAnnots() > 0) {
if (globalParams->getPrintCommands()) {
......@@ -437,7 +430,7 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
(*annotDisplayDecideCbk)(annot, annotDisplayDecideCbkData)) ||
!annotDisplayDecideCbk) {
annotList->getAnnot(i)->draw(gfx, printing);
}
}
}
out->dump();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment