]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/Link.cc
Synched with Xpdf 0.92
[evince.git] / pdf / xpdf / Link.cc
index 02b355c1a94b344f95d161bbd632e4b1048abed1..adb8c97faa8e70b13a21594ecea8f27b8aa61df4 100644 (file)
@@ -323,12 +323,39 @@ LinkLaunch::~LinkLaunch() {
 // 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() {
@@ -336,6 +363,23 @@ 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
 //------------------------------------------------------------------------
@@ -352,7 +396,7 @@ LinkUnknown::~LinkUnknown() {
 // Link
 //------------------------------------------------------------------------
 
-Link::Link(Dict *dict) {
+Link::Link(Dict *dict, GString *baseURI) {
   Object obj1, obj2, obj3, obj4;
   double t;
 
@@ -442,7 +486,13 @@ Link::Link(Dict *dict) {
       // 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
@@ -485,7 +535,7 @@ Link::~Link() {
 // Links
 //------------------------------------------------------------------------
 
-Links::Links(Object *annots) {
+Links::Links(Object *annots, GString *baseURI) {
   Link *link;
   Object obj1, obj2;
   int size;
@@ -499,7 +549,7 @@ Links::Links(Object *annots) {
     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;
@@ -530,9 +580,7 @@ LinkAction *Links::find(double x, double y) {
 
   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;
@@ -571,6 +619,7 @@ static GString *getFileSpecName(Object *fileSpecObj) {
       name = obj1.getString()->copy();
     else
       error(-1, "Illegal file spec in link");
+    obj1.free();
 
   // error
   } else {