w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Outline.cc
Go to the documentation of this file.
1 //========================================================================
2 //
3 // Outline.cc
4 //
5 // Copyright 2002-2013 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 "gmempp.h"
17 #include "GString.h"
18 #include "GList.h"
19 #include "Error.h"
20 #include "Link.h"
21 #include "TextString.h"
22 #include "Outline.h"
23 
24 //------------------------------------------------------------------------
25 
26 Outline::Outline(Object *outlineObj, XRef *xref) {
27  Object first, last;
28 
29  items = NULL;
30  if (!outlineObj->isDict()) {
31  return;
32  }
33  outlineObj->dictLookupNF("First", &first);
34  outlineObj->dictLookupNF("Last", &last);
35  if (first.isRef() && last.isRef()) {
37  }
38  first.free();
39  last.free();
40 }
41 
43  if (items) {
45  }
46 }
47 
48 //------------------------------------------------------------------------
49 
51  OutlineItem *parentA, XRef *xrefA) {
52  Object obj1;
53 
54  xref = xrefA;
55  title = NULL;
56  action = NULL;
57  kids = NULL;
58  parent = parentA;
59 
60  if (dict->lookup("Title", &obj1)->isString()) {
61  title = new TextString(obj1.getString());
62  }
63  obj1.free();
64 
65  if (!dict->lookup("Dest", &obj1)->isNull()) {
67  } else {
68  obj1.free();
69  if (!dict->lookup("A", &obj1)->isNull()) {
71  }
72  }
73  obj1.free();
74 
75  itemRefA->copy(&itemRef);
76  dict->lookupNF("First", &firstRef);
77  dict->lookupNF("Last", &lastRef);
78  dict->lookupNF("Next", &nextRef);
79 
81  if (dict->lookup("Count", &obj1)->isInt()) {
82  if (obj1.getInt() > 0) {
83  startsOpen = gTrue;
84  }
85  }
86  obj1.free();
87 
88  pageNum = -1;
89 }
90 
92  close();
93  if (title) {
94  delete title;
95  }
96  if (action) {
97  delete action;
98  }
99  itemRef.free();
100  firstRef.free();
101  lastRef.free();
102  nextRef.free();
103 }
104 
105 GList *OutlineItem::readItemList(Object *firstItemRef, Object *lastItemRef,
106  OutlineItem *parentA, XRef *xrefA) {
107  GList *items;
108  OutlineItem *item, *sibling;
109  Object obj;
110  Object *p;
111  OutlineItem *ancestor;
112  int i;
113 
114  items = new GList();
115  if (!firstItemRef->isRef() || !lastItemRef->isRef()) {
116  return items;
117  }
118  p = firstItemRef;
119  do {
120  if (!p->fetch(xrefA, &obj)->isDict()) {
121  obj.free();
122  break;
123  }
124  item = new OutlineItem(p, obj.getDict(), parentA, xrefA);
125  obj.free();
126 
127  // check for loops with parents
128  for (ancestor = parentA; ancestor; ancestor = ancestor->parent) {
129  if (p->getRefNum() == ancestor->itemRef.getRefNum() &&
130  p->getRefGen() == ancestor->itemRef.getRefGen()) {
131  error(errSyntaxError, -1, "Loop detected in outline");
132  break;
133  }
134  }
135  if (ancestor) {
136  delete item;
137  break;
138  }
139 
140  // check for loops with siblings
141  for (i = 0; i < items->getLength(); ++i) {
142  sibling = (OutlineItem *)items->get(i);
143  if (p->getRefNum() == sibling->itemRef.getRefNum() &&
144  p->getRefGen() == sibling->itemRef.getRefGen()) {
145  error(errSyntaxError, -1, "Loop detected in outline");
146  break;
147  }
148  }
149  if (i < items->getLength()) {
150  delete item;
151  break;
152  }
153 
154  items->append(item);
155  if (p->getRefNum() == lastItemRef->getRef().num &&
156  p->getRefGen() == lastItemRef->getRef().gen) {
157  break;
158  }
159  p = &item->nextRef;
160  if (!p->isRef()) {
161  break;
162  }
163  } while (p);
164  return items;
165 }
166 
168  if (!kids) {
169  kids = readItemList(&firstRef, &lastRef, this, xref);
170  }
171 }
172 
174  if (kids) {
176  kids = NULL;
177  }
178 }
179 
181  return title ? title->getUnicode() : (Unicode *)NULL;
182 }
183 
185  return title ? title->getLength() : 0;
186 }
#define deleteGList(list, T)
Definition: GList.h:94
static int item
Definition: brushtopbm.c:66
Definition: Dict.h:29
Object * lookupNF(const char *key, Object *obj)
Definition: Dict.cc:129
Object * lookup(const char *key, Object *obj, int recursion=0)
Definition: Dict.cc:122
Definition: GList.h:24
static LinkAction * parseAction(Object *obj, GString *baseURI=NULL)
Definition: Link.cc:41
static LinkAction * parseDest(Object *obj)
Definition: Link.cc:30
Definition: Object.h:84
Ref getRef()
Definition: Object.h:163
GBool isDict()
Definition: Object.h:137
void free()
Definition: Object.cc:119
GBool isRef()
Definition: Object.h:139
int getRefGen()
Definition: Object.h:165
Object * copy(Object *obj)
Definition: Object.cc:80
int getInt()
Definition: Object.h:155
GBool isInt()
Definition: Object.h:130
GBool isString()
Definition: Object.h:133
GString * getString()
Definition: Object.h:158
Dict * getDict()
Definition: Object.h:161
Object * dictLookupNF(const char *key, Object *obj)
Definition: Object.h:269
GBool isNull()
Definition: Object.h:135
int getRefNum()
Definition: Object.h:164
~OutlineItem()
Definition: Outline.cc:91
GBool startsOpen
Definition: Outline.h:77
LinkAction * action
Definition: Outline.h:72
static GList * readItemList(Object *firstItemRef, Object *lastItemRef, OutlineItem *parentA, XRef *xrefA)
Definition: Outline.cc:105
Unicode * getTitle()
Definition: Outline.cc:180
Object itemRef
Definition: Outline.h:73
XRef * xref
Definition: Outline.h:70
int pageNum
Definition: Outline.h:78
OutlineItem(Object *itemRefA, Dict *dict, OutlineItem *parentA, XRef *xrefA)
Definition: Outline.cc:50
OutlineItem * parent
Definition: Outline.h:81
Object firstRef
Definition: Outline.h:74
void open()
Definition: Outline.cc:167
int getTitleLength()
Definition: Outline.cc:184
void close()
Definition: Outline.cc:173
GList * kids
Definition: Outline.h:80
Object lastRef
Definition: Outline.h:75
TextString * title
Definition: Outline.h:71
Object nextRef
Definition: Outline.h:76
GList * items
Definition: Outline.h:39
~Outline()
Definition: Outline.cc:42
Outline(Object *outlineObj, XRef *xref)
Definition: Outline.cc:26
Unicode * getUnicode()
Definition: TextString.h:54
int getLength()
Definition: TextString.h:53
Definition: XRef.h:58
#define error(a)
Definition: dviinfo.c:48
#define gFalse
Definition: gtypes.h:18
#define gTrue
Definition: gtypes.h:17
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
@ errSyntaxError
Definition: Error.h:25
action
Definition: epdf.c:220
int getLength(char *s)
Definition: lengths.c:99
static int items
Definition: pgmtofs.c:86
static int32_t last
Definition: ppagelist.c:29
static int32_t first
Definition: ppagelist.c:29
int gen
Definition: Object.h:39
int num
Definition: Object.h:38
#define xref
Definition: tex2xindy.c:758