1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
//========================================================================
//
// Outline.cc
//
// Copyright 2002 Glyph & Cog, LLC
//
//========================================================================
#include "aconf.h"
#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif
#include "gmem.h"
#include "gstring.h"
#include "glist.h"
#include "link.h"
#include "pdfdocencoding.h"
#include "outline.h"
//------------------------------------------------------------------------
Outline::Outline(Object *outlineObj, XRef *xref) {
Object first;
items = NULL;
if (!outlineObj->isDict()) {
return;
}
items = OutlineItem::readItemList(outlineObj->dictLookupNF("First", &first),
xref);
first.free();
}
Outline::~Outline() {
if (items) {
deleteGList(items, OutlineItem);
}
}
//------------------------------------------------------------------------
OutlineItem::OutlineItem(Dict *dict, XRef *xrefA) {
Object obj1;
GString *s;
int i;
xref = xrefA;
title = NULL;
action = NULL;
kids = NULL;
if (dict->lookup("Title", &obj1)->isString()) {
s = obj1.getString();
if ((s->getChar(0) & 0xff) == 0xfe &&
(s->getChar(1) & 0xff) == 0xff) {
titleLen = (s->getLength() - 2) / 2;
title = (Unicode *)gmalloc(titleLen * sizeof(Unicode));
for (i = 0; i < titleLen; ++i) {
title[i] = ((s->getChar(2 + 2*i) & 0xff) << 8) |
(s->getChar(3 + 2*i) & 0xff);
}
} else {
titleLen = s->getLength();
title = (Unicode *)gmalloc(titleLen * sizeof(Unicode));
for (i = 0; i < titleLen; ++i) {
title[i] = pdfDocEncoding[s->getChar(i) & 0xff];
}
}
}
obj1.free();
if (!dict->lookup("Dest", &obj1)->isNull()) {
action = LinkAction::parseDest(&obj1);
} else {
obj1.free();
if (dict->lookup("A", &obj1)) {
action = LinkAction::parseAction(&obj1);
}
}
obj1.free();
dict->lookupNF("First", &firstRef);
dict->lookupNF("Next", &nextRef);
startsOpen = gFalse;
if (dict->lookup("Count", &obj1)->isInt()) {
if (obj1.getInt() > 0) {
startsOpen = gTrue;
}
}
obj1.free();
}
OutlineItem::~OutlineItem() {
close();
if (title) {
gfree(title);
}
if (action) {
delete action;
}
firstRef.free();
nextRef.free();
}
GList *OutlineItem::readItemList(Object *itemRef, XRef *xrefA) {
GList *items;
OutlineItem *item;
Object obj;
Object *p;
items = new GList();
p = itemRef;
while (p->isRef()) {
if (!p->fetch(xrefA, &obj)->isDict()) {
obj.free();
break;
}
item = new OutlineItem(obj.getDict(), xrefA);
obj.free();
items->append(item);
p = &item->nextRef;
}
return items;
}
void OutlineItem::open() {
if (!kids) {
kids = readItemList(&firstRef, xref);
}
}
void OutlineItem::close() {
if (kids) {
deleteGList(kids, OutlineItem);
kids = NULL;
}
}
|