diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-11-13 17:38:00 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-11-13 21:27:07 +0100 |
commit | 1627e0f36b0891815d53b4f27e3289ec0065d8df (patch) | |
tree | d29f5534fe446d0ed994a36190b1a0fc5f1796f0 | |
parent | 4caf574c569d7c39e44b8ad66b16417ad8653b34 (diff) | |
download | mupdf-1627e0f36b0891815d53b4f27e3289ec0065d8df.tar.xz |
Bug 692592: Handle relative file links.
The core library doesn't know where a document comes from, since we can
open it as a stream, etc. Let the viewer handle relative file URLs.
-rw-r--r-- | platform/gl/gl-main.c | 16 | ||||
-rw-r--r-- | platform/x11/pdfapp.c | 18 | ||||
-rw-r--r-- | source/pdf/pdf-link.c | 8 |
3 files changed, 34 insertions, 8 deletions
diff --git a/platform/gl/gl-main.c b/platform/gl/gl-main.c index e153a75e..1910f1b3 100644 --- a/platform/gl/gl-main.c +++ b/platform/gl/gl-main.c @@ -12,7 +12,7 @@ #endif #ifndef _WIN32 -#include <unistd.h> /* for fork and exec */ +#include <unistd.h> /* for fork, exec, and getcwd */ #else char *realpath(const char *path, char *resolved_path); /* in gl-file.c */ #endif @@ -50,6 +50,20 @@ enum static void open_browser(const char *uri) { + char buf[PATH_MAX]; + + /* Relative file:// URI, make it absolute! */ + if (!strncmp(uri, "file://", 7) && uri[7] != '/') + { + char buf_base[PATH_MAX]; + char buf_cwd[PATH_MAX]; + fz_dirname(buf_base, filename, sizeof buf_base); + getcwd(buf_cwd, sizeof buf_cwd); + fz_snprintf(buf, sizeof buf, "file://%s/%s/%s", buf_cwd, buf_base, uri+7); + fz_cleanname(buf+7); + uri = buf; + } + #ifdef _WIN32 ShellExecuteA(NULL, "open", uri, 0, 0, SW_SHOWNORMAL); #else diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index bc044062..e4d05b48 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -8,6 +8,10 @@ #include <stdlib.h> #include <stdio.h> +#ifndef _WIN32 +#include <unistd.h> /* for getcwd */ +#endif + #define BEYOND_THRESHHOLD 40 #ifndef PATH_MAX @@ -997,6 +1001,20 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai static void pdfapp_gotouri(pdfapp_t *app, char *uri) { + char buf[PATH_MAX]; + + /* Relative file:// URI, make it absolute! */ + if (!strncmp(uri, "file://", 7) && uri[7] != '/') + { + char buf_base[PATH_MAX]; + char buf_cwd[PATH_MAX]; + fz_dirname(buf_base, app->docpath, sizeof buf_base); + getcwd(buf_cwd, sizeof buf_cwd); + fz_snprintf(buf, sizeof buf, "file://%s/%s/%s", buf_cwd, buf_base, uri+7); + fz_cleanname(buf+7); + uri = buf; + } + winopenuri(app, uri); } diff --git a/source/pdf/pdf-link.c b/source/pdf/pdf-link.c index ae5beaa3..6d34cc6a 100644 --- a/source/pdf/pdf-link.c +++ b/source/pdf/pdf-link.c @@ -138,18 +138,12 @@ pdf_parse_file_spec(fz_context *ctx, pdf_document *doc, pdf_obj *file_spec, pdf_ #ifdef _WIN32 if (!pdf_name_eq(ctx, pdf_dict_get(ctx, file_spec, PDF_NAME(FS)), PDF_NAME(URL))) { - /* move the file name into the expected place and use the expected path separator */ - char *c; + /* Fix up the drive letter (change "/C/Documents/Foo" to "C:/Documents/Foo") */ if (path[0] == '/' && (('A' <= path[1] && path[1] <= 'Z') || ('a' <= path[1] && path[1] <= 'z')) && path[2] == '/') { path[0] = path[1]; path[1] = ':'; } - for (c = path; *c; c++) - { - if (*c == '/') - *c = '\\'; - } } #endif |