Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Andi Sardina Ramos
Okular
Commits
707a05f9
Commit
707a05f9
authored
Jun 13, 2005
by
Enrico Ros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
applied patch_056
svn path=/branches/kpdf/annotations/kdegraphics/kpdf/; revision=424999
parent
c885e75b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
52 deletions
+140
-52
xpdf/xpdf/Array.cc
xpdf/xpdf/Array.cc
+15
-0
xpdf/xpdf/Array.h
xpdf/xpdf/Array.h
+1
-0
xpdf/xpdf/Catalog.cc
xpdf/xpdf/Catalog.cc
+93
-51
xpdf/xpdf/Catalog.h
xpdf/xpdf/Catalog.h
+31
-1
No files found.
xpdf/xpdf/Array.cc
View file @
707a05f9
...
...
@@ -71,3 +71,18 @@ Object *Array::getNF(int i, Object *obj) {
}
return
elems
[
i
].
copy
(
obj
);
}
GBool
Array
::
getString
(
int
i
,
GString
*
string
)
{
Object
obj
;
if
(
getNF
(
i
,
&
obj
)
->
isString
())
{
string
->
clear
();
string
->
append
(
obj
.
getString
());
obj
.
free
();
return
gTrue
;
}
else
{
obj
.
free
();
return
gFalse
;
}
}
xpdf/xpdf/Array.h
View file @
707a05f9
...
...
@@ -45,6 +45,7 @@ public:
// Accessors.
Object
*
get
(
int
i
,
Object
*
obj
);
Object
*
getNF
(
int
i
,
Object
*
obj
);
GBool
getString
(
int
i
,
GString
*
string
);
private:
...
...
xpdf/xpdf/Catalog.cc
View file @
707a05f9
...
...
@@ -14,6 +14,7 @@
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include "gmem.h"
#include "Object.h"
#include "XRef.h"
...
...
@@ -91,10 +92,11 @@ Catalog::Catalog(XRef *xrefA) {
catDict
.
dictLookup
(
"Dests"
,
&
dests
);
// read root of named destination tree
if
(
catDict
.
dictLookup
(
"Names"
,
&
obj
)
->
isDict
())
obj
.
dictLookup
(
"Dests"
,
&
nameTree
);
else
nameTree
.
initNull
();
if
(
catDict
.
dictLookup
(
"Names"
,
&
obj
)
->
isDict
())
{
obj
.
dictLookup
(
"Dests"
,
&
obj2
);
destNameTree
.
init
(
xref
,
&
obj2
);
obj2
.
free
();
}
obj
.
free
();
// read base URI
...
...
@@ -142,7 +144,6 @@ Catalog::Catalog(XRef *xrefA) {
err1:
catDict
.
free
();
dests
.
initNull
();
nameTree
.
initNull
();
ok
=
gFalse
;
}
...
...
@@ -159,7 +160,7 @@ Catalog::~Catalog() {
gfree
(
pageRefs
);
}
dests
.
free
();
n
ameTree
.
free
();
destN
ameTree
.
free
();
if
(
baseURI
)
{
delete
baseURI
;
}
...
...
@@ -290,8 +291,8 @@ LinkDest *Catalog::findDest(GString *name) {
else
obj1
.
free
();
}
if
(
!
found
&&
nameTree
.
isDict
()
)
{
if
(
!
findDestInTree
(
&
nameTree
,
name
,
&
obj1
)
->
isNull
()
)
if
(
!
found
)
{
if
(
destNameTree
.
lookup
(
name
,
&
obj1
))
found
=
gTrue
;
else
obj1
.
free
();
...
...
@@ -321,62 +322,103 @@ LinkDest *Catalog::findDest(GString *name) {
return
dest
;
}
Object
*
Catalog
::
findDestInTree
(
Object
*
tree
,
GString
*
name
,
Object
*
obj
)
{
Object
names
,
name1
;
Object
kids
,
kid
,
limits
,
low
,
high
;
GBool
done
,
found
;
int
cmp
,
i
;
NameTree
::
NameTree
(
void
)
{
size
=
0
;
length
=
0
;
entries
=
NULL
;
}
NameTree
::
Entry
::
Entry
(
Array
*
array
,
int
index
)
{
if
(
!
array
->
getString
(
index
,
&
name
)
||
!
array
->
getNF
(
index
+
1
,
&
value
))
error
(
-
1
,
"Invalid page tree"
);
}
NameTree
::
Entry
::~
Entry
()
{
value
.
free
();
}
void
NameTree
::
addEntry
(
Entry
*
entry
)
{
if
(
length
==
size
)
{
if
(
length
==
0
)
{
size
=
8
;
}
else
{
size
*=
2
;
}
entries
=
(
Entry
**
)
grealloc
(
entries
,
sizeof
(
Entry
*
)
*
size
);
}
entries
[
length
]
=
entry
;
++
length
;
}
void
NameTree
::
init
(
XRef
*
xrefA
,
Object
*
tree
)
{
xref
=
xrefA
;
parse
(
tree
);
}
void
NameTree
::
parse
(
Object
*
tree
)
{
Object
names
;
Object
kids
,
kid
;
int
i
;
if
(
!
tree
->
isDict
())
return
;
// leaf node
if
(
tree
->
dictLookup
(
"Names"
,
&
names
)
->
isArray
())
{
done
=
found
=
gFalse
;
for
(
i
=
0
;
!
done
&&
i
<
names
.
arrayGetLength
();
i
+=
2
)
{
if
(
names
.
arrayGet
(
i
,
&
name1
)
->
isString
())
{
cmp
=
name
->
cmp
(
name1
.
getString
());
if
(
cmp
==
0
)
{
names
.
arrayGet
(
i
+
1
,
obj
);
found
=
gTrue
;
done
=
gTrue
;
}
else
if
(
cmp
<
0
)
{
done
=
gTrue
;
}
}
name1
.
free
();
for
(
i
=
0
;
i
<
names
.
arrayGetLength
();
i
+=
2
)
{
NameTree
::
Entry
*
entry
;
entry
=
new
Entry
(
names
.
getArray
(),
i
);
addEntry
(
entry
);
}
names
.
free
();
if
(
!
found
)
obj
->
initNull
();
return
obj
;
}
names
.
free
();
// root or intermediate node
done
=
gFalse
;
if
(
tree
->
dictLookup
(
"Kids"
,
&
kids
)
->
isArray
())
{
for
(
i
=
0
;
!
done
&&
i
<
kids
.
arrayGetLength
();
++
i
)
{
if
(
kids
.
arrayGet
(
i
,
&
kid
)
->
isDict
())
{
if
(
kid
.
dictLookup
(
"Limits"
,
&
limits
)
->
isArray
())
{
if
(
limits
.
arrayGet
(
0
,
&
low
)
->
isString
()
&&
name
->
cmp
(
low
.
getString
())
>=
0
)
{
if
(
limits
.
arrayGet
(
1
,
&
high
)
->
isString
()
&&
name
->
cmp
(
high
.
getString
())
<=
0
)
{
findDestInTree
(
&
kid
,
name
,
obj
);
done
=
gTrue
;
}
high
.
free
();
}
low
.
free
();
}
limits
.
free
();
}
for
(
i
=
0
;
i
<
kids
.
arrayGetLength
();
++
i
)
{
if
(
kids
.
arrayGet
(
i
,
&
kid
)
->
isDict
())
parse
(
&
kid
);
kid
.
free
();
}
}
kids
.
free
();
}
int
NameTree
::
Entry
::
cmp
(
const
void
*
voidKey
,
const
void
*
voidEntry
)
{
GString
*
key
=
(
GString
*
)
voidKey
;
Entry
*
entry
=
*
(
NameTree
::
Entry
**
)
voidEntry
;
return
key
->
cmp
(
&
entry
->
name
);
}
GBool
NameTree
::
lookup
(
GString
*
name
,
Object
*
obj
)
{
Entry
*
entry
;
entry
=
*
(
Entry
**
)
bsearch
(
name
,
entries
,
length
,
sizeof
(
Entry
*
),
Entry
::
cmp
);
if
(
entry
!=
NULL
)
{
entry
->
value
.
fetch
(
xref
,
obj
);
return
gTrue
;
}
else
{
printf
(
"failed to look up %s
\n
"
,
name
->
getCString
());
// name was outside of ranges of all kids
if
(
!
done
)
obj
->
initNull
();
return
obj
;
return
gFalse
;
}
}
void
NameTree
::
free
()
{
int
i
;
for
(
i
=
0
;
i
<
length
;
i
++
)
delete
entries
[
i
];
gfree
(
entries
);
}
xpdf/xpdf/Catalog.h
View file @
707a05f9
...
...
@@ -22,6 +22,36 @@ class PageAttrs;
struct
Ref
;
class
LinkDest
;
//------------------------------------------------------------------------
// NameTree
//------------------------------------------------------------------------
class
NameTree
{
public:
NameTree
();
void
init
(
XRef
*
xref
,
Object
*
tree
);
void
parse
(
Object
*
tree
);
GBool
lookup
(
GString
*
name
,
Object
*
obj
);
void
free
();
private:
struct
Entry
{
Entry
(
Array
*
array
,
int
index
);
~
Entry
();
GString
name
;
Object
value
;
void
free
();
static
int
cmp
(
const
void
*
key
,
const
void
*
entry
);
};
void
addEntry
(
Entry
*
entry
);
XRef
*
xref
;
Object
*
root
;
Entry
**
entries
;
int
size
,
length
;
};
//------------------------------------------------------------------------
// Catalog
//------------------------------------------------------------------------
...
...
@@ -86,7 +116,7 @@ private:
int
numPages
;
// number of pages
int
pagesSize
;
// size of pages array
Object
dests
;
// named destination dictionary
Object
n
ameTree
;
// name tree
NameTree
destN
ameTree
;
// name tree
GString
*
baseURI
;
// base URI for URI-type links
PageMode
pageMode
;
// page mode
Object
metadata
;
// metadata stream
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment