From f8809680945937d49f70be417e2f8ffda8a57558 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Thu, 26 Feb 2015 10:19:16 +0000 Subject: 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). --- source/pdf/pdf-annot.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'source/pdf/pdf-annot.c') 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 -- cgit v1.2.3