From ac84904af638b243284e24d5f401c3f1a21cb0ef Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Thu, 4 Jul 2013 12:11:20 +0100 Subject: Update pdf_write_document to support incremental update --- platform/x11/jstest_main.c | 4 ++++ platform/x11/pdfapp.c | 7 +++++-- platform/x11/pdfapp.h | 1 + platform/x11/win_main.c | 22 ++++++++++++++++++++++ platform/x11/x11_main.c | 11 +++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) (limited to 'platform/x11') diff --git a/platform/x11/jstest_main.c b/platform/x11/jstest_main.c index 2003ad55..a07385bc 100644 --- a/platform/x11/jstest_main.c +++ b/platform/x11/jstest_main.c @@ -108,6 +108,10 @@ void winreplacefile(char *source, char *target) { } +void wincopyfile(char *source, char *target) +{ +} + void wincursor(pdfapp_t *app, int curs) { } diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index e76c6c7c..71561f14 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -299,13 +299,15 @@ static int pdfapp_save(pdfapp_t *app) { fz_write_options opts; - opts.do_ascii = 1; + opts.do_incremental = 1; + opts.do_ascii = 0; opts.do_expand = 0; - opts.do_garbage = 1; + opts.do_garbage = 0; opts.do_linear = 0; if (strcmp(buf, app->docpath) != 0) { + wincopyfile(app->docpath, buf); fz_write_document(app->doc, buf, &opts); return 1; } @@ -316,6 +318,7 @@ static int pdfapp_save(pdfapp_t *app) fz_try(app->ctx) { + wincopyfile(app->docpath, buf); fz_write_document(app->doc, buf, &opts); written = 1; } diff --git a/platform/x11/pdfapp.h b/platform/x11/pdfapp.h index 3e40e0c4..0b89923e 100644 --- a/platform/x11/pdfapp.h +++ b/platform/x11/pdfapp.h @@ -42,6 +42,7 @@ extern void winalert(pdfapp_t *, pdf_alert_event *alert); extern void winprint(pdfapp_t *); extern void winadvancetimer(pdfapp_t *, float duration); extern void winreplacefile(char *source, char *target); +extern void wincopyfile(char *source, char *target); struct pdfapp_s { diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c index cc01d539..a22e7fc0 100644 --- a/platform/x11/win_main.c +++ b/platform/x11/win_main.c @@ -248,6 +248,28 @@ void winreplacefile(char *source, char *target) #endif } +void wincopyfile(char *source, char *target) +{ + wchar_t wsource[PATH_MAX]; + wchar_t wtarget[PATH_MAX]; + + int sz = MultiByteToWideChar(CP_UTF8, 0, source, -1, wsource, PATH_MAX); + if (sz == 0) + { + winerror(&gapp, "cannot convert filename to Unicode"); + return; + } + + sz = MultiByteToWideChar(CP_UTF8, 0, target, -1, wtarget, PATH_MAX); + if (sz == 0) + { + winerror(&gapp, "cannot convert filename to Unicode"); + return; + } + + CopyFile(wsource, wtarget, FALSE); +} + static char pd_filename[256] = "The file is encrypted."; static char pd_password[256] = ""; static wchar_t pd_passwordw[256] = {0}; diff --git a/platform/x11/x11_main.c b/platform/x11/x11_main.c index 481adce1..0bcb98f4 100644 --- a/platform/x11/x11_main.c +++ b/platform/x11/x11_main.c @@ -281,6 +281,17 @@ void winreplacefile(char *source, char *target) rename(source, target); } +void wincopyfile(char *source, char *target) +{ + char *buf = malloc(strlen(source)+strlen(target)+4); + if (buf) + { + sprintf(buf, "cp %s %s", source, target); + system(buf); + free(buf); + } +} + void cleanup(pdfapp_t *app) { fz_context *ctx = app->ctx; -- cgit v1.2.3