summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2009-11-29 04:40:31 +0100
committerTor Andersson <tor@ghostscript.com>2009-11-29 04:40:31 +0100
commit2c080e248a47cb94d2069f6523c314d039f70919 (patch)
tree46180621f350edfb63ac578a04125dcd9db31f9d /apps
parentaf27ce7576c323665bb9986fbbab63acb6c81c17 (diff)
downloadmupdf-2c080e248a47cb94d2069f6523c314d039f70919.tar.xz
Fix up indentation.
Diffstat (limited to 'apps')
-rw-r--r--apps/common/pdfapp.c40
-rw-r--r--apps/pdfclean.c462
-rw-r--r--apps/pdfdraw.c612
-rw-r--r--apps/pdfextract.c424
-rw-r--r--apps/pdfinfo.c130
-rw-r--r--apps/pdfshow.c226
-rw-r--r--apps/unix/x11pdf.c106
-rw-r--r--apps/unix/ximage.c116
-rw-r--r--apps/windows/winmain.c1187
9 files changed, 1651 insertions, 1652 deletions
diff --git a/apps/common/pdfapp.c b/apps/common/pdfapp.c
index 96eeae00..367a195c 100644
--- a/apps/common/pdfapp.c
+++ b/apps/common/pdfapp.c
@@ -81,11 +81,11 @@ void pdfapp_open(pdfapp_t *app, char *filename)
error = pdf_loadxref(app->xref, filename);
if (error)
{
- fz_catch(error, "trying to repair");
- pdfapp_warn(app, "There was a problem with file \"%s\".\nIt may be corrupted or generated by faulty software.\nTrying to repair the file.", filename);
- error = pdf_repairxref(app->xref, filename);
- if (error)
- pdfapp_error(app, error);
+ fz_catch(error, "trying to repair");
+ pdfapp_warn(app, "There was a problem with file \"%s\".\nIt may be corrupted or generated by faulty software.\nTrying to repair the file.", filename);
+ error = pdf_repairxref(app->xref, filename);
+ if (error)
+ pdfapp_error(app, error);
}
error = pdf_decryptxref(app->xref);
@@ -242,7 +242,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage)
pdfapp_error(app, error);
sprintf(buf, "%s - %d/%d", app->doctitle,
- app->pageno, app->pagecount);
+ app->pageno, app->pagecount);
wintitle(app, buf);
}
@@ -258,7 +258,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage)
bbox = fz_transformaabb(ctm, app->page->mediabox);
error = fz_rendertree(&app->image, app->rast, app->page->tree,
- ctm, fz_roundrect(bbox), 1);
+ ctm, fz_roundrect(bbox), 1);
if (error)
pdfapp_error(app, error);
@@ -342,9 +342,9 @@ void pdfapp_onkey(pdfapp_t *app, int c)
switch (c)
{
- /*
- * Zoom and rotate
- */
+ /*
+ * Zoom and rotate
+ */
case '+':
case '=':
@@ -379,9 +379,9 @@ void pdfapp_onkey(pdfapp_t *app, int c)
pdfapp_showpage(app, 0, 1);
break;
- /*
- * Pan view, but dont need to repaint image
- */
+ /*
+ * Pan view, but dont need to repaint image
+ */
case 'w':
app->shrinkwrap = 1;
@@ -409,9 +409,9 @@ void pdfapp_onkey(pdfapp_t *app, int c)
pdfapp_showpage(app, 0, 0);
break;
- /*
- * Page navigation
- */
+ /*
+ * Page navigation
+ */
case 'g':
case '\n':
@@ -438,9 +438,9 @@ void pdfapp_onkey(pdfapp_t *app, int c)
app->pageno = app->hist[--app->histlen];
break;
- /*
- * Back and forth ...
- */
+ /*
+ * Back and forth ...
+ */
case 'p':
panto = PAN_TO_BOTTOM;
@@ -575,7 +575,7 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta
else
{
/* scroll up/down, or left/right if
- shift is pressed */
+ shift is pressed */
int isx = (modifiers & (1<<0));
int xstep = isx ? 20 * dir : 0;
int ystep = !isx ? 20 * dir : 0;
diff --git a/apps/pdfclean.c b/apps/pdfclean.c
index a558d17d..755cb39c 100644
--- a/apps/pdfclean.c
+++ b/apps/pdfclean.c
@@ -26,333 +26,333 @@ static fz_error sweepref(pdf_xref *xref, fz_obj *ref);
static fz_error sweepobj(pdf_xref *xref, fz_obj *obj)
{
- fz_error error;
- int i;
+ fz_error error;
+ int i;
- if (fz_isindirect(obj))
- return sweepref(xref, obj);
+ if (fz_isindirect(obj))
+ return sweepref(xref, obj);
- if (fz_isdict(obj))
- {
- for (i = 0; i < fz_dictlen(obj); i++)
+ if (fz_isdict(obj))
{
- error = sweepobj(xref, fz_dictgetval(obj, i));
- if (error)
- return error; /* too deeply nested for rethrow */
+ for (i = 0; i < fz_dictlen(obj); i++)
+ {
+ error = sweepobj(xref, fz_dictgetval(obj, i));
+ if (error)
+ return error; /* too deeply nested for rethrow */
+ }
}
- }
- if (fz_isarray(obj))
- {
- for (i = 0; i < fz_arraylen(obj); i++)
+ if (fz_isarray(obj))
{
- error = sweepobj(xref, fz_arrayget(obj, i));
- if (error)
- return error; /* too deeply nested for rethrow */
+ for (i = 0; i < fz_arraylen(obj); i++)
+ {
+ error = sweepobj(xref, fz_arrayget(obj, i));
+ if (error)
+ return error; /* too deeply nested for rethrow */
+ }
}
- }
- return fz_okay;
+ return fz_okay;
}
static fz_error sweepref(pdf_xref *xref, fz_obj *ref)
{
- fz_error error;
- fz_obj *obj;
- fz_obj *len;
- int oid, gen;
+ fz_error error;
+ fz_obj *obj;
+ fz_obj *len;
+ int oid, gen;
- oid = fz_tonum(ref);
- gen = fz_tonum(ref);
+ oid = fz_tonum(ref);
+ gen = fz_tonum(ref);
- if (oid < 0 || oid >= xref->len)
- return fz_throw("object out of range (%d %d R)", oid, gen);
+ if (oid < 0 || oid >= xref->len)
+ return fz_throw("object out of range (%d %d R)", oid, gen);
- if (uselist[oid])
- return fz_okay;
+ if (uselist[oid])
+ return fz_okay;
- uselist[oid] = 1;
+ uselist[oid] = 1;
- obj = fz_resolveindirect(ref);
+ obj = fz_resolveindirect(ref);
- /* Bake in /Length in stream objects */
- if (xref->table[oid].stmofs)
- {
- len = fz_dictgets(obj, "Length");
- if (fz_isindirect(len))
+ /* Bake in /Length in stream objects */
+ if (xref->table[oid].stmofs)
{
- len = fz_resolveindirect(len);
- fz_dictputs(obj, "Length", len);
+ len = fz_dictgets(obj, "Length");
+ if (fz_isindirect(len))
+ {
+ len = fz_resolveindirect(len);
+ fz_dictputs(obj, "Length", len);
+ }
}
- }
- error = sweepobj(xref, obj);
- if (error)
- {
- fz_dropobj(obj);
- return error; /* too deeply nested for rethrow */
- }
+ error = sweepobj(xref, obj);
+ if (error)
+ {
+ fz_dropobj(obj);
+ return error; /* too deeply nested for rethrow */
+ }
- return fz_okay;
+ return fz_okay;
}
static void preloadobjstms(void)
{
- fz_error error;
- fz_obj *obj;
- int oid;
+ fz_error error;
+ fz_obj *obj;
+ int oid;
- for (oid = 0; oid < xref->len; oid++)
- {
- if (xref->table[oid].type == 'o')
+ for (oid = 0; oid < xref->len; oid++)
{
- error = pdf_loadobject(&obj, xref, oid, 0);
- if (error)
- die(error);
- fz_dropobj(obj);
+ if (xref->table[oid].type == 'o')
+ {
+ error = pdf_loadobject(&obj, xref, oid, 0);
+ if (error)
+ die(error);
+ fz_dropobj(obj);
+ }
}
- }
}
static void copystream(fz_obj *obj, int oid, int gen)
{
- fz_error error;
- fz_buffer *buf;
+ fz_error error;
+ fz_buffer *buf;
- error = pdf_loadrawstream(&buf, xref, oid, gen);
- if (error)
- die(error);
+ error = pdf_loadrawstream(&buf, xref, oid, gen);
+ if (error)
+ die(error);
- fprintf(out, "%d %d obj\n", oid, gen);
- fz_fprintobj(out, obj, !doexpand);
- fprintf(out, "stream\n");
- fwrite(buf->rp, 1, buf->wp - buf->rp, out);
- fprintf(out, "endstream\nendobj\n\n");
+ fprintf(out, "%d %d obj\n", oid, gen);
+ fz_fprintobj(out, obj, !doexpand);
+ fprintf(out, "stream\n");
+ fwrite(buf->rp, 1, buf->wp - buf->rp, out);
+ fprintf(out, "endstream\nendobj\n\n");
- fz_dropbuffer(buf);
+ fz_dropbuffer(buf);
}
static void expandstream(fz_obj *obj, int oid, int gen)
{
- fz_error error;
- fz_buffer *buf;
- fz_obj *newdict, *newlen;
+ fz_error error;
+ fz_buffer *buf;
+ fz_obj *newdict, *newlen;
- error = pdf_loadstream(&buf, xref, oid, gen);
- if (error)
- die(error);
+ error = pdf_loadstream(&buf, xref, oid, gen);
+ if (error)
+ die(error);
- newdict = fz_copydict(obj);
- fz_dictdels(newdict, "Filter");
- fz_dictdels(newdict, "DecodeParms");
+ newdict = fz_copydict(obj);
+ fz_dictdels(newdict, "Filter");
+ fz_dictdels(newdict, "DecodeParms");
- newlen = fz_newint(buf->wp - buf->rp);
- fz_dictputs(newdict, "Length", newlen);
- fz_dropobj(newlen);
+ newlen = fz_newint(buf->wp - buf->rp);
+ fz_dictputs(newdict, "Length", newlen);
+ fz_dropobj(newlen);
- fprintf(out, "%d %d obj\n", oid, gen);
- fz_fprintobj(out, newdict, !doexpand);
- fprintf(out, "stream\n");
- fwrite(buf->rp, 1, buf->wp - buf->rp, out);
- fprintf(out, "endstream\nendobj\n\n");
+ fprintf(out, "%d %d obj\n", oid, gen);
+ fz_fprintobj(out, newdict, !doexpand);
+ fprintf(out, "stream\n");
+ fwrite(buf->rp, 1, buf->wp - buf->rp, out);
+ fprintf(out, "endstream\nendobj\n\n");
- fz_dropobj(newdict);
+ fz_dropobj(newdict);
- fz_dropbuffer(buf);
+ fz_dropbuffer(buf);
}
static void saveobject(int oid, int gen)
{
- fz_error error;
- fz_obj *obj;
- fz_obj *type;
-
- error = pdf_loadobject(&obj, xref, oid, gen);
- if (error)
- die(error);
-
- /* skip ObjStm and XRef objects */
- if (fz_isdict(obj))
- {
- type = fz_dictgets(obj, "Type");
- if (fz_isname(type) && !strcmp(fz_toname(type), "ObjStm"))
- {
- uselist[oid] = 0;
- fz_dropobj(obj);
- return;
- }
- if (fz_isname(type) && !strcmp(fz_toname(type), "XRef"))
+ fz_error error;
+ fz_obj *obj;
+ fz_obj *type;
+
+ error = pdf_loadobject(&obj, xref, oid, gen);
+ if (error)
+ die(error);
+
+ /* skip ObjStm and XRef objects */
+ if (fz_isdict(obj))
{
- uselist[oid] = 0;
- fz_dropobj(obj);
- return;
+ type = fz_dictgets(obj, "Type");
+ if (fz_isname(type) && !strcmp(fz_toname(type), "ObjStm"))
+ {
+ uselist[oid] = 0;
+ fz_dropobj(obj);
+ return;
+ }
+ if (fz_isname(type) && !strcmp(fz_toname(type), "XRef"))
+ {
+ uselist[oid] = 0;
+ fz_dropobj(obj);
+ return;
+ }
}
- }
- if (!xref->table[oid].stmofs)
- {
- fprintf(out, "%d %d obj\n", oid, gen);
- fz_fprintobj(out, obj, !doexpand);
- fprintf(out, "endobj\n\n");
- }
- else
- {
- if (doexpand)
- expandstream(obj, oid, gen);
+ if (!xref->table[oid].stmofs)
+ {
+ fprintf(out, "%d %d obj\n", oid, gen);
+ fz_fprintobj(out, obj, !doexpand);
+ fprintf(out, "endobj\n\n");
+ }
else
- copystream(obj, oid, gen);
- }
+ {
+ if (doexpand)
+ expandstream(obj, oid, gen);
+ else
+ copystream(obj, oid, gen);
+ }
- fz_dropobj(obj);
+ fz_dropobj(obj);
}
static void savexref(void)
{
- fz_obj *trailer;
- fz_obj *obj;
- int startxref;
- int oid;
+ fz_obj *trailer;
+ fz_obj *obj;
+ int startxref;
+ int oid;
- startxref = ftell(out);
+ startxref = ftell(out);
- fprintf(out, "xref\n0 %d\n", xref->len);
- for (oid = 0; oid < xref->len; oid++)
- {
- if (uselist[oid])
- fprintf(out, "%010d %05d n \n", ofslist[oid], genlist[oid]);
- else
- fprintf(out, "%010d %05d f \n", ofslist[oid], genlist[oid]);
- }
- fprintf(out, "\n");
+ fprintf(out, "xref\n0 %d\n", xref->len);
+ for (oid = 0; oid < xref->len; oid++)
+ {
+ if (uselist[oid])
+ fprintf(out, "%010d %05d n \n", ofslist[oid], genlist[oid]);
+ else
+ fprintf(out, "%010d %05d f \n", ofslist[oid], genlist[oid]);
+ }
+ fprintf(out, "\n");
- trailer = fz_newdict(5);
+ trailer = fz_newdict(5);
- obj = fz_newint(xref->len);
- fz_dictputs(trailer, "Size", obj);
- fz_dropobj(obj);
+ obj = fz_newint(xref->len);
+ fz_dictputs(trailer, "Size", obj);
+ fz_dropobj(obj);
- obj = fz_dictgets(xref->trailer, "Info");
- if (obj)
- fz_dictputs(trailer, "Info", obj);
+ obj = fz_dictgets(xref->trailer, "Info");
+ if (obj)
+ fz_dictputs(trailer, "Info", obj);
- obj = fz_dictgets(xref->trailer, "Root");
- if (obj)
- fz_dictputs(trailer, "Root", obj);
+ obj = fz_dictgets(xref->trailer, "Root");
+ if (obj)
+ fz_dictputs(trailer, "Root", obj);
- obj = fz_dictgets(xref->trailer, "ID");
- if (obj)
- fz_dictputs(trailer, "ID", obj);
+ obj = fz_dictgets(xref->trailer, "ID");
+ if (obj)
+ fz_dictputs(trailer, "ID", obj);
- fprintf(out, "trailer\n");
- fz_fprintobj(out, trailer, !doexpand);
- fprintf(out, "\n");
+ fprintf(out, "trailer\n");
+ fz_fprintobj(out, trailer, !doexpand);
+ fprintf(out, "\n");
- fprintf(out, "startxref\n%d\n%%%%EOF\n", startxref);
+ fprintf(out, "startxref\n%d\n%%%%EOF\n", startxref);
}
static void cleanusage(void)
{
- fprintf(stderr,
- "usage: pdfclean [options] input.pdf [outfile.pdf]\n"
- " -p -\tpassword for decryption\n"
- " -g \tgarbage collect unused objects\n"
- " -x \texpand compressed streams\n");
- exit(1);
+ fprintf(stderr,
+ "usage: pdfclean [options] input.pdf [outfile.pdf]\n"
+ " -p -\tpassword for decryption\n"
+ " -g \tgarbage collect unused objects\n"
+ " -x \texpand compressed streams\n");
+ exit(1);
}
int main(int argc, char **argv)
{
- char *infile;
- char *outfile = "out.pdf";
- char *password = "";
- fz_error error;
- int c, oid;
- int lastfree;
-
- while ((c = fz_getopt(argc, argv, "gxp:")) != -1)
- {
- switch (c)
+ char *infile;
+ char *outfile = "out.pdf";
+ char *password = "";
+ fz_error error;
+ int c, oid;
+ int lastfree;
+
+ while ((c = fz_getopt(argc, argv, "gxp:")) != -1)
{
- case 'p': password = fz_optarg; break;
- case 'g': dogarbage ++; break;
- case 'x': doexpand ++; break;
- default: cleanusage(); break;
+ switch (c)
+ {
+ case 'p': password = fz_optarg; break;
+ case 'g': dogarbage ++; break;
+ case 'x': doexpand ++; break;
+ default: cleanusage(); break;
+ }
}
- }
-
- if (argc - fz_optind < 1)
- cleanusage();
- infile = argv[fz_optind++];
- if (argc - fz_optind > 0)
- outfile = argv[fz_optind++];
+ if (argc - fz_optind < 1)
+ cleanusage();
- openxref(infile, password, 0);
+ infile = argv[fz_optind++];
+ if (argc - fz_optind > 0)
+ outfile = argv[fz_optind++];
- out = fopen(outfile, "wb");
- if (!out)
- die(fz_throw("cannot open output file '%s'", outfile));
+ openxref(infile, password, 0);
- fprintf(out, "%%PDF-%d.%d\n", xref->version / 10, xref->version % 10);
- fprintf(out, "%%\342\343\317\323\n\n");
+ out = fopen(outfile, "wb");
+ if (!out)
+ die(fz_throw("cannot open output file '%s'", outfile));
- uselist = malloc(sizeof (char) * (xref->len + 1));
- ofslist = malloc(sizeof (int) * (xref->len + 1));
- genlist = malloc(sizeof (int) * (xref->len + 1));
+ fprintf(out, "%%PDF-%d.%d\n", xref->version / 10, xref->version % 10);
+ fprintf(out, "%%\342\343\317\323\n\n");
- for (oid = 0; oid < xref->len; oid++)
- {
- uselist[oid] = 0;
- ofslist[oid] = 0;
- genlist[oid] = 0;
- }
+ uselist = malloc(sizeof (char) * (xref->len + 1));
+ ofslist = malloc(sizeof (int) * (xref->len + 1));
+ genlist = malloc(sizeof (int) * (xref->len + 1));
- /* Make sure any objects hidden in compressed streams have been loaded */
- preloadobjstms();
-
- /* Sweep & mark objects from the trailer */
- error = sweepobj(xref, xref->trailer);
- if (error)
- die(fz_rethrow(error, "cannot mark used objects"));
-
- for (oid = 0; oid < xref->len; oid++)
- {
- if (xref->table[oid].type == 'f')
- uselist[oid] = 0;
+ for (oid = 0; oid < xref->len; oid++)
+ {
+ uselist[oid] = 0;
+ ofslist[oid] = 0;
+ genlist[oid] = 0;
+ }
- if (xref->table[oid].type == 'f')
- genlist[oid] = xref->table[oid].gen;
- if (xref->table[oid].type == 'n')
- genlist[oid] = xref->table[oid].gen;
- if (xref->table[oid].type == 'o')
- genlist[oid] = 0;
+ /* Make sure any objects hidden in compressed streams have been loaded */
+ preloadobjstms();
- if (dogarbage && !uselist[oid])
- continue;
+ /* Sweep & mark objects from the trailer */
+ error = sweepobj(xref, xref->trailer);
+ if (error)
+ die(fz_rethrow(error, "cannot mark used objects"));
- if (xref->table[oid].type == 'n' || xref->table[oid].type == 'o')
+ for (oid = 0; oid < xref->len; oid++)
{
- ofslist[oid] = ftell(out);
- saveobject(oid, genlist[oid]);
+ if (xref->table[oid].type == 'f')
+ uselist[oid] = 0;
+
+ if (xref->table[oid].type == 'f')
+ genlist[oid] = xref->table[oid].gen;
+ if (xref->table[oid].type == 'n')
+ genlist[oid] = xref->table[oid].gen;
+ if (xref->table[oid].type == 'o')
+ genlist[oid] = 0;
+
+ if (dogarbage && !uselist[oid])
+ continue;
+
+ if (xref->table[oid].type == 'n' || xref->table[oid].type == 'o')
+ {
+ ofslist[oid] = ftell(out);
+ saveobject(oid, genlist[oid]);
+ }
}
- }
- /* construct linked list of free object slots */
- lastfree = 0;
- for (oid = 0; oid < xref->len; oid++)
- {
- if (!uselist[oid])
+ /* construct linked list of free object slots */
+ lastfree = 0;
+ for (oid = 0; oid < xref->len; oid++)
{
- genlist[oid]++;
- ofslist[lastfree] = oid;
- lastfree = oid;
+ if (!uselist[oid])
+ {
+ genlist[oid]++;
+ ofslist[lastfree] = oid;
+ lastfree = oid;
+ }
}
- }
- savexref();
+ savexref();
- closexref();
+ closexref();
}
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index 22122e73..f6fdd6bd 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -18,12 +18,12 @@ enum { DRAWPNM, DRAWTXT, DRAWXML };
struct benchmark
{
- int pages;
- long min;
- int minpage;
- long avg;
- long max;
- int maxpage;
+ int pages;
+ long min;
+ int minpage;
+ long avg;
+ long max;
+ int maxpage;
};
static fz_renderer *drawgc = nil;
@@ -39,392 +39,392 @@ static int benchmark = 0;
static void local_cleanup(void)
{
- if (xref && xref->store)
- {
- pdf_dropstore(xref->store);
- xref->store = nil;
- }
-
- if (drawgc)
- {
- fz_droprenderer(drawgc);
- drawgc = nil;
- }
+ if (xref && xref->store)
+ {
+ pdf_dropstore(xref->store);
+ xref->store = nil;
+ }
+
+ if (drawgc)
+ {
+ fz_droprenderer(drawgc);
+ drawgc = nil;
+ }
}
static void drawusage(void)
{
- fprintf(stderr,
- "usage: pdfdraw [options] [file.pdf pages ... ]\n"
- " -b -\tdraw page in N bands\n"
- " -d -\tpassword for decryption\n"
- " -o -\tpattern (%%d for page number) for output file\n"
- " -r -\tresolution in dpi\n"
- " -t \tutf-8 text output instead of graphics\n"
- " -x \txml dump of display tree\n"
- " -m \tprint benchmark results\n"
- " example:\n"
- " pdfdraw -o output%%03d.pnm input.pdf 1-3,5,9-\n");
- exit(1);
+ fprintf(stderr,
+ "usage: pdfdraw [options] [file.pdf pages ... ]\n"
+ " -b -\tdraw page in N bands\n"
+ " -d -\tpassword for decryption\n"
+ " -o -\tpattern (%%d for page number) for output file\n"
+ " -r -\tresolution in dpi\n"
+ " -t \tutf-8 text output instead of graphics\n"
+ " -x \txml dump of display tree\n"
+ " -m \tprint benchmark results\n"
+ " example:\n"
+ " pdfdraw -o output%%03d.pnm input.pdf 1-3,5,9-\n");
+ exit(1);
}
static void gettime(long *time_)
{
- struct timeval tv;
+ struct timeval tv;
- if (gettimeofday(&tv, NULL) < 0)
- abort();
+ if (gettimeofday(&tv, NULL) < 0)
+ abort();
- *time_ = tv.tv_sec * 1000000 + tv.tv_usec;
+ *time_ = tv.tv_sec * 1000000 + tv.tv_usec;
}
static void drawloadpage(int pagenum, struct benchmark *loadtimes)
{
- fz_error error;
- fz_obj *pageobj;
- long start;
- long end;
- long elapsed;
-
- fprintf(stderr, "draw %s:%03d ", basename, pagenum);
- if (benchmark && loadtimes)
- {
- fflush(stderr);
- gettime(&start);
- }
-
- pageobj = pdf_getpageobject(xref, pagenum);
- error = pdf_loadpage(&drawpage, xref, pageobj);
- if (error)
- die(error);
-
- if (benchmark && loadtimes)
- {
- gettime(&end);
- elapsed = end - start;
-
- if (elapsed < loadtimes->min)
+ fz_error error;
+ fz_obj *pageobj;
+ long start;
+ long end;
+ long elapsed;
+
+ fprintf(stderr, "draw %s:%03d ", basename, pagenum);
+ if (benchmark && loadtimes)
{
- loadtimes->min = elapsed;
- loadtimes->minpage = pagenum;
+ fflush(stderr);
+ gettime(&start);
}
- if (elapsed > loadtimes->max)
+
+ pageobj = pdf_getpageobject(xref, pagenum);
+ error = pdf_loadpage(&drawpage, xref, pageobj);
+ if (error)
+ die(error);
+
+ if (benchmark && loadtimes)
{
- loadtimes->max = elapsed;
- loadtimes->maxpage = pagenum;
+ gettime(&end);
+ elapsed = end - start;
+
+ if (elapsed < loadtimes->min)
+ {
+ loadtimes->min = elapsed;
+ loadtimes->minpage = pagenum;
+ }
+ if (elapsed > loadtimes->max)
+ {
+ loadtimes->max = elapsed;
+ loadtimes->maxpage = pagenum;
+ }
+ loadtimes->avg += elapsed;
+ loadtimes->pages++;
}
- loadtimes->avg += elapsed;
- loadtimes->pages++;
- }
- if (benchmark)
- fflush(stderr);
+ if (benchmark)
+ fflush(stderr);
}
static void drawfreepage(void)
{
- pdf_droppage(drawpage);
- drawpage = nil;
-
- /* Flush resources between pages.
- * TODO: should check memory usage before deciding to do this.
- */
- if (xref && xref->store)
- {
- /* pdf_debugstore(xref->store); */
- pdf_agestoreditems(xref->store);
- pdf_evictageditems(xref->store);
- fflush(stderr);
- }
+ pdf_droppage(drawpage);
+ drawpage = nil;
+
+ /* Flush resources between pages.
+ * TODO: should check memory usage before deciding to do this.
+ */
+ if (xref && xref->store)
+ {
+ /* pdf_debugstore(xref->store); */
+ pdf_agestoreditems(xref->store);
+ pdf_evictageditems(xref->store);
+ fflush(stderr);
+ }
}
static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *drawtimes)
{
- fz_error error;
- fz_matrix ctm;
- fz_irect bbox;
- fz_pixmap *pix;
- char name[256];
- char pnmhdr[256];
- int i, x, y, w, h, b, bh;
- int fd = -1;
- long start;
- long end;
- long elapsed;
-
- fz_md5 digest;
-
- fz_md5init(&digest);
-
- drawloadpage(pagenum, loadtimes);
-
- if (benchmark)
- gettime(&start);
-
- ctm = fz_identity();
- ctm = fz_concat(ctm, fz_translate(0, -drawpage->mediabox.y1));
- ctm = fz_concat(ctm, fz_scale(drawzoom, -drawzoom));
- ctm = fz_concat(ctm, fz_rotate(drawrotate + drawpage->rotate));
-
- bbox = fz_roundrect(fz_transformaabb(ctm, drawpage->mediabox));
- w = bbox.x1 - bbox.x0;
- h = bbox.y1 - bbox.y0;
- bh = h / drawbands;
-
- if (drawpattern)
- {
- sprintf(name, drawpattern, drawcount++);
- fd = open(name, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0666);
- if (fd < 0)
- die(fz_throw("ioerror: could not open file '%s'", name));
-
- sprintf(pnmhdr, "P6\n%d %d\n255\n", w, h);
- write(fd, pnmhdr, strlen(pnmhdr));
- }
-
- error = fz_newpixmap(&pix, bbox.x0, bbox.y0, w, bh, 4);
- if (error)
- die(error);
-
- memset(pix->samples, 0xff, pix->h * pix->w * pix->n);
-
- for (b = 0; b < drawbands; b++)
- {
- if (drawbands > 1)
- fprintf(stderr, "drawing band %d / %d\n", b + 1, drawbands);
-
- error = fz_rendertreeover(drawgc, pix, drawpage->tree, ctm);
- if (error)
- die(error);
+ fz_error error;
+ fz_matrix ctm;
+ fz_irect bbox;
+ fz_pixmap *pix;
+ char name[256];
+ char pnmhdr[256];
+ int i, x, y, w, h, b, bh;
+ int fd = -1;
+ long start;
+ long end;
+ long elapsed;
- if (drawpattern)
- {
- for (y = 0; y < pix->h; y++)
- {
- unsigned char *src = pix->samples + y * pix->w * 4;
- unsigned char *dst = src;
+ fz_md5 digest;
- for (x = 0; x < pix->w; x++)
- {
- dst[x * 3 + 0] = src[x * 4 + 1];
- dst[x * 3 + 1] = src[x * 4 + 2];
- dst[x * 3 + 2] = src[x * 4 + 3];
- }
+ fz_md5init(&digest);
+
+ drawloadpage(pagenum, loadtimes);
+
+ if (benchmark)
+ gettime(&start);
+
+ ctm = fz_identity();
+ ctm = fz_concat(ctm, fz_translate(0, -drawpage->mediabox.y1));
+ ctm = fz_concat(ctm, fz_scale(drawzoom, -drawzoom));
+ ctm = fz_concat(ctm, fz_rotate(drawrotate + drawpage->rotate));
- write(fd, dst, pix->w * 3);
+ bbox = fz_roundrect(fz_transformaabb(ctm, drawpage->mediabox));
+ w = bbox.x1 - bbox.x0;
+ h = bbox.y1 - bbox.y0;
+ bh = h / drawbands;
- memset(src, 0xff, pix->w * 4);
- }
+ if (drawpattern)
+ {
+ sprintf(name, drawpattern, drawcount++);
+ fd = open(name, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ if (fd < 0)
+ die(fz_throw("ioerror: could not open file '%s'", name));
+
+ sprintf(pnmhdr, "P6\n%d %d\n255\n", w, h);
+ write(fd, pnmhdr, strlen(pnmhdr));
}
- fz_md5update(&digest, pix->samples, pix->h * pix->w * 4);
+ error = fz_newpixmap(&pix, bbox.x0, bbox.y0, w, bh, 4);
+ if (error)
+ die(error);
- pix->y += bh;
- if (pix->y + pix->h > bbox.y1)
- pix->h = bbox.y1 - pix->y;
- }
+ memset(pix->samples, 0xff, pix->h * pix->w * pix->n);
- fz_droppixmap(pix);
+ for (b = 0; b < drawbands; b++)
+ {
+ if (drawbands > 1)
+ fprintf(stderr, "drawing band %d / %d\n", b + 1, drawbands);
- {
- unsigned char buf[16];
- fz_md5final(&digest, buf);
- for (i = 0; i < 16; i++)
- fprintf(stderr, "%02x", buf[i]);
- }
+ error = fz_rendertreeover(drawgc, pix, drawpage->tree, ctm);
+ if (error)
+ die(error);
- if (drawpattern)
- close(fd);
+ if (drawpattern)
+ {
+ for (y = 0; y < pix->h; y++)
+ {
+ unsigned char *src = pix->samples + y * pix->w * 4;
+ unsigned char *dst = src;
+
+ for (x = 0; x < pix->w; x++)
+ {
+ dst[x * 3 + 0] = src[x * 4 + 1];
+ dst[x * 3 + 1] = src[x * 4 + 2];
+ dst[x * 3 + 2] = src[x * 4 + 3];
+ }
+
+ write(fd, dst, pix->w * 3);
+
+ memset(src, 0xff, pix->w * 4);
+ }
+ }
- drawfreepage();
+ fz_md5update(&digest, pix->samples, pix->h * pix->w * 4);
+
+ pix->y += bh;
+ if (pix->y + pix->h > bbox.y1)
+ pix->h = bbox.y1 - pix->y;
+ }
- if (benchmark)
- {
- gettime(&end);
- elapsed = end - start;
+ fz_droppixmap(pix);
- if (elapsed < drawtimes->min)
{
- drawtimes->min = elapsed;
- drawtimes->minpage = pagenum;
+ unsigned char buf[16];
+ fz_md5final(&digest, buf);
+ for (i = 0; i < 16; i++)
+ fprintf(stderr, "%02x", buf[i]);
}
- if (elapsed > drawtimes->max)
+
+ if (drawpattern)
+ close(fd);
+
+ drawfreepage();
+
+ if (benchmark)
{
- drawtimes->max = elapsed;
- drawtimes->maxpage = pagenum;
- }
- drawtimes->avg += elapsed;
- drawtimes->pages++;
+ gettime(&end);
+ elapsed = end - start;
+
+ if (elapsed < drawtimes->min)
+ {
+ drawtimes->min = elapsed;
+ drawtimes->minpage = pagenum;
+ }
+ if (elapsed > drawtimes->max)
+ {
+ drawtimes->max = elapsed;
+ drawtimes->maxpage = pagenum;
+ }
+ drawtimes->avg += elapsed;
+ drawtimes->pages++;
- fprintf(stderr, " time %.3fs",
- elapsed / 1000000.0);
- }
+ fprintf(stderr, " time %.3fs",
+ elapsed / 1000000.0);
+ }
- fprintf(stderr, "\n");
+ fprintf(stderr, "\n");
}
static void drawtxt(int pagenum)
{
- fz_error error;
- pdf_textline *line;
- fz_matrix ctm;
+ fz_error error;
+ pdf_textline *line;
+ fz_matrix ctm;
- drawloadpage(pagenum, NULL);
+ drawloadpage(pagenum, NULL);
- ctm = fz_concat(
- fz_translate(0, -drawpage->mediabox.y1),
- fz_scale(drawzoom, -drawzoom));
+ ctm = fz_concat(
+ fz_translate(0, -drawpage->mediabox.y1),
+ fz_scale(drawzoom, -drawzoom));
- error = pdf_loadtextfromtree(&line, drawpage->tree, ctm);
- if (error)
- die(error);
+ error = pdf_loadtextfromtree(&line, drawpage->tree, ctm);
+ if (error)
+ die(error);
- pdf_debugtextline(line);
- pdf_droptextline(line);
+ pdf_debugtextline(line);
+ pdf_droptextline(line);
- drawfreepage();
+ drawfreepage();
}
static void drawxml(int pagenum)
{
- drawloadpage(pagenum, NULL);
- fz_debugtree(drawpage->tree);
- drawfreepage();
+ drawloadpage(pagenum, NULL);
+ fz_debugtree(drawpage->tree);
+ drawfreepage();
}
static void drawpages(char *pagelist)
{
- int page, spage, epage;
- char *spec, *dash;
- struct benchmark loadtimes, drawtimes;
-
- if (!xref)
- drawusage();
-
- if (benchmark)
- {
- memset(&loadtimes, 0x00, sizeof (loadtimes));
- loadtimes.min = LONG_MAX;
- memset(&drawtimes, 0x00, sizeof (drawtimes));
- drawtimes.min = LONG_MAX;
- }
-
- spec = strsep(&pagelist, ",");
- while (spec)
- {
- dash = strchr(spec, '-');
-
- if (dash == spec)
- spage = epage = 1;
- else
- spage = epage = atoi(spec);
-
- if (dash)
- {
- if (strlen(dash) > 1)
- epage = atoi(dash + 1);
- else
- epage = pagecount;
- }
-
- if (spage > epage)
- page = spage, spage = epage, epage = page;
+ int page, spage, epage;
+ char *spec, *dash;
+ struct benchmark loadtimes, drawtimes;
- if (spage < 1)
- spage = 1;
- if (epage > pagecount)
- epage = pagecount;
+ if (!xref)
+ drawusage();
- printf("Drawing pages %d-%d...\n", spage, epage);
- for (page = spage; page <= epage; page++)
+ if (benchmark)
{
- switch (drawmode)
- {
- case DRAWPNM: drawpnm(page, &loadtimes, &drawtimes); break;
- case DRAWTXT: drawtxt(page); break;
- case DRAWXML: drawxml(page); break;
- }
+ memset(&loadtimes, 0x00, sizeof (loadtimes));
+ loadtimes.min = LONG_MAX;
+ memset(&drawtimes, 0x00, sizeof (drawtimes));
+ drawtimes.min = LONG_MAX;
}
spec = strsep(&pagelist, ",");
- }
+ while (spec)
+ {
+ dash = strchr(spec, '-');
+
+ if (dash == spec)
+ spage = epage = 1;
+ else
+ spage = epage = atoi(spec);
+
+ if (dash)
+ {
+ if (strlen(dash) > 1)
+ epage = atoi(dash + 1);
+ else
+ epage = pagecount;
+ }
+
+ if (spage > epage)
+ page = spage, spage = epage, epage = page;
+
+ if (spage < 1)
+ spage = 1;
+ if (epage > pagecount)
+ epage = pagecount;
- if (benchmark)
- {
- if (loadtimes.pages > 0)
+ printf("Drawing pages %d-%d...\n", spage, epage);
+ for (page = spage; page <= epage; page++)
+ {
+ switch (drawmode)
+ {
+ case DRAWPNM: drawpnm(page, &loadtimes, &drawtimes); break;
+ case DRAWTXT: drawtxt(page); break;
+ case DRAWXML: drawxml(page); break;
+ }
+ }
+
+ spec = strsep(&pagelist, ",");
+ }
+
+ if (benchmark)
{
- loadtimes.avg /= loadtimes.pages;
- drawtimes.avg /= drawtimes.pages;
-
- printf("benchmark[load]: min: %6.3fs (page % 4d), avg: %6.3fs, max: %6.3fs (page % 4d)\n",
- loadtimes.min / 1000000.0, loadtimes.minpage,
- loadtimes.avg / 1000000.0,
- loadtimes.max / 1000000.0, loadtimes.maxpage);
- printf("benchmark[draw]: min: %6.3fs (page % 4d), avg: %6.3fs, max: %6.3fs (page % 4d)\n",
- drawtimes.min / 1000000.0, drawtimes.minpage,
- drawtimes.avg / 1000000.0,
- drawtimes.max / 1000000.0, drawtimes.maxpage);
+ if (loadtimes.pages > 0)
+ {
+ loadtimes.avg /= loadtimes.pages;
+ drawtimes.avg /= drawtimes.pages;
+
+ printf("benchmark[load]: min: %6.3fs (page % 4d), avg: %6.3fs, max: %6.3fs (page % 4d)\n",
+ loadtimes.min / 1000000.0, loadtimes.minpage,
+ loadtimes.avg / 1000000.0,
+ loadtimes.max / 1000000.0, loadtimes.maxpage);
+ printf("benchmark[draw]: min: %6.3fs (page % 4d), avg: %6.3fs, max: %6.3fs (page % 4d)\n",
+ drawtimes.min / 1000000.0, drawtimes.minpage,
+ drawtimes.avg / 1000000.0,
+ drawtimes.max / 1000000.0, drawtimes.maxpage);
+ }
}
- }
}
int main(int argc, char **argv)
{
- fz_error error;
- char *password = "";
- int c;
- enum { NO_FILE_OPENED, NO_PAGES_DRAWN, DREW_PAGES } state;
-
- while ((c = fz_getopt(argc, argv, "b:d:o:r:txm")) != -1)
- {
- switch (c)
+ fz_error error;
+ char *password = "";
+ int c;
+ enum { NO_FILE_OPENED, NO_PAGES_DRAWN, DREW_PAGES } state;
+
+ while ((c = fz_getopt(argc, argv, "b:d:o:r:txm")) != -1)
{
- case 'b': drawbands = atoi(fz_optarg); break;
- case 'd': password = fz_optarg; break;
- case 'o': drawpattern = fz_optarg; break;
- case 'r': drawzoom = atof(fz_optarg) / 72.0; break;
- case 't': drawmode = DRAWTXT; break;
- case 'x': drawmode = DRAWXML; break;
- case 'm': benchmark = 1; break;
- default:
- drawusage();
- break;
+ switch (c)
+ {
+ case 'b': drawbands = atoi(fz_optarg); break;
+ case 'd': password = fz_optarg; break;
+ case 'o': drawpattern = fz_optarg; break;
+ case 'r': drawzoom = atof(fz_optarg) / 72.0; break;
+ case 't': drawmode = DRAWTXT; break;
+ case 'x': drawmode = DRAWXML; break;
+ case 'm': benchmark = 1; break;
+ default:
+ drawusage();
+ break;
+ }
}
- }
- if (fz_optind == argc)
- drawusage();
+ if (fz_optind == argc)
+ drawusage();
- setcleanup(local_cleanup);
+ setcleanup(local_cleanup);
- state = NO_FILE_OPENED;
- while (fz_optind < argc)
- {
- if (strstr(argv[fz_optind], ".pdf") || strstr(argv[fz_optind], ".PDF"))
+ state = NO_FILE_OPENED;
+ while (fz_optind < argc)
{
- if (state == NO_PAGES_DRAWN)
- drawpages("1-");
+ if (strstr(argv[fz_optind], ".pdf") || strstr(argv[fz_optind], ".PDF"))
+ {
+ if (state == NO_PAGES_DRAWN)
+ drawpages("1-");
- closexref();
+ closexref();
- error = fz_newrenderer(&drawgc, pdf_devicergb, 0, 1024 * 512);
- if (error)
- die(error);
+ error = fz_newrenderer(&drawgc, pdf_devicergb, 0, 1024 * 512);
+ if (error)
+ die(error);
- openxref(argv[fz_optind], password, 0);
- state = NO_PAGES_DRAWN;
- }
- else
- {
- drawpages(argv[fz_optind]);
- state = DREW_PAGES;
+ openxref(argv[fz_optind], password, 0);
+ state = NO_PAGES_DRAWN;
+ }
+ else
+ {
+ drawpages(argv[fz_optind]);
+ state = DREW_PAGES;
+ }
+ fz_optind++;
}
- fz_optind++;
- }
- if (state == NO_PAGES_DRAWN)
- drawpages("1-");
+ if (state == NO_PAGES_DRAWN)
+ drawpages("1-");
- closexref();
+ closexref();
}
diff --git a/apps/pdfextract.c b/apps/pdfextract.c
index 35833c0e..dfd20035 100644
--- a/apps/pdfextract.c
+++ b/apps/pdfextract.c
@@ -6,252 +6,252 @@
static void showusage(void)
{
- fprintf(stderr, "usage: pdfextract [-d password] <file> [object numbers]\n");
- fprintf(stderr, " -d \tdecrypt password\n");
- exit(1);
+ fprintf(stderr, "usage: pdfextract [-d password] <file> [object numbers]\n");
+ fprintf(stderr, " -d \tdecrypt password\n");
+ exit(1);
}
static int isimage(fz_obj *obj)
{
- fz_obj *type = fz_dictgets(obj, "Subtype");
- return fz_isname(type) && !strcmp(fz_toname(type), "Image");
+ fz_obj *type = fz_dictgets(obj, "Subtype");
+ return fz_isname(type) && !strcmp(fz_toname(type), "Image");
}
static int isfontdesc(fz_obj *obj)
{
- fz_obj *type = fz_dictgets(obj, "Type");
- return fz_isname(type) && !strcmp(fz_toname(type), "FontDescriptor");
+ fz_obj *type = fz_dictgets(obj, "Type");
+ return fz_isname(type) && !strcmp(fz_toname(type), "FontDescriptor");
}
static void saveimage(fz_obj *obj, int num, int gen)
{
- pdf_image *img = nil;
- fz_obj *ref;
- fz_error error;
- fz_pixmap *pix;
- char name[1024];
- FILE *f;
- int bpc;
- int w;
- int h;
- int n;
- int x;
- int y;
-
- ref = fz_newindirect(num, gen, xref);
-
- xref->store = pdf_newstore();
-
- error = pdf_loadimage(&img, xref, ref);
- if (error)
- die(error);
-
- n = img->super.n;
- w = img->super.w;
- h = img->super.h;
- bpc = img->bpc;
-
- error = fz_newpixmap(&pix, 0, 0, w, h, n + 1);
- if (error)
- die(error);
-
- error = img->super.loadtile(&img->super, pix);
- if (error)
- die(error);
-
- if (bpc == 1 && n == 0)
- {
- fz_pixmap *temp;
-
- error = fz_newpixmap(&temp, pix->x, pix->y, pix->w, pix->h, pdf_devicergb->n + 1);
- if (error)
- die(error);
-
- for (y = 0; y < pix->h; y++)
- for (x = 0; x < pix->w; x++)
- {
- int pixel = y * pix->w + x;
- temp->samples[pixel * temp->n + 0] = 255;
- temp->samples[pixel * temp->n + 1] = pix->samples[pixel];
- temp->samples[pixel * temp->n + 2] = pix->samples[pixel];
- temp->samples[pixel * temp->n + 3] = pix->samples[pixel];
- }
-
- fz_droppixmap(pix);
- pix = temp;
- }
-
- if (img->super.cs && strcmp(img->super.cs->name, "DeviceRGB"))
- {
- fz_pixmap *temp;
-
- error = fz_newpixmap(&temp, pix->x, pix->y, pix->w, pix->h, pdf_devicergb->n + 1);
- if (error)
- die(error);
-
- fz_convertpixmap(img->super.cs, pix, pdf_devicergb, temp);
- fz_droppixmap(pix);
- pix = temp;
- }
-
- sprintf(name, "img-%04d.pnm", num);
-
- f = fopen(name, "wb");
- if (f == NULL)
- die(fz_throw("Error creating image file"));
-
- fprintf(f, "P6\n%d %d\n%d\n", w, h, 255);
-
- for (y = 0; y < pix->h; y++)
- for (x = 0; x < pix->w; x++)
- {
- fz_sample *sample = &pix->samples[(y * pix->w + x) * (pdf_devicergb->n + 1)];
- unsigned char r = sample[1];
- unsigned char g = sample[2];
- unsigned char b = sample[3];
- fprintf(f, "%c%c%c", r, g, b);
- }
-
- if (fclose(f) < 0)
- die(fz_throw("Error closing image file"));
-
- fz_droppixmap(pix);
-
- pdf_dropstore(xref->store);
- xref->store = nil;
-
- fz_dropimage(&img->super);
-
- fz_dropobj(ref);
+ pdf_image *img = nil;
+ fz_obj *ref;
+ fz_error error;
+ fz_pixmap *pix;
+ char name[1024];
+ FILE *f;
+ int bpc;
+ int w;
+ int h;
+ int n;
+ int x;
+ int y;
+
+ ref = fz_newindirect(num, gen, xref);
+
+ xref->store = pdf_newstore();
+
+ error = pdf_loadimage(&img, xref, ref);
+ if (error)
+ die(error);
+
+ n = img->super.n;
+ w = img->super.w;
+ h = img->super.h;
+ bpc = img->bpc;
+
+ error = fz_newpixmap(&pix, 0, 0, w, h, n + 1);
+ if (error)
+ die(error);
+
+ error = img->super.loadtile(&img->super, pix);
+ if (error)
+ die(error);
+
+ if (bpc == 1 && n == 0)
+ {
+ fz_pixmap *temp;
+
+ error = fz_newpixmap(&temp, pix->x, pix->y, pix->w, pix->h, pdf_devicergb->n + 1);
+ if (error)
+ die(error);
+
+ for (y = 0; y < pix->h; y++)
+ for (x = 0; x < pix->w; x++)
+ {
+ int pixel = y * pix->w + x;
+ temp->samples[pixel * temp->n + 0] = 255;
+ temp->samples[pixel * temp->n + 1] = pix->samples[pixel];
+ temp->samples[pixel * temp->n + 2] = pix->samples[pixel];
+ temp->samples[pixel * temp->n + 3] = pix->samples[pixel];
+ }
+
+ fz_droppixmap(pix);
+ pix = temp;
+ }
+
+ if (img->super.cs && strcmp(img->super.cs->name, "DeviceRGB"))
+ {
+ fz_pixmap *temp;
+
+ error = fz_newpixmap(&temp, pix->x, pix->y, pix->w, pix->h, pdf_devicergb->n + 1);
+ if (error)
+ die(error);
+
+ fz_convertpixmap(img->super.cs, pix, pdf_devicergb, temp);
+ fz_droppixmap(pix);
+ pix = temp;
+ }
+
+ sprintf(name, "img-%04d.pnm", num);
+
+ f = fopen(name, "wb");
+ if (f == NULL)
+ die(fz_throw("Error creating image file"));
+
+ fprintf(f, "P6\n%d %d\n%d\n", w, h, 255);
+
+ for (y = 0; y < pix->h; y++)
+ for (x = 0; x < pix->w; x++)
+ {
+ fz_sample *sample = &pix->samples[(y * pix->w + x) * (pdf_devicergb->n + 1)];
+ unsigned char r = sample[1];
+ unsigned char g = sample[2];
+ unsigned char b = sample[3];
+ fprintf(f, "%c%c%c", r, g, b);
+ }
+
+ if (fclose(f) < 0)
+ die(fz_throw("Error closing image file"));
+
+ fz_droppixmap(pix);
+
+ pdf_dropstore(xref->store);
+ xref->store = nil;
+
+ fz_dropimage(&img->super);
+
+ fz_dropobj(ref);
}
static void savefont(fz_obj *dict, int num, int gen)
{
- fz_error error;
- char name[1024];
- char *subtype;
- fz_buffer *buf;
- fz_obj *stream = nil;
- fz_obj *obj;
- char *ext = "";
- FILE *f;
- unsigned char *p;
- char *fontname = "font";
-
- obj = fz_dictgets(dict, "FontName");
- if (obj)
- fontname = fz_toname(obj);
-
- obj = fz_dictgets(dict, "FontFile");
- if (obj)
- {
- stream = obj;
- ext = "pfa";
- }
-
- obj = fz_dictgets(dict, "FontFile2");
- if (obj)
- {
- stream = obj;
- ext = "ttf";
- }
-
- obj = fz_dictgets(dict, "FontFile3");
- if (obj)
- {
- stream = obj;
-
- obj = fz_dictgets(obj, "Subtype");
- if (obj && !fz_isname(obj))
- die(fz_throw("Invalid font descriptor subtype"));
-
- subtype = fz_toname(obj);
- if (!strcmp(subtype, "Type1C"))
- ext = "cff";
- else if (!strcmp(subtype, "CIDFontType0C"))
- ext = "cid";
- else
- die(fz_throw("Unhandled font type '%s'", subtype));
- }
-
- if (!stream)
- {
- fz_warn("Unhandled font type");
- return;
- }
-
- buf = fz_newbuffer(0);
-
- error = pdf_loadstream(&buf, xref, fz_tonum(stream), fz_togen(stream));
- if (error)
- die(error);
-
- sprintf(name, "%s-%04d.%s", fontname, num, ext);
-
- f = fopen(name, "wb");
- if (f == NULL)
- die(fz_throw("Error creating image file"));
-
- for (p = buf->rp; p < buf->wp; p ++)
- fprintf(f, "%c", *p);
-
- if (fclose(f) < 0)
- die(fz_throw("Error closing image file"));
-
- fz_dropbuffer(buf);
+ fz_error error;
+ char name[1024];
+ char *subtype;
+ fz_buffer *buf;
+ fz_obj *stream = nil;
+ fz_obj *obj;
+ char *ext = "";
+ FILE *f;
+ unsigned char *p;
+ char *fontname = "font";
+
+ obj = fz_dictgets(dict, "FontName");
+ if (obj)
+ fontname = fz_toname(obj);
+
+ obj = fz_dictgets(dict, "FontFile");
+ if (obj)
+ {
+ stream = obj;
+ ext = "pfa";
+ }
+
+ obj = fz_dictgets(dict, "FontFile2");
+ if (obj)
+ {
+ stream = obj;
+ ext = "ttf";
+ }
+
+ obj = fz_dictgets(dict, "FontFile3");
+ if (obj)
+ {
+ stream = obj;
+
+ obj = fz_dictgets(obj, "Subtype");
+ if (obj && !fz_isname(obj))
+ die(fz_throw("Invalid font descriptor subtype"));
+
+ subtype = fz_toname(obj);
+ if (!strcmp(subtype, "Type1C"))
+ ext = "cff";
+ else if (!strcmp(subtype, "CIDFontType0C"))
+ ext = "cid";
+ else
+ die(fz_throw("Unhandled font type '%s'", subtype));
+ }
+
+ if (!stream)
+ {
+ fz_warn("Unhandled font type");
+ return;
+ }
+
+ buf = fz_newbuffer(0);
+
+ error = pdf_loadstream(&buf, xref, fz_tonum(stream), fz_togen(stream));
+ if (error)
+ die(error);
+
+ sprintf(name, "%s-%04d.%s", fontname, num, ext);
+
+ f = fopen(name, "wb");
+ if (f == NULL)
+ die(fz_throw("Error creating image file"));
+
+ for (p = buf->rp; p < buf->wp; p ++)
+ fprintf(f, "%c", *p);
+
+ if (fclose(f) < 0)
+ die(fz_throw("Error closing image file"));
+
+ fz_dropbuffer(buf);
}
static void showobject(int num, int gen)
{
- fz_error error;
- fz_obj *obj;
+ fz_error error;
+ fz_obj *obj;
- if (!xref)
- die(fz_throw("no file specified"));
+ if (!xref)
+ die(fz_throw("no file specified"));
- error = pdf_loadobject(&obj, xref, num, gen);
- if (error)
- die(error);
+ error = pdf_loadobject(&obj, xref, num, gen);
+ if (error)
+ die(error);
- if (isimage(obj))
- saveimage(obj, num, gen);
- else if (isfontdesc(obj))
- savefont(obj, num, gen);
+ if (isimage(obj))
+ saveimage(obj, num, gen);
+ else if (isfontdesc(obj))
+ savefont(obj, num, gen);
- fz_dropobj(obj);
+ fz_dropobj(obj);
}
int main(int argc, char **argv)
{
- char *password = "";
- int c, o;
+ char *password = "";
+ int c, o;
- while ((c = fz_getopt(argc, argv, "d:")) != -1)
- {
- switch (c)
+ while ((c = fz_getopt(argc, argv, "d:")) != -1)
{
- case 'd': password = fz_optarg; break;
- default:
- showusage();
- break;
+ switch (c)
+ {
+ case 'd': password = fz_optarg; break;
+ default:
+ showusage();
+ break;
+ }
}
- }
- if (fz_optind == argc)
- showusage();
+ if (fz_optind == argc)
+ showusage();
- openxref(argv[fz_optind++], password, 0);
+ openxref(argv[fz_optind++], password, 0);
- if (fz_optind == argc)
- for (o = 0; o < xref->len; o++)
- showobject(o, 0);
- else
- while (fz_optind < argc)
- {
- showobject(atoi(argv[fz_optind]), 0);
- fz_optind++;
- }
+ if (fz_optind == argc)
+ for (o = 0; o < xref->len; o++)
+ showobject(o, 0);
+ else
+ while (fz_optind < argc)
+ {
+ showobject(atoi(argv[fz_optind]), 0);
+ fz_optind++;
+ }
- closexref();
+ closexref();
}
diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c
index 5c9bd927..b2938027 100644
--- a/apps/pdfinfo.c
+++ b/apps/pdfinfo.c
@@ -152,16 +152,16 @@ static void
infousage(void)
{
fprintf(stderr,
- "usage: pdfinfo [options] [file.pdf ... ]\n"
- " -d -\tpassword for decryption\n"
- " -f -\tlist fonts\n"
- " -i -\tlist images\n"
- " -m -\tlist dimensions\n"
- " -p -\tlist patterns\n"
- " -s -\tlist shadings\n"
- " -x -\tlist form and postscript xobjects\n"
- " example:\n"
- " pdfinfo -p mypassword a.pdf\n");
+ "usage: pdfinfo [options] [file.pdf ... ]\n"
+ " -d -\tpassword for decryption\n"
+ " -f -\tlist fonts\n"
+ " -i -\tlist images\n"
+ " -m -\tlist dimensions\n"
+ " -p -\tlist patterns\n"
+ " -s -\tlist shadings\n"
+ " -x -\tlist form and postscript xobjects\n"
+ " example:\n"
+ " pdfinfo -p mypassword a.pdf\n");
exit(1);
}
@@ -566,7 +566,7 @@ gathershadings(int page, fz_obj *pageobj, fz_obj *dict)
for (k = 0; k < shadings; k++)
if (fz_tonum(shading[k]->ref) == fz_tonum(ref) &&
- fz_togen(shading[k]->ref) == fz_togen(ref))
+ fz_togen(shading[k]->ref) == fz_togen(ref))
break;
if (k < shadings)
@@ -635,7 +635,7 @@ gatherpatterns(int page, fz_obj *pageobj, fz_obj *dict)
for (k = 0; k < patterns; k++)
if (fz_tonum(pattern[k]->ref) == fz_tonum(ref) &&
- fz_togen(pattern[k]->ref) == fz_togen(ref))
+ fz_togen(pattern[k]->ref) == fz_togen(ref))
break;
if (k < patterns)
@@ -772,12 +772,12 @@ printinfo(char *filename, int show, int page)
printf("\n");
for (i = 0; i < dims; i++)
printf(PAGE_FMT "[ %g %g %g %g ]\n",
- dim[i]->page,
- fz_tonum(dim[i]->pageobj), fz_togen(dim[i]->pageobj),
- dim[i]->u.dim.bbox->x0,
- dim[i]->u.dim.bbox->y0,
- dim[i]->u.dim.bbox->x1,
- dim[i]->u.dim.bbox->y1);
+ dim[i]->page,
+ fz_tonum(dim[i]->pageobj), fz_togen(dim[i]->pageobj),
+ dim[i]->u.dim.bbox->x0,
+ dim[i]->u.dim.bbox->y0,
+ dim[i]->u.dim.bbox->x1,
+ dim[i]->u.dim.bbox->y1);
printf("\n");
for (i = 0; i < dims; i++)
@@ -796,11 +796,11 @@ printinfo(char *filename, int show, int page)
for (i = 0; i < fonts; i++)
{
printf(PAGE_FMT "%s '%s' (%d %d R)\n",
- font[i]->page,
- fz_tonum(font[i]->pageobj), fz_togen(font[i]->pageobj),
- fz_toname(font[i]->u.font.subtype),
- fz_toname(font[i]->u.font.name),
- fz_tonum(font[i]->ref), fz_togen(font[i]->ref));
+ font[i]->page,
+ fz_tonum(font[i]->pageobj), fz_togen(font[i]->pageobj),
+ fz_toname(font[i]->u.font.subtype),
+ fz_toname(font[i]->u.font.name),
+ fz_tonum(font[i]->ref), fz_togen(font[i]->ref));
}
printf("\n");
@@ -817,29 +817,29 @@ printinfo(char *filename, int show, int page)
for (i = 0; i < images; i++)
{
printf(PAGE_FMT "[ ",
- image[i]->page,
- fz_tonum(image[i]->pageobj), fz_togen(image[i]->pageobj));
+ image[i]->page,
+ fz_tonum(image[i]->pageobj), fz_togen(image[i]->pageobj));
if (fz_isarray(image[i]->u.image.filter))
for (j = 0; j < fz_arraylen(image[i]->u.image.filter); j++)
- {
- printf("%s%s",
- fz_toname(fz_arrayget(image[i]->u.image.filter, j)),
- j == fz_arraylen(image[i]->u.image.filter) - 1 ? "" : " ");
- }
+ {
+ printf("%s%s",
+ fz_toname(fz_arrayget(image[i]->u.image.filter, j)),
+ j == fz_arraylen(image[i]->u.image.filter) - 1 ? "" : " ");
+ }
else if (image[i]->u.image.filter)
printf("%s", fz_toname(image[i]->u.image.filter));
else
printf("Raw");
printf(" ] %dx%d %dbpc %s%s%s (%d %d R)\n",
- fz_toint(image[i]->u.image.width),
- fz_toint(image[i]->u.image.height),
- image[i]->u.image.bpc ? fz_toint(image[i]->u.image.bpc) : 1,
- image[i]->u.image.cs ? fz_toname(image[i]->u.image.cs) : "ImageMask",
- image[i]->u.image.altcs ? " " : "",
- image[i]->u.image.altcs ? fz_toname(image[i]->u.image.altcs) : "",
- fz_tonum(image[i]->ref), fz_togen(image[i]->ref));
+ fz_toint(image[i]->u.image.width),
+ fz_toint(image[i]->u.image.height),
+ image[i]->u.image.bpc ? fz_toint(image[i]->u.image.bpc) : 1,
+ image[i]->u.image.cs ? fz_toname(image[i]->u.image.cs) : "ImageMask",
+ image[i]->u.image.altcs ? " " : "",
+ image[i]->u.image.altcs ? fz_toname(image[i]->u.image.altcs) : "",
+ fz_tonum(image[i]->ref), fz_togen(image[i]->ref));
}
printf("\n");
@@ -868,10 +868,10 @@ printinfo(char *filename, int show, int page)
};
printf(PAGE_FMT "%s (%d %d R)\n",
- shading[i]->page,
- fz_tonum(shading[i]->pageobj), fz_togen(shading[i]->pageobj),
- shadingtype[fz_toint(shading[i]->u.shading.type)],
- fz_tonum(shading[i]->ref), fz_togen(shading[i]->ref));
+ shading[i]->page,
+ fz_tonum(shading[i]->pageobj), fz_togen(shading[i]->pageobj),
+ shadingtype[fz_toint(shading[i]->u.shading.type)],
+ fz_tonum(shading[i]->ref), fz_togen(shading[i]->ref));
}
printf("\n");
@@ -908,12 +908,12 @@ printinfo(char *filename, int show, int page)
};
printf(PAGE_FMT "%s %s %s (%d %d R)\n",
- pattern[i]->page,
- fz_tonum(pattern[i]->pageobj), fz_togen(pattern[i]->pageobj),
- patterntype[fz_toint(pattern[i]->u.pattern.pattern)],
- painttype[fz_toint(pattern[i]->u.pattern.paint)],
- tilingtype[fz_toint(pattern[i]->u.pattern.tiling)],
- fz_tonum(pattern[i]->ref), fz_togen(pattern[i]->ref));
+ pattern[i]->page,
+ fz_tonum(pattern[i]->pageobj), fz_togen(pattern[i]->pageobj),
+ patterntype[fz_toint(pattern[i]->u.pattern.pattern)],
+ painttype[fz_toint(pattern[i]->u.pattern.paint)],
+ tilingtype[fz_toint(pattern[i]->u.pattern.tiling)],
+ fz_tonum(pattern[i]->ref), fz_togen(pattern[i]->ref));
}
printf("\n");
@@ -930,11 +930,11 @@ printinfo(char *filename, int show, int page)
for (i = 0; i < forms; i++)
{
printf(PAGE_FMT "%s%s (%d %d R)\n",
- form[i]->page,
- fz_tonum(form[i]->pageobj), fz_togen(form[i]->pageobj),
- form[i]->u.form.group ? "Group" : "",
- form[i]->u.form.reference ? "Reference" : "",
- fz_tonum(form[i]->ref), fz_togen(form[i]->ref));
+ form[i]->page,
+ fz_tonum(form[i]->pageobj), fz_togen(form[i]->pageobj),
+ form[i]->u.form.group ? "Group" : "",
+ form[i]->u.form.reference ? "Reference" : "",
+ fz_tonum(form[i]->ref), fz_togen(form[i]->ref));
}
printf("\n");
@@ -951,9 +951,9 @@ printinfo(char *filename, int show, int page)
for (i = 0; i < psobjs; i++)
{
printf(PAGE_FMT "(%d %d R)\n",
- psobj[i]->page,
- fz_tonum(psobj[i]->pageobj), fz_togen(psobj[i]->pageobj),
- fz_tonum(psobj[i]->ref), fz_togen(psobj[i]->ref));
+ psobj[i]->page,
+ fz_tonum(psobj[i]->pageobj), fz_togen(psobj[i]->pageobj),
+ fz_tonum(psobj[i]->ref), fz_togen(psobj[i]->ref));
}
printf("\n");
@@ -1040,16 +1040,16 @@ int main(int argc, char **argv)
{
switch (c)
{
- case 'm': if (show == ALL) show = DIMENSIONS; else show |= DIMENSIONS; break;
- case 'f': if (show == ALL) show = FONTS; else show |= FONTS; break;
- case 'i': if (show == ALL) show = IMAGES; else show |= IMAGES; break;
- case 's': if (show == ALL) show = SHADINGS; else show |= SHADINGS; break;
- case 'p': if (show == ALL) show = PATTERNS; else show |= PATTERNS; break;
- case 'x': if (show == ALL) show = XOBJS; else show |= XOBJS; break;
- case 'd': password = fz_optarg; break;
- default:
- infousage();
- break;
+ case 'm': if (show == ALL) show = DIMENSIONS; else show |= DIMENSIONS; break;
+ case 'f': if (show == ALL) show = FONTS; else show |= FONTS; break;
+ case 'i': if (show == ALL) show = IMAGES; else show |= IMAGES; break;
+ case 's': if (show == ALL) show = SHADINGS; else show |= SHADINGS; break;
+ case 'p': if (show == ALL) show = PATTERNS; else show |= PATTERNS; break;
+ case 'x': if (show == ALL) show = XOBJS; else show |= XOBJS; break;
+ case 'd': password = fz_optarg; break;
+ default:
+ infousage();
+ break;
}
}
diff --git a/apps/pdfshow.c b/apps/pdfshow.c
index 19fab461..9ada637f 100644
--- a/apps/pdfshow.c
+++ b/apps/pdfshow.c
@@ -10,153 +10,153 @@ static int showcolumn;
static void showusage(void)
{
- fprintf(stderr, "usage: pdfshow [-bx] [-d password] <file> [xref] [trailer] [object numbers]\n");
- fprintf(stderr, " -b \tprint streams as raw binary data\n");
- fprintf(stderr, " -x \tdecompress streams\n");
- fprintf(stderr, " -d \tdecrypt password\n");
- exit(1);
+ fprintf(stderr, "usage: pdfshow [-bx] [-d password] <file> [xref] [trailer] [object numbers]\n");
+ fprintf(stderr, " -b \tprint streams as raw binary data\n");
+ fprintf(stderr, " -x \tdecompress streams\n");
+ fprintf(stderr, " -d \tdecrypt password\n");
+ exit(1);
}
static void showtrailer(void)
{
- if (!xref)
- die(fz_throw("no file specified"));
- printf("trailer\n");
- fz_debugobj(xref->trailer);
- printf("\n");
+ if (!xref)
+ die(fz_throw("no file specified"));
+ printf("trailer\n");
+ fz_debugobj(xref->trailer);
+ printf("\n");
}
static void showxref(void)
{
- if (!xref)
- die(fz_throw("no file specified"));
- pdf_debugxref(xref);
- printf("\n");
+ if (!xref)
+ die(fz_throw("no file specified"));
+ pdf_debugxref(xref);
+ printf("\n");
}
static void showsafe(unsigned char *buf, int n)
{
- int i;
- for (i = 0; i < n; i++) {
- if (buf[i] == '\r' || buf[i] == '\n') {
- putchar('\n');
- showcolumn = 0;
+ int i;
+ for (i = 0; i < n; i++) {
+ if (buf[i] == '\r' || buf[i] == '\n') {
+ putchar('\n');
+ showcolumn = 0;
+ }
+ else if (buf[i] < 32 || buf[i] > 126) {
+ putchar('.');
+ showcolumn ++;
+ }
+ else {
+ putchar(buf[i]);
+ showcolumn ++;
+ }
+ if (showcolumn == 79) {
+ putchar('\n');
+ showcolumn = 0;
+ }
}
- else if (buf[i] < 32 || buf[i] > 126) {
- putchar('.');
- showcolumn ++;
- }
- else {
- putchar(buf[i]);
- showcolumn ++;
- }
- if (showcolumn == 79) {
- putchar('\n');
- showcolumn = 0;
- }
- }
}
static void showstream(int num, int gen)
{
- fz_error error;
- fz_stream *stm;
- unsigned char buf[2048];
- int n;
-
- showcolumn = 0;
-
- if (showdecode)
- error = pdf_openstream(&stm, xref, num, gen);
- else
- error = pdf_openrawstream(&stm, xref, num, gen);
- if (error)
- die(error);
-
- while (1)
- {
- error = fz_read(&n, stm, buf, sizeof buf);
- if (error)
- die(error);
- if (n == 0)
- break;
- if (showbinary)
- fwrite(buf, 1, n, stdout);
+ fz_error error;
+ fz_stream *stm;
+ unsigned char buf[2048];
+ int n;
+
+ showcolumn = 0;
+
+ if (showdecode)
+ error = pdf_openstream(&stm, xref, num, gen);
else
- showsafe(buf, n);
- }
+ error = pdf_openrawstream(&stm, xref, num, gen);
+ if (error)
+ die(error);
+
+ while (1)
+ {
+ error = fz_read(&n, stm, buf, sizeof buf);
+ if (error)
+ die(error);
+ if (n == 0)
+ break;
+ if (showbinary)
+ fwrite(buf, 1, n, stdout);
+ else
+ showsafe(buf, n);
+ }
- fz_dropstream(stm);
+ fz_dropstream(stm);
}
static void showobject(int num, int gen)
{
- fz_error error;
- fz_obj *obj;
-
- if (!xref)
- die(fz_throw("no file specified"));
-
- error = pdf_loadobject(&obj, xref, num, gen);
- if (error)
- die(error);
-
- if (pdf_isstream(xref, num, gen))
- {
- printf("%d %d obj\n", num, gen);
- fz_debugobj(obj);
- printf("stream\n");
- showstream(num, gen);
- printf("endstream\n");
- printf("endobj\n\n");
- }
- else
- {
- printf("%d %d obj\n", num, gen);
- fz_debugobj(obj);
- printf("endobj\n\n");
- }
-
- fz_dropobj(obj);
+ fz_error error;
+ fz_obj *obj;
+
+ if (!xref)
+ die(fz_throw("no file specified"));
+
+ error = pdf_loadobject(&obj, xref, num, gen);
+ if (error)
+ die(error);
+
+ if (pdf_isstream(xref, num, gen))
+ {
+ printf("%d %d obj\n", num, gen);
+ fz_debugobj(obj);
+ printf("stream\n");
+ showstream(num, gen);
+ printf("endstream\n");
+ printf("endobj\n\n");
+ }
+ else
+ {
+ printf("%d %d obj\n", num, gen);
+ fz_debugobj(obj);
+ printf("endobj\n\n");
+ }
+
+ fz_dropobj(obj);
}
int main(int argc, char **argv)
{
- char *password = "";
- int c;
+ char *password = "";
+ int c;
- while ((c = fz_getopt(argc, argv, "d:bx")) != -1)
- {
- switch (c)
+ while ((c = fz_getopt(argc, argv, "d:bx")) != -1)
{
- case 'd': password = fz_optarg; break;
- case 'b': showbinary ++; break;
- case 'x': showdecode ++; break;
- default:
- showusage();
- break;
+ switch (c)
+ {
+ case 'd': password = fz_optarg; break;
+ case 'b': showbinary ++; break;
+ case 'x': showdecode ++; break;
+ default:
+ showusage();
+ break;
+ }
}
- }
- if (fz_optind == argc)
- showusage();
+ if (fz_optind == argc)
+ showusage();
- openxref(argv[fz_optind++], password, 0);
+ openxref(argv[fz_optind++], password, 0);
- if (fz_optind == argc)
- showtrailer();
+ if (fz_optind == argc)
+ showtrailer();
- while (fz_optind < argc)
- {
- if (!strcmp(argv[fz_optind], "trailer"))
- showtrailer();
- else if (!strcmp(argv[fz_optind], "xref"))
- showxref();
- else
- showobject(atoi(argv[fz_optind]), 0);
- fz_optind++;
- }
+ while (fz_optind < argc)
+ {
+ if (!strcmp(argv[fz_optind], "trailer"))
+ showtrailer();
+ else if (!strcmp(argv[fz_optind], "xref"))
+ showxref();
+ else
+ showobject(atoi(argv[fz_optind]), 0);
+ fz_optind++;
+ }
- closexref();
+ closexref();
}
diff --git a/apps/unix/x11pdf.c b/apps/unix/x11pdf.c
index ee9349af..ac4fe6d6 100644
--- a/apps/unix/x11pdf.c
+++ b/apps/unix/x11pdf.c
@@ -16,27 +16,27 @@
#ifndef timeradd
#define timeradd(a, b, result) \
- do { \
- (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
- (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
- if ((result)->tv_usec >= 1000000) \
- { \
- ++(result)->tv_sec; \
- (result)->tv_usec -= 1000000; \
- } \
- } while (0)
+ do { \
+ (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
+ if ((result)->tv_usec >= 1000000) \
+ { \
+ ++(result)->tv_sec; \
+ (result)->tv_usec -= 1000000; \
+ } \
+ } while (0)
#endif
#ifndef timersub
#define timersub(a, b, result) \
- do { \
- (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
- (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
- if ((result)->tv_usec < 0) { \
- --(result)->tv_sec; \
- (result)->tv_usec += 1000000; \
- } \
- } while (0)
+ do { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
+ if ((result)->tv_usec < 0) { \
+ --(result)->tv_sec; \
+ (result)->tv_usec += 1000000; \
+ } \
+ } while (0)
#endif
extern int ximage_init(Display *display, int screen, Visual *visual);
@@ -131,17 +131,17 @@ static void winopen(void)
XAllocColor(xdpy, DefaultColormap(xdpy, xscr), &xshcolor);
xwin = XCreateWindow(xdpy, DefaultRootWindow(xdpy),
- 10, 10, 200, 100, 1,
- ximage_get_depth(),
- InputOutput,
- ximage_get_visual(),
- 0,
- nil);
+ 10, 10, 200, 100, 1,
+ ximage_get_depth(),
+ InputOutput,
+ ximage_get_visual(),
+ 0,
+ nil);
XSetWindowColormap(xdpy, xwin, ximage_get_colormap());
XSelectInput(xdpy, xwin,
- StructureNotifyMask | ExposureMask | KeyPressMask |
- PointerMotionMask | ButtonPressMask | ButtonReleaseMask);
+ StructureNotifyMask | ExposureMask | KeyPressMask |
+ PointerMotionMask | ButtonPressMask | ButtonReleaseMask);
mapped = 0;
@@ -154,7 +154,7 @@ static void winopen(void)
{
wmhints->flags = IconPixmapHint;
wmhints->icon_pixmap = XCreateBitmapFromData(xdpy, xwin,
- (char *) gs_l_xbm_bits, gs_l_xbm_width, gs_l_xbm_height);
+ (char *) gs_l_xbm_bits, gs_l_xbm_width, gs_l_xbm_height);
if (wmhints->icon_pixmap)
{
XSetWMHints(xdpy, xwin, wmhints);
@@ -290,12 +290,12 @@ static void winblit(pdfapp_t *app)
invertcopyrect();
ximage_blit(xwin, xgc,
- x0, y0,
- gapp.image->samples,
- 0, 0,
- gapp.image->w,
- gapp.image->h,
- gapp.image->w * gapp.image->n);
+ x0, y0,
+ gapp.image->samples,
+ 0, 0,
+ gapp.image->w,
+ gapp.image->h,
+ gapp.image->w * gapp.image->n);
if (gapp.iscopying || justcopied)
invertcopyrect();
@@ -363,7 +363,7 @@ void windocopy(pdfapp_t *app)
*utf8 = 0;
*latin1 = 0;
-printf("oncopy utf8=%zd latin1=%zd\n", strlen(copyutf8), strlen(copylatin1));
+ printf("oncopy utf8=%zd latin1=%zd\n", strlen(copyutf8), strlen(copylatin1));
XSetSelectionOwner(xdpy, XA_PRIMARY, xwin, copytime);
@@ -374,7 +374,7 @@ void onselreq(Window requestor, Atom selection, Atom target, Atom property, Time
{
XEvent nevt;
-printf("onselreq\n");
+ printf("onselreq\n");
if (property == None)
property = target;
@@ -395,31 +395,31 @@ printf("onselreq\n");
atomlist[1] = XA_TIMESTAMP;
atomlist[2] = XA_STRING;
atomlist[3] = XA_UTF8_STRING;
-printf(" -> targets\n");
+ printf(" -> targets\n");
XChangeProperty(xdpy, requestor, property, target,
- 32, PropModeReplace,
- (unsigned char *)atomlist, sizeof(atomlist)/sizeof(Atom));
+ 32, PropModeReplace,
+ (unsigned char *)atomlist, sizeof(atomlist)/sizeof(Atom));
}
else if (target == XA_STRING)
{
-printf(" -> string %zd\n", strlen(copylatin1));
+ printf(" -> string %zd\n", strlen(copylatin1));
XChangeProperty(xdpy, requestor, property, target,
- 8, PropModeReplace,
- (unsigned char *)copylatin1, strlen(copylatin1));
+ 8, PropModeReplace,
+ (unsigned char *)copylatin1, strlen(copylatin1));
}
else if (target == XA_UTF8_STRING)
{
-printf(" -> utf8string\n");
+ printf(" -> utf8string\n");
XChangeProperty(xdpy, requestor, property, target,
- 8, PropModeReplace,
- (unsigned char *)copyutf8, strlen(copyutf8));
+ 8, PropModeReplace,
+ (unsigned char *)copyutf8, strlen(copyutf8));
}
else
{
-printf(" -> unknown\n");
+ printf(" -> unknown\n");
nevt.xselection.property = None;
}
@@ -472,7 +472,7 @@ static void usage(void)
static void winawaitevent(struct timeval *tmo, struct timeval *tmo_at)
{
if (tmo_at->tv_sec == 0 && tmo_at->tv_usec == 0 &&
- tmo->tv_sec == 0 && tmo->tv_usec == 0)
+ tmo->tv_sec == 0 && tmo->tv_usec == 0)
XNextEvent(xdpy, &xevt);
else
{
@@ -568,7 +568,7 @@ int main(int argc, char **argv)
winawaitevent(&tmo, &tmo_at);
if (tmo_at.tv_sec != 0 && tmo_at.tv_usec != 0 &&
- tmo.tv_sec == 0 && tmo.tv_usec == 0)
+ tmo.tv_sec == 0 && tmo.tv_usec == 0)
{
/* redraw page */
winblit(&gapp);
@@ -587,12 +587,12 @@ int main(int argc, char **argv)
if (gapp.image)
{
if (xevt.xconfigure.width != reqw ||
- xevt.xconfigure.height != reqh)
+ xevt.xconfigure.height != reqh)
gapp.shrinkwrap = 0;
}
pdfapp_onresize(&gapp,
- xevt.xconfigure.width,
- xevt.xconfigure.height);
+ xevt.xconfigure.width,
+ xevt.xconfigure.height);
break;
case KeyPress:
@@ -636,10 +636,10 @@ int main(int argc, char **argv)
case SelectionRequest:
onselreq(xevt.xselectionrequest.requestor,
- xevt.xselectionrequest.selection,
- xevt.xselectionrequest.target,
- xevt.xselectionrequest.property,
- xevt.xselectionrequest.time);
+ xevt.xselectionrequest.selection,
+ xevt.xselectionrequest.target,
+ xevt.xselectionrequest.property,
+ xevt.xselectionrequest.time);
break;
}
}
diff --git a/apps/unix/ximage.c b/apps/unix/ximage.c
index 34221d0f..5b03f559 100644
--- a/apps/unix/ximage.c
+++ b/apps/unix/ximage.c
@@ -21,13 +21,13 @@
extern int ffs(int);
typedef void (*ximage_convert_func_t)
- (
- const unsigned char *src,
- int srcstride,
- unsigned char *dst,
- int dststride,
- int w,
- int h
+(
+ const unsigned char *src,
+ int srcstride,
+ unsigned char *dst,
+ int dststride,
+ int w,
+ int h
);
#define POOLSIZE 4
@@ -84,7 +84,7 @@ static struct
int shmcode;
XImage *pool[POOLSIZE];
/* MUST exist during the lifetime of the shared ximage according to the
- xc/doc/hardcopy/Xext/mit-shm.PS.gz */
+ xc/doc/hardcopy/Xext/mit-shm.PS.gz */
XShmSegmentInfo shminfo[POOLSIZE];
int lastused;
} info;
@@ -173,15 +173,15 @@ make_colormap(void)
info.rgbcube[i].green = (g * 36) << 8;
info.rgbcube[i].blue = (b * 85) << 8;
info.rgbcube[i].flags =
- DoRed | DoGreen | DoBlue;
+ DoRed | DoGreen | DoBlue;
i++;
}
}
}
info.colormap = XCreateColormap(info.display,
- RootWindow(info.display, info.screen),
- info.visual.visual,
- AllocAll);
+ RootWindow(info.display, info.screen),
+ info.visual.visual,
+ AllocAll);
XStoreColors(info.display, info.colormap, info.rgbcube, 256);
return;
}
@@ -191,7 +191,7 @@ make_colormap(void)
return;
}
fprintf(stderr, "Cannot handle visual class %d with depth: %d\n",
- info.visual.class, info.visual.depth);
+ info.visual.class, info.visual.depth);
return;
}
@@ -220,11 +220,11 @@ select_mode(void)
bs = ffs(bm) - 1;
printf("ximage: mode %d/%d %08lx %08lx %08lx (%ld,%ld,%ld) %s%s\n",
- info.visual.depth,
- info.bitsperpixel,
- rm, gm, bm, rs, gs, bs,
- byteorder == MSBFirst ? "msb" : "lsb",
- byterev ? " <swap>":"");
+ info.visual.depth,
+ info.bitsperpixel,
+ rm, gm, bm, rs, gs, bs,
+ byteorder == MSBFirst ? "msb" : "lsb",
+ byterev ? " <swap>":"");
info.mode = UNKNOWN;
if (info.bitsperpixel == 8) {
@@ -273,8 +273,8 @@ create_pool(void)
for (i = 0; i < POOLSIZE; i++) {
info.pool[i] = createximage(info.display,
- info.visual.visual, &info.shminfo[i], info.visual.depth,
- WIDTH, HEIGHT);
+ info.visual.visual, &info.shminfo[i], info.visual.depth,
+ WIDTH, HEIGHT);
if (info.pool[i] == nil) {
return 0;
}
@@ -401,11 +401,11 @@ ximage_get_colormap(void)
void
ximage_blit(Drawable d, GC gc,
- int dstx, int dsty,
- unsigned char *srcdata,
- int srcx, int srcy,
- int srcw, int srch,
- int srcstride)
+ int dstx, int dsty,
+ unsigned char *srcdata,
+ int srcx, int srcy,
+ int srcw, int srch,
+ int srcstride)
{
XImage *image;
int ax, ay;
@@ -422,12 +422,12 @@ ximage_blit(Drawable d, GC gc,
image = next_pool_image();
srcptr = srcdata +
- (ay + srcy) * srcstride +
- (ax + srcx) * 4;
+ (ay + srcy) * srcstride +
+ (ax + srcx) * 4;
info.convert_func(srcptr, srcstride,
- (unsigned char *) image->data,
- image->bytes_per_line, w, h);
+ (unsigned char *) image->data,
+ image->bytes_per_line, w, h);
if (info.useshm)
{
@@ -499,17 +499,17 @@ ximage_convert_bgra8888(PARAMS)
for (x = 0; x < w; x++) {
val = s[x];
d[x] =
- (val >> 24) |
- ((val >> 8) & 0xff00) |
- (val << 24) |
- ((val << 8) & 0xff0000);
-/*
+ (val >> 24) |
+ ((val >> 8) & 0xff00) |
+ (val << 24) |
+ ((val << 8) & 0xff0000);
+ /*
d[x] =
- (((val >> 24) & 0xff) << 0) |
- (((val >> 16) & 0xff) << 8) |
- (((val >> 8) & 0xff) << 16) |
- (((val >> 0) & 0xff) << 24);
-*/
+ (((val >> 24) & 0xff) << 0) |
+ (((val >> 16) & 0xff) << 8) |
+ (((val >> 8) & 0xff) << 16) |
+ (((val >> 0) & 0xff) << 24);
+ */
}
d += dststride>>2;
s += srcstride>>2;
@@ -531,7 +531,7 @@ ximage_convert_abgr8888(PARAMS)
val = s[x];
#if 1 /* FZ_MSB */
d[x] = (val & 0xff00ff00) |
- (((val << 16) | (val >> 16)) & 0x00ff00ff);
+ (((val << 16) | (val >> 16)) & 0x00ff00ff);
#else /* FZ_LSB */
d[x] = (val << 24) | ((val >> 8) & 0xff);
#endif
@@ -598,9 +598,9 @@ ximage_convert_rgb565(PARAMS)
g = src[4*x + 2];
b = src[4*x + 3];
((unsigned short *)dst)[x] =
- ((r & 0xF8) << 8) |
- ((g & 0xFC) << 3) |
- (b >> 3);
+ ((r & 0xF8) << 8) |
+ ((g & 0xFC) << 3) |
+ (b >> 3);
}
src += srcstride;
dst += dststride;
@@ -618,13 +618,13 @@ ximage_convert_rgb565_br(PARAMS)
g = src[4*x + 2];
b = src[4*x + 3];
/* final word is:
- g4 g3 g2 b7 b6 b5 b4 b3 r7 r6 r5 r4 r3 g7 g6 g5
- */
+ g4 g3 g2 b7 b6 b5 b4 b3 r7 r6 r5 r4 r3 g7 g6 g5
+ */
((unsigned short *)dst)[x] =
- (r & 0xF8) |
- ((g & 0xE0) >> 5) |
- ((g & 0x1C) << 11) |
- ((b & 0xF8) << 5);
+ (r & 0xF8) |
+ ((g & 0xE0) >> 5) |
+ ((g & 0x1C) << 11) |
+ ((b & 0xF8) << 5);
}
src += srcstride;
dst += dststride;
@@ -642,9 +642,9 @@ ximage_convert_rgb555(PARAMS)
g = src[4*x + 2];
b = src[4*x + 3];
((unsigned short *)dst)[x] =
- ((r & 0xF8) << 7) |
- ((g & 0xF8) << 2) |
- (b >> 3);
+ ((r & 0xF8) << 7) |
+ ((g & 0xF8) << 2) |
+ (b >> 3);
}
src += srcstride;
dst += dststride;
@@ -662,13 +662,13 @@ ximage_convert_rgb555_br(PARAMS)
g = src[4*x + 2];
b = src[4*x + 3];
/* final word is:
- g5 g4 g3 b7 b6 b5 b4 b3 0 r7 r6 r5 r4 r3 g7 g6
- */
+ g5 g4 g3 b7 b6 b5 b4 b3 0 r7 r6 r5 r4 r3 g7 g6
+ */
((unsigned short *)dst)[x] =
- ((r & 0xF8) >> 1) |
- ((g & 0xC0) >> 6) |
- ((g & 0x38) << 10) |
- ((b & 0xF8) << 5);
+ ((r & 0xF8) >> 1) |
+ ((g & 0xC0) >> 6) |
+ ((g & 0x38) << 10) |
+ ((b & 0xF8) << 5);
}
src += srcstride;
dst += dststride;
diff --git a/apps/windows/winmain.c b/apps/windows/winmain.c
index c9ef91bf..294ae9eb 100644
--- a/apps/windows/winmain.c
+++ b/apps/windows/winmain.c
@@ -32,70 +32,70 @@ static pdfapp_t gapp;
void associate(char *argv0)
{
- char tmp[256];
- char *name = "Adobe PDF Document";
- HKEY key, kicon, kshell, kopen, kcmd;
- DWORD disp;
+ char tmp[256];
+ char *name = "Adobe PDF Document";
+ HKEY key, kicon, kshell, kopen, kcmd;
+ DWORD disp;
- /* HKEY_CLASSES_ROOT\.pdf */
+ /* HKEY_CLASSES_ROOT\.pdf */
- if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
- ".pdf", 0, NULL, REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &key, &disp))
- return;
+ if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
+ ".pdf", 0, NULL, REG_OPTION_NON_VOLATILE,
+ KEY_WRITE, NULL, &key, &disp))
+ return;
- if (RegSetValueEx(key, "", 0, REG_SZ, "MuPDF", strlen("MuPDF")+1))
- return;
+ if (RegSetValueEx(key, "", 0, REG_SZ, "MuPDF", strlen("MuPDF")+1))
+ return;
- RegCloseKey(key);
+ RegCloseKey(key);
- /* HKEY_CLASSES_ROOT\MuPDF */
+ /* HKEY_CLASSES_ROOT\MuPDF */
- if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
- "MuPDF", 0, NULL, REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &key, &disp))
- return;
+ if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
+ "MuPDF", 0, NULL, REG_OPTION_NON_VOLATILE,
+ KEY_WRITE, NULL, &key, &disp))
+ return;
- if (RegSetValueEx(key, "", 0, REG_SZ, name, strlen(name)+1))
- return;
+ if (RegSetValueEx(key, "", 0, REG_SZ, name, strlen(name)+1))
+ return;
- /* HKEY_CLASSES_ROOT\MuPDF\DefaultIcon */
+ /* HKEY_CLASSES_ROOT\MuPDF\DefaultIcon */
- if (RegCreateKeyEx(key,
- "DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &kicon, &disp))
- return;
+ if (RegCreateKeyEx(key,
+ "DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE,
+ KEY_WRITE, NULL, &kicon, &disp))
+ return;
- sprintf(tmp, "%s,1", argv0);
- if (RegSetValueEx(kicon, "", 0, REG_SZ, tmp, strlen(tmp)+1))
- return;
+ sprintf(tmp, "%s,1", argv0);
+ if (RegSetValueEx(kicon, "", 0, REG_SZ, tmp, strlen(tmp)+1))
+ return;
- RegCloseKey(kicon);
+ RegCloseKey(kicon);
- /* HKEY_CLASSES_ROOT\MuPDF\Shell\Open\Command */
+ /* HKEY_CLASSES_ROOT\MuPDF\Shell\Open\Command */
- if (RegCreateKeyEx(key,
- "shell", 0, NULL, REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &kshell, &disp))
- return;
- if (RegCreateKeyEx(kshell,
- "open", 0, NULL, REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &kopen, &disp))
- return;
- if (RegCreateKeyEx(kopen,
- "command", 0, NULL, REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &kcmd, &disp))
- return;
+ if (RegCreateKeyEx(key,
+ "shell", 0, NULL, REG_OPTION_NON_VOLATILE,
+ KEY_WRITE, NULL, &kshell, &disp))
+ return;
+ if (RegCreateKeyEx(kshell,
+ "open", 0, NULL, REG_OPTION_NON_VOLATILE,
+ KEY_WRITE, NULL, &kopen, &disp))
+ return;
+ if (RegCreateKeyEx(kopen,
+ "command", 0, NULL, REG_OPTION_NON_VOLATILE,
+ KEY_WRITE, NULL, &kcmd, &disp))
+ return;
- sprintf(tmp, "\"%s\" \"%%1\"", argv0);
- if (RegSetValueEx(kcmd, "", 0, REG_SZ, tmp, strlen(tmp)+1))
- return;
+ sprintf(tmp, "\"%s\" \"%%1\"", argv0);
+ if (RegSetValueEx(kcmd, "", 0, REG_SZ, tmp, strlen(tmp)+1))
+ return;
- RegCloseKey(kcmd);
- RegCloseKey(kopen);
- RegCloseKey(kshell);
+ RegCloseKey(kcmd);
+ RegCloseKey(kopen);
+ RegCloseKey(kshell);
- RegCloseKey(key);
+ RegCloseKey(key);
}
/*
@@ -104,30 +104,30 @@ void associate(char *argv0)
void winwarn(pdfapp_t *app, char *msg)
{
- MessageBoxA(hwndframe, msg, "MuPDF: Warning", MB_ICONWARNING);
+ MessageBoxA(hwndframe, msg, "MuPDF: Warning", MB_ICONWARNING);
}
void winerror(pdfapp_t *app, fz_error error)
{
- fz_catch(error, "displaying error message to user");
- MessageBoxA(hwndframe, fz_errorbuf, "MuPDF: Error", MB_ICONERROR);
- exit(1);
+ fz_catch(error, "displaying error message to user");
+ MessageBoxA(hwndframe, fz_errorbuf, "MuPDF: Error", MB_ICONERROR);
+ exit(1);
}
int winfilename(char *buf, int len)
{
- OPENFILENAME ofn;
- strcpy(buf, "");
- memset(&ofn, 0, sizeof(OPENFILENAME));
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = hwndframe;
- ofn.lpstrFile = buf;
- ofn.nMaxFile = len;
- ofn.lpstrInitialDir = NULL;
- ofn.lpstrTitle = "MuPDF: Open PDF file";
- ofn.lpstrFilter = "PDF Files (*.pdf)\0*.pdf\0All Files\0*\0\0";
- ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
- return GetOpenFileName(&ofn);
+ OPENFILENAME ofn;
+ strcpy(buf, "");
+ memset(&ofn, 0, sizeof(OPENFILENAME));
+ ofn.lStructSize = sizeof(OPENFILENAME);
+ ofn.hwndOwner = hwndframe;
+ ofn.lpstrFile = buf;
+ ofn.nMaxFile = len;
+ ofn.lpstrInitialDir = NULL;
+ ofn.lpstrTitle = "MuPDF: Open PDF file";
+ ofn.lpstrFilter = "PDF Files (*.pdf)\0*.pdf\0All Files\0*\0\0";
+ ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
+ return GetOpenFileName(&ofn);
}
static char pd_filename[256] = "The file is encrypted.";
@@ -137,145 +137,144 @@ static int pd_okay = 0;
INT CALLBACK
dlogpassproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch(message)
- {
- case WM_INITDIALOG:
- SetDlgItemText(hwnd, 4, pd_filename);
- return TRUE;
- case WM_COMMAND:
- switch(wParam)
+ switch(message)
{
- case 1:
- pd_okay = 1;
- GetDlgItemText(hwnd, 3, pd_password, sizeof pd_password);
- EndDialog(hwnd, 0);
- return TRUE;
- case 2:
- pd_okay = 0;
- EndDialog(hwnd, 0);
- return TRUE;
+ case WM_INITDIALOG:
+ SetDlgItemText(hwnd, 4, pd_filename);
+ return TRUE;
+ case WM_COMMAND:
+ switch(wParam)
+ {
+ case 1:
+ pd_okay = 1;
+ GetDlgItemText(hwnd, 3, pd_password, sizeof pd_password);
+ EndDialog(hwnd, 0);
+ return TRUE;
+ case 2:
+ pd_okay = 0;
+ EndDialog(hwnd, 0);
+ return TRUE;
+ }
+ break;
}
- break;
- }
- return FALSE;
+ return FALSE;
}
char *winpassword(pdfapp_t *app, char *filename)
{
- char buf[124], *s;
- strcpy(buf, filename);
- s = buf;
- if (strrchr(s, '\\')) s = strrchr(s, '\\') + 1;
- if (strrchr(s, '/')) s = strrchr(s, '/') + 1;
- if (strlen(s) > 32)
- strcpy(s + 30, "...");
- sprintf(pd_filename, "The file \"%s\" is encrypted.", s);
- DialogBox(NULL, "IDD_DLOGPASS", hwndframe, dlogpassproc);
- if (pd_okay)
- return pd_password;
- return NULL;
+ char buf[124], *s;
+ strcpy(buf, filename);
+ s = buf;
+ if (strrchr(s, '\\')) s = strrchr(s, '\\') + 1;
+ if (strrchr(s, '/')) s = strrchr(s, '/') + 1;
+ if (strlen(s) > 32)
+ strcpy(s + 30, "...");
+ sprintf(pd_filename, "The file \"%s\" is encrypted.", s);
+ DialogBox(NULL, "IDD_DLOGPASS", hwndframe, dlogpassproc);
+ if (pd_okay)
+ return pd_password;
+ return NULL;
}
INT CALLBACK
dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- char buf[256];
- pdf_xref *xref = gapp.xref;
- fz_obj *obj;
+ char buf[256];
+ pdf_xref *xref = gapp.xref;
+ fz_obj *obj;
- switch(message)
- {
- case WM_INITDIALOG:
-
- SetDlgItemTextA(hwnd, 0x10, gapp.filename);
-
- sprintf(buf, "PDF %d.%d", xref->version / 10, xref->version % 10);
- SetDlgItemTextA(hwnd, 0x11, buf);
-
- if (xref->crypt)
- {
- sprintf(buf, "Standard %d bit %s", xref->crypt->length,
- xref->crypt->strf.method == PDF_CRYPT_AESV2 ? "AES" : "RC4");
- SetDlgItemTextA(hwnd, 0x12, buf);
- strcpy(buf, "");
- if (xref->crypt->p & (1 << 2))
- strcat(buf, "print, ");
- if (xref->crypt->p & (1 << 3))
- strcat(buf, "modify, ");
- if (xref->crypt->p & (1 << 4))
- strcat(buf, "copy, ");
- if (xref->crypt->p & (1 << 5))
- strcat(buf, "annotate, ");
- if (strlen(buf) > 2)
- buf[strlen(buf)-2] = 0;
- else
- strcpy(buf, "none");
- SetDlgItemTextA(hwnd, 0x13, buf);
- }
- else
+ switch(message)
{
- SetDlgItemTextA(hwnd, 0x12, "None");
- SetDlgItemTextA(hwnd, 0x13, "n/a");
- }
-
- if (!xref->info)
- return TRUE;
+ case WM_INITDIALOG:
+
+ SetDlgItemTextA(hwnd, 0x10, gapp.filename);
+
+ sprintf(buf, "PDF %d.%d", xref->version / 10, xref->version % 10);
+ SetDlgItemTextA(hwnd, 0x11, buf);
+
+ if (xref->crypt)
+ {
+ sprintf(buf, "Standard %d bit %s", xref->crypt->length,
+ xref->crypt->strf.method == PDF_CRYPT_AESV2 ? "AES" : "RC4");
+ SetDlgItemTextA(hwnd, 0x12, buf);
+ strcpy(buf, "");
+ if (xref->crypt->p & (1 << 2))
+ strcat(buf, "print, ");
+ if (xref->crypt->p & (1 << 3))
+ strcat(buf, "modify, ");
+ if (xref->crypt->p & (1 << 4))
+ strcat(buf, "copy, ");
+ if (xref->crypt->p & (1 << 5))
+ strcat(buf, "annotate, ");
+ if (strlen(buf) > 2)
+ buf[strlen(buf)-2] = 0;
+ else
+ strcpy(buf, "none");
+ SetDlgItemTextA(hwnd, 0x13, buf);
+ }
+ else
+ {
+ SetDlgItemTextA(hwnd, 0x12, "None");
+ SetDlgItemTextA(hwnd, 0x13, "n/a");
+ }
+
+ if (!xref->info)
+ return TRUE;
#define SETUCS(ID) \
- { \
- fz_error error; \
- unsigned short *ucs; \
- error = pdf_toucs2(&ucs, obj); \
- if (!error) \
{ \
- SetDlgItemTextW(hwnd, ID, ucs); \
- fz_free(ucs); \
- } \
+ fz_error error; \
+ unsigned short *ucs; \
+ error = pdf_toucs2(&ucs, obj); \
+ if (!error) \
+ { \
+ SetDlgItemTextW(hwnd, ID, ucs); \
+ fz_free(ucs); \
+ } \
+ }
+
+ if ((obj = fz_dictgets(xref->info, "Title"))) SETUCS(0x20)
+ if ((obj = fz_dictgets(xref->info, "Author"))) SETUCS(0x21)
+ if ((obj = fz_dictgets(xref->info, "Subject"))) SETUCS(0x22)
+ if ((obj = fz_dictgets(xref->info, "Keywords"))) SETUCS(0x23)
+ if ((obj = fz_dictgets(xref->info, "Creator"))) SETUCS(0x24)
+ if ((obj = fz_dictgets(xref->info, "Producer"))) SETUCS(0x25)
+ if ((obj = fz_dictgets(xref->info, "CreationDate"))) SETUCS(0x26)
+ if ((obj = fz_dictgets(xref->info, "ModDate"))) SETUCS(0x27)
+ return TRUE;
+
+ case WM_COMMAND:
+ EndDialog(hwnd, 0);
+ return TRUE;
}
-
- if ((obj = fz_dictgets(xref->info, "Title"))) SETUCS(0x20)
- if ((obj = fz_dictgets(xref->info, "Author"))) SETUCS(0x21)
- if ((obj = fz_dictgets(xref->info, "Subject"))) SETUCS(0x22)
- if ((obj = fz_dictgets(xref->info, "Keywords"))) SETUCS(0x23)
- if ((obj = fz_dictgets(xref->info, "Creator"))) SETUCS(0x24)
- if ((obj = fz_dictgets(xref->info, "Producer"))) SETUCS(0x25)
- if ((obj = fz_dictgets(xref->info, "CreationDate"))) SETUCS(0x26)
- if ((obj = fz_dictgets(xref->info, "ModDate"))) SETUCS(0x27)
-
- return TRUE;
-
- case WM_COMMAND:
- EndDialog(hwnd, 0);
- return TRUE;
- }
- return FALSE;
+ return FALSE;
}
void info()
{
- DialogBox(NULL, "IDD_DLOGINFO", hwndframe, dloginfoproc);
+ DialogBox(NULL, "IDD_DLOGINFO", hwndframe, dloginfoproc);
}
INT CALLBACK
dlogaboutproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch(message)
- {
- case WM_INITDIALOG:
- SetDlgItemTextA(hwnd, 0x10, gapp.filename);
- SetDlgItemTextA(hwnd, 2, "MuPDF is Copyright (C) 2006-2008 artofcode, LLC");
- SetDlgItemTextA(hwnd, 3, pdfapp_usage(&gapp));
- return TRUE;
- case WM_COMMAND:
- EndDialog(hwnd, 0);
- return TRUE;
- }
- return FALSE;
+ switch(message)
+ {
+ case WM_INITDIALOG:
+ SetDlgItemTextA(hwnd, 0x10, gapp.filename);
+ SetDlgItemTextA(hwnd, 2, "MuPDF is Copyright (C) 2006-2008 artofcode, LLC");
+ SetDlgItemTextA(hwnd, 3, pdfapp_usage(&gapp));
+ return TRUE;
+ case WM_COMMAND:
+ EndDialog(hwnd, 0);
+ return TRUE;
+ }
+ return FALSE;
}
void help()
{
- DialogBox(NULL, "IDD_DLOGABOUT", hwndframe, dlogaboutproc);
+ DialogBox(NULL, "IDD_DLOGABOUT", hwndframe, dlogaboutproc);
}
/*
@@ -284,193 +283,193 @@ void help()
void winopen()
{
- WNDCLASS wc;
- HMENU menu;
- RECT r;
-
- /* Create and register window frame class */
- wc.style = 0;
- wc.lpfnWndProc = frameproc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = GetModuleHandle(NULL);
- wc.hIcon = LoadIcon(wc.hInstance, "IDI_ICONAPP");
- wc.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "FrameWindow";
- assert(RegisterClass(&wc) && "Register window class");
-
- /* Create and register window view class */
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = viewproc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = GetModuleHandle(NULL);
- wc.hIcon = NULL;
- wc.hCursor = NULL;
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "ViewWindow";
- assert(RegisterClass(&wc) && "Register window class");
-
- /* Get screen size */
- SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
- gapp.scrw = r.right - r.left;
- gapp.scrh = r.bottom - r.top;
-
- /* Create cursors */
- arrowcurs = LoadCursor(NULL, IDC_ARROW);
- handcurs = LoadCursor(NULL, IDC_HAND);
- waitcurs = LoadCursor(NULL, IDC_WAIT);
-
- /* And a background color */
- bgbrush = CreateSolidBrush(RGB(0x70,0x70,0x70));
- shbrush = CreateSolidBrush(RGB(0x40,0x40,0x40));
-
- /* Init DIB info for buffer */
- dibinf = malloc(sizeof(BITMAPINFO) + 12);
- assert(dibinf != NULL);
- dibinf->bmiHeader.biSize = sizeof(dibinf->bmiHeader);
- dibinf->bmiHeader.biPlanes = 1;
- dibinf->bmiHeader.biBitCount = 24;
- dibinf->bmiHeader.biCompression = BI_RGB;
- dibinf->bmiHeader.biXPelsPerMeter = 2834;
- dibinf->bmiHeader.biYPelsPerMeter = 2834;
- dibinf->bmiHeader.biClrUsed = 0;
- dibinf->bmiHeader.biClrImportant = 0;
- dibinf->bmiHeader.biClrUsed = 0;
-
- /* Create window */
- hwndframe = CreateWindow("FrameWindow", // window class name
- NULL, // window caption
- WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
- CW_USEDEFAULT, CW_USEDEFAULT, // initial position
- 300, // initial x size
- 300, // initial y size
- 0, // parent window handle
- 0, // window menu handle
- 0, // program instance handle
- 0); // creation parameters
-
- hwndview = CreateWindow("ViewWindow", // window class name
- NULL,
- WS_VISIBLE | WS_CHILD,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
- hwndframe, 0, 0, 0);
-
- hdc = NULL;
-
- SetWindowTextA(hwndframe, "MuPDF");
-
- menu = GetSystemMenu(hwndframe, 0);
- AppendMenu(menu, MF_SEPARATOR, 0, NULL);
- AppendMenu(menu, MF_STRING, ID_ABOUT, "About MuPDF...");
- AppendMenu(menu, MF_STRING, ID_DOCINFO, "Document Properties...");
-
- SetCursor(arrowcurs);
+ WNDCLASS wc;
+ HMENU menu;
+ RECT r;
+
+ /* Create and register window frame class */
+ wc.style = 0;
+ wc.lpfnWndProc = frameproc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.hIcon = LoadIcon(wc.hInstance, "IDI_ICONAPP");
+ wc.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = NULL;
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = "FrameWindow";
+ assert(RegisterClass(&wc) && "Register window class");
+
+ /* Create and register window view class */
+ wc.style = CS_HREDRAW | CS_VREDRAW;
+ wc.lpfnWndProc = viewproc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.hIcon = NULL;
+ wc.hCursor = NULL;
+ wc.hbrBackground = NULL;
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = "ViewWindow";
+ assert(RegisterClass(&wc) && "Register window class");
+
+ /* Get screen size */
+ SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
+ gapp.scrw = r.right - r.left;
+ gapp.scrh = r.bottom - r.top;
+
+ /* Create cursors */
+ arrowcurs = LoadCursor(NULL, IDC_ARROW);
+ handcurs = LoadCursor(NULL, IDC_HAND);
+ waitcurs = LoadCursor(NULL, IDC_WAIT);
+
+ /* And a background color */
+ bgbrush = CreateSolidBrush(RGB(0x70,0x70,0x70));
+ shbrush = CreateSolidBrush(RGB(0x40,0x40,0x40));
+
+ /* Init DIB info for buffer */
+ dibinf = malloc(sizeof(BITMAPINFO) + 12);
+ assert(dibinf != NULL);
+ dibinf->bmiHeader.biSize = sizeof(dibinf->bmiHeader);
+ dibinf->bmiHeader.biPlanes = 1;
+ dibinf->bmiHeader.biBitCount = 24;
+ dibinf->bmiHeader.biCompression = BI_RGB;
+ dibinf->bmiHeader.biXPelsPerMeter = 2834;
+ dibinf->bmiHeader.biYPelsPerMeter = 2834;
+ dibinf->bmiHeader.biClrUsed = 0;
+ dibinf->bmiHeader.biClrImportant = 0;
+ dibinf->bmiHeader.biClrUsed = 0;
+
+ /* Create window */
+ hwndframe = CreateWindow("FrameWindow", // window class name
+ NULL, // window caption
+ WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
+ CW_USEDEFAULT, CW_USEDEFAULT, // initial position
+ 300, // initial x size
+ 300, // initial y size
+ 0, // parent window handle
+ 0, // window menu handle
+ 0, // program instance handle
+ 0); // creation parameters
+
+ hwndview = CreateWindow("ViewWindow", // window class name
+ NULL,
+ WS_VISIBLE | WS_CHILD,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ hwndframe, 0, 0, 0);
+
+ hdc = NULL;
+
+ SetWindowTextA(hwndframe, "MuPDF");
+
+ menu = GetSystemMenu(hwndframe, 0);
+ AppendMenu(menu, MF_SEPARATOR, 0, NULL);
+ AppendMenu(menu, MF_STRING, ID_ABOUT, "About MuPDF...");
+ AppendMenu(menu, MF_STRING, ID_DOCINFO, "Document Properties...");
+
+ SetCursor(arrowcurs);
}
void wincursor(pdfapp_t *app, int curs)
{
- if (curs == ARROW)
- SetCursor(arrowcurs);
- if (curs == HAND)
- SetCursor(handcurs);
- if (curs == WAIT)
- SetCursor(waitcurs);
+ if (curs == ARROW)
+ SetCursor(arrowcurs);
+ if (curs == HAND)
+ SetCursor(handcurs);
+ if (curs == WAIT)
+ SetCursor(waitcurs);
}
void wintitle(pdfapp_t *app, char *title)
{
- unsigned short wide[256], *dp;
- char *sp;
- int rune;
-
- dp = wide;
- sp = title;
- while (*sp && dp < wide + 255)
- {
- sp += chartorune(&rune, sp);
- *dp++ = rune;
- }
- *dp = 0;
-
- SetWindowTextW(hwndframe, wide);
+ unsigned short wide[256], *dp;
+ char *sp;
+ int rune;
+
+ dp = wide;
+ sp = title;
+ while (*sp && dp < wide + 255)
+ {
+ sp += chartorune(&rune, sp);
+ *dp++ = rune;
+ }
+ *dp = 0;
+
+ SetWindowTextW(hwndframe, wide);
}
void winconvert(pdfapp_t *app, fz_pixmap *image)
{
- int y, x;
+ int y, x;
- if (bmpdata)
- fz_free(bmpdata);
+ if (bmpdata)
+ fz_free(bmpdata);
- bmpstride = ((image->w * 3 + 3) / 4) * 4;
- bmpdata = fz_malloc(image->h * bmpstride);
- if (!bmpdata)
- return;
+ bmpstride = ((image->w * 3 + 3) / 4) * 4;
+ bmpdata = fz_malloc(image->h * bmpstride);
+ if (!bmpdata)
+ return;
- for (y = 0; y < image->h; y++)
- {
- unsigned char *p = bmpdata + y * bmpstride;
- unsigned char *s = image->samples + y * image->w * 4;
- for (x = 0; x < image->w; x++)
+ for (y = 0; y < image->h; y++)
{
- p[x * 3 + 0] = s[x * 4 + 3];
- p[x * 3 + 1] = s[x * 4 + 2];
- p[x * 3 + 2] = s[x * 4 + 1];
+ unsigned char *p = bmpdata + y * bmpstride;
+ unsigned char *s = image->samples + y * image->w * 4;
+ for (x = 0; x < image->w; x++)
+ {
+ p[x * 3 + 0] = s[x * 4 + 3];
+ p[x * 3 + 1] = s[x * 4 + 2];
+ p[x * 3 + 2] = s[x * 4 + 1];
+ }
}
- }
}
void invertcopyrect(void)
{
- unsigned char *p;
- int x0 = gapp.selr.x0 - gapp.panx;
- int x1 = gapp.selr.x1 - gapp.panx;
- int y0 = gapp.selr.y0 - gapp.pany;
- int y1 = gapp.selr.y1 - gapp.pany;
- int x, y;
-
- x0 = CLAMP(x0, 0, gapp.image->w - 1);
- x1 = CLAMP(x1, 0, gapp.image->w - 1);
- y0 = CLAMP(y0, 0, gapp.image->h - 1);
- y1 = CLAMP(y1, 0, gapp.image->h - 1);
-
- for (y = y0; y < y1; y++)
- {
- p = bmpdata + y * bmpstride + x0 * 3;
- for (x = x0; x < x1; x++)
+ unsigned char *p;
+ int x0 = gapp.selr.x0 - gapp.panx;
+ int x1 = gapp.selr.x1 - gapp.panx;
+ int y0 = gapp.selr.y0 - gapp.pany;
+ int y1 = gapp.selr.y1 - gapp.pany;
+ int x, y;
+
+ x0 = CLAMP(x0, 0, gapp.image->w - 1);
+ x1 = CLAMP(x1, 0, gapp.image->w - 1);
+ y0 = CLAMP(y0, 0, gapp.image->h - 1);
+ y1 = CLAMP(y1, 0, gapp.image->h - 1);
+
+ for (y = y0; y < y1; y++)
{
- p[0] = 255 - p[0];
- p[1] = 255 - p[1];
- p[2] = 255 - p[2];
- p += 3;
+ p = bmpdata + y * bmpstride + x0 * 3;
+ for (x = x0; x < x1; x++)
+ {
+ p[0] = 255 - p[0];
+ p[1] = 255 - p[1];
+ p[2] = 255 - p[2];
+ p += 3;
+ }
}
- }
- justcopied = 1;
+ justcopied = 1;
}
void winblit()
{
- int x0 = gapp.panx;
- int y0 = gapp.pany;
- int x1 = gapp.panx + gapp.image->w;
- int y1 = gapp.pany + gapp.image->h;
- RECT r;
-
- if (bmpdata)
- {
- if (gapp.iscopying || justcopied)
- invertcopyrect();
-
- dibinf->bmiHeader.biWidth = gapp.image->w;
- dibinf->bmiHeader.biHeight = -gapp.image->h;
- dibinf->bmiHeader.biSizeImage = gapp.image->h * bmpstride;
- SetDIBitsToDevice(hdc,
+ int x0 = gapp.panx;
+ int y0 = gapp.pany;
+ int x1 = gapp.panx + gapp.image->w;
+ int y1 = gapp.pany + gapp.image->h;
+ RECT r;
+
+ if (bmpdata)
+ {
+ if (gapp.iscopying || justcopied)
+ invertcopyrect();
+
+ dibinf->bmiHeader.biWidth = gapp.image->w;
+ dibinf->bmiHeader.biHeight = -gapp.image->h;
+ dibinf->bmiHeader.biSizeImage = gapp.image->h * bmpstride;
+ SetDIBitsToDevice(hdc,
gapp.panx, /* destx */
gapp.pany, /* desty */
gapp.image->w, /* destw */
@@ -482,49 +481,49 @@ void winblit()
bmpdata, /* pBits */
dibinf, /* pInfo */
DIB_RGB_COLORS /* color use flag */
- );
-
- if (gapp.iscopying || justcopied)
- invertcopyrect();
- }
-
- /* Grey background */
- r.top = 0; r.bottom = gapp.winh;
- r.left = 0; r.right = x0;
- FillRect(hdc, &r, bgbrush);
- r.left = x1; r.right = gapp.winw;
- FillRect(hdc, &r, bgbrush);
- r.left = 0; r.right = gapp.winw;
- r.top = 0; r.bottom = y0;
- FillRect(hdc, &r, bgbrush);
- r.top = y1; r.bottom = gapp.winh;
- FillRect(hdc, &r, bgbrush);
-
- /* Drop shadow */
- r.left = x0 + 2;
- r.right = x1 + 2;
- r.top = y1;
- r.bottom = y1 + 2;
- FillRect(hdc, &r, shbrush);
- r.left = x1;
- r.right = x1 + 2;
- r.top = y0 + 2;
- r.bottom = y1;
- FillRect(hdc, &r, shbrush);
+ );
+
+ if (gapp.iscopying || justcopied)
+ invertcopyrect();
+ }
+
+ /* Grey background */
+ r.top = 0; r.bottom = gapp.winh;
+ r.left = 0; r.right = x0;
+ FillRect(hdc, &r, bgbrush);
+ r.left = x1; r.right = gapp.winw;
+ FillRect(hdc, &r, bgbrush);
+ r.left = 0; r.right = gapp.winw;
+ r.top = 0; r.bottom = y0;
+ FillRect(hdc, &r, bgbrush);
+ r.top = y1; r.bottom = gapp.winh;
+ FillRect(hdc, &r, bgbrush);
+
+ /* Drop shadow */
+ r.left = x0 + 2;
+ r.right = x1 + 2;
+ r.top = y1;
+ r.bottom = y1 + 2;
+ FillRect(hdc, &r, shbrush);
+ r.left = x1;
+ r.right = x1 + 2;
+ r.top = y0 + 2;
+ r.bottom = y1;
+ FillRect(hdc, &r, shbrush);
}
void winresize(pdfapp_t *app, int w, int h)
{
- ShowWindow(hwndframe, SW_SHOWDEFAULT);
- w += GetSystemMetrics(SM_CXFRAME) * 2;
- h += GetSystemMetrics(SM_CYFRAME) * 2;
- h += GetSystemMetrics(SM_CYCAPTION);
- SetWindowPos(hwndframe, 0, 0, 0, w, h, SWP_NOZORDER | SWP_NOMOVE);
+ ShowWindow(hwndframe, SW_SHOWDEFAULT);
+ w += GetSystemMetrics(SM_CXFRAME) * 2;
+ h += GetSystemMetrics(SM_CYFRAME) * 2;
+ h += GetSystemMetrics(SM_CYCAPTION);
+ SetWindowPos(hwndframe, 0, 0, 0, w, h, SWP_NOZORDER | SWP_NOMOVE);
}
void winrepaint(pdfapp_t *app)
{
- InvalidateRect(hwndview, NULL, 0);
+ InvalidateRect(hwndview, NULL, 0);
}
/*
@@ -533,280 +532,280 @@ void winrepaint(pdfapp_t *app)
void windocopy(pdfapp_t *app)
{
- HGLOBAL handle;
- unsigned short *ucsbuf;
+ HGLOBAL handle;
+ unsigned short *ucsbuf;
- if (!OpenClipboard(hwndframe))
- return;
- EmptyClipboard();
+ if (!OpenClipboard(hwndframe))
+ return;
+ EmptyClipboard();
- handle = GlobalAlloc(GMEM_MOVEABLE, 4096 * sizeof(unsigned short));
- if (!handle)
- {
- CloseClipboard();
- return;
- }
+ handle = GlobalAlloc(GMEM_MOVEABLE, 4096 * sizeof(unsigned short));
+ if (!handle)
+ {
+ CloseClipboard();
+ return;
+ }
- ucsbuf = GlobalLock(handle);
- pdfapp_oncopy(&gapp, ucsbuf, 4096);
- GlobalUnlock(handle);
+ ucsbuf = GlobalLock(handle);
+ pdfapp_oncopy(&gapp, ucsbuf, 4096);
+ GlobalUnlock(handle);
- SetClipboardData(CF_UNICODETEXT, handle);
- CloseClipboard();
+ SetClipboardData(CF_UNICODETEXT, handle);
+ CloseClipboard();
- justcopied = 1; /* keep inversion around for a while... */
+ justcopied = 1; /* keep inversion around for a while... */
}
void winopenuri(pdfapp_t *app, char *buf)
{
- ShellExecute(hwndframe, "open", buf, 0, 0, SW_SHOWNORMAL);
+ ShellExecute(hwndframe, "open", buf, 0, 0, SW_SHOWNORMAL);
}
void handlekey(int c)
{
- if (GetCapture() == hwndview)
- return;
-
- if (justcopied)
- {
- justcopied = 0;
- winrepaint(&gapp);
- }
-
- /* translate VK into ascii equivalents */
- switch (c)
- {
- case VK_F1: c = '?'; break;
- case VK_ESCAPE: c = 'q'; break;
- case VK_DOWN: c = 'd'; break;
- case VK_UP: c = 'u'; break;
- case VK_LEFT: c = 'p'; break;
- case VK_RIGHT: c = 'n'; break;
- case VK_PRIOR: c = 'b'; break;
- case VK_NEXT: c = ' '; break;
- }
-
- if (c == 'q')
- exit(0);
- else if (c == '?' || c == 'h')
- help();
- else
- pdfapp_onkey(&gapp, c);
-}
-
-void handlemouse(int x, int y, int btn, int state)
-{
- if (state != 0 && justcopied)
- {
- justcopied = 0;
- winrepaint(&gapp);
- }
-
- if (state == 1)
- SetCapture(hwndview);
- if (state == -1)
- ReleaseCapture();
-
- pdfapp_onmouse(&gapp, x, y, btn, 0, state);
-}
-
-LRESULT CALLBACK
-frameproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- switch(message)
- {
- case WM_SETFOCUS:
- PostMessage(hwnd, WM_APP+5, 0, 0);
- return 0;
- case WM_APP+5:
- SetFocus(hwndview);
- return 0;
+ if (GetCapture() == hwndview)
+ return;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
-
- case WM_SYSCOMMAND:
- if (wParam == ID_ABOUT)
+ if (justcopied)
{
- help();
- return 0;
+ justcopied = 0;
+ winrepaint(&gapp);
}
- if (wParam == ID_DOCINFO)
+
+ /* translate VK into ascii equivalents */
+ switch (c)
{
- info();
- return 0;
+ case VK_F1: c = '?'; break;
+ case VK_ESCAPE: c = 'q'; break;
+ case VK_DOWN: c = 'd'; break;
+ case VK_UP: c = 'u'; break;
+ case VK_LEFT: c = 'p'; break;
+ case VK_RIGHT: c = 'n'; break;
+ case VK_PRIOR: c = 'b'; break;
+ case VK_NEXT: c = ' '; break;
}
- break;
- case WM_SIZE:
+ if (c == 'q')
+ exit(0);
+ else if (c == '?' || c == 'h')
+ help();
+ else
+ pdfapp_onkey(&gapp, c);
+}
+
+void handlemouse(int x, int y, int btn, int state)
+{
+ if (state != 0 && justcopied)
{
- // More generally, you should use GetEffectiveClientRect
- // if you have a toolbar etc.
- RECT rect;
- GetClientRect(hwnd, &rect);
- MoveWindow(hwndview, rect.left, rect.top,
- rect.right-rect.left, rect.bottom-rect.top, TRUE);
+ justcopied = 0;
+ winrepaint(&gapp);
}
- return 0;
-
- case WM_SIZING:
- gapp.shrinkwrap = 0;
- break;
- case WM_NOTIFY:
- case WM_COMMAND:
- return SendMessage(hwndview, message, wParam, lParam);
- }
+ if (state == 1)
+ SetCapture(hwndview);
+ if (state == -1)
+ ReleaseCapture();
- return DefWindowProc(hwnd, message, wParam, lParam);
+ pdfapp_onmouse(&gapp, x, y, btn, 0, state);
}
LRESULT CALLBACK
-viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+frameproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- static int oldx = 0;
- static int oldy = 0;
- int x = (signed short) LOWORD(lParam);
- int y = (signed short) HIWORD(lParam);
-
- switch (message)
- {
- case WM_SIZE:
- if (wParam == SIZE_MINIMIZED)
- return 0;
- if (wParam == SIZE_MAXIMIZED)
- gapp.shrinkwrap = 0;
- pdfapp_onresize(&gapp, LOWORD(lParam), HIWORD(lParam));
- break;
-
- /* Paint events are low priority and automagically catenated
- * so we don't need to do any fancy waiting to defer repainting.
- */
- case WM_PAINT:
+ switch(message)
{
- //puts("WM_PAINT");
- PAINTSTRUCT ps;
- hdc = BeginPaint(hwnd, &ps);
- winblit();
- hdc = NULL;
- EndPaint(hwnd, &ps);
- return 0;
+ case WM_SETFOCUS:
+ PostMessage(hwnd, WM_APP+5, 0, 0);
+ return 0;
+ case WM_APP+5:
+ SetFocus(hwndview);
+ return 0;
+
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ return 0;
+
+ case WM_SYSCOMMAND:
+ if (wParam == ID_ABOUT)
+ {
+ help();
+ return 0;
+ }
+ if (wParam == ID_DOCINFO)
+ {
+ info();
+ return 0;
+ }
+ break;
+
+ case WM_SIZE:
+ {
+ // More generally, you should use GetEffectiveClientRect
+ // if you have a toolbar etc.
+ RECT rect;
+ GetClientRect(hwnd, &rect);
+ MoveWindow(hwndview, rect.left, rect.top,
+ rect.right-rect.left, rect.bottom-rect.top, TRUE);
+ }
+ return 0;
+
+ case WM_SIZING:
+ gapp.shrinkwrap = 0;
+ break;
+
+ case WM_NOTIFY:
+ case WM_COMMAND:
+ return SendMessage(hwndview, message, wParam, lParam);
}
- case WM_ERASEBKGND:
- return 1; // well, we don't need to erase to redraw cleanly
-
- /* Mouse events */
-
- case WM_LBUTTONDOWN:
- SetFocus(hwndview);
- oldx = x; oldy = y;
- handlemouse(x, y, 1, 1);
- return 0;
- case WM_MBUTTONDOWN:
- SetFocus(hwndview);
- oldx = x; oldy = y;
- handlemouse(x, y, 2, 1);
- return 0;
- case WM_RBUTTONDOWN:
- SetFocus(hwndview);
- oldx = x; oldy = y;
- handlemouse(x, y, 3, 1);
- return 0;
-
- case WM_LBUTTONUP:
- oldx = x; oldy = y;
- handlemouse(x, y, 1, -1);
- return 0;
- case WM_MBUTTONUP:
- oldx = x; oldy = y;
- handlemouse(x, y, 2, -1);
- return 0;
- case WM_RBUTTONUP:
- oldx = x; oldy = y;
- handlemouse(x, y, 3, -1);
- return 0;
-
- case WM_MOUSEMOVE:
- oldx = x; oldy = y;
- handlemouse(x, y, 0, 0);
- return 0;
-
- /* Mouse wheel */
- case WM_MOUSEWHEEL:
- if ((signed short)HIWORD(wParam) > 0)
- handlekey(LOWORD(wParam) & MK_SHIFT ? '+' : 'u');
- else
- handlekey(LOWORD(wParam) & MK_SHIFT ? '-' : 'd');
- return 0;
+ return DefWindowProc(hwnd, message, wParam, lParam);
+}
- /* Keyboard events */
+LRESULT CALLBACK
+viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ static int oldx = 0;
+ static int oldy = 0;
+ int x = (signed short) LOWORD(lParam);
+ int y = (signed short) HIWORD(lParam);
- case WM_KEYDOWN:
- /* only handle special keys */
- switch (wParam)
+ switch (message)
{
- case VK_F1:
- case VK_LEFT:
- case VK_UP:
- case VK_PRIOR:
- case VK_RIGHT:
- case VK_DOWN:
- case VK_NEXT:
- case VK_ESCAPE:
- handlekey(wParam);
- handlemouse(oldx, oldy, 0, 0); /* update cursor */
- return 0;
+ case WM_SIZE:
+ if (wParam == SIZE_MINIMIZED)
+ return 0;
+ if (wParam == SIZE_MAXIMIZED)
+ gapp.shrinkwrap = 0;
+ pdfapp_onresize(&gapp, LOWORD(lParam), HIWORD(lParam));
+ break;
+
+ /* Paint events are low priority and automagically catenated
+ * so we don't need to do any fancy waiting to defer repainting.
+ */
+ case WM_PAINT:
+ {
+ //puts("WM_PAINT");
+ PAINTSTRUCT ps;
+ hdc = BeginPaint(hwnd, &ps);
+ winblit();
+ hdc = NULL;
+ EndPaint(hwnd, &ps);
+ return 0;
+ }
+
+ case WM_ERASEBKGND:
+ return 1; // well, we don't need to erase to redraw cleanly
+
+ /* Mouse events */
+
+ case WM_LBUTTONDOWN:
+ SetFocus(hwndview);
+ oldx = x; oldy = y;
+ handlemouse(x, y, 1, 1);
+ return 0;
+ case WM_MBUTTONDOWN:
+ SetFocus(hwndview);
+ oldx = x; oldy = y;
+ handlemouse(x, y, 2, 1);
+ return 0;
+ case WM_RBUTTONDOWN:
+ SetFocus(hwndview);
+ oldx = x; oldy = y;
+ handlemouse(x, y, 3, 1);
+ return 0;
+
+ case WM_LBUTTONUP:
+ oldx = x; oldy = y;
+ handlemouse(x, y, 1, -1);
+ return 0;
+ case WM_MBUTTONUP:
+ oldx = x; oldy = y;
+ handlemouse(x, y, 2, -1);
+ return 0;
+ case WM_RBUTTONUP:
+ oldx = x; oldy = y;
+ handlemouse(x, y, 3, -1);
+ return 0;
+
+ case WM_MOUSEMOVE:
+ oldx = x; oldy = y;
+ handlemouse(x, y, 0, 0);
+ return 0;
+
+ /* Mouse wheel */
+ case WM_MOUSEWHEEL:
+ if ((signed short)HIWORD(wParam) > 0)
+ handlekey(LOWORD(wParam) & MK_SHIFT ? '+' : 'u');
+ else
+ handlekey(LOWORD(wParam) & MK_SHIFT ? '-' : 'd');
+ return 0;
+
+ /* Keyboard events */
+
+ case WM_KEYDOWN:
+ /* only handle special keys */
+ switch (wParam)
+ {
+ case VK_F1:
+ case VK_LEFT:
+ case VK_UP:
+ case VK_PRIOR:
+ case VK_RIGHT:
+ case VK_DOWN:
+ case VK_NEXT:
+ case VK_ESCAPE:
+ handlekey(wParam);
+ handlemouse(oldx, oldy, 0, 0); /* update cursor */
+ return 0;
+ }
+ return 1;
+
+ /* unicode encoded chars, including escape, backspace etc... */
+ case WM_CHAR:
+ handlekey(wParam);
+ handlemouse(oldx, oldy, 0, 0); /* update cursor */
+ return 0;
}
- return 1;
-
- /* unicode encoded chars, including escape, backspace etc... */
- case WM_CHAR:
- handlekey(wParam);
- handlemouse(oldx, oldy, 0, 0); /* update cursor */
- return 0;
- }
- fflush(stdout);
+ fflush(stdout);
- /* Pass on unhandled events to Windows */
- return DefWindowProc(hwnd, message, wParam, lParam);
+ /* Pass on unhandled events to Windows */
+ return DefWindowProc(hwnd, message, wParam, lParam);
}
int main(int argc, char **argv)
{
- MSG msg;
- char buf[1024];
- char *filename;
+ MSG msg;
+ char buf[1024];
+ char *filename;
- fz_cpudetect();
- fz_accelerate();
+ fz_cpudetect();
+ fz_accelerate();
- pdfapp_init(&gapp);
+ pdfapp_init(&gapp);
- associate(argv[0]);
- winopen();
+ associate(argv[0]);
+ winopen();
- if (argc == 2)
- filename = fz_strdup(argv[1]);
- else
- {
- if (!winfilename(buf, sizeof buf))
- exit(0);
- filename = buf;
- }
+ if (argc == 2)
+ filename = fz_strdup(argv[1]);
+ else
+ {
+ if (!winfilename(buf, sizeof buf))
+ exit(0);
+ filename = buf;
+ }
- pdfapp_open(&gapp, filename);
+ pdfapp_open(&gapp, filename);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
+ while (GetMessage(&msg, NULL, 0, 0))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
- pdfapp_close(&gapp);
+ pdfapp_close(&gapp);
- return 0;
+ return 0;
}