]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/Annot.cc
(redraw): fix pixbuf data offset.
[evince.git] / pdf / xpdf / Annot.cc
1 //========================================================================
2 //
3 // Annot.cc
4 //
5 // Copyright 2000-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <aconf.h>
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include "gmem.h"
16 #include "Object.h"
17 #include "Gfx.h"
18 #include "Annot.h"
19
20 //------------------------------------------------------------------------
21 // Annot
22 //------------------------------------------------------------------------
23
24 Annot::Annot(XRef *xrefA, Dict *dictA) {
25   Object apObj, asObj, obj1, obj2;
26   double t;
27
28   ok = gFalse;
29   xref = xrefA;
30   dict = dictA;
31   dict->incRef(); 
32
33   dictA->lookup("Subtype", &subtype); 
34   if (dictA->lookup("AP", &apObj)->isDict()) {
35     if (dictA->lookup("AS", &asObj)->isName()) {
36       if (apObj.dictLookup("N", &obj1)->isDict()) {
37         if (obj1.dictLookupNF(asObj.getName(), &obj2)->isRef()) {
38           obj2.copy(&appearance);
39           ok = gTrue;
40         }
41         obj2.free();
42       }
43       obj1.free();
44     } else {
45       if (apObj.dictLookupNF("N", &obj1)->isRef()) {
46         obj1.copy(&appearance);
47         ok = gTrue;
48       }
49       obj1.free();
50     }
51     asObj.free();
52   }
53   apObj.free();
54
55   if (dictA->lookup("Rect", &obj1)->isArray() &&
56       obj1.arrayGetLength() == 4) {
57     //~ should check object types here
58     obj1.arrayGet(0, &obj2);
59     xMin = obj2.getNum();
60     obj2.free();
61     obj1.arrayGet(1, &obj2);
62     yMin = obj2.getNum();
63     obj2.free();
64     obj1.arrayGet(2, &obj2);
65     xMax = obj2.getNum();
66     obj2.free();
67     obj1.arrayGet(3, &obj2);
68     yMax = obj2.getNum();
69     obj2.free();
70     if (xMin > xMax) {
71       t = xMin; xMin = xMax; xMax = t;
72     }
73     if (yMin > yMax) {
74       t = yMin; yMin = yMax; yMax = t;
75     }
76   } else {
77     //~ this should return an error
78     xMin = yMin = 0;
79     xMax = yMax = 1;
80   }
81   obj1.free();
82 }
83
84 Annot::~Annot() {
85   appearance.free();
86 }
87
88 void Annot::draw(Gfx *gfx) {
89   Object obj;
90
91   if (appearance.fetch(xref, &obj)->isStream()) {
92     gfx->doAnnot(&obj, xMin, yMin, xMax, yMax);
93   }
94   obj.free();
95 }
96
97 //------------------------------------------------------------------------
98 // Annots
99 //------------------------------------------------------------------------
100
101 Annots::Annots(XRef *xref, Object *annotsObj) {
102   Annot *annot;
103   Object obj1;
104   int size;
105   int i;
106
107   annots = NULL;
108   size = 0;
109   nAnnots = 0;
110
111   if (annotsObj->isArray()) {
112     for (i = 0; i < annotsObj->arrayGetLength(); ++i) {
113       if (annotsObj->arrayGet(i, &obj1)->isDict()) {
114         annot = new Annot(xref, obj1.getDict());
115         if (annot->isOk()) {
116           if (nAnnots >= size) {
117             size += 16;
118             annots = (Annot **)grealloc(annots, size * sizeof(Annot *));
119           }
120           annots[nAnnots++] = annot;
121         } else {
122           delete annot;
123         }
124       }
125       obj1.free();
126     }
127   }
128 }
129
130 Annots::~Annots() {
131   int i;
132
133   for (i = 0; i < nAnnots; ++i) {
134     delete annots[i];
135   }
136   gfree(annots);
137 }