Commit af97e5f8 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos

2007-08-06 Carlos Garcia Campos <carlosgc@gnome.org>

	* poppler/Annot.cc:
	* poppler/Annot.h:
	* poppler/Form.cc:
	* poppler/Form.h:
	* poppler/Page.cc: Do not always regenerate appearance stream for
	every form widget, but only when it's actually needed.
parent 74627e71
2007-08-06 Carlos Garcia Campos <carlosgc@gnome.org>
* poppler/Annot.cc:
* poppler/Annot.h:
* poppler/Form.cc:
* poppler/Form.h:
* poppler/Page.cc: Do not always regenerate appearance stream for
every form widget, but only when it's actually needed.
2007-07-31 Jeff Muizelaar <jeff@infidigm.net>
* poppler/GlobalParams.cc: s/GList/GooList/ some Windows code.
......
......@@ -111,11 +111,18 @@ void Annot::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog
appearBuf = NULL;
fontSize = 0;
type = NULL;
//widget = NULL;
widget = NULL;
borderStyle = NULL;
//----- get the FormWidget
if (hasRef) {
Form *form = catalog->getForm ();
if (form)
widget = form->findWidgetByRef (ref);
}
//----- parse the type
if (dict->lookup("Subtype", &obj1)->isName()) {
type = new GooString(obj1.getName());
}
......@@ -177,39 +184,39 @@ void Annot::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog
}
obj1.free();
}
} else {
//for other type of annots, lookup for AP and copy it to the appearance stream
Object apObj, asObj;
if (dict->lookup("AP", &apObj)->isDict()) {
if (dict->lookup("AS", &asObj)->isName()) {
if (apObj.dictLookup("N", &obj1)->isDict()) {
if (obj1.dictLookupNF(asObj.getName(), &obj2)->isRef()) {
obj2.copy(&appearance);
ok = gTrue;
} else {
obj2.free();
if (obj1.dictLookupNF("Off", &obj2)->isRef()) {
obj2.copy(&appearance);
ok = gTrue;
}
}
obj2.free();
}
obj1.free();
} else {
if (apObj.dictLookupNF("N", &obj1)->isRef()) {
obj1.copy(&appearance);
}
if (dict->lookup("AP", &apObj)->isDict()) {
if (dict->lookup("AS", &asObj)->isName()) {
if (apObj.dictLookup("N", &obj1)->isDict()) {
if (obj1.dictLookupNF(asObj.getName(), &obj2)->isRef()) {
obj2.copy(&appearance);
ok = gTrue;
}
obj1.free();
} else {
obj2.free();
if (obj1.dictLookupNF("Off", &obj2)->isRef()) {
obj2.copy(&appearance);
ok = gTrue;
} else
regen = gTrue;
}
obj2.free();
}
asObj.free();
obj1.free();
} else {
// If field doesn't have an AP we'll have to generate it
regen = gTrue;
if (apObj.dictLookupNF("N", &obj1)->isRef()) {
obj1.copy(&appearance);
ok = gTrue;
} else
regen = gTrue;
obj1.free();
}
apObj.free();
asObj.free();
} else {
// If field doesn't have an AP we'll have to generate it
regen = gTrue;
}
apObj.free();
obj3.free();
//----- parse the border style
......@@ -343,15 +350,26 @@ void Annot::generateFieldAppearance(Dict *field, Dict *annot, Dict *acroForm) {
GooString **text;
GBool *selection;
int dashLength, ff, quadding, comb, nOptions, topIdx, i, j;
//do not regenerate appearance if we don't need to
if (!regen)
return;
GBool modified;
// must be a Widget annotation
if (type->cmp("Widget")) {
return;
}
// do not regenerate appearence if widget has not changed
if (widget && widget->isModified ()) {
modified = gTrue;
} else {
modified = gFalse;
}
// only regenerate when it doesn't have an AP or
// it already has an AP but widget has been modified
if (!regen && !modified) {
return;
}
appearBuf = new GooString ();
// get the appearance characteristics (MK) dictionary
if (annot->lookup("MK", &mkObj)->isDict()) {
......
......@@ -19,6 +19,7 @@ class Catalog;
class CharCodeToUnicode;
class GfxFont;
class GfxFontDict;
class FormWidget;
//------------------------------------------------------------------------
// AnnotBorderStyle
......@@ -87,8 +88,6 @@ public:
double getFontSize() { return fontSize; }
private:
// void writeTextString (GooString* vStr, CharCodeToUnicode* ccToUnicode, GooString* appearBuf, GfxFont* font);
// void generateAppearance(Dict *acroForm, Dict *dict);
void setColor(Array *a, GBool fill, int adjust);
void drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
GBool multiline, int comb, int quadding,
......@@ -110,8 +109,9 @@ private:
void initialize (XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog);
XRef *xref; // the xref table for this PDF file
Ref ref; // object ref identifying this annotation
GooString *type; // annotation type
Ref ref; // object ref identifying this annotation
FormWidget *widget; // FormWidget object for this annotation
GooString *type; // annotation type
Object appearance; // a reference to the Form XObject stream
// for the normal appearance
GooString *appearBuf;
......
......@@ -54,6 +54,7 @@ FormWidget::FormWidget(XRef *xrefA, Object *aobj, unsigned num, Ref aref)
double t;
ID = 0;
fontSize = 0.0;
modified = gFalse;
childNum = num;
xref = xrefA;
aobj->copy(&obj);
......@@ -367,6 +368,7 @@ void FormWidgetText::setContent(GooString* new_content)
obj.getDict()->set("V", &obj1);
//notify the xref about the update
xref->setModifiedObject(&obj, ref);
modified = gTrue;
}
}
......@@ -507,6 +509,7 @@ void FormWidgetChoice::_updateV ()
obj.getDict()->set("V", &obj1);
//notify the xref about the update
xref->setModifiedObject(&obj, ref);
modified = gTrue;
}
bool FormWidgetChoice::_checkRange (int i)
......@@ -1107,14 +1110,12 @@ Form::Form(XRef *xrefA, Object* acroForm)
oref.free();
}
}
checkForNeedAppearances(acroForm);
}
Form::~Form() {
int i;
for(i = 0; i< numFields; ++i)
delete rootFields[i];
delete rootFields[i];
gfree (rootFields);
}
......@@ -1137,24 +1138,6 @@ Object *Form::fieldLookup(Dict *field, char *key, Object *obj) {
return obj;
}
void Form::checkForNeedAppearances (Object *acroForm)
{
//NeedAppearances needs to be set to 'true' in the AcroForm entry of the Catalog to enable dynamic appearance generation
Object* catalog = new Object();
Ref catRef;
catRef.gen = xref->getRootGen();
catRef.num = xref->getRootNum();
catalog = xref->getCatalog(catalog);
catalog->dictLookup("AcroForm", acroForm);
Object obj1;
obj1.initBool(true);
acroForm->dictSet("NeedAppearances", &obj1);
catalog->dictSet("AcroForm", acroForm);
xref->setModifiedObject(catalog, catRef);
delete catalog;
}
void Form::createFieldFromDict (Object* obj, FormField** ptr, XRef *xrefA, const Ref& pref)
{
Object obj2;
......
......@@ -79,6 +79,8 @@ public:
void setFontSize(double f) { fontSize = f; }
double getFontSize () { return fontSize; }
GBool isModified () { return modified; }
virtual bool isReadOnly() const = 0;
// return the unique ID corresponding to pageNum/fieldNum
......@@ -95,6 +97,7 @@ protected:
Object obj;
Ref ref;
XRef *xref;
GBool modified;
//index of this field in the parent's child list
unsigned childNum;
......@@ -444,7 +447,6 @@ public:
void createFieldFromDict (Object* obj, FormField** ptr, XRef *xref, const Ref& aref);
void postWidgetsLoad();
void checkForNeedAppearances (Object *acroForm);
private:
FormField** rootFields;
int numFields;
......
......@@ -415,13 +415,9 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
acroForm = catalog->getAcroForm()->isDict() ?
catalog->getAcroForm()->getDict() : NULL;
if (acroForm) {
if (acroForm->lookup("NeedAppearances", &obj)) {
if (obj.isBool() && obj.getBool()) {
annotList->generateAppearances(acroForm);
}
}
obj.free();
annotList->generateAppearances(acroForm);
}
if (annotList->getNumAnnots() > 0) {
if (globalParams->getPrintCommands()) {
printf("***** Annotations\n");
......
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