1 //========================================================================
5 // Copyright 2002-2003 Glyph & Cog, LLC
7 //========================================================================
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
16 #include "goo/GooString.h"
17 #include "goo/GooList.h"
19 #include "PDFDocEncoding.h"
21 #include "UGooString.h"
23 //------------------------------------------------------------------------
25 Outline::Outline(Object
*outlineObj
, XRef
*xref
) {
29 if (!outlineObj
->isDict()) {
32 items
= OutlineItem::readItemList(outlineObj
->dictLookupNF("First", &first
),
33 outlineObj
->dictLookupNF("Last", &last
),
41 deleteGooList(items
, OutlineItem
);
45 //------------------------------------------------------------------------
47 OutlineItem::OutlineItem(Dict
*dict
, XRef
*xrefA
) {
57 if (dict
->lookup("Title", &obj1
)->isString()) {
59 if ((s
->getChar(0) & 0xff) == 0xfe &&
60 (s
->getChar(1) & 0xff) == 0xff) {
61 titleLen
= (s
->getLength() - 2) / 2;
62 title
= (Unicode
*)gmallocn(titleLen
, sizeof(Unicode
));
63 for (i
= 0; i
< titleLen
; ++i
) {
64 title
[i
] = ((s
->getChar(2 + 2*i
) & 0xff) << 8) |
65 (s
->getChar(3 + 2*i
) & 0xff);
68 titleLen
= s
->getLength();
69 title
= (Unicode
*)gmallocn(titleLen
, sizeof(Unicode
));
70 for (i
= 0; i
< titleLen
; ++i
) {
71 title
[i
] = pdfDocEncoding
[s
->getChar(i
) & 0xff];
79 if (!dict
->lookup("Dest", &obj1
)->isNull()) {
80 action
= LinkAction::parseDest(&obj1
);
83 if (!dict
->lookup("A", &obj1
)->isNull()) {
84 action
= LinkAction::parseAction(&obj1
);
89 dict
->lookupNF("First", &firstRef
);
90 dict
->lookupNF("Last", &lastRef
);
91 dict
->lookupNF("Next", &nextRef
);
94 if (dict
->lookup("Count", &obj1
)->isInt()) {
95 if (obj1
.getInt() > 0) {
102 OutlineItem::~OutlineItem() {
115 GooList
*OutlineItem::readItemList(Object
*firstItemRef
, Object
*lastItemRef
,
122 items
= new GooList();
125 if (!p
->fetch(xrefA
, &obj
)->isDict()) {
129 item
= new OutlineItem(obj
.getDict(), xrefA
);
132 if (p
->getRef().num
== lastItemRef
->getRef().num
&&
133 p
->getRef().gen
== lastItemRef
->getRef().gen
) {
139 if (!items
->getLength()) {
147 void OutlineItem::open() {
149 kids
= readItemList(&firstRef
, &lastRef
, xref
);
153 void OutlineItem::close() {
155 deleteGooList(kids
, OutlineItem
);