source: trunk/poppler/mypoppler/poppler/Outline.cc @ 257

Last change on this file since 257 was 257, checked in by Eugene Romanenko, 13 years ago

PDF plugin: Poppler library updated to version 0.10.0

File size: 3.8 KB
Line 
1//========================================================================
2//
3// Outline.cc
4//
5// Copyright 2002-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com>
17//
18// To see a description of the changes please see the Changelog file that
19// came with your tarball or type make ChangeLog if you are building from git
20//
21//========================================================================
22
23#include <config.h>
24
25#ifdef USE_GCC_PRAGMAS
26#pragma implementation
27#endif
28
29#include "goo/gmem.h"
30#include "goo/GooString.h"
31#include "goo/GooList.h"
32#include "Link.h"
33#include "PDFDocEncoding.h"
34#include "Outline.h"
35
36//------------------------------------------------------------------------
37
38Outline::Outline(Object *outlineObj, XRef *xref) {
39  Object first, last;
40
41  items = NULL;
42  if (!outlineObj->isDict()) {
43    return;
44  }
45  items = OutlineItem::readItemList(outlineObj->dictLookupNF("First", &first),
46                                    outlineObj->dictLookupNF("Last", &last),
47                                    xref);
48  first.free();
49  last.free();
50}
51
52Outline::~Outline() {
53  if (items) {
54    deleteGooList(items, OutlineItem);
55  }
56}
57
58//------------------------------------------------------------------------
59
60OutlineItem::OutlineItem(Dict *dict, XRef *xrefA) {
61  Object obj1;
62  GooString *s;
63  int i;
64
65  xref = xrefA;
66  title = NULL;
67  action = NULL;
68  kids = NULL;
69
70  if (dict->lookup("Title", &obj1)->isString()) {
71    s = obj1.getString();
72    if ((s->getChar(0) & 0xff) == 0xfe &&
73        (s->getChar(1) & 0xff) == 0xff) {
74      titleLen = (s->getLength() - 2) / 2;
75      title = (Unicode *)gmallocn(titleLen, sizeof(Unicode));
76      for (i = 0; i < titleLen; ++i) {
77        title[i] = ((s->getChar(2 + 2*i) & 0xff) << 8) |
78                   (s->getChar(3 + 2*i) & 0xff);
79      }
80    } else {
81      titleLen = s->getLength();
82      title = (Unicode *)gmallocn(titleLen, sizeof(Unicode));
83      for (i = 0; i < titleLen; ++i) {
84        title[i] = pdfDocEncoding[s->getChar(i) & 0xff];
85      }
86    }
87  } else {
88    titleLen = 0;
89  }
90  obj1.free();
91
92  if (!dict->lookup("Dest", &obj1)->isNull()) {
93    action = LinkAction::parseDest(&obj1);
94  } else {
95      obj1.free();
96    if (!dict->lookup("A", &obj1)->isNull()) {
97        action = LinkAction::parseAction(&obj1);
98  }
99  }
100  obj1.free();
101
102  dict->lookupNF("First", &firstRef);
103  dict->lookupNF("Last", &lastRef);
104  dict->lookupNF("Next", &nextRef);
105
106  startsOpen = gFalse;
107  if (dict->lookup("Count", &obj1)->isInt()) {
108    if (obj1.getInt() > 0) {
109      startsOpen = gTrue;
110    }
111  }
112  obj1.free();
113}
114
115OutlineItem::~OutlineItem() {
116  close();
117  if (title) {
118    gfree(title);
119  }
120  if (action) {
121    delete action;
122  }
123  firstRef.free();
124  lastRef.free();
125  nextRef.free();
126}
127
128GooList *OutlineItem::readItemList(Object *firstItemRef, Object *lastItemRef,
129                                 XRef *xrefA) {
130  GooList *items;
131  OutlineItem *item;
132  Object obj;
133  Object *p;
134
135  items = new GooList();
136  p = firstItemRef;
137  while (p->isRef()) {
138    if (!p->fetch(xrefA, &obj)->isDict()) {
139      obj.free();
140      break;
141    }
142    item = new OutlineItem(obj.getDict(), xrefA);
143    obj.free();
144    items->append(item);
145    if (p->getRef().num == lastItemRef->getRef().num &&
146        p->getRef().gen == lastItemRef->getRef().gen) {
147      break;
148    }
149    p = &item->nextRef;
150  }
151
152  if (!items->getLength()) {
153    delete items;
154    items = NULL;
155  }
156
157  return items;
158}
159
160void OutlineItem::open() {
161  if (!kids) {
162    kids = readItemList(&firstRef, &lastRef, xref);
163  }
164}
165
166void OutlineItem::close() {
167  if (kids) {
168    deleteGooList(kids, OutlineItem);
169    kids = NULL;
170  }
171}
Note: See TracBrowser for help on using the repository browser.