summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-06-26 15:59:17 +0100
committerRobin Watts <robin.watts@artifex.com>2015-06-26 19:06:22 +0100
commit2b08c7f7ed2d4bc3874e5d2734c7d4a0ca3ad966 (patch)
tree09f71d07e0c16cd4a64048387ae9c718d57bebd3
parent7b5720137cef833476d4015cce6402e3c272ccad (diff)
downloadmupdf-2b08c7f7ed2d4bc3874e5d2734c7d4a0ca3ad966.tar.xz
Bug 696053: Update windows mupdf to respect command line flags.
Previously, only the unix executable had been updated to take command line flags; update the windows one in line with it. We have to cope with the argv being in Unicode; add a windows specific version of getoptw for this. Also note that that fprintf's in the windows mupdf exe won't work as GUI apps don't have a console window, and can't write to the parent one. Fixing that is a larger project than I have time for right now.
-rw-r--r--include/mupdf/fitz/getopt.h9
-rw-r--r--platform/win32/libmupdf.vcproj4
-rw-r--r--platform/x11/win_main.c69
-rw-r--r--source/fitz/getoptw.c72
4 files changed, 136 insertions, 18 deletions
diff --git a/include/mupdf/fitz/getopt.h b/include/mupdf/fitz/getopt.h
index e70e1cd1..3890c618 100644
--- a/include/mupdf/fitz/getopt.h
+++ b/include/mupdf/fitz/getopt.h
@@ -8,4 +8,13 @@ extern int fz_getopt(int nargc, char * const *nargv, const char *ostr);
extern int fz_optind;
extern char *fz_optarg;
+/*
+ Windows unicode versions.
+*/
+#if defined(_WIN32) || defined(_WIN64)
+extern int fz_getoptw(int nargc, wchar_t * const *nargv, const wchar_t *ostr);
+extern int fz_optindw;
+extern wchar_t *fz_optargw;
+#endif
+
#endif
diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj
index ffd01798..07ceb673 100644
--- a/platform/win32/libmupdf.vcproj
+++ b/platform/win32/libmupdf.vcproj
@@ -870,6 +870,10 @@
>
</File>
<File
+ RelativePath="..\..\source\fitz\getoptw.c"
+ >
+ </File>
+ <File
RelativePath="..\..\source\fitz\glyph.c"
>
</File>
diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c
index 40d91004..538f02f5 100644
--- a/platform/x11/win_main.c
+++ b/platform/x11/win_main.c
@@ -39,6 +39,7 @@ static pdfapp_t gapp;
static wchar_t wbuf[PATH_MAX];
static char filename[PATH_MAX];
+static char layout_css_buf[PATH_MAX];
/*
* Create registry keys to associate MuPDF with PDF and XPS files.
@@ -1191,6 +1192,19 @@ get_system_dpi(void)
return ((hdpi + vdpi) * 96.0 + 0.5) / 200;
}
+static void usage(void)
+{
+ fprintf(stderr, "usage: mupdf [options] file.pdf [page]\n");
+ fprintf(stderr, "\t-p -\tpassword\n");
+ fprintf(stderr, "\t-r -\tresolution\n");
+ fprintf(stderr, "\t-A -\tset anti-aliasing quality in bits (0=off, 8=best)\n");
+ fprintf(stderr, "\t-C -\tRRGGBB (tint color in hexadecimal syntax)\n");
+ fprintf(stderr, "\t-W -\tpage width for EPUB layout\n");
+ fprintf(stderr, "\t-H -\tpage height for EPUB layout\n");
+ fprintf(stderr, "\t-S -\tfont size for EPUB layout\n");
+ exit(1);
+}
+
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
@@ -1200,9 +1214,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
MSG msg;
int code;
fz_context *ctx;
- int arg;
int bps = 0;
int displayRes = get_system_dpi();
+ int c;
+ wchar_t *password = NULL;
+ wchar_t *layout_css = NULL;
ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT);
if (!ctx)
@@ -1211,6 +1227,30 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
exit(1);
}
pdfapp_init(ctx, &gapp);
+
+ while ((c = fz_getoptw(argc, argv, L"p:r:A:C:W:H:S:U:b:")) != -1)
+ {
+ switch (c)
+ {
+ case 'C':
+ c = wcstol(fz_optargw, NULL, 16);
+ gapp.tint = 1;
+ gapp.tint_r = (c >> 16) & 255;
+ gapp.tint_g = (c >> 8) & 255;
+ gapp.tint_b = (c) & 255;
+ break;
+ case 'p': password = fz_optargw; break;
+ case 'r': displayRes = _wtoi(fz_optargw); break;
+ case 'A': fz_set_aa_level(ctx, _wtoi(fz_optargw)); break;
+ case 'W': gapp.layout_w = _wtoi(fz_optargw); break;
+ case 'H': gapp.layout_h = _wtoi(fz_optargw); break;
+ case 'S': gapp.layout_em = _wtoi(fz_optargw); break;
+ case 'b': bps = (fz_optargw && *fz_optargw) ? _wtoi(fz_optargw) : 4096; break;
+ case 'U': layout_css = fz_optargw; break;
+ default: usage();
+ }
+ }
+
pdfapp_setresolution(&gapp, displayRes);
GetModuleFileNameA(NULL, argv0, sizeof argv0);
@@ -1218,24 +1258,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
winopen();
- arg = 1;
- while (arg < argc)
+ if (fz_optindw < argc)
{
- if (!wcscmp(argv[arg], L"-p"))
- {
- if (arg+1 < argc)
- bps = _wtoi(argv[++arg]);
- else
- bps = 4096;
- }
- else
- break;
- arg++;
- }
-
- if (arg < argc)
- {
- wcscpy(wbuf, argv[arg]);
+ wcscpy(wbuf, argv[fz_optindw]);
}
else
{
@@ -1247,6 +1272,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
if (code == 0)
winerror(&gapp, "cannot convert filename to utf-8");
+ if (layout_css)
+ {
+ code = WideCharToMultiByte(CP_UTF8, 0, layout_css, -1, layout_css_buf, sizeof layout_css_buf, NULL, NULL);
+ if (code == 0)
+ winerror(&gapp, "cannot convert layout_css filename to utf-8");
+ gapp.layout_css = layout_css_buf;
+ }
+
if (bps)
pdfapp_open_progressive(&gapp, filename, 0, bps);
else
diff --git a/source/fitz/getoptw.c b/source/fitz/getoptw.c
new file mode 100644
index 00000000..55b8d015
--- /dev/null
+++ b/source/fitz/getoptw.c
@@ -0,0 +1,72 @@
+/*
+ * This is a version of the public domain getopt implementation by
+ * Henry Spencer originally posted to net.sources. Adapted to
+ * windows wchar's.
+ *
+ * This file is in the public domain.
+ */
+
+#if defined(_WIN64) || defined(_WIN32)
+
+#include <stdio.h>
+#include <string.h>
+#include <windows.h>
+
+#define getoptw fz_getoptw
+#define optargw fz_optargw
+#define optindw fz_optindw
+
+wchar_t *optargw; /* Global argument pointer. */
+int optindw = 0; /* Global argv index. */
+
+static wchar_t *scan = NULL; /* Private scan pointer. */
+
+int
+getoptw(wchar_t argc, wchar_t *argv[], wchar_t *optstring)
+{
+ wchar_t c;
+ wchar_t *place;
+
+ optargw = NULL;
+
+ if (!scan || *scan == '\0') {
+ if (optindw == 0)
+ optindw++;
+
+ if (optindw >= argc || argv[optindw][0] != '-' || argv[optindw][1] == '\0')
+ return EOF;
+ if (argv[optindw][1] == '-' && argv[optindw][2] == '\0') {
+ optindw++;
+ return EOF;
+ }
+
+ scan = argv[optindw]+1;
+ optindw++;
+ }
+
+ c = *scan++;
+ place = wcschr(optstring, c);
+
+ if (!place || c == ':') {
+ fprintf(stderr, "%s: unknown option -%C\n", argv[0], c);
+ return '?';
+ }
+
+ place++;
+ if (*place == ':') {
+ if (*scan != '\0') {
+ optargw = scan;
+ scan = NULL;
+ } else if( optindw < argc ) {
+ optargw = argv[optindw];
+ optindw++;
+ } else {
+ fprintf(stderr, "%s: option requires argument -%C\n", argv[0], c);
+ return ':';
+ }
+ }
+
+ return c;
+}
+
+#endif