summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-annot.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-02-26 10:19:16 +0000
committerRobin Watts <robin.watts@artifex.com>2015-02-26 10:19:16 +0000
commitf8809680945937d49f70be417e2f8ffda8a57558 (patch)
treebadd75fe8e180c288207369f53e011951c6a0250 /source/pdf/pdf-annot.c
parentc47220017efa6daccd6e12ebb93b0d82b892dad3 (diff)
downloadmupdf-f8809680945937d49f70be417e2f8ffda8a57558.tar.xz
tweak pdf_parse_file_spec
pdf_parse_file_spec sometimes extracts the wrong path from a FileSpec: E.g. the /DOS path should never be returned under Unix systems, neither should be the old /Mac paths. For consistency, this patch also converts filesystem paths under Windows into a format applications will expect (e.g. from "/C/path/..." to "C:\path\..."). Finally, pdf_parse_file_spec is exposed to callers (SumatraPDF requires that for manually processing FZ_ANNOT_FILEATTACHMENT and embedded files).
Diffstat (limited to 'source/pdf/pdf-annot.c')
-rw-r--r--source/pdf/pdf-annot.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c
index b25c24df..79114211 100644
--- a/source/pdf/pdf-annot.c
+++ b/source/pdf/pdf-annot.c
@@ -217,30 +217,50 @@ pdf_parse_link_dest(fz_context *ctx, pdf_document *doc, fz_link_kind kind, pdf_o
return ld;
}
-static char *
+char *
pdf_parse_file_spec(fz_context *ctx, pdf_document *doc, pdf_obj *file_spec)
{
pdf_obj *filename;
+ char *path = NULL;
if (pdf_is_string(ctx, file_spec))
- return pdf_to_utf8(ctx, doc, file_spec);
+ filename = file_spec;
if (pdf_is_dict(ctx, file_spec)) {
- filename = pdf_dict_gets(ctx, file_spec, "UF");
+#if defined(_WIN32) || defined(_WIN64)
+ filename = pdf_dict_gets(ctx, file_spec, "DOS");
+#else
+ filename = pdf_dict_gets(ctx, file_spec, "Unix");
+#endif
if (!filename)
- filename = pdf_dict_gets(ctx, file_spec, "F");
- if (!filename)
- filename = pdf_dict_gets(ctx, file_spec, "Unix");
- if (!filename)
- filename = pdf_dict_gets(ctx, file_spec, "Mac");
- if (!filename)
- filename = pdf_dict_gets(ctx, file_spec, "DOS");
+ filename = pdf_dict_getsa(ctx, file_spec, "UF", "F");
+ }
- return pdf_to_utf8(ctx, doc, filename);
+ if (!pdf_is_string(ctx, filename))
+ {
+ fz_warn(ctx, "cannot parse file specification");
+ return NULL;
}
- fz_warn(ctx, "cannot parse file specification");
- return NULL;
+ path = pdf_to_utf8(ctx, doc, filename);
+#if defined(_WIN32) || defined(_WIN64)
+ if (strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, file_spec, "FS")), "URL") != 0)
+ {
+ /* move the file name into the expected place and use the expected path separator */
+ char *c;
+ 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
+ return path;
}
fz_link_dest