fix getsup (HH)
[luatex.git] / source / libs / poppler / poppler-src / poppler / Outline.cc
blobbf46be264fedd333108e2e87b5b61cb4d5d68b44
1 //========================================================================
2 //
3 // Outline.cc
4 //
5 // Copyright 2002-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com>
17 // Copyright (C) 2008, 2016 Albert Astals Cid <aacid@kde.org>
18 // Copyright (C) 2009 Nick Jones <nick.jones@network-box.com>
19 // Copyright (C) 2016 Jason Crain <jason@aquaticape.us>
21 // To see a description of the changes please see the Changelog file that
22 // came with your tarball or type make ChangeLog if you are building from git
24 //========================================================================
26 #include <config.h>
28 #ifdef USE_GCC_PRAGMAS
29 #pragma implementation
30 #endif
32 #include "goo/gmem.h"
33 #include "goo/GooString.h"
34 #include "goo/GooList.h"
35 #include "XRef.h"
36 #include "Link.h"
37 #include "PDFDocEncoding.h"
38 #include "Outline.h"
39 #include "UTF.h"
41 //------------------------------------------------------------------------
43 Outline::Outline(Object *outlineObj, XRef *xref) {
44 Object first, last;
46 items = NULL;
47 if (!outlineObj->isDict()) {
48 return;
50 items = OutlineItem::readItemList(outlineObj->dictLookupNF("First", &first), xref);
51 first.free();
52 last.free();
55 Outline::~Outline() {
56 if (items) {
57 deleteGooList(items, OutlineItem);
61 //------------------------------------------------------------------------
63 OutlineItem::OutlineItem(Dict *dict, XRef *xrefA) {
64 Object obj1;
65 GooString *s;
67 xref = xrefA;
68 title = NULL;
69 action = NULL;
70 kids = NULL;
72 if (dict->lookup("Title", &obj1)->isString()) {
73 s = obj1.getString();
74 titleLen = TextStringToUCS4(s, &title);
75 } else {
76 titleLen = 0;
78 obj1.free();
80 if (!dict->lookup("Dest", &obj1)->isNull()) {
81 action = LinkAction::parseDest(&obj1);
82 } else {
83 obj1.free();
84 if (!dict->lookup("A", &obj1)->isNull()) {
85 action = LinkAction::parseAction(&obj1);
88 obj1.free();
90 dict->lookupNF("First", &firstRef);
91 dict->lookupNF("Last", &lastRef);
92 dict->lookupNF("Next", &nextRef);
94 startsOpen = gFalse;
95 if (dict->lookup("Count", &obj1)->isInt()) {
96 if (obj1.getInt() > 0) {
97 startsOpen = gTrue;
100 obj1.free();
103 OutlineItem::~OutlineItem() {
104 close();
105 if (title) {
106 gfree(title);
108 if (action) {
109 delete action;
111 firstRef.free();
112 lastRef.free();
113 nextRef.free();
116 GooList *OutlineItem::readItemList(Object *firstItemRef, XRef *xrefA) {
117 GooList *items;
118 char* alreadyRead;
119 OutlineItem *item;
120 Object obj;
121 Object *p;
123 items = new GooList();
125 alreadyRead = (char *)gmalloc(xrefA->getNumObjects());
126 memset(alreadyRead, 0, xrefA->getNumObjects());
128 p = firstItemRef;
129 while (p->isRef() &&
130 (p->getRefNum() >= 0) &&
131 (p->getRefNum() < xrefA->getNumObjects()) &&
132 !alreadyRead[p->getRefNum()]) {
133 if (!p->fetch(xrefA, &obj)->isDict()) {
134 obj.free();
135 break;
137 alreadyRead[p->getRefNum()] = 1;
138 item = new OutlineItem(obj.getDict(), xrefA);
139 obj.free();
140 items->append(item);
141 p = &item->nextRef;
144 gfree(alreadyRead);
146 if (!items->getLength()) {
147 delete items;
148 items = NULL;
151 return items;
154 void OutlineItem::open() {
155 if (!kids) {
156 kids = readItemList(&firstRef, xref);
160 void OutlineItem::close() {
161 if (kids) {
162 deleteGooList(kids, OutlineItem);
163 kids = NULL;