Bringing apdf from vendor into main branch.
[AROS-Contrib.git] / apdf / xpdf / Outline2.cc
blob2f41764b92956848605d56ab8a9c19edf2d622ec
1 //========================================================================
2 //
3 // Outline2.cc
4 //
5 // Copyright 1999-2005 Emmanuel Lesueur
6 //
7 //========================================================================
9 #ifdef __GNUC__
10 #pragma implementation
11 #endif
13 #include <stddef.h>
14 #include "gmem.h"
15 #include "Object.h"
16 #include "Dict.h"
17 #include "Error.h"
18 #include "Action.h"
19 #include "Outline2.h"
21 //------------------------------------------------------------------------
22 // Outline
23 //------------------------------------------------------------------------
25 Outline::~Outline() {
26 delete action;
27 delete children;
30 //------------------------------------------------------------------------
31 // OutlineTree
32 //------------------------------------------------------------------------
34 OutlineTree::~OutlineTree() {
35 if (beg) {
36 Outline **p = cur;
37 while (p != beg)
38 delete *--p;
39 gfree(beg);
43 void OutlineTree::addChild(Outline *outline) {
44 DEBUG_INFO
45 if (cur == end) {
46 int sz = cur - beg;
47 beg = (Outline **)greallocn(beg, sz + 16, sizeof(*beg));
48 cur = beg + sz;
49 end = beg + sz + 16;
51 *cur++ = outline;
54 OutlineTree *OutlineTree::read(Object *root) {
55 DEBUG_INFO
56 Object outline;
57 OutlineTree *tree = NULL;
58 if (root->dictLookup("First", &outline)->isDict()) {
59 Object obj;
60 GBool opened = gFalse;
62 if (root->dictLookup("Count", &obj)->isInt() && obj.getInt() > 0)
63 opened = gTrue;
64 obj.free();
65 tree = new OutlineTree(opened);
67 while (gTrue) {
68 Action *action = NULL;
69 if (!outline.dictLookup("Dest", &obj)->isNull())
70 action = new ActionGoTo(new Destination(&obj));
71 else {
72 obj.free();
73 if (outline.dictLookup("A", &obj)->isDict())
74 action = Action::makeAction(&obj);
76 obj.free();
77 outline.dictLookup("Title", &obj);
78 if (obj.isString()) {
79 tree->addChild(new Outline(obj.getString(), action, read(&outline)));
80 } else {
81 error(-1, "Bad outline title.");
82 delete action;
84 obj.free();
85 outline.dictLookup("Next", &obj);
86 outline.free();
87 if(obj.isDict()) {
88 outline = obj;
89 obj.clear();
90 } else {
91 obj.free();
92 break;
96 outline.free();
97 return tree;