diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2012-04-20 16:00:13 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-04-20 16:10:02 +0100 |
commit | c6e27a74283a1fa31a930f1909dbc46e131f0447 (patch) | |
tree | b0104b5dd19f07fec8d2c03720c3efc8a8f60166 /apps | |
parent | 9fbd2de7411f6c87c6f1ad0d9adfba9fe5164e0f (diff) | |
download | mupdf-c6e27a74283a1fa31a930f1909dbc46e131f0447.tar.xz |
Pass UTF8 filename to fz_open_document / fz_open_file to remove kludges.
Use _wopen on a UTF8 -> wchar_t decoded filename to support UTF8 filenames
for win32.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/pdfapp.c | 16 | ||||
-rw-r--r-- | apps/pdfapp.h | 2 | ||||
-rw-r--r-- | apps/win_main.c | 16 | ||||
-rw-r--r-- | apps/x11_main.c | 16 |
4 files changed, 7 insertions, 43 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 66513570..52bb4c48 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -89,26 +89,14 @@ void pdfapp_invert(pdfapp_t *app, fz_bbox rect) fz_invert_pixmap_rect(app->image, rect); } -void pdfapp_open(pdfapp_t *app, char *filename, int fd, int reload) +void pdfapp_open(pdfapp_t *app, char *filename, int reload) { fz_context *ctx = app->ctx; - fz_stream *file; char *password = ""; fz_try(ctx) { - file = fz_open_fd(ctx, fd); - - if (strstr(filename, ".rels")) - app->doc = (fz_document*) xps_open_document(ctx, filename); - else if (strstr(filename, ".xps") || strstr(filename, ".XPS") || strstr(filename, ".rels")) - app->doc = (fz_document*) xps_open_document_with_stream(file); - else if (strstr(filename, ".cbz") || strstr(filename, ".CBZ") || strstr(filename, ".zip") || strstr(filename, ".ZIP")) - app->doc = (fz_document*) cbz_open_document_with_stream(file); - else - app->doc = (fz_document*) pdf_open_document_with_stream(file); - - fz_close(file); + app->doc = fz_open_document(ctx, filename); if (fz_needs_password(app->doc)) { diff --git a/apps/pdfapp.h b/apps/pdfapp.h index 6812323b..f93b816a 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -100,7 +100,7 @@ struct pdfapp_s }; void pdfapp_init(fz_context *ctx, pdfapp_t *app); -void pdfapp_open(pdfapp_t *app, char *filename, int fd, int reload); +void pdfapp_open(pdfapp_t *app, char *filename, int reload); void pdfapp_close(pdfapp_t *app); char *pdfapp_version(pdfapp_t *app); diff --git a/apps/win_main.c b/apps/win_main.c index cc71a120..358b21bb 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -594,15 +594,8 @@ void windocopy(pdfapp_t *app) void winreloadfile(pdfapp_t *app) { - int fd; - pdfapp_close(app); - - fd = _wopen(wbuf, O_BINARY | O_RDONLY, 0666); - if (fd < 0) - winerror(&gapp, "cannot reload file"); - - pdfapp_open(app, filename, fd, 1); + pdfapp_open(app, filename, 1); } void winopenuri(pdfapp_t *app, char *buf) @@ -834,7 +827,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); char argv0[256]; MSG msg; - int fd; int code; fz_context *ctx; @@ -861,15 +853,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow exit(0); } - fd = _wopen(wbuf, O_BINARY | O_RDONLY, 0666); - if (fd < 0) - winerror(&gapp, "cannot open file"); - code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL); if (code == 0) winerror(&gapp, "cannot convert filename to utf-8"); - pdfapp_open(&gapp, filename, fd, 0); + pdfapp_open(&gapp, filename, 0); while (GetMessage(&msg, NULL, 0, 0)) { diff --git a/apps/x11_main.c b/apps/x11_main.c index b62f97db..6ab5b43a 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -532,15 +532,8 @@ void onselreq(Window requestor, Atom selection, Atom target, Atom property, Time void winreloadfile(pdfapp_t *app) { - int fd; - pdfapp_close(app); - - fd = open(filename, O_RDONLY, 0666); - if (fd < 0) - fz_throw(gapp.ctx, "cannot reload file '%s'", filename); - - pdfapp_open(app, filename, fd, 1); + pdfapp_open(app, filename, 1); } void winopenuri(pdfapp_t *app, char *buf) @@ -612,7 +605,6 @@ int main(int argc, char **argv) int oldy = 0; int resolution = -1; int pageno = 1; - int fd; fd_set fds; int width = -1; int height = -1; @@ -663,11 +655,7 @@ int main(int argc, char **argv) gapp.resolution = resolution; gapp.pageno = pageno; - fd = open(filename, O_RDONLY, 0666); - if (fd < 0) - fz_throw(gapp.ctx, "cannot open file '%s'", filename); - - pdfapp_open(&gapp, filename, fd, 0); + pdfapp_open(&gapp, filename, 0); FD_ZERO(&fds); |