~ubuntu-branches/ubuntu/natty/luatex/natty

« back to all changes in this revision

Viewing changes to source/libs/poppler/poppler-0.12.4/poppler/Dict.cc

  • Committer: Package Import Robot
  • Author(s): Norbert Preining
  • Date: 2010-12-13 23:22:59 UTC
  • mfrom: (0.2.1) (1.5.4) (4.3.12 experimental)
  • Revision ID: package-import@ubuntu.com-20101213232259-nqq2mq5z5x6qldw3
Tags: 0.65.0-1
* new upstream release
* ship two source packages as they are distributed by upstream, only
  renamed to match source package requirements. Fix debian/rules
  to install the manual pdf from the right place

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// Dict.cc
 
4
//
 
5
// Copyright 1996-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 Kristian Høgsberg <krh@redhat.com>
 
17
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
 
18
// Copyright (C) 2007-2008 Julien Rebetez <julienr@svn.gnome.org>
 
19
// Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
 
20
//
 
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
 
23
//
 
24
//========================================================================
 
25
 
 
26
#include <config.h>
 
27
 
 
28
#ifdef USE_GCC_PRAGMAS
 
29
#pragma implementation
 
30
#endif
 
31
 
 
32
#include <stddef.h>
 
33
#include <string.h>
 
34
#include "goo/gmem.h"
 
35
#include "Object.h"
 
36
#include "XRef.h"
 
37
#include "Dict.h"
 
38
 
 
39
//------------------------------------------------------------------------
 
40
// Dict
 
41
//------------------------------------------------------------------------
 
42
 
 
43
Dict::Dict(XRef *xrefA) {
 
44
  xref = xrefA;
 
45
  entries = NULL;
 
46
  size = length = 0;
 
47
  ref = 1;
 
48
}
 
49
 
 
50
Dict::Dict(Dict* dictA) {
 
51
  xref = dictA->xref;
 
52
  size = length = dictA->length;
 
53
  ref = 1;
 
54
 
 
55
  entries = (DictEntry *)gmallocn(size, sizeof(DictEntry));
 
56
  for (int i=0; i<length; i++) {
 
57
    entries[i].key = strdup(dictA->entries[i].key);
 
58
    dictA->entries[i].val.copy(&entries[i].val);
 
59
  }
 
60
}
 
61
 
 
62
Dict::~Dict() {
 
63
  int i;
 
64
 
 
65
  for (i = 0; i < length; ++i) {
 
66
    gfree(entries[i].key);
 
67
    entries[i].val.free();
 
68
  }
 
69
  gfree(entries);
 
70
}
 
71
 
 
72
void Dict::add(char *key, Object *val) {
 
73
  if (length == size) {
 
74
    if (length == 0) {
 
75
      size = 8;
 
76
    } else {
 
77
      size *= 2;
 
78
    }
 
79
    entries = (DictEntry *)greallocn(entries, size, sizeof(DictEntry));
 
80
  }
 
81
  entries[length].key = key;
 
82
  entries[length].val = *val;
 
83
  ++length;
 
84
}
 
85
 
 
86
inline DictEntry *Dict::find(char *key) {
 
87
  int i;
 
88
 
 
89
  for (i = length - 1; i >=0; --i) {
 
90
    if (!strcmp(key, entries[i].key))
 
91
      return &entries[i];
 
92
  }
 
93
  return NULL;
 
94
}
 
95
 
 
96
void Dict::remove(char *key) {
 
97
  int i; 
 
98
  bool found = false;
 
99
  DictEntry tmp;
 
100
  if(length == 0) return;
 
101
 
 
102
  for(i=0; i<length; i++) {
 
103
    if (!strcmp(key, entries[i].key)) {
 
104
      found = true;
 
105
      break;
 
106
    }
 
107
  }
 
108
  if(!found) return;
 
109
  //replace the deleted entry with the last entry
 
110
  length -= 1;
 
111
  tmp = entries[length];
 
112
  if (i!=length) //don't copy the last entry if it is deleted 
 
113
    entries[i] = tmp;
 
114
}
 
115
 
 
116
void Dict::set(char *key, Object *val) {
 
117
  DictEntry *e;
 
118
  e = find (key);
 
119
  if (e) {
 
120
    e->val.free();
 
121
    e->val = *val;
 
122
  } else {
 
123
    add (copyString(key), val);
 
124
  }
 
125
}
 
126
 
 
127
 
 
128
GBool Dict::is(char *type) {
 
129
  DictEntry *e;
 
130
 
 
131
  return (e = find("Type")) && e->val.isName(type);
 
132
}
 
133
 
 
134
Object *Dict::lookup(char *key, Object *obj) {
 
135
  DictEntry *e;
 
136
 
 
137
  return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull();
 
138
}
 
139
 
 
140
Object *Dict::lookupNF(char *key, Object *obj) {
 
141
  DictEntry *e;
 
142
 
 
143
  return (e = find(key)) ? e->val.copy(obj) : obj->initNull();
 
144
}
 
145
 
 
146
GBool Dict::lookupInt(const char *key, const char *alt_key, int *value)
 
147
{
 
148
  Object obj1;
 
149
  GBool success = gFalse;
 
150
  
 
151
  lookup ((char *) key, &obj1);
 
152
  if (obj1.isNull () && alt_key != NULL) {
 
153
    obj1.free ();
 
154
    lookup ((char *) alt_key, &obj1);
 
155
  }
 
156
  if (obj1.isInt ()) {
 
157
    *value = obj1.getInt ();
 
158
    success = gTrue;
 
159
  }
 
160
 
 
161
  obj1.free ();
 
162
 
 
163
  return success;
 
164
}
 
165
 
 
166
char *Dict::getKey(int i) {
 
167
  return entries[i].key;
 
168
}
 
169
 
 
170
Object *Dict::getVal(int i, Object *obj) {
 
171
  return entries[i].val.fetch(xref, obj);
 
172
}
 
173
 
 
174
Object *Dict::getValNF(int i, Object *obj) {
 
175
  return entries[i].val.copy(obj);
 
176
}