Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Annot.cc

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

Generated on Sat Nov 5 16:18:12 2005 for OPIE by  doxygen 1.4.2