poppler/Annot.cc | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-)
New commits: commit 31db47d077825045edd1a2d229e873a6f8e09fb1 Author: Carlos Garcia Campos <[email protected]> Date: Sun Jun 17 12:00:43 2012 +0200 Simplify AnnotAppearance::getAppearanceStream() - Use a switch instead of if to get the stream object - Use the return value of dictLookupNF to check whether the object is null - Don't fetch the stream to check the reference is valid, this is already done when used diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 9778bd2..e55ddde 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -783,50 +783,38 @@ AnnotAppearance::~AnnotAppearance() { appearDict.free(); } -void AnnotAppearance::getAppearanceStream(AnnotAppearance::AnnotAppearanceType type, const char *state, Object *dest) { +void AnnotAppearance::getAppearanceStream(AnnotAppearanceType type, const char *state, Object *dest) { Object apData, stream; apData.initNull(); // Obtain dictionary or stream associated to appearance type - if (type == appearRollover) { - appearDict.dictLookupNF("R", &apData); - } else if (type == appearDown) { - appearDict.dictLookupNF("D", &apData); - } - if (apData.isNull()) { // Normal appearance, also used as fallback + switch (type) { + case appearRollover: + if (appearDict.dictLookupNF("R", &apData)->isNull()) + appearDict.dictLookupNF("N", &apData); + break; + case appearDown: + if (appearDict.dictLookupNF("D", &apData)->isNull()) + appearDict.dictLookupNF("N", &apData); + break; + case appearNormal: appearDict.dictLookupNF("N", &apData); - } - - // Search state if it's a subdictionary - if (apData.isDict() && state) { - Object obj1; - apData.dictLookupNF(state, &obj1); - apData.free(); - obj1.copy(&apData); - obj1.free(); + break; } dest->initNull(); - // Sanity check on the value we are about to return: it must be a ref to stream - if (apData.isRef()) { - apData.fetch(xref, &stream); - if (stream.isStream()) { - apData.copy(dest); - } else { - error(errSyntaxWarning, -1, "AP points to a non-stream object"); - } - stream.free(); - } + if (apData.isDict() && state) + apData.dictLookupNF(state, dest); + else if (apData.isRef()) + apData.copy(dest); apData.free(); } GooString * AnnotAppearance::getStateKey(int i) { Object obj1; GooString * res = NULL; - appearDict.dictLookupNF("N", &obj1); - if (obj1.isDict()) { + if (appearDict.dictLookupNF("N", &obj1)->isDict()) res = new GooString(obj1.dictGetKey(i)); - } obj1.free(); return res; } @@ -834,10 +822,8 @@ GooString * AnnotAppearance::getStateKey(int i) { int AnnotAppearance::getNumStates() { Object obj1; int res = 0; - appearDict.dictLookupNF("N", &obj1); - if (obj1.isDict()) { + if (appearDict.dictLookupNF("N", &obj1)->isDict()) res = obj1.dictGetLength(); - } obj1.free(); return res; } _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
