filters

Annot.cc

00001 //========================================================================
00002 //
00003 // Annot.cc
00004 //
00005 // Copyright 2000-2002 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #include <aconf.h>
00010 
00011 #ifdef USE_GCC_PRAGMAS
00012 #pragma implementation
00013 #endif
00014 
00015 #include "gmem.h"
00016 #include "Object.h"
00017 #include "Gfx.h"
00018 #include "Annot.h"
00019 
00020 //------------------------------------------------------------------------
00021 // Annot
00022 //------------------------------------------------------------------------
00023 
00024 Annot::Annot(XRef *xrefA, Dict *dict) {
00025   Object apObj, asObj, obj1, obj2;
00026   double t;
00027 
00028   ok = gFalse;
00029   xref = xrefA;
00030 
00031   if (dict->lookup("AP", &apObj)->isDict()) {
00032     if (dict->lookup("AS", &asObj)->isName()) {
00033       if (apObj.dictLookup("N", &obj1)->isDict()) {
00034     if (obj1.dictLookupNF(asObj.getName(), &obj2)->isRef()) {
00035       obj2.copy(&appearance);
00036       ok = gTrue;
00037     }
00038     obj2.free();
00039       }
00040       obj1.free();
00041     } else {
00042       if (apObj.dictLookupNF("N", &obj1)->isRef()) {
00043     obj1.copy(&appearance);
00044     ok = gTrue;
00045       }
00046       obj1.free();
00047     }
00048     asObj.free();
00049   }
00050   apObj.free();
00051 
00052   if (dict->lookup("Rect", &obj1)->isArray() &&
00053       obj1.arrayGetLength() == 4) {
00054     //~ should check object types here
00055     obj1.arrayGet(0, &obj2);
00056     xMin = obj2.getNum();
00057     obj2.free();
00058     obj1.arrayGet(1, &obj2);
00059     yMin = obj2.getNum();
00060     obj2.free();
00061     obj1.arrayGet(2, &obj2);
00062     xMax = obj2.getNum();
00063     obj2.free();
00064     obj1.arrayGet(3, &obj2);
00065     yMax = obj2.getNum();
00066     obj2.free();
00067     if (xMin > xMax) {
00068       t = xMin; xMin = xMax; xMax = t;
00069     }
00070     if (yMin > yMax) {
00071       t = yMin; yMin = yMax; yMax = t;
00072     }
00073   } else {
00074     //~ this should return an error
00075     xMin = yMin = 0;
00076     xMax = yMax = 1;
00077   }
00078   obj1.free();
00079 }
00080 
00081 Annot::~Annot() {
00082   appearance.free();
00083 }
00084 
00085 void Annot::draw(Gfx *gfx) {
00086   Object obj;
00087 
00088   if (appearance.fetch(xref, &obj)->isStream()) {
00089     gfx->doAnnot(&obj, xMin, yMin, xMax, yMax);
00090   }
00091   obj.free();
00092 }
00093 
00094 //------------------------------------------------------------------------
00095 // Annots
00096 //------------------------------------------------------------------------
00097 
00098 Annots::Annots(XRef *xref, Object *annotsObj) {
00099   Annot *annot;
00100   Object obj1, obj2;
00101   int size;
00102   int i;
00103 
00104   annots = NULL;
00105   size = 0;
00106   nAnnots = 0;
00107 
00108   if (annotsObj->isArray()) {
00109     for (i = 0; i < annotsObj->arrayGetLength(); ++i) {
00110       if (annotsObj->arrayGet(i, &obj1)->isDict()) {
00111     obj1.dictLookup("Subtype", &obj2);
00112     if (obj2.isName("Widget") ||
00113         obj2.isName("Stamp")) {
00114       annot = new Annot(xref, obj1.getDict());
00115       if (annot->isOk()) {
00116         if (nAnnots >= size) {
00117           size += 16;
00118           annots = (Annot **)grealloc(annots, size * sizeof(Annot *));
00119         }
00120         annots[nAnnots++] = annot;
00121       } else {
00122         delete annot;
00123       }
00124     }
00125     obj2.free();
00126       }
00127       obj1.free();
00128     }
00129   }
00130 }
00131 
00132 Annots::~Annots() {
00133   int i;
00134 
00135   for (i = 0; i < nAnnots; ++i) {
00136     delete annots[i];
00137   }
00138   gfree(annots);
00139 }
KDE Home | KDE Accessibility Home | Description of Access Keys