// LinkURI
//------------------------------------------------------------------------
-LinkURI::LinkURI(Object *uriObj) {
+LinkURI::LinkURI(Object *uriObj, GString *baseURI) {
+ GString *uri2;
+ int n;
+ char c;
+
uri = NULL;
- if (uriObj->isString())
- uri = uriObj->getString()->copy();
- else
+ if (uriObj->isString()) {
+ uri2 = uriObj->getString()->copy();
+ if (baseURI) {
+ n = strcspn(uri2->getCString(), "/:");
+ if (n == uri2->getLength() || uri2->getChar(n) == '/') {
+ uri = baseURI->copy();
+ c = uri->getChar(uri->getLength() - 1);
+ if (c == '/' || c == '?') {
+ if (uri2->getChar(0) == '/') {
+ uri2->del(0);
+ }
+ } else {
+ if (uri2->getChar(0) != '/') {
+ uri->append('/');
+ }
+ }
+ uri->append(uri2);
+ delete uri2;
+ } else {
+ uri = uri2;
+ }
+ } else {
+ uri = uri2;
+ }
+ } else {
error(-1, "Illegal URI-type link");
+ }
}
LinkURI::~LinkURI() {
delete uri;
}
+//------------------------------------------------------------------------
+// LinkNamed
+//------------------------------------------------------------------------
+
+LinkNamed::LinkNamed(Object *nameObj) {
+ name = NULL;
+ if (nameObj->isName()) {
+ name = new GString(nameObj->getName());
+ }
+}
+
+LinkNamed::~LinkNamed() {
+ if (name) {
+ delete name;
+ }
+}
+
//------------------------------------------------------------------------
// LinkUnknown
//------------------------------------------------------------------------
// Link
//------------------------------------------------------------------------
-Link::Link(Dict *dict) {
+Link::Link(Dict *dict, GString *baseURI) {
Object obj1, obj2, obj3, obj4;
double t;
// URI action
} else if (obj2.isName("URI")) {
obj1.dictLookup("URI", &obj3);
- action = new LinkURI(&obj3);
+ action = new LinkURI(&obj3, baseURI);
+ obj3.free();
+
+ // Named action
+ } else if (obj2.isName("Named")) {
+ obj1.dictLookup("N", &obj3);
+ action = new LinkNamed(&obj3);
obj3.free();
// unknown action
// Links
//------------------------------------------------------------------------
-Links::Links(Object *annots) {
+Links::Links(Object *annots, GString *baseURI) {
Link *link;
Object obj1, obj2;
int size;
for (i = 0; i < annots->arrayGetLength(); ++i) {
if (annots->arrayGet(i, &obj1)->isDict()) {
if (obj1.dictLookup("Subtype", &obj2)->isName("Link")) {
- link = new Link(obj1.getDict());
+ link = new Link(obj1.getDict(), baseURI);
if (link->isOk()) {
if (numLinks >= size) {
size += 16;
for (i = 0; i < numLinks; ++i) {
if (links[i]->inRect(x, y)) {
- if (links[i]->getAction())
- return links[i]->getAction();
- return NULL;
+ return links[i]->getAction();
}
}
return NULL;
name = obj1.getString()->copy();
else
error(-1, "Illegal file spec in link");
+ obj1.free();
// error
} else {