summaryrefslogtreecommitdiff
path: root/poppler/OptionalContent.cc
diff options
context:
space:
mode:
Diffstat (limited to 'poppler/OptionalContent.cc')
-rw-r--r--poppler/OptionalContent.cc144
1 files changed, 44 insertions, 100 deletions
diff --git a/poppler/OptionalContent.cc b/poppler/OptionalContent.cc
index dd839707..d2e878e4 100644
--- a/poppler/OptionalContent.cc
+++ b/poppler/OptionalContent.cc
@@ -43,50 +43,40 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
optionalContentGroups = new GooList();
display = NULL;
- Object ocgList;
- ocgObject->dictLookup("OCGs", &ocgList);
+ Object ocgList = ocgObject->dictLookup("OCGs");
if (!ocgList.isArray()) {
error(errSyntaxError, -1, "Expected the optional content group list, but wasn't able to find it, or it isn't an Array");
- ocgList.free();
ok = gFalse;
return;
}
// we now enumerate over the ocgList, and build up the optionalContentGroups list.
for(int i = 0; i < ocgList.arrayGetLength(); ++i) {
- Object ocg;
- ocgList.arrayGet(i, &ocg);
+ Object ocg = ocgList.arrayGet(i);
if (!ocg.isDict()) {
- ocg.free();
break;
}
OptionalContentGroup *thisOptionalContentGroup = new OptionalContentGroup(ocg.getDict());
- ocg.free();
- ocgList.arrayGetNF(i, &ocg);
+ ocg = ocgList.arrayGetNF(i);
if (!ocg.isRef()) {
delete thisOptionalContentGroup;
break;
}
// TODO: we should create a lookup map from Ref to the OptionalContentGroup
thisOptionalContentGroup->setRef( ocg.getRef() );
- ocg.free();
// the default is ON - we change state later, depending on BaseState, ON and OFF
thisOptionalContentGroup->setState(OptionalContentGroup::On);
optionalContentGroups->append(thisOptionalContentGroup);
}
- Object defaultOcgConfig;
- ocgObject->dictLookup("D", &defaultOcgConfig);
+ Object defaultOcgConfig = ocgObject->dictLookup("D");
if (!defaultOcgConfig.isDict()) {
error(errSyntaxError, -1, "Expected the default config, but wasn't able to find it, or it isn't a Dictionary");
- defaultOcgConfig.free();
- ocgList.free();
ok = gFalse;
return;
}
- Object baseState;
- defaultOcgConfig.dictLookup("BaseState", &baseState);
+ Object baseState = defaultOcgConfig.dictLookup("BaseState");
if (baseState.isName("OFF")) {
for (int i = 0; i < optionalContentGroups->getLength(); ++i) {
OptionalContentGroup *group;
@@ -95,22 +85,17 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
group->setState(OptionalContentGroup::Off);
}
}
- baseState.free();
- Object on;
- defaultOcgConfig.dictLookup("ON", &on);
+ Object on = defaultOcgConfig.dictLookup("ON");
if (on.isArray()) {
// ON is an optional element
for (int i = 0; i < on.arrayGetLength(); ++i) {
- Object reference;
- on.arrayGetNF(i, &reference);
+ Object reference = on.arrayGetNF(i);
if (!reference.isRef()) {
// there can be null entries
- reference.free();
break;
}
OptionalContentGroup *group = findOcgByRef( reference.getRef() );
- reference.free();
if (!group) {
error(errSyntaxWarning, -1, "Couldn't find group for reference");
break;
@@ -118,22 +103,17 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
group->setState(OptionalContentGroup::On);
}
}
- on.free();
- Object off;
- defaultOcgConfig.dictLookup("OFF", &off);
+ Object off = defaultOcgConfig.dictLookup("OFF");
if (off.isArray()) {
// OFF is an optional element
for (int i = 0; i < off.arrayGetLength(); ++i) {
- Object reference;
- off.arrayGetNF(i, &reference);
+ Object reference = off.arrayGetNF(i);
if (!reference.isRef()) {
// there can be null entries
- reference.free();
break;
}
OptionalContentGroup *group = findOcgByRef( reference.getRef() );
- reference.free();
if (!group) {
error(errSyntaxWarning, -1, "Couldn't find group for reference to set OFF");
break;
@@ -141,22 +121,15 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
group->setState(OptionalContentGroup::Off);
}
}
- off.free();
- defaultOcgConfig.dictLookup("Order", &order);
- defaultOcgConfig.dictLookup("RBGroups", &rbgroups);
-
- ocgList.free();
- defaultOcgConfig.free();
+ order = defaultOcgConfig.dictLookup("Order");
+ rbgroups = defaultOcgConfig.dictLookup("RBGroups");
}
OCGs::~OCGs()
{
deleteGooList(optionalContentGroups, OptionalContentGroup);
- order.free();
- if (display)
- delete display;
- rbgroups.free();
+ delete display;
}
@@ -193,12 +166,7 @@ OCDisplayNode *OCGs::getDisplayRoot()
bool OCGs::optContentIsVisible( Object *dictRef )
{
- Object dictObj;
Dict *dict;
- Object dictType;
- Object ocg;
- Object policy;
- Object ve;
bool result = true;
if (dictRef->isNull())
@@ -210,22 +178,22 @@ bool OCGs::optContentIsVisible( Object *dictRef )
return oc->getState() == OptionalContentGroup::On;
}
- dictRef->fetch( m_xref, &dictObj );
+ Object dictObj = dictRef->fetch( m_xref);
if ( ! dictObj.isDict() ) {
error(errSyntaxWarning, -1, "Unexpected oc reference target: {0:d}", dictObj.getType() );
- dictObj.free();
return result;
}
dict = dictObj.getDict();
// printf("checking if optContent is visible\n");
- dict->lookup("Type", &dictType);
+ Object dictType = dict->lookup("Type");
if (dictType.isName("OCMD")) {
- if (dict->lookup("VE", &ve)->isArray()) {
+ Object ve = dict->lookup("VE");
+ if (ve.isArray()) {
result = evalOCVisibilityExpr(&ve, 0);
} else {
- dict->lookupNF("OCGs", &ocg);
+ Object ocg = dict->lookupNF("OCGs");
if (ocg.isArray()) {
- dict->lookup("P", &policy);
+ Object policy = dict->lookup("P");
if (policy.isName("AllOn")) {
result = allOn( ocg.getArray() );
} else if (policy.isName("AllOff")) {
@@ -236,7 +204,6 @@ bool OCGs::optContentIsVisible( Object *dictRef )
// this is the default
result = anyOn( ocg.getArray() );
}
- policy.free();
} else if (ocg.isRef()) {
OptionalContentGroup *oc = findOcgByRef( ocg.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::Off ) {
@@ -245,26 +212,20 @@ bool OCGs::optContentIsVisible( Object *dictRef )
result = true ;
}
}
- ocg.free();
}
- ve.free();
} else if ( dictType.isName("OCG") ) {
OptionalContentGroup* oc = findOcgByRef( dictRef->getRef() );
if ( oc && oc->getState() == OptionalContentGroup::Off ) {
result=false;
}
}
- dictType.free();
- dictObj.free();
// printf("visibility: %s\n", result? "on" : "off");
return result;
}
GBool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
OptionalContentGroup *ocg;
- Object expr2, op, obj;
GBool ret;
- int i;
if (recursion > visibilityExprRecursionLimit) {
error(errSyntaxError, -1,
@@ -276,19 +237,17 @@ GBool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
return ocg->getState() == OptionalContentGroup::On;
}
}
- expr->fetch(m_xref, &expr2);
+ Object expr2 = expr->fetch(m_xref);
if (!expr2.isArray() || expr2.arrayGetLength() < 1) {
error(errSyntaxError, -1,
"Invalid optional content visibility expression");
- expr2.free();
return gTrue;
}
- expr2.arrayGet(0, &op);
+ Object op = expr2.arrayGet(0);
if (op.isName("Not")) {
if (expr2.arrayGetLength() == 2) {
- expr2.arrayGetNF(1, &obj);
+ Object obj = expr2.arrayGetNF(1);
ret = !evalOCVisibilityExpr(&obj, recursion + 1);
- obj.free();
} else {
error(errSyntaxError, -1,
"Invalid optional content visibility expression");
@@ -296,33 +255,28 @@ GBool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
}
} else if (op.isName("And")) {
ret = gTrue;
- for (i = 1; i < expr2.arrayGetLength() && ret; ++i) {
- expr2.arrayGetNF(i, &obj);
+ for (int i = 1; i < expr2.arrayGetLength() && ret; ++i) {
+ Object obj = expr2.arrayGetNF(i);
ret = evalOCVisibilityExpr(&obj, recursion + 1);
- obj.free();
}
} else if (op.isName("Or")) {
ret = gFalse;
- for (i = 1; i < expr2.arrayGetLength() && !ret; ++i) {
- expr2.arrayGetNF(i, &obj);
+ for (int i = 1; i < expr2.arrayGetLength() && !ret; ++i) {
+ Object obj = expr2.arrayGetNF(i);
ret = evalOCVisibilityExpr(&obj, recursion + 1);
- obj.free();
}
} else {
error(errSyntaxError, -1,
"Invalid optional content visibility expression");
ret = gTrue;
}
- op.free();
- expr2.free();
return ret;
}
bool OCGs::allOn( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
- Object ocgItem;
- ocgArray->getNF(i, &ocgItem);
+ Object ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::Off ) {
@@ -336,8 +290,7 @@ bool OCGs::allOn( Array *ocgArray )
bool OCGs::allOff( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
- Object ocgItem;
- ocgArray->getNF(i, &ocgItem);
+ Object ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::On ) {
@@ -351,8 +304,7 @@ bool OCGs::allOff( Array *ocgArray )
bool OCGs::anyOn( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
- Object ocgItem;
- ocgArray->getNF(i, &ocgItem);
+ Object ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::On ) {
@@ -366,8 +318,7 @@ bool OCGs::anyOn( Array *ocgArray )
bool OCGs::anyOff( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
- Object ocgItem;
- ocgArray->getNF(i, &ocgItem);
+ Object ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::Off ) {
@@ -382,42 +333,39 @@ bool OCGs::anyOff( Array *ocgArray )
OptionalContentGroup::OptionalContentGroup(Dict *ocgDict) : m_name(NULL)
{
- Object obj1, obj2, obj3;
- Object ocgName;
- ocgDict->lookup("Name", &ocgName);
+ Object ocgName = ocgDict->lookup("Name");
if (!ocgName.isString()) {
error(errSyntaxWarning, -1, "Expected the name of the OCG, but wasn't able to find it, or it isn't a String");
} else {
m_name = new GooString( ocgName.getString() );
}
- ocgName.free();
viewState = printState = ocUsageUnset;
- if (ocgDict->lookup("Usage", &obj1)->isDict()) {
- if (obj1.dictLookup("View", &obj2)->isDict()) {
- if (obj2.dictLookup("ViewState", &obj3)->isName()) {
+ Object obj1 = ocgDict->lookup("Usage");
+ if (obj1.isDict()) {
+ Object obj2 = obj1.dictLookup("View");
+ if (obj2.isDict()) {
+ Object obj3 = obj2.dictLookup("ViewState");
+ if (obj3.isName()) {
if (obj3.isName("ON")) {
viewState = ocUsageOn;
} else {
viewState = ocUsageOff;
}
}
- obj3.free();
}
- obj2.free();
- if (obj1.dictLookup("Print", &obj2)->isDict()) {
- if (obj2.dictLookup("PrintState", &obj3)->isName()) {
+ obj2 = obj1.dictLookup("Print");
+ if (obj2.isDict()) {
+ Object obj3 = obj2.dictLookup("PrintState");
+ if (obj3.isName()) {
if (obj3.isName("ON")) {
printState = ocUsageOn;
} else {
printState = ocUsageOff;
}
}
- obj3.free();
}
- obj2.free();
}
- obj1.free();
}
OptionalContentGroup::OptionalContentGroup(GooString *label)
@@ -450,7 +398,6 @@ OptionalContentGroup::~OptionalContentGroup()
OCDisplayNode *OCDisplayNode::parse(Object *obj, OCGs *oc,
XRef *xref, int recursion) {
- Object obj2, obj3;
OptionalContentGroup *ocgA;
OCDisplayNode *node, *child;
int i;
@@ -464,25 +411,24 @@ OCDisplayNode *OCDisplayNode::parse(Object *obj, OCGs *oc,
return new OCDisplayNode(ocgA);
}
}
- obj->fetch(xref, &obj2);
+ Object obj2 = obj->fetch(xref);
if (!obj2.isArray()) {
- obj2.free();
return NULL;
}
i = 0;
if (obj2.arrayGetLength() >= 1) {
- if (obj2.arrayGet(0, &obj3)->isString()) {
+ Object obj3 = obj2.arrayGet(0);
+ if (obj3.isString()) {
node = new OCDisplayNode(obj3.getString());
i = 1;
} else {
node = new OCDisplayNode();
}
- obj3.free();
} else {
node = new OCDisplayNode();
}
for (; i < obj2.arrayGetLength(); ++i) {
- obj2.arrayGetNF(i, &obj3);
+ Object obj3 = obj2.arrayGetNF(i);
if ((child = OCDisplayNode::parse(&obj3, oc, xref, recursion + 1))) {
if (!child->ocg && !child->name && node->getNumChildren() > 0) {
node->getChild(node->getNumChildren() - 1)->addChildren(child->takeChildren());
@@ -491,9 +437,7 @@ OCDisplayNode *OCDisplayNode::parse(Object *obj, OCGs *oc,
node->addChild(child);
}
}
- obj3.free();
}
- obj2.free();
return node;
}