diff options
79 files changed, 5169 insertions, 4935 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; } diff --git a/fitz/base_cpudep.c b/fitz/base_cpudep.c index 9dcaa1cc..e9956bd2 100644 --- a/fitz/base_cpudep.c +++ b/fitz/base_cpudep.c @@ -98,7 +98,7 @@ static const featuretest features[] = { { mmxext, HAVE_MMXEXT, "mmxext" }, { sse, HAVE_SSE, "sse" }, { sse2, HAVE_SSE2, "sse2" }, -/* { sse3, HAVE_SSE3, "sse3" }, */ + /* { sse3, HAVE_SSE3, "sse3" }, */ #ifdef ARCH_X86_64 { amd64, HAVE_AMD64, "amd64" } #endif @@ -266,7 +266,7 @@ void fz_cpudetect(void) /* static __attribute__((constructor, used)) void fzcpudetect(void) { - fz_cpudetect(); +fz_cpudetect(); } */ diff --git a/fitz/base_error.c b/fitz/base_error.c index 5c52e330..fd07bb78 100644 --- a/fitz/base_error.c +++ b/fitz/base_error.c @@ -7,72 +7,72 @@ static int fz_errorclear = 1; static void fz_printerror(int type, const char *file, int line, const char *func, char *msg) { - char buf[100]; - int len; + char buf[100]; + int len; - snprintf(buf, sizeof buf, "%c %s:%d: %s(): %s", type, file, line, func, msg); - len = strlen(buf); + snprintf(buf, sizeof buf, "%c %s:%d: %s(): %s", type, file, line, func, msg); + len = strlen(buf); - fputs(buf, stderr); - putc('\n', stderr); + fputs(buf, stderr); + putc('\n', stderr); - if (fz_errorclear) - { - fz_errorclear = 0; - fz_errorlen = 0; - memset(fz_errorbuf, 0, sizeof fz_errorbuf); - } + if (fz_errorclear) + { + fz_errorclear = 0; + fz_errorlen = 0; + memset(fz_errorbuf, 0, sizeof fz_errorbuf); + } - if (fz_errorlen + len + 2 < sizeof fz_errorbuf) - { - memcpy(fz_errorbuf + fz_errorlen, buf, len); - fz_errorlen += len; - fz_errorbuf[fz_errorlen++] = '\n'; - fz_errorbuf[fz_errorlen] = 0; - } + if (fz_errorlen + len + 2 < sizeof fz_errorbuf) + { + memcpy(fz_errorbuf + fz_errorlen, buf, len); + fz_errorlen += len; + fz_errorbuf[fz_errorlen++] = '\n'; + fz_errorbuf[fz_errorlen] = 0; + } } void fz_warn(char *fmt, ...) { - va_list ap; - fprintf(stderr, "warning: "); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); + va_list ap; + fprintf(stderr, "warning: "); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); } fz_error fz_throwimp(const char *file, int line, const char *func, char *fmt, ...) { - char buf[100]; - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, sizeof buf, fmt, ap); - va_end(ap); - fz_printerror('+', file, line, func, buf); - return -1; + char buf[100]; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, sizeof buf, fmt, ap); + va_end(ap); + fz_printerror('+', file, line, func, buf); + return -1; } fz_error fz_rethrowimp(fz_error cause, const char *file, int line, const char *func, char *fmt, ...) { - char buf[100]; - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, sizeof buf, fmt, ap); - va_end(ap); - fz_printerror('|', file, line, func, buf); - return cause; + char buf[100]; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, sizeof buf, fmt, ap); + va_end(ap); + fz_printerror('|', file, line, func, buf); + return cause; } fz_error fz_catchimp(fz_error cause, const char *file, int line, const char *func, char *fmt, ...) { - char buf[100]; - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, sizeof buf, fmt, ap); - va_end(ap); - fz_printerror('\\', file, line, func, buf); - fz_errorclear = 1; - return cause; + char buf[100]; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, sizeof buf, fmt, ap); + va_end(ap); + fz_printerror('\\', file, line, func, buf); + fz_errorclear = 1; + return cause; } diff --git a/fitz/base_hash.c b/fitz/base_hash.c index cd866041..927cc104 100644 --- a/fitz/base_hash.c +++ b/fitz/base_hash.c @@ -203,8 +203,8 @@ fz_hashremove(fz_hashtable *table, void *key) { code = hash(ents[look].key, table->keylen) % size; if ((code <= hole && hole < look) || - (look < code && code <= hole) || - (hole < look && look < code)) + (look < code && code <= hole) || + (hole < look && look < code)) { ents[hole] = ents[look]; ents[look].val = nil; diff --git a/fitz/base_matrix.c b/fitz/base_matrix.c index 43de613d..42481733 100644 --- a/fitz/base_matrix.c +++ b/fitz/base_matrix.c @@ -13,8 +13,8 @@ void fz_invert3x3(float *dst, float *m) (c1 * D2(a2,a3,b2,b3)) det = D3(M3(m,0,0), M3(m,1,0), M3(m,2,0), - M3(m,0,1), M3(m,1,1), M3(m,2,1), - M3(m,0,2), M3(m,1,2), M3(m,2,2)); + M3(m,0,1), M3(m,1,1), M3(m,2,1), + M3(m,0,2), M3(m,1,2), M3(m,2,2)); if (det == 0) det = 1.0; det = 1.0 / det; @@ -140,7 +140,7 @@ int fz_isrectilinear(fz_matrix m) { return (fabs(m.b) < FLT_EPSILON && fabs(m.c) < FLT_EPSILON) || - (fabs(m.a) < FLT_EPSILON && fabs(m.d) < FLT_EPSILON); + (fabs(m.a) < FLT_EPSILON && fabs(m.d) < FLT_EPSILON); } float diff --git a/fitz/base_string.c b/fitz/base_string.c index f0fd4522..e4b8eb67 100644 --- a/fitz/base_string.c +++ b/fitz/base_string.c @@ -3,62 +3,62 @@ char *fz_strsep(char **stringp, const char *delim) { - char *ret = *stringp; - if (ret == NULL) return NULL; - if ((*stringp = strpbrk(*stringp, delim)) != NULL) - *((*stringp)++) = '\0'; - return ret; + char *ret = *stringp; + if (ret == NULL) return NULL; + if ((*stringp = strpbrk(*stringp, delim)) != NULL) + *((*stringp)++) = '\0'; + return ret; } int fz_strlcpy(char *dst, const char *src, int siz) { - register char *d = dst; - register const char *s = src; - register int n = siz; + register char *d = dst; + register const char *s = src; + register int n = siz; - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } - return(s - src - 1); /* count does not include NUL */ + return(s - src - 1); /* count does not include NUL */ } int fz_strlcat(char *dst, const char *src, int siz) { - register char *d = dst; - register const char *s = src; - register int n = siz; - int dlen; + register char *d = dst; + register const char *s = src; + register int n = siz; + int dlen; - /* Find the end of dst and adjust bytes left but don't go past end */ - while (*d != '\0' && n-- != 0) - d++; - dlen = d - dst; - n = siz - dlen; + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != '\0' && n-- != 0) + d++; + dlen = d - dst; + n = siz - dlen; - if (n == 0) - return dlen + strlen(s); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; + if (n == 0) + return dlen + strlen(s); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; } - s++; - } - *d = '\0'; + *d = '\0'; - return dlen + (s - src); /* count does not include NUL */ + return dlen + (s - src); /* count does not include NUL */ } diff --git a/fitz/crypt_aes.c b/fitz/crypt_aes.c index 8f706813..246739da 100644 --- a/fitz/crypt_aes.c +++ b/fitz/crypt_aes.c @@ -1,39 +1,39 @@ /* - * FIPS-197 compliant AES implementation + * FIPS-197 compliant AES implementation * - * Copyright (C) 2006-2007 Christophe Devine + * Copyright (C) 2006-2007 Christophe Devine * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: * - * * Redistributions of source code _must_ retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form may or may not reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of XySSL nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code _must_ retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form may or may not reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of XySSL nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* - * The AES block cipher was designed by Vincent Rijmen and Joan Daemen. + * The AES block cipher was designed by Vincent Rijmen and Joan Daemen. * - * http://csrc.nist.gov/encryption/aes/rijndael/Rijndael.pdf - * http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf + * http://csrc.nist.gov/encryption/aes/rijndael/Rijndael.pdf + * http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf */ #include "fitz_base.h" @@ -47,22 +47,22 @@ * 32-bit integer manipulation macros (little endian) */ #ifndef GET_ULONG_LE -#define GET_ULONG_LE(n,b,i) \ -{ \ - (n) = ( (unsigned long) (b)[(i) ] ) \ - | ( (unsigned long) (b)[(i) + 1] << 8 ) \ - | ( (unsigned long) (b)[(i) + 2] << 16 ) \ - | ( (unsigned long) (b)[(i) + 3] << 24 ); \ +#define GET_ULONG_LE(n,b,i) \ +{ \ + (n) = ( (unsigned long) (b)[(i) ] ) \ + | ( (unsigned long) (b)[(i) + 1] << 8 ) \ + | ( (unsigned long) (b)[(i) + 2] << 16 ) \ + | ( (unsigned long) (b)[(i) + 3] << 24 ); \ } #endif #ifndef PUT_ULONG_LE -#define PUT_ULONG_LE(n,b,i) \ -{ \ - (b)[(i) ] = (unsigned char) ( (n) ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \ +#define PUT_ULONG_LE(n,b,i) \ +{ \ + (b)[(i) ] = (unsigned char) ( (n) ); \ + (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \ + (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \ + (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \ } #endif @@ -72,38 +72,38 @@ */ static const unsigned char FSb[256] = { - 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, - 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, - 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, - 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, - 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, - 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, - 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, - 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, - 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, - 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, - 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, - 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, - 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, - 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, - 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, - 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, - 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, - 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, - 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, - 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, - 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, - 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, - 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, - 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, - 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, - 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, - 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, - 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, - 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, - 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, - 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, - 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, + 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, + 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, + 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, + 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, + 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, + 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, + 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, + 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, + 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, + 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, + 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, + 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, + 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, + 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, + 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, + 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, + 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, + 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, + 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, + 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, + 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, + 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, + 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, + 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, + 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, + 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, + 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, + 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, + 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, + 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 }; /* @@ -111,70 +111,70 @@ static const unsigned char FSb[256] = */ #define FT \ \ - V(A5,63,63,C6), V(84,7C,7C,F8), V(99,77,77,EE), V(8D,7B,7B,F6), \ - V(0D,F2,F2,FF), V(BD,6B,6B,D6), V(B1,6F,6F,DE), V(54,C5,C5,91), \ - V(50,30,30,60), V(03,01,01,02), V(A9,67,67,CE), V(7D,2B,2B,56), \ - V(19,FE,FE,E7), V(62,D7,D7,B5), V(E6,AB,AB,4D), V(9A,76,76,EC), \ - V(45,CA,CA,8F), V(9D,82,82,1F), V(40,C9,C9,89), V(87,7D,7D,FA), \ - V(15,FA,FA,EF), V(EB,59,59,B2), V(C9,47,47,8E), V(0B,F0,F0,FB), \ - V(EC,AD,AD,41), V(67,D4,D4,B3), V(FD,A2,A2,5F), V(EA,AF,AF,45), \ - V(BF,9C,9C,23), V(F7,A4,A4,53), V(96,72,72,E4), V(5B,C0,C0,9B), \ - V(C2,B7,B7,75), V(1C,FD,FD,E1), V(AE,93,93,3D), V(6A,26,26,4C), \ - V(5A,36,36,6C), V(41,3F,3F,7E), V(02,F7,F7,F5), V(4F,CC,CC,83), \ - V(5C,34,34,68), V(F4,A5,A5,51), V(34,E5,E5,D1), V(08,F1,F1,F9), \ - V(93,71,71,E2), V(73,D8,D8,AB), V(53,31,31,62), V(3F,15,15,2A), \ - V(0C,04,04,08), V(52,C7,C7,95), V(65,23,23,46), V(5E,C3,C3,9D), \ - V(28,18,18,30), V(A1,96,96,37), V(0F,05,05,0A), V(B5,9A,9A,2F), \ - V(09,07,07,0E), V(36,12,12,24), V(9B,80,80,1B), V(3D,E2,E2,DF), \ - V(26,EB,EB,CD), V(69,27,27,4E), V(CD,B2,B2,7F), V(9F,75,75,EA), \ - V(1B,09,09,12), V(9E,83,83,1D), V(74,2C,2C,58), V(2E,1A,1A,34), \ - V(2D,1B,1B,36), V(B2,6E,6E,DC), V(EE,5A,5A,B4), V(FB,A0,A0,5B), \ - V(F6,52,52,A4), V(4D,3B,3B,76), V(61,D6,D6,B7), V(CE,B3,B3,7D), \ - V(7B,29,29,52), V(3E,E3,E3,DD), V(71,2F,2F,5E), V(97,84,84,13), \ - V(F5,53,53,A6), V(68,D1,D1,B9), V(00,00,00,00), V(2C,ED,ED,C1), \ - V(60,20,20,40), V(1F,FC,FC,E3), V(C8,B1,B1,79), V(ED,5B,5B,B6), \ - V(BE,6A,6A,D4), V(46,CB,CB,8D), V(D9,BE,BE,67), V(4B,39,39,72), \ - V(DE,4A,4A,94), V(D4,4C,4C,98), V(E8,58,58,B0), V(4A,CF,CF,85), \ - V(6B,D0,D0,BB), V(2A,EF,EF,C5), V(E5,AA,AA,4F), V(16,FB,FB,ED), \ - V(C5,43,43,86), V(D7,4D,4D,9A), V(55,33,33,66), V(94,85,85,11), \ - V(CF,45,45,8A), V(10,F9,F9,E9), V(06,02,02,04), V(81,7F,7F,FE), \ - V(F0,50,50,A0), V(44,3C,3C,78), V(BA,9F,9F,25), V(E3,A8,A8,4B), \ - V(F3,51,51,A2), V(FE,A3,A3,5D), V(C0,40,40,80), V(8A,8F,8F,05), \ - V(AD,92,92,3F), V(BC,9D,9D,21), V(48,38,38,70), V(04,F5,F5,F1), \ - V(DF,BC,BC,63), V(C1,B6,B6,77), V(75,DA,DA,AF), V(63,21,21,42), \ - V(30,10,10,20), V(1A,FF,FF,E5), V(0E,F3,F3,FD), V(6D,D2,D2,BF), \ - V(4C,CD,CD,81), V(14,0C,0C,18), V(35,13,13,26), V(2F,EC,EC,C3), \ - V(E1,5F,5F,BE), V(A2,97,97,35), V(CC,44,44,88), V(39,17,17,2E), \ - V(57,C4,C4,93), V(F2,A7,A7,55), V(82,7E,7E,FC), V(47,3D,3D,7A), \ - V(AC,64,64,C8), V(E7,5D,5D,BA), V(2B,19,19,32), V(95,73,73,E6), \ - V(A0,60,60,C0), V(98,81,81,19), V(D1,4F,4F,9E), V(7F,DC,DC,A3), \ - V(66,22,22,44), V(7E,2A,2A,54), V(AB,90,90,3B), V(83,88,88,0B), \ - V(CA,46,46,8C), V(29,EE,EE,C7), V(D3,B8,B8,6B), V(3C,14,14,28), \ - V(79,DE,DE,A7), V(E2,5E,5E,BC), V(1D,0B,0B,16), V(76,DB,DB,AD), \ - V(3B,E0,E0,DB), V(56,32,32,64), V(4E,3A,3A,74), V(1E,0A,0A,14), \ - V(DB,49,49,92), V(0A,06,06,0C), V(6C,24,24,48), V(E4,5C,5C,B8), \ - V(5D,C2,C2,9F), V(6E,D3,D3,BD), V(EF,AC,AC,43), V(A6,62,62,C4), \ - V(A8,91,91,39), V(A4,95,95,31), V(37,E4,E4,D3), V(8B,79,79,F2), \ - V(32,E7,E7,D5), V(43,C8,C8,8B), V(59,37,37,6E), V(B7,6D,6D,DA), \ - V(8C,8D,8D,01), V(64,D5,D5,B1), V(D2,4E,4E,9C), V(E0,A9,A9,49), \ - V(B4,6C,6C,D8), V(FA,56,56,AC), V(07,F4,F4,F3), V(25,EA,EA,CF), \ - V(AF,65,65,CA), V(8E,7A,7A,F4), V(E9,AE,AE,47), V(18,08,08,10), \ - V(D5,BA,BA,6F), V(88,78,78,F0), V(6F,25,25,4A), V(72,2E,2E,5C), \ - V(24,1C,1C,38), V(F1,A6,A6,57), V(C7,B4,B4,73), V(51,C6,C6,97), \ - V(23,E8,E8,CB), V(7C,DD,DD,A1), V(9C,74,74,E8), V(21,1F,1F,3E), \ - V(DD,4B,4B,96), V(DC,BD,BD,61), V(86,8B,8B,0D), V(85,8A,8A,0F), \ - V(90,70,70,E0), V(42,3E,3E,7C), V(C4,B5,B5,71), V(AA,66,66,CC), \ - V(D8,48,48,90), V(05,03,03,06), V(01,F6,F6,F7), V(12,0E,0E,1C), \ - V(A3,61,61,C2), V(5F,35,35,6A), V(F9,57,57,AE), V(D0,B9,B9,69), \ - V(91,86,86,17), V(58,C1,C1,99), V(27,1D,1D,3A), V(B9,9E,9E,27), \ - V(38,E1,E1,D9), V(13,F8,F8,EB), V(B3,98,98,2B), V(33,11,11,22), \ - V(BB,69,69,D2), V(70,D9,D9,A9), V(89,8E,8E,07), V(A7,94,94,33), \ - V(B6,9B,9B,2D), V(22,1E,1E,3C), V(92,87,87,15), V(20,E9,E9,C9), \ - V(49,CE,CE,87), V(FF,55,55,AA), V(78,28,28,50), V(7A,DF,DF,A5), \ - V(8F,8C,8C,03), V(F8,A1,A1,59), V(80,89,89,09), V(17,0D,0D,1A), \ - V(DA,BF,BF,65), V(31,E6,E6,D7), V(C6,42,42,84), V(B8,68,68,D0), \ - V(C3,41,41,82), V(B0,99,99,29), V(77,2D,2D,5A), V(11,0F,0F,1E), \ - V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C) + V(A5,63,63,C6), V(84,7C,7C,F8), V(99,77,77,EE), V(8D,7B,7B,F6), \ + V(0D,F2,F2,FF), V(BD,6B,6B,D6), V(B1,6F,6F,DE), V(54,C5,C5,91), \ + V(50,30,30,60), V(03,01,01,02), V(A9,67,67,CE), V(7D,2B,2B,56), \ + V(19,FE,FE,E7), V(62,D7,D7,B5), V(E6,AB,AB,4D), V(9A,76,76,EC), \ + V(45,CA,CA,8F), V(9D,82,82,1F), V(40,C9,C9,89), V(87,7D,7D,FA), \ + V(15,FA,FA,EF), V(EB,59,59,B2), V(C9,47,47,8E), V(0B,F0,F0,FB), \ + V(EC,AD,AD,41), V(67,D4,D4,B3), V(FD,A2,A2,5F), V(EA,AF,AF,45), \ + V(BF,9C,9C,23), V(F7,A4,A4,53), V(96,72,72,E4), V(5B,C0,C0,9B), \ + V(C2,B7,B7,75), V(1C,FD,FD,E1), V(AE,93,93,3D), V(6A,26,26,4C), \ + V(5A,36,36,6C), V(41,3F,3F,7E), V(02,F7,F7,F5), V(4F,CC,CC,83), \ + V(5C,34,34,68), V(F4,A5,A5,51), V(34,E5,E5,D1), V(08,F1,F1,F9), \ + V(93,71,71,E2), V(73,D8,D8,AB), V(53,31,31,62), V(3F,15,15,2A), \ + V(0C,04,04,08), V(52,C7,C7,95), V(65,23,23,46), V(5E,C3,C3,9D), \ + V(28,18,18,30), V(A1,96,96,37), V(0F,05,05,0A), V(B5,9A,9A,2F), \ + V(09,07,07,0E), V(36,12,12,24), V(9B,80,80,1B), V(3D,E2,E2,DF), \ + V(26,EB,EB,CD), V(69,27,27,4E), V(CD,B2,B2,7F), V(9F,75,75,EA), \ + V(1B,09,09,12), V(9E,83,83,1D), V(74,2C,2C,58), V(2E,1A,1A,34), \ + V(2D,1B,1B,36), V(B2,6E,6E,DC), V(EE,5A,5A,B4), V(FB,A0,A0,5B), \ + V(F6,52,52,A4), V(4D,3B,3B,76), V(61,D6,D6,B7), V(CE,B3,B3,7D), \ + V(7B,29,29,52), V(3E,E3,E3,DD), V(71,2F,2F,5E), V(97,84,84,13), \ + V(F5,53,53,A6), V(68,D1,D1,B9), V(00,00,00,00), V(2C,ED,ED,C1), \ + V(60,20,20,40), V(1F,FC,FC,E3), V(C8,B1,B1,79), V(ED,5B,5B,B6), \ + V(BE,6A,6A,D4), V(46,CB,CB,8D), V(D9,BE,BE,67), V(4B,39,39,72), \ + V(DE,4A,4A,94), V(D4,4C,4C,98), V(E8,58,58,B0), V(4A,CF,CF,85), \ + V(6B,D0,D0,BB), V(2A,EF,EF,C5), V(E5,AA,AA,4F), V(16,FB,FB,ED), \ + V(C5,43,43,86), V(D7,4D,4D,9A), V(55,33,33,66), V(94,85,85,11), \ + V(CF,45,45,8A), V(10,F9,F9,E9), V(06,02,02,04), V(81,7F,7F,FE), \ + V(F0,50,50,A0), V(44,3C,3C,78), V(BA,9F,9F,25), V(E3,A8,A8,4B), \ + V(F3,51,51,A2), V(FE,A3,A3,5D), V(C0,40,40,80), V(8A,8F,8F,05), \ + V(AD,92,92,3F), V(BC,9D,9D,21), V(48,38,38,70), V(04,F5,F5,F1), \ + V(DF,BC,BC,63), V(C1,B6,B6,77), V(75,DA,DA,AF), V(63,21,21,42), \ + V(30,10,10,20), V(1A,FF,FF,E5), V(0E,F3,F3,FD), V(6D,D2,D2,BF), \ + V(4C,CD,CD,81), V(14,0C,0C,18), V(35,13,13,26), V(2F,EC,EC,C3), \ + V(E1,5F,5F,BE), V(A2,97,97,35), V(CC,44,44,88), V(39,17,17,2E), \ + V(57,C4,C4,93), V(F2,A7,A7,55), V(82,7E,7E,FC), V(47,3D,3D,7A), \ + V(AC,64,64,C8), V(E7,5D,5D,BA), V(2B,19,19,32), V(95,73,73,E6), \ + V(A0,60,60,C0), V(98,81,81,19), V(D1,4F,4F,9E), V(7F,DC,DC,A3), \ + V(66,22,22,44), V(7E,2A,2A,54), V(AB,90,90,3B), V(83,88,88,0B), \ + V(CA,46,46,8C), V(29,EE,EE,C7), V(D3,B8,B8,6B), V(3C,14,14,28), \ + V(79,DE,DE,A7), V(E2,5E,5E,BC), V(1D,0B,0B,16), V(76,DB,DB,AD), \ + V(3B,E0,E0,DB), V(56,32,32,64), V(4E,3A,3A,74), V(1E,0A,0A,14), \ + V(DB,49,49,92), V(0A,06,06,0C), V(6C,24,24,48), V(E4,5C,5C,B8), \ + V(5D,C2,C2,9F), V(6E,D3,D3,BD), V(EF,AC,AC,43), V(A6,62,62,C4), \ + V(A8,91,91,39), V(A4,95,95,31), V(37,E4,E4,D3), V(8B,79,79,F2), \ + V(32,E7,E7,D5), V(43,C8,C8,8B), V(59,37,37,6E), V(B7,6D,6D,DA), \ + V(8C,8D,8D,01), V(64,D5,D5,B1), V(D2,4E,4E,9C), V(E0,A9,A9,49), \ + V(B4,6C,6C,D8), V(FA,56,56,AC), V(07,F4,F4,F3), V(25,EA,EA,CF), \ + V(AF,65,65,CA), V(8E,7A,7A,F4), V(E9,AE,AE,47), V(18,08,08,10), \ + V(D5,BA,BA,6F), V(88,78,78,F0), V(6F,25,25,4A), V(72,2E,2E,5C), \ + V(24,1C,1C,38), V(F1,A6,A6,57), V(C7,B4,B4,73), V(51,C6,C6,97), \ + V(23,E8,E8,CB), V(7C,DD,DD,A1), V(9C,74,74,E8), V(21,1F,1F,3E), \ + V(DD,4B,4B,96), V(DC,BD,BD,61), V(86,8B,8B,0D), V(85,8A,8A,0F), \ + V(90,70,70,E0), V(42,3E,3E,7C), V(C4,B5,B5,71), V(AA,66,66,CC), \ + V(D8,48,48,90), V(05,03,03,06), V(01,F6,F6,F7), V(12,0E,0E,1C), \ + V(A3,61,61,C2), V(5F,35,35,6A), V(F9,57,57,AE), V(D0,B9,B9,69), \ + V(91,86,86,17), V(58,C1,C1,99), V(27,1D,1D,3A), V(B9,9E,9E,27), \ + V(38,E1,E1,D9), V(13,F8,F8,EB), V(B3,98,98,2B), V(33,11,11,22), \ + V(BB,69,69,D2), V(70,D9,D9,A9), V(89,8E,8E,07), V(A7,94,94,33), \ + V(B6,9B,9B,2D), V(22,1E,1E,3C), V(92,87,87,15), V(20,E9,E9,C9), \ + V(49,CE,CE,87), V(FF,55,55,AA), V(78,28,28,50), V(7A,DF,DF,A5), \ + V(8F,8C,8C,03), V(F8,A1,A1,59), V(80,89,89,09), V(17,0D,0D,1A), \ + V(DA,BF,BF,65), V(31,E6,E6,D7), V(C6,42,42,84), V(B8,68,68,D0), \ + V(C3,41,41,82), V(B0,99,99,29), V(77,2D,2D,5A), V(11,0F,0F,1E), \ + V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C) #define V(a,b,c,d) 0x##a##b##c##d static const unsigned long FT0[256] = { FT }; @@ -199,38 +199,38 @@ static const unsigned long FT3[256] = { FT }; */ static const unsigned char RSb[256] = { - 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, - 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, - 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, - 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, - 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, - 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, - 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, - 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, - 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, - 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, - 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, - 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, - 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, - 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, - 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, - 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, - 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, - 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, - 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, - 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, - 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, - 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, - 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, - 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, - 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, - 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, - 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, - 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, - 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, - 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, - 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, - 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, + 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, + 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, + 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, + 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, + 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, + 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, + 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, + 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, + 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, + 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, + 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, + 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, + 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, + 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, + 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, + 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, + 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, + 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, + 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, + 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, + 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, + 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, + 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, + 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, + 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, + 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, + 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, + 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D }; /* @@ -238,70 +238,70 @@ static const unsigned char RSb[256] = */ #define RT \ \ - V(50,A7,F4,51), V(53,65,41,7E), V(C3,A4,17,1A), V(96,5E,27,3A), \ - V(CB,6B,AB,3B), V(F1,45,9D,1F), V(AB,58,FA,AC), V(93,03,E3,4B), \ - V(55,FA,30,20), V(F6,6D,76,AD), V(91,76,CC,88), V(25,4C,02,F5), \ - V(FC,D7,E5,4F), V(D7,CB,2A,C5), V(80,44,35,26), V(8F,A3,62,B5), \ - V(49,5A,B1,DE), V(67,1B,BA,25), V(98,0E,EA,45), V(E1,C0,FE,5D), \ - V(02,75,2F,C3), V(12,F0,4C,81), V(A3,97,46,8D), V(C6,F9,D3,6B), \ - V(E7,5F,8F,03), V(95,9C,92,15), V(EB,7A,6D,BF), V(DA,59,52,95), \ - V(2D,83,BE,D4), V(D3,21,74,58), V(29,69,E0,49), V(44,C8,C9,8E), \ - V(6A,89,C2,75), V(78,79,8E,F4), V(6B,3E,58,99), V(DD,71,B9,27), \ - V(B6,4F,E1,BE), V(17,AD,88,F0), V(66,AC,20,C9), V(B4,3A,CE,7D), \ - V(18,4A,DF,63), V(82,31,1A,E5), V(60,33,51,97), V(45,7F,53,62), \ - V(E0,77,64,B1), V(84,AE,6B,BB), V(1C,A0,81,FE), V(94,2B,08,F9), \ - V(58,68,48,70), V(19,FD,45,8F), V(87,6C,DE,94), V(B7,F8,7B,52), \ - V(23,D3,73,AB), V(E2,02,4B,72), V(57,8F,1F,E3), V(2A,AB,55,66), \ - V(07,28,EB,B2), V(03,C2,B5,2F), V(9A,7B,C5,86), V(A5,08,37,D3), \ - V(F2,87,28,30), V(B2,A5,BF,23), V(BA,6A,03,02), V(5C,82,16,ED), \ - V(2B,1C,CF,8A), V(92,B4,79,A7), V(F0,F2,07,F3), V(A1,E2,69,4E), \ - V(CD,F4,DA,65), V(D5,BE,05,06), V(1F,62,34,D1), V(8A,FE,A6,C4), \ - V(9D,53,2E,34), V(A0,55,F3,A2), V(32,E1,8A,05), V(75,EB,F6,A4), \ - V(39,EC,83,0B), V(AA,EF,60,40), V(06,9F,71,5E), V(51,10,6E,BD), \ - V(F9,8A,21,3E), V(3D,06,DD,96), V(AE,05,3E,DD), V(46,BD,E6,4D), \ - V(B5,8D,54,91), V(05,5D,C4,71), V(6F,D4,06,04), V(FF,15,50,60), \ - V(24,FB,98,19), V(97,E9,BD,D6), V(CC,43,40,89), V(77,9E,D9,67), \ - V(BD,42,E8,B0), V(88,8B,89,07), V(38,5B,19,E7), V(DB,EE,C8,79), \ - V(47,0A,7C,A1), V(E9,0F,42,7C), V(C9,1E,84,F8), V(00,00,00,00), \ - V(83,86,80,09), V(48,ED,2B,32), V(AC,70,11,1E), V(4E,72,5A,6C), \ - V(FB,FF,0E,FD), V(56,38,85,0F), V(1E,D5,AE,3D), V(27,39,2D,36), \ - V(64,D9,0F,0A), V(21,A6,5C,68), V(D1,54,5B,9B), V(3A,2E,36,24), \ - V(B1,67,0A,0C), V(0F,E7,57,93), V(D2,96,EE,B4), V(9E,91,9B,1B), \ - V(4F,C5,C0,80), V(A2,20,DC,61), V(69,4B,77,5A), V(16,1A,12,1C), \ - V(0A,BA,93,E2), V(E5,2A,A0,C0), V(43,E0,22,3C), V(1D,17,1B,12), \ - V(0B,0D,09,0E), V(AD,C7,8B,F2), V(B9,A8,B6,2D), V(C8,A9,1E,14), \ - V(85,19,F1,57), V(4C,07,75,AF), V(BB,DD,99,EE), V(FD,60,7F,A3), \ - V(9F,26,01,F7), V(BC,F5,72,5C), V(C5,3B,66,44), V(34,7E,FB,5B), \ - V(76,29,43,8B), V(DC,C6,23,CB), V(68,FC,ED,B6), V(63,F1,E4,B8), \ - V(CA,DC,31,D7), V(10,85,63,42), V(40,22,97,13), V(20,11,C6,84), \ - V(7D,24,4A,85), V(F8,3D,BB,D2), V(11,32,F9,AE), V(6D,A1,29,C7), \ - V(4B,2F,9E,1D), V(F3,30,B2,DC), V(EC,52,86,0D), V(D0,E3,C1,77), \ - V(6C,16,B3,2B), V(99,B9,70,A9), V(FA,48,94,11), V(22,64,E9,47), \ - V(C4,8C,FC,A8), V(1A,3F,F0,A0), V(D8,2C,7D,56), V(EF,90,33,22), \ - V(C7,4E,49,87), V(C1,D1,38,D9), V(FE,A2,CA,8C), V(36,0B,D4,98), \ - V(CF,81,F5,A6), V(28,DE,7A,A5), V(26,8E,B7,DA), V(A4,BF,AD,3F), \ - V(E4,9D,3A,2C), V(0D,92,78,50), V(9B,CC,5F,6A), V(62,46,7E,54), \ - V(C2,13,8D,F6), V(E8,B8,D8,90), V(5E,F7,39,2E), V(F5,AF,C3,82), \ - V(BE,80,5D,9F), V(7C,93,D0,69), V(A9,2D,D5,6F), V(B3,12,25,CF), \ - V(3B,99,AC,C8), V(A7,7D,18,10), V(6E,63,9C,E8), V(7B,BB,3B,DB), \ - V(09,78,26,CD), V(F4,18,59,6E), V(01,B7,9A,EC), V(A8,9A,4F,83), \ - V(65,6E,95,E6), V(7E,E6,FF,AA), V(08,CF,BC,21), V(E6,E8,15,EF), \ - V(D9,9B,E7,BA), V(CE,36,6F,4A), V(D4,09,9F,EA), V(D6,7C,B0,29), \ - V(AF,B2,A4,31), V(31,23,3F,2A), V(30,94,A5,C6), V(C0,66,A2,35), \ - V(37,BC,4E,74), V(A6,CA,82,FC), V(B0,D0,90,E0), V(15,D8,A7,33), \ - V(4A,98,04,F1), V(F7,DA,EC,41), V(0E,50,CD,7F), V(2F,F6,91,17), \ - V(8D,D6,4D,76), V(4D,B0,EF,43), V(54,4D,AA,CC), V(DF,04,96,E4), \ - V(E3,B5,D1,9E), V(1B,88,6A,4C), V(B8,1F,2C,C1), V(7F,51,65,46), \ - V(04,EA,5E,9D), V(5D,35,8C,01), V(73,74,87,FA), V(2E,41,0B,FB), \ - V(5A,1D,67,B3), V(52,D2,DB,92), V(33,56,10,E9), V(13,47,D6,6D), \ - V(8C,61,D7,9A), V(7A,0C,A1,37), V(8E,14,F8,59), V(89,3C,13,EB), \ - V(EE,27,A9,CE), V(35,C9,61,B7), V(ED,E5,1C,E1), V(3C,B1,47,7A), \ - V(59,DF,D2,9C), V(3F,73,F2,55), V(79,CE,14,18), V(BF,37,C7,73), \ - V(EA,CD,F7,53), V(5B,AA,FD,5F), V(14,6F,3D,DF), V(86,DB,44,78), \ - V(81,F3,AF,CA), V(3E,C4,68,B9), V(2C,34,24,38), V(5F,40,A3,C2), \ - V(72,C3,1D,16), V(0C,25,E2,BC), V(8B,49,3C,28), V(41,95,0D,FF), \ - V(71,01,A8,39), V(DE,B3,0C,08), V(9C,E4,B4,D8), V(90,C1,56,64), \ - V(61,84,CB,7B), V(70,B6,32,D5), V(74,5C,6C,48), V(42,57,B8,D0) + V(50,A7,F4,51), V(53,65,41,7E), V(C3,A4,17,1A), V(96,5E,27,3A), \ + V(CB,6B,AB,3B), V(F1,45,9D,1F), V(AB,58,FA,AC), V(93,03,E3,4B), \ + V(55,FA,30,20), V(F6,6D,76,AD), V(91,76,CC,88), V(25,4C,02,F5), \ + V(FC,D7,E5,4F), V(D7,CB,2A,C5), V(80,44,35,26), V(8F,A3,62,B5), \ + V(49,5A,B1,DE), V(67,1B,BA,25), V(98,0E,EA,45), V(E1,C0,FE,5D), \ + V(02,75,2F,C3), V(12,F0,4C,81), V(A3,97,46,8D), V(C6,F9,D3,6B), \ + V(E7,5F,8F,03), V(95,9C,92,15), V(EB,7A,6D,BF), V(DA,59,52,95), \ + V(2D,83,BE,D4), V(D3,21,74,58), V(29,69,E0,49), V(44,C8,C9,8E), \ + V(6A,89,C2,75), V(78,79,8E,F4), V(6B,3E,58,99), V(DD,71,B9,27), \ + V(B6,4F,E1,BE), V(17,AD,88,F0), V(66,AC,20,C9), V(B4,3A,CE,7D), \ + V(18,4A,DF,63), V(82,31,1A,E5), V(60,33,51,97), V(45,7F,53,62), \ + V(E0,77,64,B1), V(84,AE,6B,BB), V(1C,A0,81,FE), V(94,2B,08,F9), \ + V(58,68,48,70), V(19,FD,45,8F), V(87,6C,DE,94), V(B7,F8,7B,52), \ + V(23,D3,73,AB), V(E2,02,4B,72), V(57,8F,1F,E3), V(2A,AB,55,66), \ + V(07,28,EB,B2), V(03,C2,B5,2F), V(9A,7B,C5,86), V(A5,08,37,D3), \ + V(F2,87,28,30), V(B2,A5,BF,23), V(BA,6A,03,02), V(5C,82,16,ED), \ + V(2B,1C,CF,8A), V(92,B4,79,A7), V(F0,F2,07,F3), V(A1,E2,69,4E), \ + V(CD,F4,DA,65), V(D5,BE,05,06), V(1F,62,34,D1), V(8A,FE,A6,C4), \ + V(9D,53,2E,34), V(A0,55,F3,A2), V(32,E1,8A,05), V(75,EB,F6,A4), \ + V(39,EC,83,0B), V(AA,EF,60,40), V(06,9F,71,5E), V(51,10,6E,BD), \ + V(F9,8A,21,3E), V(3D,06,DD,96), V(AE,05,3E,DD), V(46,BD,E6,4D), \ + V(B5,8D,54,91), V(05,5D,C4,71), V(6F,D4,06,04), V(FF,15,50,60), \ + V(24,FB,98,19), V(97,E9,BD,D6), V(CC,43,40,89), V(77,9E,D9,67), \ + V(BD,42,E8,B0), V(88,8B,89,07), V(38,5B,19,E7), V(DB,EE,C8,79), \ + V(47,0A,7C,A1), V(E9,0F,42,7C), V(C9,1E,84,F8), V(00,00,00,00), \ + V(83,86,80,09), V(48,ED,2B,32), V(AC,70,11,1E), V(4E,72,5A,6C), \ + V(FB,FF,0E,FD), V(56,38,85,0F), V(1E,D5,AE,3D), V(27,39,2D,36), \ + V(64,D9,0F,0A), V(21,A6,5C,68), V(D1,54,5B,9B), V(3A,2E,36,24), \ + V(B1,67,0A,0C), V(0F,E7,57,93), V(D2,96,EE,B4), V(9E,91,9B,1B), \ + V(4F,C5,C0,80), V(A2,20,DC,61), V(69,4B,77,5A), V(16,1A,12,1C), \ + V(0A,BA,93,E2), V(E5,2A,A0,C0), V(43,E0,22,3C), V(1D,17,1B,12), \ + V(0B,0D,09,0E), V(AD,C7,8B,F2), V(B9,A8,B6,2D), V(C8,A9,1E,14), \ + V(85,19,F1,57), V(4C,07,75,AF), V(BB,DD,99,EE), V(FD,60,7F,A3), \ + V(9F,26,01,F7), V(BC,F5,72,5C), V(C5,3B,66,44), V(34,7E,FB,5B), \ + V(76,29,43,8B), V(DC,C6,23,CB), V(68,FC,ED,B6), V(63,F1,E4,B8), \ + V(CA,DC,31,D7), V(10,85,63,42), V(40,22,97,13), V(20,11,C6,84), \ + V(7D,24,4A,85), V(F8,3D,BB,D2), V(11,32,F9,AE), V(6D,A1,29,C7), \ + V(4B,2F,9E,1D), V(F3,30,B2,DC), V(EC,52,86,0D), V(D0,E3,C1,77), \ + V(6C,16,B3,2B), V(99,B9,70,A9), V(FA,48,94,11), V(22,64,E9,47), \ + V(C4,8C,FC,A8), V(1A,3F,F0,A0), V(D8,2C,7D,56), V(EF,90,33,22), \ + V(C7,4E,49,87), V(C1,D1,38,D9), V(FE,A2,CA,8C), V(36,0B,D4,98), \ + V(CF,81,F5,A6), V(28,DE,7A,A5), V(26,8E,B7,DA), V(A4,BF,AD,3F), \ + V(E4,9D,3A,2C), V(0D,92,78,50), V(9B,CC,5F,6A), V(62,46,7E,54), \ + V(C2,13,8D,F6), V(E8,B8,D8,90), V(5E,F7,39,2E), V(F5,AF,C3,82), \ + V(BE,80,5D,9F), V(7C,93,D0,69), V(A9,2D,D5,6F), V(B3,12,25,CF), \ + V(3B,99,AC,C8), V(A7,7D,18,10), V(6E,63,9C,E8), V(7B,BB,3B,DB), \ + V(09,78,26,CD), V(F4,18,59,6E), V(01,B7,9A,EC), V(A8,9A,4F,83), \ + V(65,6E,95,E6), V(7E,E6,FF,AA), V(08,CF,BC,21), V(E6,E8,15,EF), \ + V(D9,9B,E7,BA), V(CE,36,6F,4A), V(D4,09,9F,EA), V(D6,7C,B0,29), \ + V(AF,B2,A4,31), V(31,23,3F,2A), V(30,94,A5,C6), V(C0,66,A2,35), \ + V(37,BC,4E,74), V(A6,CA,82,FC), V(B0,D0,90,E0), V(15,D8,A7,33), \ + V(4A,98,04,F1), V(F7,DA,EC,41), V(0E,50,CD,7F), V(2F,F6,91,17), \ + V(8D,D6,4D,76), V(4D,B0,EF,43), V(54,4D,AA,CC), V(DF,04,96,E4), \ + V(E3,B5,D1,9E), V(1B,88,6A,4C), V(B8,1F,2C,C1), V(7F,51,65,46), \ + V(04,EA,5E,9D), V(5D,35,8C,01), V(73,74,87,FA), V(2E,41,0B,FB), \ + V(5A,1D,67,B3), V(52,D2,DB,92), V(33,56,10,E9), V(13,47,D6,6D), \ + V(8C,61,D7,9A), V(7A,0C,A1,37), V(8E,14,F8,59), V(89,3C,13,EB), \ + V(EE,27,A9,CE), V(35,C9,61,B7), V(ED,E5,1C,E1), V(3C,B1,47,7A), \ + V(59,DF,D2,9C), V(3F,73,F2,55), V(79,CE,14,18), V(BF,37,C7,73), \ + V(EA,CD,F7,53), V(5B,AA,FD,5F), V(14,6F,3D,DF), V(86,DB,44,78), \ + V(81,F3,AF,CA), V(3E,C4,68,B9), V(2C,34,24,38), V(5F,40,A3,C2), \ + V(72,C3,1D,16), V(0C,25,E2,BC), V(8B,49,3C,28), V(41,95,0D,FF), \ + V(71,01,A8,39), V(DE,B3,0C,08), V(9C,E4,B4,D8), V(90,C1,56,64), \ + V(61,84,CB,7B), V(70,B6,32,D5), V(74,5C,6C,48), V(42,57,B8,D0) #define V(a,b,c,d) 0x##a##b##c##d static const unsigned long RT0[256] = { RT }; @@ -326,9 +326,9 @@ static const unsigned long RT3[256] = { RT }; */ static const unsigned long RCON[10] = { - 0x00000001, 0x00000002, 0x00000004, 0x00000008, - 0x00000010, 0x00000020, 0x00000040, 0x00000080, - 0x0000001B, 0x00000036 + 0x00000001, 0x00000002, 0x00000004, 0x00000008, + 0x00000010, 0x00000020, 0x00000040, 0x00000080, + 0x0000001B, 0x00000036 }; #else @@ -367,78 +367,78 @@ static int aes_init_done = 0; static void aes_gen_tables( void ) { - int i, x, y, z; - int pow[256]; - int log[256]; - - /* - * compute pow and log tables over GF(2^8) - */ - for( i = 0, x = 1; i < 256; i++ ) - { - pow[i] = x; - log[x] = i; - x = ( x ^ XTIME( x ) ) & 0xFF; - } - - /* - * calculate the round constants - */ - for( i = 0, x = 1; i < 10; i++ ) - { - RCON[i] = (unsigned long) x; - x = XTIME( x ) & 0xFF; - } - - /* - * generate the forward and reverse S-boxes - */ - FSb[0x00] = 0x63; - RSb[0x63] = 0x00; - - for( i = 1; i < 256; i++ ) - { - x = pow[255 - log[i]]; - - y = x; y = ( (y << 1) | (y >> 7) ) & 0xFF; - x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; - x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; - x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; - x ^= y ^ 0x63; - - FSb[i] = (unsigned char) x; - RSb[x] = (unsigned char) i; - } - - /* - * generate the forward and reverse tables - */ - for( i = 0; i < 256; i++ ) - { - x = FSb[i]; - y = XTIME( x ) & 0xFF; - z = ( y ^ x ) & 0xFF; - - FT0[i] = ( (unsigned long) y ) ^ - ( (unsigned long) x << 8 ) ^ - ( (unsigned long) x << 16 ) ^ - ( (unsigned long) z << 24 ); - - FT1[i] = ROTL8( FT0[i] ); - FT2[i] = ROTL8( FT1[i] ); - FT3[i] = ROTL8( FT2[i] ); - - x = RSb[i]; - - RT0[i] = ( (unsigned long) MUL( 0x0E, x ) ) ^ - ( (unsigned long) MUL( 0x09, x ) << 8 ) ^ - ( (unsigned long) MUL( 0x0D, x ) << 16 ) ^ - ( (unsigned long) MUL( 0x0B, x ) << 24 ); - - RT1[i] = ROTL8( RT0[i] ); - RT2[i] = ROTL8( RT1[i] ); - RT3[i] = ROTL8( RT2[i] ); - } + int i, x, y, z; + int pow[256]; + int log[256]; + + /* + * compute pow and log tables over GF(2^8) + */ + for( i = 0, x = 1; i < 256; i++ ) + { + pow[i] = x; + log[x] = i; + x = ( x ^ XTIME( x ) ) & 0xFF; + } + + /* + * calculate the round constants + */ + for( i = 0, x = 1; i < 10; i++ ) + { + RCON[i] = (unsigned long) x; + x = XTIME( x ) & 0xFF; + } + + /* + * generate the forward and reverse S-boxes + */ + FSb[0x00] = 0x63; + RSb[0x63] = 0x00; + + for( i = 1; i < 256; i++ ) + { + x = pow[255 - log[i]]; + + y = x; y = ( (y << 1) | (y >> 7) ) & 0xFF; + x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; + x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; + x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; + x ^= y ^ 0x63; + + FSb[i] = (unsigned char) x; + RSb[x] = (unsigned char) i; + } + + /* + * generate the forward and reverse tables + */ + for( i = 0; i < 256; i++ ) + { + x = FSb[i]; + y = XTIME( x ) & 0xFF; + z = ( y ^ x ) & 0xFF; + + FT0[i] = ( (unsigned long) y ) ^ + ( (unsigned long) x << 8 ) ^ + ( (unsigned long) x << 16 ) ^ + ( (unsigned long) z << 24 ); + + FT1[i] = ROTL8( FT0[i] ); + FT2[i] = ROTL8( FT1[i] ); + FT3[i] = ROTL8( FT2[i] ); + + x = RSb[i]; + + RT0[i] = ( (unsigned long) MUL( 0x0E, x ) ) ^ + ( (unsigned long) MUL( 0x09, x ) << 8 ) ^ + ( (unsigned long) MUL( 0x0D, x ) << 16 ) ^ + ( (unsigned long) MUL( 0x0B, x ) << 24 ); + + RT1[i] = ROTL8( RT0[i] ); + RT2[i] = ROTL8( RT1[i] ); + RT3[i] = ROTL8( RT2[i] ); + } } #endif @@ -448,102 +448,102 @@ static void aes_gen_tables( void ) */ void aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize ) { - int i; - unsigned long *RK; + int i; + unsigned long *RK; #if !defined(XYSSL_AES_ROM_TABLES) - if( aes_init_done == 0 ) - { - aes_gen_tables(); - aes_init_done = 1; - } + if( aes_init_done == 0 ) + { + aes_gen_tables(); + aes_init_done = 1; + } #endif - switch( keysize ) - { - case 128: ctx->nr = 10; break; - case 192: ctx->nr = 12; break; - case 256: ctx->nr = 14; break; - default : return; - } + switch( keysize ) + { + case 128: ctx->nr = 10; break; + case 192: ctx->nr = 12; break; + case 256: ctx->nr = 14; break; + default : return; + } #if defined(PADLOCK_ALIGN16) - ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf ); + ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf ); #else - ctx->rk = RK = ctx->buf; + ctx->rk = RK = ctx->buf; #endif - for( i = 0; i < (keysize >> 5); i++ ) - { - GET_ULONG_LE( RK[i], key, i << 2 ); - } - - switch( ctx->nr ) - { - case 10: - - for( i = 0; i < 10; i++, RK += 4 ) - { - RK[4] = RK[0] ^ RCON[i] ^ - ( FSb[ ( RK[3] >> 8 ) & 0xFF ] ) ^ - ( FSb[ ( RK[3] >> 16 ) & 0xFF ] << 8 ) ^ - ( FSb[ ( RK[3] >> 24 ) & 0xFF ] << 16 ) ^ - ( FSb[ ( RK[3] ) & 0xFF ] << 24 ); - - RK[5] = RK[1] ^ RK[4]; - RK[6] = RK[2] ^ RK[5]; - RK[7] = RK[3] ^ RK[6]; - } - break; - - case 12: - - for( i = 0; i < 8; i++, RK += 6 ) - { - RK[6] = RK[0] ^ RCON[i] ^ - ( FSb[ ( RK[5] >> 8 ) & 0xFF ] ) ^ - ( FSb[ ( RK[5] >> 16 ) & 0xFF ] << 8 ) ^ - ( FSb[ ( RK[5] >> 24 ) & 0xFF ] << 16 ) ^ - ( FSb[ ( RK[5] ) & 0xFF ] << 24 ); - - RK[7] = RK[1] ^ RK[6]; - RK[8] = RK[2] ^ RK[7]; - RK[9] = RK[3] ^ RK[8]; - RK[10] = RK[4] ^ RK[9]; - RK[11] = RK[5] ^ RK[10]; - } - break; - - case 14: - - for( i = 0; i < 7; i++, RK += 8 ) - { - RK[8] = RK[0] ^ RCON[i] ^ - ( FSb[ ( RK[7] >> 8 ) & 0xFF ] ) ^ - ( FSb[ ( RK[7] >> 16 ) & 0xFF ] << 8 ) ^ - ( FSb[ ( RK[7] >> 24 ) & 0xFF ] << 16 ) ^ - ( FSb[ ( RK[7] ) & 0xFF ] << 24 ); - - RK[9] = RK[1] ^ RK[8]; - RK[10] = RK[2] ^ RK[9]; - RK[11] = RK[3] ^ RK[10]; - - RK[12] = RK[4] ^ - ( FSb[ ( RK[11] ) & 0xFF ] ) ^ - ( FSb[ ( RK[11] >> 8 ) & 0xFF ] << 8 ) ^ - ( FSb[ ( RK[11] >> 16 ) & 0xFF ] << 16 ) ^ - ( FSb[ ( RK[11] >> 24 ) & 0xFF ] << 24 ); - - RK[13] = RK[5] ^ RK[12]; - RK[14] = RK[6] ^ RK[13]; - RK[15] = RK[7] ^ RK[14]; - } - break; - - default: - - break; - } + for( i = 0; i < (keysize >> 5); i++ ) + { + GET_ULONG_LE( RK[i], key, i << 2 ); + } + + switch( ctx->nr ) + { + case 10: + + for( i = 0; i < 10; i++, RK += 4 ) + { + RK[4] = RK[0] ^ RCON[i] ^ + ( FSb[ ( RK[3] >> 8 ) & 0xFF ] ) ^ + ( FSb[ ( RK[3] >> 16 ) & 0xFF ] << 8 ) ^ + ( FSb[ ( RK[3] >> 24 ) & 0xFF ] << 16 ) ^ + ( FSb[ ( RK[3] ) & 0xFF ] << 24 ); + + RK[5] = RK[1] ^ RK[4]; + RK[6] = RK[2] ^ RK[5]; + RK[7] = RK[3] ^ RK[6]; + } + break; + + case 12: + + for( i = 0; i < 8; i++, RK += 6 ) + { + RK[6] = RK[0] ^ RCON[i] ^ + ( FSb[ ( RK[5] >> 8 ) & 0xFF ] ) ^ + ( FSb[ ( RK[5] >> 16 ) & 0xFF ] << 8 ) ^ + ( FSb[ ( RK[5] >> 24 ) & 0xFF ] << 16 ) ^ + ( FSb[ ( RK[5] ) & 0xFF ] << 24 ); + + RK[7] = RK[1] ^ RK[6]; + RK[8] = RK[2] ^ RK[7]; + RK[9] = RK[3] ^ RK[8]; + RK[10] = RK[4] ^ RK[9]; + RK[11] = RK[5] ^ RK[10]; + } + break; + + case 14: + + for( i = 0; i < 7; i++, RK += 8 ) + { + RK[8] = RK[0] ^ RCON[i] ^ + ( FSb[ ( RK[7] >> 8 ) & 0xFF ] ) ^ + ( FSb[ ( RK[7] >> 16 ) & 0xFF ] << 8 ) ^ + ( FSb[ ( RK[7] >> 24 ) & 0xFF ] << 16 ) ^ + ( FSb[ ( RK[7] ) & 0xFF ] << 24 ); + + RK[9] = RK[1] ^ RK[8]; + RK[10] = RK[2] ^ RK[9]; + RK[11] = RK[3] ^ RK[10]; + + RK[12] = RK[4] ^ + ( FSb[ ( RK[11] ) & 0xFF ] ) ^ + ( FSb[ ( RK[11] >> 8 ) & 0xFF ] << 8 ) ^ + ( FSb[ ( RK[11] >> 16 ) & 0xFF ] << 16 ) ^ + ( FSb[ ( RK[11] >> 24 ) & 0xFF ] << 24 ); + + RK[13] = RK[5] ^ RK[12]; + RK[14] = RK[6] ^ RK[13]; + RK[15] = RK[7] ^ RK[14]; + } + break; + + default: + + break; + } } /* @@ -551,287 +551,287 @@ void aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize ) */ void aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize ) { - int i, j; - aes_context cty; - unsigned long *RK; - unsigned long *SK; - - switch( keysize ) - { - case 128: ctx->nr = 10; break; - case 192: ctx->nr = 12; break; - case 256: ctx->nr = 14; break; - default : return; - } + int i, j; + aes_context cty; + unsigned long *RK; + unsigned long *SK; + + switch( keysize ) + { + case 128: ctx->nr = 10; break; + case 192: ctx->nr = 12; break; + case 256: ctx->nr = 14; break; + default : return; + } #if defined(PADLOCK_ALIGN16) - ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf ); + ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf ); #else - ctx->rk = RK = ctx->buf; + ctx->rk = RK = ctx->buf; #endif - aes_setkey_enc( &cty, key, keysize ); - SK = cty.rk + cty.nr * 4; - - *RK++ = *SK++; - *RK++ = *SK++; - *RK++ = *SK++; - *RK++ = *SK++; - - for( i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8 ) - { - for( j = 0; j < 4; j++, SK++ ) - { - *RK++ = RT0[ FSb[ ( *SK ) & 0xFF ] ] ^ - RT1[ FSb[ ( *SK >> 8 ) & 0xFF ] ] ^ - RT2[ FSb[ ( *SK >> 16 ) & 0xFF ] ] ^ - RT3[ FSb[ ( *SK >> 24 ) & 0xFF ] ]; - } - } - - *RK++ = *SK++; - *RK++ = *SK++; - *RK++ = *SK++; - *RK++ = *SK++; - - memset( &cty, 0, sizeof( aes_context ) ); + aes_setkey_enc( &cty, key, keysize ); + SK = cty.rk + cty.nr * 4; + + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + + for( i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8 ) + { + for( j = 0; j < 4; j++, SK++ ) + { + *RK++ = RT0[ FSb[ ( *SK ) & 0xFF ] ] ^ + RT1[ FSb[ ( *SK >> 8 ) & 0xFF ] ] ^ + RT2[ FSb[ ( *SK >> 16 ) & 0xFF ] ] ^ + RT3[ FSb[ ( *SK >> 24 ) & 0xFF ] ]; + } + } + + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + + memset( &cty, 0, sizeof( aes_context ) ); } -#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ -{ \ - X0 = *RK++ ^ FT0[ ( Y0 ) & 0xFF ] ^ \ - FT1[ ( Y1 >> 8 ) & 0xFF ] ^ \ - FT2[ ( Y2 >> 16 ) & 0xFF ] ^ \ - FT3[ ( Y3 >> 24 ) & 0xFF ]; \ - \ - X1 = *RK++ ^ FT0[ ( Y1 ) & 0xFF ] ^ \ - FT1[ ( Y2 >> 8 ) & 0xFF ] ^ \ - FT2[ ( Y3 >> 16 ) & 0xFF ] ^ \ - FT3[ ( Y0 >> 24 ) & 0xFF ]; \ - \ - X2 = *RK++ ^ FT0[ ( Y2 ) & 0xFF ] ^ \ - FT1[ ( Y3 >> 8 ) & 0xFF ] ^ \ - FT2[ ( Y0 >> 16 ) & 0xFF ] ^ \ - FT3[ ( Y1 >> 24 ) & 0xFF ]; \ - \ - X3 = *RK++ ^ FT0[ ( Y3 ) & 0xFF ] ^ \ - FT1[ ( Y0 >> 8 ) & 0xFF ] ^ \ - FT2[ ( Y1 >> 16 ) & 0xFF ] ^ \ - FT3[ ( Y2 >> 24 ) & 0xFF ]; \ +#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ +{ \ + X0 = *RK++ ^ FT0[ ( Y0 ) & 0xFF ] ^ \ + FT1[ ( Y1 >> 8 ) & 0xFF ] ^ \ + FT2[ ( Y2 >> 16 ) & 0xFF ] ^ \ + FT3[ ( Y3 >> 24 ) & 0xFF ]; \ + \ + X1 = *RK++ ^ FT0[ ( Y1 ) & 0xFF ] ^ \ + FT1[ ( Y2 >> 8 ) & 0xFF ] ^ \ + FT2[ ( Y3 >> 16 ) & 0xFF ] ^ \ + FT3[ ( Y0 >> 24 ) & 0xFF ]; \ + \ + X2 = *RK++ ^ FT0[ ( Y2 ) & 0xFF ] ^ \ + FT1[ ( Y3 >> 8 ) & 0xFF ] ^ \ + FT2[ ( Y0 >> 16 ) & 0xFF ] ^ \ + FT3[ ( Y1 >> 24 ) & 0xFF ]; \ + \ + X3 = *RK++ ^ FT0[ ( Y3 ) & 0xFF ] ^ \ + FT1[ ( Y0 >> 8 ) & 0xFF ] ^ \ + FT2[ ( Y1 >> 16 ) & 0xFF ] ^ \ + FT3[ ( Y2 >> 24 ) & 0xFF ]; \ } -#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ -{ \ - X0 = *RK++ ^ RT0[ ( Y0 ) & 0xFF ] ^ \ - RT1[ ( Y3 >> 8 ) & 0xFF ] ^ \ - RT2[ ( Y2 >> 16 ) & 0xFF ] ^ \ - RT3[ ( Y1 >> 24 ) & 0xFF ]; \ - \ - X1 = *RK++ ^ RT0[ ( Y1 ) & 0xFF ] ^ \ - RT1[ ( Y0 >> 8 ) & 0xFF ] ^ \ - RT2[ ( Y3 >> 16 ) & 0xFF ] ^ \ - RT3[ ( Y2 >> 24 ) & 0xFF ]; \ - \ - X2 = *RK++ ^ RT0[ ( Y2 ) & 0xFF ] ^ \ - RT1[ ( Y1 >> 8 ) & 0xFF ] ^ \ - RT2[ ( Y0 >> 16 ) & 0xFF ] ^ \ - RT3[ ( Y3 >> 24 ) & 0xFF ]; \ - \ - X3 = *RK++ ^ RT0[ ( Y3 ) & 0xFF ] ^ \ - RT1[ ( Y2 >> 8 ) & 0xFF ] ^ \ - RT2[ ( Y1 >> 16 ) & 0xFF ] ^ \ - RT3[ ( Y0 >> 24 ) & 0xFF ]; \ +#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ +{ \ + X0 = *RK++ ^ RT0[ ( Y0 ) & 0xFF ] ^ \ + RT1[ ( Y3 >> 8 ) & 0xFF ] ^ \ + RT2[ ( Y2 >> 16 ) & 0xFF ] ^ \ + RT3[ ( Y1 >> 24 ) & 0xFF ]; \ + \ + X1 = *RK++ ^ RT0[ ( Y1 ) & 0xFF ] ^ \ + RT1[ ( Y0 >> 8 ) & 0xFF ] ^ \ + RT2[ ( Y3 >> 16 ) & 0xFF ] ^ \ + RT3[ ( Y2 >> 24 ) & 0xFF ]; \ + \ + X2 = *RK++ ^ RT0[ ( Y2 ) & 0xFF ] ^ \ + RT1[ ( Y1 >> 8 ) & 0xFF ] ^ \ + RT2[ ( Y0 >> 16 ) & 0xFF ] ^ \ + RT3[ ( Y3 >> 24 ) & 0xFF ]; \ + \ + X3 = *RK++ ^ RT0[ ( Y3 ) & 0xFF ] ^ \ + RT1[ ( Y2 >> 8 ) & 0xFF ] ^ \ + RT2[ ( Y1 >> 16 ) & 0xFF ] ^ \ + RT3[ ( Y0 >> 24 ) & 0xFF ]; \ } /* * AES-ECB block encryption/decryption */ void aes_crypt_ecb( aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16] ) + int mode, + const unsigned char input[16], + unsigned char output[16] ) { - int i; - unsigned long *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; + int i; + unsigned long *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; #if defined(XYSSL_PADLOCK_C) && defined(XYSSL_HAVE_X86) - if( padlock_supports( PADLOCK_ACE ) ) - { - if( padlock_xcryptecb( ctx, mode, input, output ) == 0 ) - return; - } + if( padlock_supports( PADLOCK_ACE ) ) + { + if( padlock_xcryptecb( ctx, mode, input, output ) == 0 ) + return; + } #endif - RK = ctx->rk; - - GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++; - GET_ULONG_LE( X1, input, 4 ); X1 ^= *RK++; - GET_ULONG_LE( X2, input, 8 ); X2 ^= *RK++; - GET_ULONG_LE( X3, input, 12 ); X3 ^= *RK++; - - if( mode == AES_DECRYPT ) - { - for( i = (ctx->nr >> 1) - 1; i > 0; i-- ) - { - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - } - - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - - X0 = *RK++ ^ ( RSb[ ( Y0 ) & 0xFF ] ) ^ - ( RSb[ ( Y3 >> 8 ) & 0xFF ] << 8 ) ^ - ( RSb[ ( Y2 >> 16 ) & 0xFF ] << 16 ) ^ - ( RSb[ ( Y1 >> 24 ) & 0xFF ] << 24 ); - - X1 = *RK++ ^ ( RSb[ ( Y1 ) & 0xFF ] ) ^ - ( RSb[ ( Y0 >> 8 ) & 0xFF ] << 8 ) ^ - ( RSb[ ( Y3 >> 16 ) & 0xFF ] << 16 ) ^ - ( RSb[ ( Y2 >> 24 ) & 0xFF ] << 24 ); - - X2 = *RK++ ^ ( RSb[ ( Y2 ) & 0xFF ] ) ^ - ( RSb[ ( Y1 >> 8 ) & 0xFF ] << 8 ) ^ - ( RSb[ ( Y0 >> 16 ) & 0xFF ] << 16 ) ^ - ( RSb[ ( Y3 >> 24 ) & 0xFF ] << 24 ); - - X3 = *RK++ ^ ( RSb[ ( Y3 ) & 0xFF ] ) ^ - ( RSb[ ( Y2 >> 8 ) & 0xFF ] << 8 ) ^ - ( RSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^ - ( RSb[ ( Y0 >> 24 ) & 0xFF ] << 24 ); - } - else /* AES_ENCRYPT */ - { - for( i = (ctx->nr >> 1) - 1; i > 0; i-- ) - { - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - } - - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - - X0 = *RK++ ^ ( FSb[ ( Y0 ) & 0xFF ] ) ^ - ( FSb[ ( Y1 >> 8 ) & 0xFF ] << 8 ) ^ - ( FSb[ ( Y2 >> 16 ) & 0xFF ] << 16 ) ^ - ( FSb[ ( Y3 >> 24 ) & 0xFF ] << 24 ); - - X1 = *RK++ ^ ( FSb[ ( Y1 ) & 0xFF ] ) ^ - ( FSb[ ( Y2 >> 8 ) & 0xFF ] << 8 ) ^ - ( FSb[ ( Y3 >> 16 ) & 0xFF ] << 16 ) ^ - ( FSb[ ( Y0 >> 24 ) & 0xFF ] << 24 ); - - X2 = *RK++ ^ ( FSb[ ( Y2 ) & 0xFF ] ) ^ - ( FSb[ ( Y3 >> 8 ) & 0xFF ] << 8 ) ^ - ( FSb[ ( Y0 >> 16 ) & 0xFF ] << 16 ) ^ - ( FSb[ ( Y1 >> 24 ) & 0xFF ] << 24 ); - - X3 = *RK++ ^ ( FSb[ ( Y3 ) & 0xFF ] ) ^ - ( FSb[ ( Y0 >> 8 ) & 0xFF ] << 8 ) ^ - ( FSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^ - ( FSb[ ( Y2 >> 24 ) & 0xFF ] << 24 ); - } - - PUT_ULONG_LE( X0, output, 0 ); - PUT_ULONG_LE( X1, output, 4 ); - PUT_ULONG_LE( X2, output, 8 ); - PUT_ULONG_LE( X3, output, 12 ); + RK = ctx->rk; + + GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++; + GET_ULONG_LE( X1, input, 4 ); X1 ^= *RK++; + GET_ULONG_LE( X2, input, 8 ); X2 ^= *RK++; + GET_ULONG_LE( X3, input, 12 ); X3 ^= *RK++; + + if( mode == AES_DECRYPT ) + { + for( i = (ctx->nr >> 1) - 1; i > 0; i-- ) + { + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); + } + + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); + + X0 = *RK++ ^ ( RSb[ ( Y0 ) & 0xFF ] ) ^ + ( RSb[ ( Y3 >> 8 ) & 0xFF ] << 8 ) ^ + ( RSb[ ( Y2 >> 16 ) & 0xFF ] << 16 ) ^ + ( RSb[ ( Y1 >> 24 ) & 0xFF ] << 24 ); + + X1 = *RK++ ^ ( RSb[ ( Y1 ) & 0xFF ] ) ^ + ( RSb[ ( Y0 >> 8 ) & 0xFF ] << 8 ) ^ + ( RSb[ ( Y3 >> 16 ) & 0xFF ] << 16 ) ^ + ( RSb[ ( Y2 >> 24 ) & 0xFF ] << 24 ); + + X2 = *RK++ ^ ( RSb[ ( Y2 ) & 0xFF ] ) ^ + ( RSb[ ( Y1 >> 8 ) & 0xFF ] << 8 ) ^ + ( RSb[ ( Y0 >> 16 ) & 0xFF ] << 16 ) ^ + ( RSb[ ( Y3 >> 24 ) & 0xFF ] << 24 ); + + X3 = *RK++ ^ ( RSb[ ( Y3 ) & 0xFF ] ) ^ + ( RSb[ ( Y2 >> 8 ) & 0xFF ] << 8 ) ^ + ( RSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^ + ( RSb[ ( Y0 >> 24 ) & 0xFF ] << 24 ); + } + else /* AES_ENCRYPT */ + { + for( i = (ctx->nr >> 1) - 1; i > 0; i-- ) + { + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); + } + + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); + + X0 = *RK++ ^ ( FSb[ ( Y0 ) & 0xFF ] ) ^ + ( FSb[ ( Y1 >> 8 ) & 0xFF ] << 8 ) ^ + ( FSb[ ( Y2 >> 16 ) & 0xFF ] << 16 ) ^ + ( FSb[ ( Y3 >> 24 ) & 0xFF ] << 24 ); + + X1 = *RK++ ^ ( FSb[ ( Y1 ) & 0xFF ] ) ^ + ( FSb[ ( Y2 >> 8 ) & 0xFF ] << 8 ) ^ + ( FSb[ ( Y3 >> 16 ) & 0xFF ] << 16 ) ^ + ( FSb[ ( Y0 >> 24 ) & 0xFF ] << 24 ); + + X2 = *RK++ ^ ( FSb[ ( Y2 ) & 0xFF ] ) ^ + ( FSb[ ( Y3 >> 8 ) & 0xFF ] << 8 ) ^ + ( FSb[ ( Y0 >> 16 ) & 0xFF ] << 16 ) ^ + ( FSb[ ( Y1 >> 24 ) & 0xFF ] << 24 ); + + X3 = *RK++ ^ ( FSb[ ( Y3 ) & 0xFF ] ) ^ + ( FSb[ ( Y0 >> 8 ) & 0xFF ] << 8 ) ^ + ( FSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^ + ( FSb[ ( Y2 >> 24 ) & 0xFF ] << 24 ); + } + + PUT_ULONG_LE( X0, output, 0 ); + PUT_ULONG_LE( X1, output, 4 ); + PUT_ULONG_LE( X2, output, 8 ); + PUT_ULONG_LE( X3, output, 12 ); } /* * AES-CBC buffer encryption/decryption */ void aes_crypt_cbc( aes_context *ctx, - int mode, - int length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ) + int mode, + int length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) { - int i; - unsigned char temp[16]; + int i; + unsigned char temp[16]; #if defined(XYSSL_PADLOCK_C) && defined(XYSSL_HAVE_X86) - if( padlock_supports( PADLOCK_ACE ) ) - { - if( padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 ) - return; - } + if( padlock_supports( PADLOCK_ACE ) ) + { + if( padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 ) + return; + } #endif - if( mode == AES_DECRYPT ) - { - while( length > 0 ) - { - memcpy( temp, input, 16 ); - aes_crypt_ecb( ctx, mode, input, output ); - - for( i = 0; i < 16; i++ ) - output[i] = (unsigned char)( output[i] ^ iv[i] ); - - memcpy( iv, temp, 16 ); - - input += 16; - output += 16; - length -= 16; - } - } - else - { - while( length > 0 ) - { - for( i = 0; i < 16; i++ ) - output[i] = (unsigned char)( input[i] ^ iv[i] ); - - aes_crypt_ecb( ctx, mode, output, output ); - memcpy( iv, output, 16 ); - - input += 16; - output += 16; - length -= 16; - } - } + if( mode == AES_DECRYPT ) + { + while( length > 0 ) + { + memcpy( temp, input, 16 ); + aes_crypt_ecb( ctx, mode, input, output ); + + for( i = 0; i < 16; i++ ) + output[i] = (unsigned char)( output[i] ^ iv[i] ); + + memcpy( iv, temp, 16 ); + + input += 16; + output += 16; + length -= 16; + } + } + else + { + while( length > 0 ) + { + for( i = 0; i < 16; i++ ) + output[i] = (unsigned char)( input[i] ^ iv[i] ); + + aes_crypt_ecb( ctx, mode, output, output ); + memcpy( iv, output, 16 ); + + input += 16; + output += 16; + length -= 16; + } + } } /* * AES-CFB buffer encryption/decryption */ void aes_crypt_cfb( aes_context *ctx, - int mode, - int length, - int *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ) + int mode, + int length, + int *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) { - int c, n = *iv_off; - - if( mode == AES_DECRYPT ) - { - while( length-- ) - { - if( n == 0 ) - aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); - - c = *input++; - *output++ = (unsigned char)( c ^ iv[n] ); - iv[n] = (unsigned char) c; - - n = (n + 1) & 0x0F; - } - } - else - { - while( length-- ) - { - if( n == 0 ) - aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); - - iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); - - n = (n + 1) & 0x0F; - } - } - - *iv_off = n; + int c, n = *iv_off; + + if( mode == AES_DECRYPT ) + { + while( length-- ) + { + if( n == 0 ) + aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); + + c = *input++; + *output++ = (unsigned char)( c ^ iv[n] ); + iv[n] = (unsigned char) c; + + n = (n + 1) & 0x0F; + } + } + else + { + while( length-- ) + { + if( n == 0 ) + aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); + + iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); + + n = (n + 1) & 0x0F; + } + } + + *iv_off = n; } #if defined(XYSSL_SELF_TEST) @@ -845,42 +845,42 @@ void aes_crypt_cfb( aes_context *ctx, */ static const unsigned char aes_test_ecb_dec[3][16] = { - { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58, - 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 }, - { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, - 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 }, - { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D, - 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE } + { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58, + 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 }, + { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, + 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 }, + { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D, + 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE } }; static const unsigned char aes_test_ecb_enc[3][16] = { - { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73, - 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F }, - { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, - 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 }, - { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D, - 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 } + { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73, + 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F }, + { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, + 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 }, + { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D, + 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 } }; static const unsigned char aes_test_cbc_dec[3][16] = { - { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73, - 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 }, - { 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75, - 0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B }, - { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75, - 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 } + { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73, + 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 }, + { 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75, + 0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B }, + { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75, + 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 } }; static const unsigned char aes_test_cbc_enc[3][16] = { - { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84, - 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D }, - { 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB, - 0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 }, - { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5, - 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 } + { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84, + 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D }, + { 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB, + 0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 }, + { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5, + 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 } }; /* @@ -888,22 +888,22 @@ static const unsigned char aes_test_cbc_enc[3][16] = */ static const unsigned char aes_test_cfb_dec[3][16] = { - { 0xBA, 0x75, 0x0C, 0xC9, 0x77, 0xF8, 0xD4, 0xE1, - 0x3E, 0x0F, 0xB5, 0x46, 0x2E, 0xA6, 0x33, 0xF6 }, - { 0xDB, 0x40, 0x4A, 0x98, 0x7B, 0xAA, 0xA3, 0xF3, - 0x92, 0x35, 0xAD, 0x58, 0x09, 0x9B, 0xFF, 0x6E }, - { 0xA8, 0x17, 0x41, 0x0E, 0x76, 0x71, 0x60, 0xE5, - 0xFD, 0x37, 0xC5, 0x43, 0xCC, 0xC8, 0xD6, 0xDA } + { 0xBA, 0x75, 0x0C, 0xC9, 0x77, 0xF8, 0xD4, 0xE1, + 0x3E, 0x0F, 0xB5, 0x46, 0x2E, 0xA6, 0x33, 0xF6 }, + { 0xDB, 0x40, 0x4A, 0x98, 0x7B, 0xAA, 0xA3, 0xF3, + 0x92, 0x35, 0xAD, 0x58, 0x09, 0x9B, 0xFF, 0x6E }, + { 0xA8, 0x17, 0x41, 0x0E, 0x76, 0x71, 0x60, 0xE5, + 0xFD, 0x37, 0xC5, 0x43, 0xCC, 0xC8, 0xD6, 0xDA } }; static const unsigned char aes_test_cfb_enc[3][16] = { - { 0x45, 0x62, 0xC5, 0xA1, 0xF9, 0x10, 0x8F, 0xE0, - 0x87, 0x24, 0x25, 0x68, 0xB5, 0x12, 0xF3, 0x8B }, - { 0xB8, 0xD4, 0xD5, 0x09, 0xF5, 0xEE, 0x08, 0x38, - 0x48, 0x9B, 0x9D, 0xAD, 0x11, 0xB4, 0x2E, 0xD2 }, - { 0xE9, 0x10, 0x80, 0xDA, 0xEE, 0x2D, 0x81, 0xD9, - 0x41, 0x78, 0x91, 0xD5, 0x98, 0x78, 0xE1, 0xFA } + { 0x45, 0x62, 0xC5, 0xA1, 0xF9, 0x10, 0x8F, 0xE0, + 0x87, 0x24, 0x25, 0x68, 0xB5, 0x12, 0xF3, 0x8B }, + { 0xB8, 0xD4, 0xD5, 0x09, 0xF5, 0xEE, 0x08, 0x38, + 0x48, 0x9B, 0x9D, 0xAD, 0x11, 0xB4, 0x2E, 0xD2 }, + { 0xE9, 0x10, 0x80, 0xDA, 0xEE, 0x2D, 0x81, 0xD9, + 0x41, 0x78, 0x91, 0xD5, 0x98, 0x78, 0xE1, 0xFA } }; /* @@ -911,190 +911,190 @@ static const unsigned char aes_test_cfb_enc[3][16] = */ int aes_self_test( int verbose ) { - int i, j, u, v, offset; - unsigned char key[32]; - unsigned char buf[16]; - unsigned char prv[16]; - unsigned char iv[16]; - aes_context ctx; - - memset( key, 0, 32 ); - - /* - * ECB mode - */ - for( i = 0; i < 6; i++ ) - { - u = i >> 1; - v = i & 1; - - if( verbose != 0 ) - printf( " AES-ECB-%3d (%s): ", 128 + u * 64, - ( v == AES_DECRYPT ) ? "dec" : "enc" ); - - memset( buf, 0, 16 ); - - if( v == AES_DECRYPT ) - { - aes_setkey_dec( &ctx, key, 128 + u * 64 ); - - for( j = 0; j < 10000; j++ ) - aes_crypt_ecb( &ctx, v, buf, buf ); - - if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 ) - { - if( verbose != 0 ) - printf( "failed\n" ); - - return( 1 ); - } - } - else - { - aes_setkey_enc( &ctx, key, 128 + u * 64 ); - - for( j = 0; j < 10000; j++ ) - aes_crypt_ecb( &ctx, v, buf, buf ); - - if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 ) - { - if( verbose != 0 ) - printf( "failed\n" ); - - return( 1 ); - } - } - - if( verbose != 0 ) - printf( "passed\n" ); - } - - if( verbose != 0 ) - printf( "\n" ); - - /* - * CBC mode - */ - for( i = 0; i < 6; i++ ) - { - u = i >> 1; - v = i & 1; - - if( verbose != 0 ) - printf( " AES-CBC-%3d (%s): ", 128 + u * 64, - ( v == AES_DECRYPT ) ? "dec" : "enc" ); - - memset( iv , 0, 16 ); - memset( prv, 0, 16 ); - memset( buf, 0, 16 ); - - if( v == AES_DECRYPT ) - { - aes_setkey_dec( &ctx, key, 128 + u * 64 ); - - for( j = 0; j < 10000; j++ ) - aes_crypt_cbc( &ctx, v, 16, iv, buf, buf ); - - if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 ) - { - if( verbose != 0 ) - printf( "failed\n" ); - - return( 1 ); - } - } - else - { - aes_setkey_enc( &ctx, key, 128 + u * 64 ); - - for( j = 0; j < 10000; j++ ) - { - unsigned char tmp[16]; - - aes_crypt_cbc( &ctx, v, 16, iv, buf, buf ); - - memcpy( tmp, prv, 16 ); - memcpy( prv, buf, 16 ); - memcpy( buf, tmp, 16 ); - } - - if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 ) - { - if( verbose != 0 ) - printf( "failed\n" ); - - return( 1 ); - } - } - - if( verbose != 0 ) - printf( "passed\n" ); - } - - if( verbose != 0 ) - printf( "\n" ); - - /* - * CFB mode - */ - for( i = 0; i < 6; i++ ) - { - u = i >> 1; - v = i & 1; - - if( verbose != 0 ) - printf( " AES-CFB-%3d (%s): ", 128 + u * 64, - ( v == AES_DECRYPT ) ? "dec" : "enc" ); - - memset( iv , 0, 16 ); - memset( buf, 0, 16 ); - offset = 0; - - if( v == AES_DECRYPT ) - { - aes_setkey_dec( &ctx, key, 128 + u * 64 ); - - for( j = 0; j < 10000; j++ ) - aes_crypt_cfb( &ctx, v, 16, &offset, iv, buf, buf ); - - if( memcmp( buf, aes_test_cfb_dec[u], 16 ) != 0 ) - { - if( verbose != 0 ) - printf( "failed\n" ); - - return( 1 ); - } - } - else - { - aes_setkey_enc( &ctx, key, 128 + u * 64 ); - - for( j = 0; j < 10000; j++ ) - aes_crypt_cfb( &ctx, v, 16, &offset, iv, buf, buf ); - - if( memcmp( buf, aes_test_cfb_enc[u], 16 ) != 0 ) - { - if( verbose != 0 ) - printf( "failed\n" ); - - return( 1 ); - } - } - - if( verbose != 0 ) - printf( "passed\n" ); - } - - - if( verbose != 0 ) - printf( "\n" ); - - return( 0 ); + int i, j, u, v, offset; + unsigned char key[32]; + unsigned char buf[16]; + unsigned char prv[16]; + unsigned char iv[16]; + aes_context ctx; + + memset( key, 0, 32 ); + + /* + * ECB mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + v = i & 1; + + if( verbose != 0 ) + printf( " AES-ECB-%3d (%s): ", 128 + u * 64, + ( v == AES_DECRYPT ) ? "dec" : "enc" ); + + memset( buf, 0, 16 ); + + if( v == AES_DECRYPT ) + { + aes_setkey_dec( &ctx, key, 128 + u * 64 ); + + for( j = 0; j < 10000; j++ ) + aes_crypt_ecb( &ctx, v, buf, buf ); + + if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 ) + { + if( verbose != 0 ) + printf( "failed\n" ); + + return( 1 ); + } + } + else + { + aes_setkey_enc( &ctx, key, 128 + u * 64 ); + + for( j = 0; j < 10000; j++ ) + aes_crypt_ecb( &ctx, v, buf, buf ); + + if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 ) + { + if( verbose != 0 ) + printf( "failed\n" ); + + return( 1 ); + } + } + + if( verbose != 0 ) + printf( "passed\n" ); + } + + if( verbose != 0 ) + printf( "\n" ); + + /* + * CBC mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + v = i & 1; + + if( verbose != 0 ) + printf( " AES-CBC-%3d (%s): ", 128 + u * 64, + ( v == AES_DECRYPT ) ? "dec" : "enc" ); + + memset( iv , 0, 16 ); + memset( prv, 0, 16 ); + memset( buf, 0, 16 ); + + if( v == AES_DECRYPT ) + { + aes_setkey_dec( &ctx, key, 128 + u * 64 ); + + for( j = 0; j < 10000; j++ ) + aes_crypt_cbc( &ctx, v, 16, iv, buf, buf ); + + if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 ) + { + if( verbose != 0 ) + printf( "failed\n" ); + + return( 1 ); + } + } + else + { + aes_setkey_enc( &ctx, key, 128 + u * 64 ); + + for( j = 0; j < 10000; j++ ) + { + unsigned char tmp[16]; + + aes_crypt_cbc( &ctx, v, 16, iv, buf, buf ); + + memcpy( tmp, prv, 16 ); + memcpy( prv, buf, 16 ); + memcpy( buf, tmp, 16 ); + } + + if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 ) + { + if( verbose != 0 ) + printf( "failed\n" ); + + return( 1 ); + } + } + + if( verbose != 0 ) + printf( "passed\n" ); + } + + if( verbose != 0 ) + printf( "\n" ); + + /* + * CFB mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + v = i & 1; + + if( verbose != 0 ) + printf( " AES-CFB-%3d (%s): ", 128 + u * 64, + ( v == AES_DECRYPT ) ? "dec" : "enc" ); + + memset( iv , 0, 16 ); + memset( buf, 0, 16 ); + offset = 0; + + if( v == AES_DECRYPT ) + { + aes_setkey_dec( &ctx, key, 128 + u * 64 ); + + for( j = 0; j < 10000; j++ ) + aes_crypt_cfb( &ctx, v, 16, &offset, iv, buf, buf ); + + if( memcmp( buf, aes_test_cfb_dec[u], 16 ) != 0 ) + { + if( verbose != 0 ) + printf( "failed\n" ); + + return( 1 ); + } + } + else + { + aes_setkey_enc( &ctx, key, 128 + u * 64 ); + + for( j = 0; j < 10000; j++ ) + aes_crypt_cfb( &ctx, v, 16, &offset, iv, buf, buf ); + + if( memcmp( buf, aes_test_cfb_enc[u], 16 ) != 0 ) + { + if( verbose != 0 ) + printf( "failed\n" ); + + return( 1 ); + } + } + + if( verbose != 0 ) + printf( "passed\n" ); + } + + + if( verbose != 0 ) + printf( "\n" ); + + return( 0 ); } int main(int argc, char *argv[]) { - return aes_self_test(1); + return aes_self_test(1); } #endif /* defined(XYSSL_SELF_TEST) */ diff --git a/fitz/crypt_md5.c b/fitz/crypt_md5.c index d4043550..37f6c776 100644 --- a/fitz/crypt_md5.c +++ b/fitz/crypt_md5.c @@ -99,9 +99,9 @@ static void decode(unsigned int *output, const unsigned char *input, const unsig for (i = 0, j = 0; j < len; i++, j += 4) { output[i] = ((unsigned int)input[j]) | - (((unsigned int)input[j+1]) << 8) | - (((unsigned int)input[j+2]) << 16) | - (((unsigned int)input[j+3]) << 24); + (((unsigned int)input[j+1]) << 8) | + (((unsigned int)input[j+2]) << 16) | + (((unsigned int)input[j+3]) << 24); } } diff --git a/fitz/filt_aesd.c b/fitz/filt_aesd.c index 122a284d..a4425c2e 100644 --- a/fitz/filt_aesd.c +++ b/fitz/filt_aesd.c @@ -5,19 +5,19 @@ typedef struct fz_aesd_s fz_aesd; struct fz_aesd_s { - fz_filter super; - fz_aes aes; - unsigned char iv[16]; - int ivcount; + fz_filter super; + fz_aes aes; + unsigned char iv[16]; + int ivcount; }; fz_filter * fz_newaesdfilter(unsigned char *key, unsigned keylen) { - FZ_NEWFILTER(fz_aesd, f, aesdfilter); - aes_setkey_dec(&f->aes, key, keylen * 8); - f->ivcount = 0; - return (fz_filter *)f; + FZ_NEWFILTER(fz_aesd, f, aesdfilter); + aes_setkey_dec(&f->aes, key, keylen * 8); + f->ivcount = 0; + return (fz_filter *)f; } void @@ -28,43 +28,43 @@ fz_dropaesdfilter(fz_filter *f) fz_error fz_processaesdfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out) { - fz_aesd *f = (fz_aesd*)filter; - int n; + fz_aesd *f = (fz_aesd*)filter; + int n; - while (1) - { - if (in->rp + 16 > in->wp) + while (1) { - if (in->eof) - return fz_iodone; - return fz_ioneedin; - } + if (in->rp + 16 > in->wp) + { + if (in->eof) + return fz_iodone; + return fz_ioneedin; + } - if (f->ivcount < 16) - { - f->iv[f->ivcount++] = *in->rp++; - } - else - { - if (out->wp + 16 > out->ep) - return fz_ioneedout; + if (f->ivcount < 16) + { + f->iv[f->ivcount++] = *in->rp++; + } + else + { + if (out->wp + 16 > out->ep) + return fz_ioneedout; - n = MIN(in->wp - in->rp, out->ep - out->wp); - n = (n / 16) * 16; + n = MIN(in->wp - in->rp, out->ep - out->wp); + n = (n / 16) * 16; - aes_crypt_cbc(&f->aes, AES_DECRYPT, n, f->iv, in->rp, out->wp); - in->rp += n; - out->wp += n; + aes_crypt_cbc(&f->aes, AES_DECRYPT, n, f->iv, in->rp, out->wp); + in->rp += n; + out->wp += n; - /* Remove padding bytes */ - if (in->eof && in->rp == in->wp) - { - int pad = out->wp[-1]; - if (pad < 1 || pad > 16) - return fz_throw("aes padding out of range: %d", pad); - out->wp -= pad; - } + /* Remove padding bytes */ + if (in->eof && in->rp == in->wp) + { + int pad = out->wp[-1]; + if (pad < 1 || pad > 16) + return fz_throw("aes padding out of range: %d", pad); + out->wp -= pad; + } + } } - } } diff --git a/fitz/filt_basic.c b/fitz/filt_basic.c index 4eea42bf..cbbc9907 100644 --- a/fitz/filt_basic.c +++ b/fitz/filt_basic.c @@ -4,8 +4,8 @@ fz_filter * fz_newcopyfilter(void) { - FZ_NEWFILTER(fz_filter, f, copyfilter); - return f; + FZ_NEWFILTER(fz_filter, f, copyfilter); + return f; } void @@ -16,28 +16,28 @@ fz_dropcopyfilter(fz_filter *f) fz_error fz_processcopyfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out) { - int n; + int n; - while (1) - { - if (in->rp + 1 > in->wp) + while (1) { - if (in->eof) - return fz_iodone; - return fz_ioneedin; - } + if (in->rp + 1 > in->wp) + { + if (in->eof) + return fz_iodone; + return fz_ioneedin; + } - if (out->wp + 1 > out->ep) - return fz_ioneedout; + if (out->wp + 1 > out->ep) + return fz_ioneedout; - n = MIN(in->wp - in->rp, out->ep - out->wp); - if (n) - { - memcpy(out->wp, in->rp, n); - in->rp += n; - out->wp += n; + n = MIN(in->wp - in->rp, out->ep - out->wp); + if (n) + { + memcpy(out->wp, in->rp, n); + in->rp += n; + out->wp += n; + } } - } } typedef struct fz_nullfilter_s fz_nullfilter; @@ -71,7 +71,7 @@ fz_processnullfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out) n = MIN(in->wp - in->rp, out->ep - out->wp); if (f->len >= 0) - n = MIN(n, f->len - f->cur); + n = MIN(n, f->len - f->cur); if (n) { @@ -301,8 +301,8 @@ fz_processa85d(fz_filter *filter, fz_buffer *in, fz_buffer *out) case 4: f->word = f->word * 85 + 0xffL; *(out->wp+2) = f->word >> 8; -o2: *(out->wp+1) = f->word >> 16; -o1: *(out->wp+0) = f->word >> 24; + o2: *(out->wp+1) = f->word >> 16; + o1: *(out->wp+0) = f->word >> 24; out->wp += f->count - 1; break; } diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 99c7821a..f9b30e42 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -175,79 +175,79 @@ fz_processdctd(fz_filter *filter, fz_buffer *in, fz_buffer *out) switch (d->stage) { - case 0: - i = jpeg_read_header(&d->cinfo, TRUE); - if (i == JPEG_SUSPENDED) - goto needinput; + case 0: + i = jpeg_read_header(&d->cinfo, TRUE); + if (i == JPEG_SUSPENDED) + goto needinput; - /* default value if ColorTransform is not set */ - if (d->colortransform == -1) - { - if (d->cinfo.num_components == 3) + /* default value if ColorTransform is not set */ + if (d->colortransform == -1) + { + if (d->cinfo.num_components == 3) d->colortransform = 1; - else + else d->colortransform = 0; - } - - if (d->cinfo.saw_Adobe_marker) - d->colortransform = d->cinfo.Adobe_transform; - - /* Guess the input colorspace, and set output colorspace accordingly */ - switch (d->cinfo.num_components) - { - case 3: - if (d->colortransform) - d->cinfo.jpeg_color_space = JCS_YCbCr; - else - d->cinfo.jpeg_color_space = JCS_RGB; - break; - case 4: - if (d->colortransform) - d->cinfo.jpeg_color_space = JCS_YCCK; - else - d->cinfo.jpeg_color_space = JCS_CMYK; - break; - } - - /* fall through */ - d->stage = 1; - - case 1: - b = jpeg_start_decompress(&d->cinfo); - if (b == FALSE) - goto needinput; + } - /* fall through */ - d->stage = 2; + if (d->cinfo.saw_Adobe_marker) + d->colortransform = d->cinfo.Adobe_transform; + + /* Guess the input colorspace, and set output colorspace accordingly */ + switch (d->cinfo.num_components) + { + case 3: + if (d->colortransform) + d->cinfo.jpeg_color_space = JCS_YCbCr; + else + d->cinfo.jpeg_color_space = JCS_RGB; + break; + case 4: + if (d->colortransform) + d->cinfo.jpeg_color_space = JCS_YCCK; + else + d->cinfo.jpeg_color_space = JCS_CMYK; + break; + } - case 2: - stride = d->cinfo.output_width * d->cinfo.output_components; + /* fall through */ + d->stage = 1; - while (d->cinfo.output_scanline < d->cinfo.output_height) - { - if (out->wp + stride > out->ep) - goto needoutput; + case 1: + b = jpeg_start_decompress(&d->cinfo); + if (b == FALSE) + goto needinput; - scanlines[0] = out->wp; + /* fall through */ + d->stage = 2; - i = jpeg_read_scanlines(&d->cinfo, scanlines, 1); + case 2: + stride = d->cinfo.output_width * d->cinfo.output_components; - if (i == 0) - goto needinput; + while (d->cinfo.output_scanline < d->cinfo.output_height) + { + if (out->wp + stride > out->ep) + goto needoutput; - out->wp += stride; - } + scanlines[0] = out->wp; - /* fall through */ - d->stage = 3; + i = jpeg_read_scanlines(&d->cinfo, scanlines, 1); - case 3: - b = jpeg_finish_decompress(&d->cinfo); - if (b == FALSE) + if (i == 0) goto needinput; - d->stage = 4; - in->rp = in->wp - d->src.super.bytes_in_buffer; - return fz_iodone; + + out->wp += stride; + } + + /* fall through */ + d->stage = 3; + + case 3: + b = jpeg_finish_decompress(&d->cinfo); + if (b == FALSE) + goto needinput; + d->stage = 4; + in->rp = in->wp - d->src.super.bytes_in_buffer; + return fz_iodone; } needinput: diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c index 7a244dfa..24597c38 100644 --- a/fitz/filt_faxd.c +++ b/fitz/filt_faxd.c @@ -97,10 +97,10 @@ findchangingcolor(const unsigned char *line, int x, int w, int color) } static const unsigned char lm[8] = - { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01 }; +{ 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01 }; static const unsigned char rm[8] = - { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE }; +{ 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE }; static inline void setbits(unsigned char *line, int x0, int x1) @@ -357,83 +357,83 @@ dec2d(fz_faxd *fax) switch (code) { - case H: - fax->stage = SH1; - break; - - case P: - b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); - if (b1 >= fax->columns) - b2 = fax->columns; - else - b2 = findchanging(fax->ref, b1, fax->columns); - if (fax->c) setbits(fax->dst, fax->a, b2); - fax->a = b2; - break; - - case V0: - b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); - if (fax->c) setbits(fax->dst, fax->a, b1); - fax->a = b1; - fax->c = !fax->c; - break; + case H: + fax->stage = SH1; + break; + + case P: + b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); + if (b1 >= fax->columns) + b2 = fax->columns; + else + b2 = findchanging(fax->ref, b1, fax->columns); + if (fax->c) setbits(fax->dst, fax->a, b2); + fax->a = b2; + break; + + case V0: + b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); + if (fax->c) setbits(fax->dst, fax->a, b1); + fax->a = b1; + fax->c = !fax->c; + break; - case VR1: - b1 = 1 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); - if (b1 >= fax->columns) b1 = fax->columns; - if (fax->c) setbits(fax->dst, fax->a, b1); - fax->a = b1; - fax->c = !fax->c; - break; + case VR1: + b1 = 1 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); + if (b1 >= fax->columns) b1 = fax->columns; + if (fax->c) setbits(fax->dst, fax->a, b1); + fax->a = b1; + fax->c = !fax->c; + break; - case VR2: - b1 = 2 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); - if (b1 >= fax->columns) b1 = fax->columns; - if (fax->c) setbits(fax->dst, fax->a, b1); - fax->a = b1; - fax->c = !fax->c; - break; + case VR2: + b1 = 2 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); + if (b1 >= fax->columns) b1 = fax->columns; + if (fax->c) setbits(fax->dst, fax->a, b1); + fax->a = b1; + fax->c = !fax->c; + break; - case VR3: - b1 = 3 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); - if (b1 >= fax->columns) b1 = fax->columns; - if (fax->c) setbits(fax->dst, fax->a, b1); - fax->a = b1; - fax->c = !fax->c; - break; + case VR3: + b1 = 3 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); + if (b1 >= fax->columns) b1 = fax->columns; + if (fax->c) setbits(fax->dst, fax->a, b1); + fax->a = b1; + fax->c = !fax->c; + break; - case VL1: - b1 = -1 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); - if (b1 < 0) b1 = 0; - if (fax->c) setbits(fax->dst, fax->a, b1); - fax->a = b1; - fax->c = !fax->c; - break; + case VL1: + b1 = -1 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); + if (b1 < 0) b1 = 0; + if (fax->c) setbits(fax->dst, fax->a, b1); + fax->a = b1; + fax->c = !fax->c; + break; - case VL2: - b1 = -2 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); - if (b1 < 0) b1 = 0; - if (fax->c) setbits(fax->dst, fax->a, b1); - fax->a = b1; - fax->c = !fax->c; - break; + case VL2: + b1 = -2 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); + if (b1 < 0) b1 = 0; + if (fax->c) setbits(fax->dst, fax->a, b1); + fax->a = b1; + fax->c = !fax->c; + break; - case VL3: - b1 = -3 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); - if (b1 < 0) b1 = 0; - if (fax->c) setbits(fax->dst, fax->a, b1); - fax->a = b1; - fax->c = !fax->c; - break; + case VL3: + b1 = -3 + findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c); + if (b1 < 0) b1 = 0; + if (fax->c) setbits(fax->dst, fax->a, b1); + fax->a = b1; + fax->c = !fax->c; + break; - case UNCOMPRESSED: - return fz_throw("uncompressed data in faxd"); + case UNCOMPRESSED: + return fz_throw("uncompressed data in faxd"); - case ERROR: - return fz_throw("invalid code in 2d faxd"); + case ERROR: + return fz_throw("invalid code in 2d faxd"); - default: - return fz_throw("invalid code in 2d faxd (%d)", code); + default: + return fz_throw("invalid code in 2d faxd (%d)", code); } return 0; diff --git a/fitz/filt_jpxd.c b/fitz/filt_jpxd.c index 4f34e41a..fff6a306 100644 --- a/fitz/filt_jpxd.c +++ b/fitz/filt_jpxd.c @@ -18,146 +18,146 @@ struct fz_jpxd_s static void fz_opj_error_callback(const char *msg, void *client_data) { - fprintf(stderr, "openjpeg error: %s", msg); + fprintf(stderr, "openjpeg error: %s", msg); } static void fz_opj_warning_callback(const char *msg, void *client_data) { - fprintf(stderr, "openjpeg warning: %s", msg); + fprintf(stderr, "openjpeg warning: %s", msg); } static void fz_opj_info_callback(const char *msg, void *client_data) { - /* fprintf(stdout, "openjpeg info: %s", msg); */ + /* fprintf(stdout, "openjpeg info: %s", msg); */ } fz_error fz_newjpxd(fz_filter **fp, fz_obj *params) { - FZ_NEWFILTER(fz_jpxd, d, jpxd); + FZ_NEWFILTER(fz_jpxd, d, jpxd); - d->info = nil; - d->image = nil; - d->stage = 0; + d->info = nil; + d->image = nil; + d->stage = 0; - d->x = 0; - d->y = 0; - d->k = 0; + d->x = 0; + d->y = 0; + d->k = 0; - memset(&d->evtmgr, 0, sizeof(d->evtmgr)); - d->evtmgr.error_handler = fz_opj_error_callback; - d->evtmgr.warning_handler = fz_opj_warning_callback; - d->evtmgr.info_handler = fz_opj_info_callback; + memset(&d->evtmgr, 0, sizeof(d->evtmgr)); + d->evtmgr.error_handler = fz_opj_error_callback; + d->evtmgr.warning_handler = fz_opj_warning_callback; + d->evtmgr.info_handler = fz_opj_info_callback; - opj_set_default_decoder_parameters(&d->params); + opj_set_default_decoder_parameters(&d->params); - d->info = opj_create_decompress(CODEC_JP2); - if (!d->info) - return fz_throw("opj_create_decompress failed"); + d->info = opj_create_decompress(CODEC_JP2); + if (!d->info) + return fz_throw("opj_create_decompress failed"); - opj_set_event_mgr((opj_common_ptr)d->info, &d->evtmgr, stderr); - opj_setup_decoder(d->info, &d->params); + opj_set_event_mgr((opj_common_ptr)d->info, &d->evtmgr, stderr); + opj_setup_decoder(d->info, &d->params); - return fz_okay; + return fz_okay; } void fz_dropjpxd(fz_filter *filter) { - fz_jpxd *d = (fz_jpxd*)filter; - if (d->image) opj_image_destroy(d->image); - if (d->info) opj_destroy_decompress(d->info); + fz_jpxd *d = (fz_jpxd*)filter; + if (d->image) opj_image_destroy(d->image); + if (d->info) opj_destroy_decompress(d->info); } fz_error fz_processjpxd(fz_filter *filter, fz_buffer *in, fz_buffer *out) { - fz_jpxd *d = (fz_jpxd*)filter; - int n, w, h, depth, sgnd; - int k, v; + fz_jpxd *d = (fz_jpxd*)filter; + int n, w, h, depth, sgnd; + int k, v; - opj_cio_t *cio; + opj_cio_t *cio; - switch (d->stage) - { + switch (d->stage) + { case 0: goto input; case 1: goto decode; case 2: goto output; - } + } input: - /* Wait until we have the entire file in the input buffer */ - if (!in->eof) - return fz_ioneedin; + /* Wait until we have the entire file in the input buffer */ + if (!in->eof) + return fz_ioneedin; - d->stage = 1; + d->stage = 1; decode: - cio = opj_cio_open((opj_common_ptr)d->info, in->rp, in->wp - in->rp); - in->rp = in->wp; + cio = opj_cio_open((opj_common_ptr)d->info, in->rp, in->wp - in->rp); + in->rp = in->wp; + + d->image = opj_decode(d->info, cio); + if (!d->image) + { + opj_cio_close(cio); + return fz_throw("opj_decode failed"); + } - d->image = opj_decode(d->info, cio); - if (!d->image) - { opj_cio_close(cio); - return fz_throw("opj_decode failed"); - } - opj_cio_close(cio); + d->stage = 2; - d->stage = 2; + for (k = 1; k < d->image->numcomps; k++) + { + if (d->image->comps[k].w != d->image->comps[0].w) + return fz_throw("image components have different width"); + if (d->image->comps[k].h != d->image->comps[0].h) + return fz_throw("image components have different height"); + if (d->image->comps[k].prec != d->image->comps[0].prec) + return fz_throw("image components have different precision"); + } - for (k = 1; k < d->image->numcomps; k++) - { - if (d->image->comps[k].w != d->image->comps[0].w) - return fz_throw("image components have different width"); - if (d->image->comps[k].h != d->image->comps[0].h) - return fz_throw("image components have different height"); - if (d->image->comps[k].prec != d->image->comps[0].prec) - return fz_throw("image components have different precision"); - } + { + n = d->image->numcomps; + w = d->image->comps[0].w; + h = d->image->comps[0].h; + depth = d->image->comps[0].prec; + } - { +output: n = d->image->numcomps; w = d->image->comps[0].w; h = d->image->comps[0].h; depth = d->image->comps[0].prec; - } + sgnd = d->image->comps[0].sgnd; -output: - n = d->image->numcomps; - w = d->image->comps[0].w; - h = d->image->comps[0].h; - depth = d->image->comps[0].prec; - sgnd = d->image->comps[0].sgnd; - - while (d->y < h) - { - while (d->x < w) + while (d->y < h) { - while (d->k < n) - { - if (out->wp == out->ep) - return fz_ioneedout; - - v = d->image->comps[d->k].data[d->y * w + d->x]; - if (sgnd) - v = v + (1 << (depth - 1)); - if (depth > 8) - v = v >> (depth - 8); - - *out->wp++ = v; - - d->k ++; - } - d->x ++; - d->k = 0; + while (d->x < w) + { + while (d->k < n) + { + if (out->wp == out->ep) + return fz_ioneedout; + + v = d->image->comps[d->k].data[d->y * w + d->x]; + if (sgnd) + v = v + (1 << (depth - 1)); + if (depth > 8) + v = v >> (depth - 8); + + *out->wp++ = v; + + d->k ++; + } + d->x ++; + d->k = 0; + } + d->y ++; + d->x = 0; } - d->y ++; - d->x = 0; - } - return fz_iodone; + return fz_iodone; } diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c index b86b2515..a3067bdb 100644 --- a/fitz/filt_predict.c +++ b/fitz/filt_predict.c @@ -37,10 +37,10 @@ fz_newpredictd(fz_obj *params) if (obj) p->predictor = fz_toint(obj); - if (p->predictor != 1 && p->predictor != 2 && - p->predictor != 10 && p->predictor != 11 && - p->predictor != 12 && p->predictor != 13 && - p->predictor != 14 && p->predictor != 15) + if (p->predictor != 1 && p->predictor != 2 && + p->predictor != 10 && p->predictor != 11 && + p->predictor != 12 && p->predictor != 13 && + p->predictor != 14 && p->predictor != 15) { fz_warn("invalid predictor: %d", p->predictor); p->predictor = 1; @@ -86,10 +86,10 @@ getcomponent(unsigned char *buf, int x, int bpc) { switch (bpc) { - case 1: return buf[x / 8] >> (7 - (x % 8)) & 0x01; - case 2: return buf[x / 4] >> ((3 - (x % 4)) * 2) & 0x03; - case 4: return buf[x / 2] >> ((1 - (x % 2)) * 4) & 0x0f; - case 8: return buf[x]; + case 1: return buf[x / 8] >> (7 - (x % 8)) & 0x01; + case 2: return buf[x / 4] >> ((3 - (x % 4)) * 2) & 0x03; + case 4: return buf[x / 2] >> ((1 - (x % 2)) * 4) & 0x0f; + case 8: return buf[x]; } return 0; } @@ -99,10 +99,10 @@ putcomponent(unsigned char *buf, int x, int bpc, int value) { switch (bpc) { - case 1: buf[x / 8] |= value << (7 - (x % 8)); break; - case 2: buf[x / 4] |= value << ((3 - (x % 4)) * 2); break; - case 4: buf[x / 2] |= value << ((1 - (x % 2)) * 4); break; - case 8: buf[x] = value; break; + case 1: buf[x / 8] |= value << (7 - (x % 8)); break; + case 2: buf[x / 4] |= value << ((3 - (x % 4)) * 2); break; + case 4: buf[x / 2] |= value << ((1 - (x % 2)) * 4); break; + case 8: buf[x] = value; break; } } @@ -160,11 +160,11 @@ fz_predictpng(fz_predict *p, unsigned char *in, unsigned char *out, int predicto { switch (predictor) { - case 0: out[i] = in[i]; break; - case 1: out[i] = in[i] + left[k]; break; - case 2: out[i] = in[i] + p->ref[i]; break; - case 3: out[i] = in[i] + (left[k] + p->ref[i]) / 2; break; - case 4: out[i] = in[i] + paeth(left[k], p->ref[i], upleft[k]); break; + case 0: out[i] = in[i]; break; + case 1: out[i] = in[i] + left[k]; break; + case 2: out[i] = in[i] + p->ref[i]; break; + case 3: out[i] = in[i] + (left[k] + p->ref[i]) / 2; break; + case 4: out[i] = in[i] + paeth(left[k], p->ref[i], upleft[k]); break; } left[k] = out[i]; upleft[k] = p->ref[i]; diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h index ecced36e..769cd284 100644 --- a/fitz/fitz_base.h +++ b/fitz/fitz_base.h @@ -76,7 +76,7 @@ extern int gettimeofday(struct timeval *tv, struct timezone *tz); #define R_OK 4 #endif -#else /* C99 or close enough */ +#else /* C99 or close enough */ #include <unistd.h> #define FZ_FLEX @@ -232,7 +232,7 @@ extern fz_rect fz_infiniterect; /* / a b 0 \ | c d 0 | - \ e f 1 / +\ e f 1 / */ struct fz_matrix_s @@ -315,5 +315,5 @@ fz_error fz_scalepixmap(fz_pixmap **dstp, fz_pixmap *src, int xdenom, int ydenom /* needed for tiled rendering */ fz_error fz_newscaledpixmap(fz_pixmap **dstp, int w, int h, int n, int xdenom, int ydenom); fz_error fz_scalepixmaptile(fz_pixmap *dstp, int xoffs, int yoffs, - fz_pixmap *tile, int xdenom, int ydenom); + fz_pixmap *tile, int xdenom, int ydenom); diff --git a/fitz/fitz_stream.h b/fitz/fitz_stream.h index 7328b6d1..df3dec29 100644 --- a/fitz/fitz_stream.h +++ b/fitz/fitz_stream.h @@ -317,9 +317,9 @@ typedef struct fz_aes_s fz_aes; void aes_setkey_enc( fz_aes *ctx, const unsigned char *key, int keysize ); void aes_setkey_dec( fz_aes *ctx, const unsigned char *key, int keysize ); void aes_crypt_cbc( fz_aes *ctx, int mode, int length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ); + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); /* * Stream API for Fitz. @@ -393,18 +393,18 @@ int fz_peekbytex(fz_stream *stm); static inline int fz_readbyte(fz_stream *stm) { - fz_buffer *buf = stm->buffer; - if (buf->rp < buf->wp) - return *buf->rp++; - return fz_readbytex(stm); + fz_buffer *buf = stm->buffer; + if (buf->rp < buf->wp) + return *buf->rp++; + return fz_readbytex(stm); } static inline int fz_peekbyte(fz_stream *stm) { - fz_buffer *buf = stm->buffer; - if (buf->rp < buf->wp) - return *buf->rp; - return fz_peekbytex(stm); + fz_buffer *buf = stm->buffer; + if (buf->rp < buf->wp) + return *buf->rp; + return fz_peekbytex(stm); } #endif diff --git a/fitz/fitz_tree.h b/fitz/fitz_tree.h index 95044a4e..74962048 100644 --- a/fitz/fitz_tree.h +++ b/fitz/fitz_tree.h @@ -278,7 +278,7 @@ TODO the unicode textels struct fz_textgid_s { float e, f; int gid; }; struct fz_textucs_s { int idx; int ucs; }; - */ +*/ typedef struct fz_textel_s fz_textel; diff --git a/fitz/node_optimize.c b/fitz/node_optimize.c new file mode 100644 index 00000000..056fc782 --- /dev/null +++ b/fitz/node_optimize.c @@ -0,0 +1,235 @@ +#include "fitz_base.h" +#include "fitz_tree.h" + +/* + * Remove (mask ... white) until we get something not white + */ + +static int iswhitenode(fz_solidnode *node) +{ + if (!strcmp(node->cs->name, "DeviceGray")) + return fabs(node->samples[0] - 1.0) < FLT_EPSILON; + if (!strcmp(node->cs->name, "DeviceRGB")) + return fabs(node->samples[0] - 1.0) < FLT_EPSILON && + fabs(node->samples[1] - 1.0) < FLT_EPSILON && + fabs(node->samples[2] - 1.0) < FLT_EPSILON; + if (!strcmp(node->cs->name, "DeviceCMYK")) + return fabs(node->samples[0]) < FLT_EPSILON && + fabs(node->samples[1]) < FLT_EPSILON && + fabs(node->samples[2]) < FLT_EPSILON && + fabs(node->samples[3]) < FLT_EPSILON; + return 0; +} + +static int cleanwhite(fz_node *node) +{ + fz_node *current; + fz_node *next; + fz_node *shape; + fz_node *color; + + for (current = node->first; current; current = next) + { + next = current->next; + + if (fz_islinknode(current)) + return 1; + else if (fz_isimagenode(current)) + return 1; + else if (fz_isshadenode(current)) + return 1; + else if (fz_issolidnode(current)) + { + if (!iswhitenode((fz_solidnode*)current)) + return 1; + } + + else if (fz_ismasknode(current)) + { + shape = current->first; + color = shape->next; + if (fz_issolidnode(color)) + { + if (iswhitenode((fz_solidnode*)color)) + fz_removenode(current); + else + return 1; + } + else + { + if (cleanwhite(current)) + return 1; + } + } + + else + { + if (cleanwhite(current)) + return 1; + } + } + + return 0; +} + +/* + * Remove useless overs that only have one child. + */ + +static void cleanovers(fz_node *node) +{ + fz_node *prev; + fz_node *next; + fz_node *current; + fz_node *child; + + prev = nil; + for (current = node->first; current; current = next) + { + next = current->next; + + if (fz_isovernode(current)) + { + if (current->first == current->last) + { + child = current->first; + fz_removenode(current); + if (child) + { + if (prev) + fz_insertnodeafter(prev, child); + else + fz_insertnodefirst(node, child); + } + current = child; + } + } + + if (current) + prev = current; + } + + for (current = node->first; current; current = current->next) + cleanovers(current); +} + +/* + * Remove rectangular clip-masks whose contents fit... + */ + +static int getrect(fz_pathnode *path, fz_rect *bboxp) +{ + float x, y, w, h; + + /* move x y, line x+w y, line x+w y+h, line x y+h, close */ + + if (path->len != 13) + return 0; + + if (path->els[0].k != FZ_MOVETO) return 0; + x = path->els[1].v; + y = path->els[2].v; + + if (path->els[3].k != FZ_LINETO) return 0; + w = path->els[4].v - x; + if (path->els[5].v != y) return 0; + + if (path->els[6].k != FZ_LINETO) return 0; + if (path->els[7].v != x + w) return 0; + h = path->els[8].v - y; + + if (path->els[9].k != FZ_LINETO) return 0; + if (path->els[10].v != x) return 0; + if (path->els[11].v != y + h) return 0; + + if (path->els[12].k != FZ_CLOSEPATH) return 0; + + bboxp->x0 = MIN(x, x + w); + bboxp->y0 = MIN(y, y + h); + bboxp->x1 = MAX(x, x + w); + bboxp->y1 = MAX(y, y + h); + + return 1; +} + +static int fitsinside(fz_node *node, fz_rect clip) +{ + fz_rect bbox; + bbox = fz_boundnode(node, fz_identity()); + if (fz_isinfiniterect(bbox)) return 0; + if (fz_isemptyrect(bbox)) return 1; + if (bbox.x0 < clip.x0) return 0; + if (bbox.x1 > clip.x1) return 0; + if (bbox.y0 < clip.y0) return 0; + if (bbox.y1 > clip.y1) return 0; + return 1; +} + +static void cleanmasks(fz_node *node) +{ + fz_node *prev; + fz_node *current; + fz_node *shape; + fz_node *color; + fz_rect bbox; + + for (current = node->first; current; current = current->next) + cleanmasks(current); + + prev = nil; + for (current = node->first; current; current = current->next) + { +retry: + if (!current) + break; + + if (fz_ismasknode(current)) + { + shape = current->first; + color = shape->next; + + if (color == nil) + { + fz_removenode(current); + prev = nil; + current = node->first; + goto retry; + } + + if (fz_ispathnode(shape)) + { + if (getrect((fz_pathnode*)shape, &bbox)) + { + if (fitsinside(color, bbox)) + { + fz_removenode(current); + if (prev) + fz_insertnodeafter(prev, color); + else + fz_insertnodefirst(node, color); + current = color; + goto retry; + } + } + } + } + + prev = current; + } +} + +/* + * + */ + +fz_error +fz_optimizetree(fz_tree *tree) +{ + if (getenv("DONTOPT")) + return fz_okay; + cleanwhite(tree->root); + cleanovers(tree->root); + cleanmasks(tree->root); + return fz_okay; +} + diff --git a/fitz/node_path.c b/fitz/node_path.c index 843184d0..1ef469eb 100644 --- a/fitz/node_path.c +++ b/fitz/node_path.c @@ -107,9 +107,9 @@ fz_lineto(fz_pathnode *path, float x, float y) fz_error fz_curveto(fz_pathnode *path, - float x1, float y1, - float x2, float y2, - float x3, float y3) + float x1, float y1, + float x2, float y2, + float x3, float y3) { if (path->len == 0) return fz_throw("no current point"); diff --git a/fitz/node_toxml.c b/fitz/node_toxml.c index f5f1a81e..173b41b7 100644 --- a/fitz/node_toxml.c +++ b/fitz/node_toxml.c @@ -47,9 +47,9 @@ static void xmltransform(fz_transformnode *node, int level) { indent(level); printf("<transform matrix=\"%g %g %g %g %g %g\">\n", - node->m.a, node->m.b, - node->m.c, node->m.d, - node->m.e, node->m.f); + node->m.a, node->m.b, + node->m.c, node->m.d, + node->m.e, node->m.f); xmlnode(node->super.first, level + 1); indent(level); printf("</transform>\n"); @@ -84,10 +84,10 @@ static void xmlpath(fz_pathnode *node, int level) if (node->paint == FZ_STROKE) { printf("<path fill=\"stroke\" cap=\"%d\" join=\"%d\" width=\"%g\" miter=\"%g\"", - node->linecap, - node->linejoin, - node->linewidth, - node->miterlimit); + node->linecap, + node->linejoin, + node->linewidth, + node->miterlimit); if (node->dash) { printf(" phase=\"%g\" array=\"", node->dash->phase); @@ -100,7 +100,7 @@ static void xmlpath(fz_pathnode *node, int level) else { printf("<path fill=\"%s\">\n", - node->paint == FZ_FILL ? "nonzero" : "evenodd"); + node->paint == FZ_FILL ? "nonzero" : "evenodd"); } fz_debugpathnode(node, level + 2); @@ -115,17 +115,17 @@ static void xmltext(fz_textnode *node, int level) indent(level); printf("<text font=\"%s\" matrix=\"%g %g %g %g\">\n", node->font->name, - node->trm.a, node->trm.b, node->trm.c, node->trm.d); + node->trm.a, node->trm.b, node->trm.c, node->trm.d); for (i = 0; i < node->len; i++) { indent(level + 1); if (node->els[i].ucs >= 32 && node->els[i].ucs < 128) printf("<g ucs=\"%c\" gid=%d x=\"%g\" y=\"%g\" />\n", - node->els[i].ucs, node->els[i].gid, node->els[i].x, node->els[i].y); + node->els[i].ucs, node->els[i].gid, node->els[i].x, node->els[i].y); else printf("<g ucs=\"U+%04X\" gid=%d x=\"%g\" y=\"%g\" />\n", - node->els[i].ucs, node->els[i].gid, node->els[i].x, node->els[i].y); + node->els[i].ucs, node->els[i].gid, node->els[i].x, node->els[i].y); } indent(level); @@ -137,7 +137,7 @@ static void xmlimage(fz_imagenode *node, int level) fz_image *image = node->image; indent(level); printf("<image w=\"%d\" h=\"%d\" n=\"%d\" a=\"%d\" />\n", - image->w, image->h, image->n, image->a); + image->w, image->h, image->n, image->a); } static void xmlshade(fz_shadenode *node, int level) diff --git a/fitz/obj_parse.c b/fitz/obj_parse.c index 1b500d3d..31753222 100644 --- a/fitz/obj_parse.c +++ b/fitz/obj_parse.c @@ -35,7 +35,7 @@ static inline int isregular(int ch) static inline int fromhex(char ch) { if (ch >= '0' && ch <= '9') - return ch - '0'; + return ch - '0'; else if (ch >= 'A' && ch <= 'F') return ch - 'A' + 0xA; else if (ch >= 'a' && ch <= 'f') @@ -322,21 +322,21 @@ static fz_error parseobj(fz_obj **obj, pdf_xref *xref, char **sp, struct vap *v) case 'f': *obj = fz_newreal((float)va_arg(v->ap, double)); break; case 'n': *obj = fz_newname(va_arg(v->ap, char*)); break; case 'r': - num = va_arg(v->ap, int); - gen = va_arg(v->ap, int); - *obj = fz_newindirect(num, gen, xref); - break; + num = va_arg(v->ap, int); + gen = va_arg(v->ap, int); + *obj = fz_newindirect(num, gen, xref); + break; case 's': - tmp = va_arg(v->ap, char*); - *obj = fz_newstring(tmp, strlen(tmp)); - break; + tmp = va_arg(v->ap, char*); + *obj = fz_newstring(tmp, strlen(tmp)); + break; case '#': - tmp = va_arg(v->ap, char*); - len = va_arg(v->ap, int); - *obj = fz_newstring(tmp, len); - break; + tmp = va_arg(v->ap, char*); + len = va_arg(v->ap, int); + *obj = fz_newstring(tmp, len); + break; default: - return fz_throw("unknown format specifier in packobj: '%c'", *s); + return fz_throw("unknown format specifier in packobj: '%c'", *s); } s ++; diff --git a/fitz/obj_print.c b/fitz/obj_print.c index ad5bb344..a26f8f3d 100644 --- a/fitz/obj_print.c +++ b/fitz/obj_print.c @@ -336,6 +336,6 @@ fz_fprintobj(FILE *fp, fz_obj *obj, int tight) void fz_debugobj(fz_obj *obj) { - fz_fprintobj(stdout, obj, 0); + fz_fprintobj(stdout, obj, 0); } diff --git a/fitz/res_font.c b/fitz/res_font.c index cb6bc333..5f14d129 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -226,7 +226,7 @@ fz_renderftglyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) return fz_warn("freetype setting character size: %s", ft_errorstring(fterr)); fterr = FT_Load_Glyph(font->ftface, gid, - FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM); + FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM); if (fterr) return fz_throw("freetype failed to load glyph: %s", ft_errorstring(fterr)); @@ -254,7 +254,7 @@ fz_renderftglyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) * into FT_Set_Char_Size instead */ - m.xx = trm.a * 64; /* should be 65536 */ + m.xx = trm.a * 64; /* should be 65536 */ m.yx = trm.b * 64; m.xy = trm.c * 64; m.yy = trm.d * 64; @@ -268,30 +268,30 @@ fz_renderftglyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) if (font->fthint) { - /* Enable hinting, but keep the huge char size so that - * it is hinted for a character. This will in effect nullify - * the effect of grid fitting. This form of hinting should - * only be used for DynaLab and similar tricky TrueType fonts, - * so that we get the correct outline shape. - */ + /* Enable hinting, but keep the huge char size so that + * it is hinted for a character. This will in effect nullify + * the effect of grid fitting. This form of hinting should + * only be used for DynaLab and similar tricky TrueType fonts, + * so that we get the correct outline shape. + */ #ifdef USE_HINTING - /* If you really want grid fitting, enable this code. */ - float scale = fz_matrixexpansion(trm); - m.xx = trm.a * 65536 / scale; - m.xy = trm.b * 65536 / scale; - m.yx = trm.c * 65536 / scale; - m.yy = trm.d * 65536 / scale; - v.x = 0; - v.y = 0; - - fterr = FT_Set_Char_Size(face, 64 * scale, 64 * scale, 72, 72); - if (fterr) - fz_warn("freetype setting character size: %s", ft_errorstring(fterr)); - FT_Set_Transform(face, &m, &v); + /* If you really want grid fitting, enable this code. */ + float scale = fz_matrixexpansion(trm); + m.xx = trm.a * 65536 / scale; + m.xy = trm.b * 65536 / scale; + m.yx = trm.c * 65536 / scale; + m.yy = trm.d * 65536 / scale; + v.x = 0; + v.y = 0; + + fterr = FT_Set_Char_Size(face, 64 * scale, 64 * scale, 72, 72); + if (fterr) + fz_warn("freetype setting character size: %s", ft_errorstring(fterr)); + FT_Set_Transform(face, &m, &v); #endif - fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP); - if (fterr) - fz_warn("freetype load glyph (gid %d): %s", gid, ft_errorstring(fterr)); + fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP); + if (fterr) + fz_warn("freetype load glyph (gid %d): %s", gid, ft_errorstring(fterr)); } else { @@ -346,7 +346,7 @@ fz_newtype3font(char *name, fz_matrix matrix) font->t3procs[i] = nil; font->t3widths[i] = 0; } - + return font; } @@ -418,13 +418,13 @@ fz_debugfont(fz_font *font) if (font->t3procs) { printf(" type3 matrix [%g %g %g %g]\n", - font->t3matrix.a, font->t3matrix.b, - font->t3matrix.c, font->t3matrix.d); + font->t3matrix.a, font->t3matrix.b, + font->t3matrix.c, font->t3matrix.d); } printf(" bbox [%d %d %d %d]\n", - font->bbox.x0, font->bbox.y0, - font->bbox.x1, font->bbox.y1); + font->bbox.x0, font->bbox.y0, + font->bbox.x1, font->bbox.y1); printf("}\n"); } diff --git a/fitz/stm_buffer.c b/fitz/stm_buffer.c index c47c76fa..bfc0b0dc 100644 --- a/fitz/stm_buffer.c +++ b/fitz/stm_buffer.c @@ -65,7 +65,7 @@ fz_growbuffer(fz_buffer *buf) fz_warn("assert: grow borrowed memory"); return; } - + buf->bp = fz_realloc(buf->bp, (ep * 3) / 2); buf->rp = buf->bp + rp; buf->wp = buf->bp + wp; @@ -77,7 +77,7 @@ fz_rewindbuffer(fz_buffer *buf) { if (!buf->ownsdata) { - fz_warn("assert: rewind borrowed memory"); + fz_warn("assert: rewind borrowed memory"); return; } diff --git a/fitz/stm_filter.c b/fitz/stm_filter.c index 55428391..21fce662 100644 --- a/fitz/stm_filter.c +++ b/fitz/stm_filter.c @@ -12,7 +12,7 @@ fz_process(fz_filter *f, fz_buffer *in, fz_buffer *out) oldwp = out->wp; if (f->done) - return fz_iodone; + return fz_iodone; assert(!out->eof); diff --git a/fitz/stm_misc.c b/fitz/stm_misc.c index 7f7cf76f..3663107e 100644 --- a/fitz/stm_misc.c +++ b/fitz/stm_misc.c @@ -78,7 +78,7 @@ fz_readall(fz_stream *stm, int sizehint) fz_buffer *buf; if (sizehint == 0) - sizehint = 4 * 1024; + sizehint = 4 * 1024; buf = fz_newbuffer(sizehint); diff --git a/fitz/stm_open.c b/fitz/stm_open.c index 0f9e94f8..48e9587f 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -109,7 +109,7 @@ fz_stream * fz_openrmemory(unsigned char *mem, int len) { fz_buffer *buf; fz_stream *stm; - + buf = fz_newbufferwithmemory(mem, len); stm = fz_openrbuffer(buf); fz_dropbuffer(buf); diff --git a/fitz/util_getopt.c b/fitz/util_getopt.c index 9d8573dc..22ac8148 100644 --- a/fitz/util_getopt.c +++ b/fitz/util_getopt.c @@ -48,8 +48,8 @@ static char sccsid[] = "@(#)getopt.c 4.13 (Berkeley) 2/23/91"; * get option letter from argument vector */ int opterr = 1, /* if error message should be printed */ - optind = 1, /* index into parent argv vector */ - optopt; /* character checked for validity */ +optind = 1, /* index into parent argv vector */ +optopt; /* character checked for validity */ char *optarg; /* argument associated with option */ #define BADCH (int)'?' @@ -73,7 +73,7 @@ int fz_getopt(int nargc, char * const * nargv, const char *ostr) } } /* option letter okay? */ if ((optopt = (int)*place++) == (int)':' || - !(oli = strchr(ostr, optopt))) { + !(oli = strchr(ostr, optopt))) { /* * if the user didn't specify '-' as an option, * assume it means EOF. @@ -88,7 +88,7 @@ int fz_getopt(int nargc, char * const * nargv, const char *ostr) else ++p; (void)fprintf(stderr, "%s: illegal option -- %c\n", - p, optopt); + p, optopt); } return(BADCH); } @@ -108,8 +108,8 @@ int fz_getopt(int nargc, char * const * nargv, const char *ostr) ++p; if (opterr) (void)fprintf(stderr, - "%s: option requires an argument -- %c\n", - p, optopt); + "%s: option requires an argument -- %c\n", + p, optopt); return(BADCH); } else /* white space */ diff --git a/fitz/util_gettimeofday.c b/fitz/util_gettimeofday.c index fee36673..d7ce5083 100644 --- a/fitz/util_gettimeofday.c +++ b/fitz/util_gettimeofday.c @@ -3,48 +3,48 @@ #include <windows.h> #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 #else - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL #endif struct timezone { - int tz_minuteswest; /* minutes W of Greenwich */ - int tz_dsttime; /* type of dst correction */ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ }; int gettimeofday(struct timeval *tv, struct timezone *tz) { - FILETIME ft; - unsigned __int64 tmpres = 0; - static int tzflag = 0; - - if (NULL != tv) - { - GetSystemTimeAsFileTime(&ft); - - tmpres |= ft.dwHighDateTime; - tmpres <<= 32; - tmpres |= ft.dwLowDateTime; - - tmpres /= 10; /*convert into microseconds*/ - /*converting file time to unix epoch*/ - tmpres -= DELTA_EPOCH_IN_MICROSECS; - tv->tv_sec = (long)(tmpres / 1000000UL); - tv->tv_usec = (long)(tmpres % 1000000UL); - } - - if (NULL != tz) - { - if (!tzflag) - { - _tzset(); - tzflag++; - } - tz->tz_minuteswest = _timezone / 60; - tz->tz_dsttime = _daylight; - } - - return 0; + FILETIME ft; + unsigned __int64 tmpres = 0; + static int tzflag = 0; + + if (NULL != tv) + { + GetSystemTimeAsFileTime(&ft); + + tmpres |= ft.dwHighDateTime; + tmpres <<= 32; + tmpres |= ft.dwLowDateTime; + + tmpres /= 10; /*convert into microseconds*/ + /*converting file time to unix epoch*/ + tmpres -= DELTA_EPOCH_IN_MICROSECS; + tv->tv_sec = (long)(tmpres / 1000000UL); + tv->tv_usec = (long)(tmpres % 1000000UL); + } + + if (NULL != tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; } diff --git a/fitzdraw/archx86.c b/fitzdraw/archx86.c index abbdf1e0..f3d9ef24 100644 --- a/fitzdraw/archx86.c +++ b/fitzdraw/archx86.c @@ -12,18 +12,18 @@ typedef unsigned char byte; #ifdef HAVE_MMX /* -mmmx for gcc >= 3.4 enables the mmx intrinsic functions, icc and VC - shouldn't require anything */ +shouldn't require anything */ #include <mmintrin.h> static void duff_4i1o4mmx(byte *sp0, int sw, byte *mp0, int mw, byte *dp0, int dw, int w0, int h) { /* - rendering all pages of - x11pdf ~/doc/OpenGL/Presentations/CEDEC2003_Venus_and_Vulcan.pdf - % cumulative self self total - time seconds seconds calls ms/call ms/call name - 30.50 20.04 20.04 261 76.76 76.76 duff_4i1o4 - 21.67 22.02 10.95 221 49.55 49.55 duff_4i1o4mmx + rendering all pages of + x11pdf ~/doc/OpenGL/Presentations/CEDEC2003_Venus_and_Vulcan.pdf + % cumulative self self total + time seconds seconds calls ms/call ms/call name + 30.50 20.04 20.04 261 76.76 76.76 duff_4i1o4 + 21.67 22.02 10.95 221 49.55 49.55 duff_4i1o4mmx */ __m64 mzero = _mm_setzero_si64(); while (h--) @@ -89,7 +89,7 @@ getargb(unsigned *s, int w, int h, int u, int v) static void img_4o4mmx(FZ_PSRC, FZ_PDST, FZ_PCTM) { /* since mmx does not have an unsigned multiply instruction we use - 17.15 fixed point */ + 17.15 fixed point */ u0 >>= 1; v0 >>= 1; fa >>= 1; fb >>= 1; fc >>= 1; fd >>= 1; @@ -115,8 +115,8 @@ static void img_4o4mmx(FZ_PSRC, FZ_PDST, FZ_PCTM) int fv = v & 0x7fff; int atedge = - (iu < 0) | (iu >= (srcw - 1)) | - (iv < 0) | (iv >= (srch - 1)); + (iu < 0) | (iu >= (srcw - 1)) | + (iv < 0) | (iv >= (srch - 1)); __m64 ms0s1; __m64 ms2s3; diff --git a/fitzdraw/blendmodes.c b/fitzdraw/blendmodes.c index e14b8a32..0b6fedcc 100644 --- a/fitzdraw/blendmodes.c +++ b/fitzdraw/blendmodes.c @@ -190,7 +190,7 @@ fz_saturation_rgb(int *bdr, int *bdg, int *bdb, int sr, int sg, int sb) { int tr, tg, tb; setsat(*bdr, *bdg, *bdb, sat(sr, sg, sb), &tr, &tg, &tb); - setlum(tr, tg, tb, lum(*bdr, *bdg, *bdb), bdr, bdg, bdb); + setlum(tr, tg, tb, lum(*bdr, *bdg, *bdb), bdr, bdg, bdb); } @@ -210,4 +210,4 @@ fz_luminosity_rgb(int *bdr, int *bdg, int *bdb, int sr, int sg, int sb) //fz_separable_blend(, fz_blendkind mode) //{ -//} + //} diff --git a/fitzdraw/glyphcache.c b/fitzdraw/glyphcache.c index f3f6d38d..0b602857 100644 --- a/fitzdraw/glyphcache.c +++ b/fitzdraw/glyphcache.c @@ -144,7 +144,7 @@ hashinsert(fz_glyphcache *arena, fz_key *key, fz_val *val) { fz_hash *tab = arena->hash; int pos = hashkey(key) % arena->slots; -int didcoll = 0; + int didcoll = 0; while (1) { @@ -153,14 +153,14 @@ int didcoll = 0; tab[pos].key = *key; tab[pos].val = val; tab[pos].val->ent = &tab[pos]; -if (didcoll) hcoll ++; else hokay ++; hdist += didcoll; + if (didcoll) hcoll ++; else hokay ++; hdist += didcoll; return; } pos = pos + 1; if (pos == arena->slots) pos = 0; -didcoll ++; + didcoll ++; } } @@ -168,51 +168,51 @@ didcoll ++; static void hashremove(fz_glyphcache *arena, fz_key *key) { - fz_hash *tab = arena->hash; - unsigned int pos = hashkey(key) % arena->slots; - unsigned int hole; - unsigned int look; - unsigned int code; +fz_hash *tab = arena->hash; +unsigned int pos = hashkey(key) % arena->slots; +unsigned int hole; +unsigned int look; +unsigned int code; - while (1) - { - if (!tab[pos].val) - return; // boo hoo! tried to remove non-existant key +while (1) +{ +if (!tab[pos].val) +return; // boo hoo! tried to remove non-existant key - if (memcmp(key, &tab[pos].key, sizeof (fz_key)) == 0) - { - tab[pos].val = nil; - - hole = pos; - look = hole + 1; - if (look == arena->slots) - look = 0; - - while (tab[look].val) - { - code = (hashkey(&tab[look].key) % arena->slots); - if ((code <= hole && hole < look) || - (look < code && code <= hole) || - (hole < look && look < code)) - { - tab[hole] = tab[look]; - tab[hole].val->ent = &tab[hole]; - tab[look].val = nil; - hole = look; - } - - look = look + 1; - if (look == arena->slots) - look = 0; - } +if (memcmp(key, &tab[pos].key, sizeof (fz_key)) == 0) +{ +tab[pos].val = nil; - return; - } +hole = pos; +look = hole + 1; +if (look == arena->slots) +look = 0; - pos = pos + 1; - if (pos == arena->slots) - pos = 0; - } +while (tab[look].val) +{ +code = (hashkey(&tab[look].key) % arena->slots); +if ((code <= hole && hole < look) || +(look < code && code <= hole) || +(hole < look && look < code)) +{ +tab[hole] = tab[look]; +tab[hole].val->ent = &tab[hole]; +tab[look].val = nil; +hole = look; +} + +look = look + 1; +if (look == arena->slots) +look = 0; +} + +return; +} + +pos = pos + 1; +if (pos == arena->slots) +pos = 0; +} } */ @@ -226,31 +226,31 @@ fz_debugglyphcache(fz_glyphcache *arena) printf("out-of-space evicts: %d\n", coos); printf("out-of-hash evicts: %d\n", covf); printf("hits = %d misses = %d ratio = %g\n", ghits, gmisses, (float)ghits / (ghits + gmisses)); -/* + /* int i; for (i = 0; i < arena->slots; i++) { - if (!arena->hash[i].val) - printf("glyph % 4d: empty\n", i); - else { - fz_key *k = &arena->hash[i].key; - fz_val *b = arena->hash[i].val; - printf("glyph % 4d: %p %d [%g %g %g %g + %d %d] " - "-> [%dx%d %d,%d]\n", i, - k->fid, k->cid, - k->a / 65536.0, - k->b / 65536.0, - k->c / 65536.0, - k->d / 65536.0, - k->e, k->f, - b->w, b->h, b->x, b->y); - } + if (!arena->hash[i].val) + printf("glyph % 4d: empty\n", i); + else { + fz_key *k = &arena->hash[i].key; + fz_val *b = arena->hash[i].val; + printf("glyph % 4d: %p %d [%g %g %g %g + %d %d] " + "-> [%dx%d %d,%d]\n", i, + k->fid, k->cid, + k->a / 65536.0, + k->b / 65536.0, + k->c / 65536.0, + k->d / 65536.0, + k->e, k->f, + b->w, b->h, b->x, b->y); + } } for (i = 0; i < arena->load; i++) - printf("lru %04d: glyph %d (%d)\n", i, - arena->lru[i].ent - arena->hash, arena->lru[i].uses); -*/ + printf("lru %04d: glyph %d (%d)\n", i, + arena->lru[i].ent - arena->hash, arena->lru[i].uses); + */ } static void @@ -273,33 +273,33 @@ bubble(fz_glyphcache *arena, int i) static void evictlast(fz_glyphcache *arena) { - fz_val *lru = arena->lru; - unsigned char *s, *e; - int i, k; - fz_key key; +fz_val *lru = arena->lru; +unsigned char *s, *e; +int i, k; +fz_key key; - if (arena->load == 0) - return; +if (arena->load == 0) +return; - k = arena->load - 1; - s = lru[k].samples; - e = s + lru[k].w * lru[k].h; +k = arena->load - 1; +s = lru[k].samples; +e = s + lru[k].w * lru[k].h; - // pack buffer to fill hole - memmove(s, e, arena->buffer + arena->used - e); - memset(arena->buffer + arena->used - (e - s), 0, e - s); - arena->used -= e - s; +// pack buffer to fill hole +memmove(s, e, arena->buffer + arena->used - e); +memset(arena->buffer + arena->used - (e - s), 0, e - s); +arena->used -= e - s; - // update lru pointers - for (i = 0; i < k; i++) // XXX this is DOG slow! XXX - if (lru[i].samples >= e) - lru[i].samples -= e - s; +// update lru pointers +for (i = 0; i < k; i++) // XXX this is DOG slow! XXX +if (lru[i].samples >= e) +lru[i].samples -= e - s; - // remove hash entry - key = lru[k].ent->key; - hashremove(arena, &key); +// remove hash entry +key = lru[k].ent->key; +hashremove(arena, &key); - arena->load --; +arena->load --; } */ @@ -354,19 +354,19 @@ fz_renderglyph(fz_glyphcache *arena, fz_glyph *glyph, fz_font *font, int cid, fz if (font->ftface) { - error = fz_renderftglyph(glyph, font, cid, ctm); - if (error) - return error; + error = fz_renderftglyph(glyph, font, cid, ctm); + if (error) + return error; } else if (font->t3procs) { - error = fz_rendert3glyph(glyph, font, cid, ctm); - if (error) - return error; + error = fz_rendert3glyph(glyph, font, cid, ctm); + if (error) + return error; } else { - return fz_throw("uninitialized font structure"); + return fz_throw("uninitialized font structure"); } size = glyph->w * glyph->h; diff --git a/fitzdraw/imagescale.c b/fitzdraw/imagescale.c index 79d31c06..147e31af 100644 --- a/fitzdraw/imagescale.c +++ b/fitzdraw/imagescale.c @@ -229,8 +229,8 @@ fz_scalepixmaptile(fz_pixmap *dst, int xoffs, int yoffs, fz_pixmap *src, int xde { for (iy = 0; iy < ydenom; iy++) srowx(src->samples + (y + iy) * src->w * n, - buf + iy * ow * n, - src->w, xdenom); + buf + iy * ow * n, + src->w, xdenom); scolx(buf, dstsamples + oy * dst->w * n, ow, ydenom); } @@ -239,8 +239,8 @@ fz_scalepixmaptile(fz_pixmap *dst, int xoffs, int yoffs, fz_pixmap *src, int xde { for (iy = 0; iy < remaining; iy++) srowx(src->samples + (y + iy) * src->w * n, - buf + iy * ow * n, - src->w, xdenom); + buf + iy * ow * n, + src->w, xdenom); scolx(buf, dstsamples + oy * dst->w * n, ow, remaining); } } @@ -251,8 +251,8 @@ fz_scalepixmaptile(fz_pixmap *dst, int xoffs, int yoffs, fz_pixmap *src, int xde { for (iy = 0; iy < ydenom; iy++) fz_srown(src->samples + (y + iy) * src->w * n, - buf + iy * ow * n, - src->w, xdenom, n); + buf + iy * ow * n, + src->w, xdenom, n); fz_scoln(buf, dstsamples + oy * dst->w * n, ow, ydenom, n); } @@ -261,8 +261,8 @@ fz_scalepixmaptile(fz_pixmap *dst, int xoffs, int yoffs, fz_pixmap *src, int xde { for (iy = 0; iy < remaining; iy++) fz_srown(src->samples + (y + iy) * src->w * n, - buf + iy * ow * n, - src->w, xdenom, n); + buf + iy * ow * n, + src->w, xdenom, n); fz_scoln(buf, dstsamples + oy * dst->w * n, ow, remaining, n); } @@ -314,8 +314,8 @@ fz_scalepixmap(fz_pixmap **dstp, fz_pixmap *src, int xdenom, int ydenom) { for (iy = 0; iy < ydenom; iy++) srowx(src->samples + (y + iy) * src->w * n, - buf + iy * ow * n, - src->w, xdenom); + buf + iy * ow * n, + src->w, xdenom); scolx(buf, dst->samples + oy * dst->w * n, dst->w, ydenom); } @@ -324,8 +324,8 @@ fz_scalepixmap(fz_pixmap **dstp, fz_pixmap *src, int xdenom, int ydenom) { for (iy = 0; iy < remaining; iy++) srowx(src->samples + (y + iy) * src->w * n, - buf + iy * ow * n, - src->w, xdenom); + buf + iy * ow * n, + src->w, xdenom); scolx(buf, dst->samples + oy * dst->w * n, dst->w, remaining); } } @@ -336,8 +336,8 @@ fz_scalepixmap(fz_pixmap **dstp, fz_pixmap *src, int xdenom, int ydenom) { for (iy = 0; iy < ydenom; iy++) fz_srown(src->samples + (y + iy) * src->w * n, - buf + iy * ow * n, - src->w, xdenom, n); + buf + iy * ow * n, + src->w, xdenom, n); fz_scoln(buf, dst->samples + oy * dst->w * n, dst->w, ydenom, n); } @@ -346,8 +346,8 @@ fz_scalepixmap(fz_pixmap **dstp, fz_pixmap *src, int xdenom, int ydenom) { for (iy = 0; iy < remaining; iy++) fz_srown(src->samples + (y + iy) * src->w * n, - buf + iy * ow * n, - src->w, xdenom, n); + buf + iy * ow * n, + src->w, xdenom, n); fz_scoln(buf, dst->samples + oy * dst->w * n, dst->w, remaining, n); } } diff --git a/fitzdraw/imageunpack.c b/fitzdraw/imageunpack.c index 50a65253..15d060f8 100644 --- a/fitzdraw/imageunpack.c +++ b/fitzdraw/imageunpack.c @@ -37,14 +37,14 @@ static void decodetile(fz_pixmap *pix, int skip, float *decode) return; switch (n) { - case 1: + case 1: while (wh--) { p[0] = min[0] + fz_mul255(sub[0], p[0]); p ++; } break; - case 2: + case 2: if (justinvert) { unsigned *wp = (unsigned *)p; @@ -69,14 +69,14 @@ static void decodetile(fz_pixmap *pix, int skip, float *decode) } } else - while (wh--) + while (wh--) { p[0] = min[0] + fz_mul255(sub[0], p[0]); p[1] = min[1] + fz_mul255(sub[1], p[1]); p += 2; } break; - default: + default: while (wh--) { for (i = 0; i < n; i++) @@ -219,11 +219,11 @@ static void loadtile1(byte * restrict src, int sw, byte * restrict dst, int dw, } static void loadtile2(byte * restrict src, int sw, byte * restrict dst, int dw, int w, int h, int pad) - TILE(ttwo) +TILE(ttwo) static void loadtile4(byte * restrict src, int sw, byte * restrict dst, int dw, int w, int h, int pad) - TILE(tnib) +TILE(tnib) static void loadtile8(byte * restrict src, int sw, byte * restrict dst, int dw, int w, int h, int pad) - TILE(toct) +TILE(toct) void (*fz_decodetile)(fz_pixmap *pix, int skip, float *decode) = decodetile; void (*fz_loadtile1)(byte*, int sw, byte*, int dw, int w, int h, int pad) = loadtile1; diff --git a/fitzdraw/meshdraw.c b/fitzdraw/meshdraw.c index 108c8768..ba1e036c 100644 --- a/fitzdraw/meshdraw.c +++ b/fitzdraw/meshdraw.c @@ -77,8 +77,8 @@ static inline void copyvert(float *dst, float *src, int n) } static int clippoly(float src[MAXV][MAXN], - float dst[MAXV][MAXN], int len, int n, - float val, int isy, int ismax) + float dst[MAXV][MAXN], int len, int n, + float val, int isy, int ismax) { float cv1[MAXN]; float cv2[MAXN]; @@ -100,18 +100,18 @@ static int clippoly(float src[MAXV][MAXN], switch (r) { - case IN: - copyvert(dst[cp++], cv2, n); - break; - case OUT: - break; - case LEAVE: - copyvert(dst[cp++], cv2, n); - break; - case ENTER: - copyvert(dst[cp++], cv1, n); - copyvert(dst[cp++], cv2, n); - break; + case IN: + copyvert(dst[cp++], cv2, n); + break; + case OUT: + break; + case LEAVE: + copyvert(dst[cp++], cv2, n); + break; + case ENTER: + copyvert(dst[cp++], cv1, n); + copyvert(dst[cp++], cv2, n); + break; } v1 = v2; } @@ -339,7 +339,7 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *destcs, fz_pixmap { n = 2 + shade->cs->n; error = fz_newpixmap(&temp, dest->x, dest->y, dest->w, dest->h, - shade->cs->n + 1); + shade->cs->n + 1); if (error) return error; } @@ -359,14 +359,14 @@ fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *destcs, fz_pixmap p.y = shade->mesh[(i * 3 + k) * n + 1]; p = fz_transformpoint(ctm, p); if (isnan(p.y) || isnan(p.x)) // How is this happening? - goto baddata; + goto baddata; tri[k][0] = p.x; tri[k][1] = p.y; for (j = 2; j < n; j++) tri[k][j] = shade->mesh[( i * 3 + k) * n + j] * 255; } fz_drawtriangle(temp, tri[0], tri[1], tri[2], n); - baddata: +baddata: ; } diff --git a/fitzdraw/pathscan.c b/fitzdraw/pathscan.c index 64397563..dc0ca7c7 100644 --- a/fitzdraw/pathscan.c +++ b/fitzdraw/pathscan.c @@ -434,8 +434,8 @@ static inline void toalpha(unsigned char *list, int n) } static inline void blit(fz_pixmap *pix, int x, int y, - unsigned char *list, int skipx, int len, - unsigned char *argb, int over) + unsigned char *list, int skipx, int len, + unsigned char *argb, int over) { unsigned char *dst; unsigned char cov; diff --git a/fitzdraw/pathstroke.c b/fitzdraw/pathstroke.c index 94409789..13e70dd4 100644 --- a/fitzdraw/pathstroke.c +++ b/fitzdraw/pathstroke.c @@ -38,9 +38,9 @@ line(struct sctx *s, float x0, float y0, float x1, float y1) static fz_error arc(struct sctx *s, - float xc, float yc, - float x0, float y0, - float x1, float y1) + float xc, float yc, + float x0, float y0, + float x1, float y1) { fz_error error; float th0, th1, r; @@ -255,17 +255,17 @@ linecap(struct sctx *s, fz_point a, fz_point b) if (linecap == SQUARE) { error = line(s, b.x - dlx, b.y - dly, - b.x - dlx - dly, - b.y - dly + dlx); + b.x - dlx - dly, + b.y - dly + dlx); if (error) return error; error = line(s, b.x - dlx - dly, - b.y - dly + dlx, - b.x + dlx - dly, - b.y + dly + dlx); + b.y - dly + dlx, + b.x + dlx - dly, + b.y + dly + dlx); if (error) return error; error = line(s, b.x + dlx - dly, - b.y + dly + dlx, - b.x + dlx, b.y + dly); + b.y + dly + dlx, + b.x + dlx, b.y + dly); if (error) return error; } diff --git a/fitzdraw/pixmap.c b/fitzdraw/pixmap.c index e3d9a285..78c8dc2f 100644 --- a/fitzdraw/pixmap.c +++ b/fitzdraw/pixmap.c @@ -30,9 +30,9 @@ fz_error fz_newpixmapwithrect(fz_pixmap **pixp, fz_irect r, int n) { return fz_newpixmap(pixp, - r.x0, r.y0, - r.x1 - r.x0, - r.y1 - r.y0, n); + r.x0, r.y0, + r.x1 - r.x0, + r.y1 - r.y0, n); } fz_error diff --git a/fitzdraw/render.c b/fitzdraw/render.c index 97941d95..b4cfa4fa 100644 --- a/fitzdraw/render.c +++ b/fitzdraw/render.c @@ -95,14 +95,14 @@ static fz_error rendertransform(fz_renderer *gc, fz_transformnode *transform, fz_matrix ctm) { fz_error error; -DEBUG("transform [%g %g %g %g %g %g]\n", -transform->m.a, transform->m.b, -transform->m.c, transform->m.d, -transform->m.e, transform->m.f); -DEBUG("{\n"); + DEBUG("transform [%g %g %g %g %g %g]\n", + transform->m.a, transform->m.b, + transform->m.c, transform->m.d, + transform->m.e, transform->m.f); + DEBUG("{\n"); ctm = fz_concat(transform->m, ctm); error = rendernode(gc, transform->super.first, ctm); -DEBUG("}\n"); + DEBUG("}\n"); return error; } @@ -133,7 +133,7 @@ rendersolid(fz_renderer *gc, fz_solidnode *solid, fz_matrix ctm) gc->argb[5] = rgb[1] * 255; gc->argb[6] = rgb[2] * 255; -DEBUG("solid %s [%d %d %d %d];\n", solid->cs->name, gc->argb[0], gc->argb[1], gc->argb[2], gc->argb[3]); + DEBUG("solid %s [%d %d %d %d];\n", solid->cs->name, gc->argb[0], gc->argb[1], gc->argb[2], gc->argb[3]); if (gc->flag == FOVER) { @@ -148,20 +148,20 @@ DEBUG("solid %s [%d %d %d %d];\n", solid->cs->name, gc->argb[0], gc->argb[1], gc p = gc->dest->samples; n = gc->dest->w * gc->dest->h; } - + a = gc->argb[0]; r = gc->argb[1]; g = gc->argb[2]; b = gc->argb[3]; if ((p - (unsigned char *)0) & 3) { - while (n--) - { - p[0] = a; - p[1] = r; - p[2] = g; - p[3] = b; - p += 4; - } + while (n--) + { + p[0] = a; + p[1] = r; + p[2] = g; + p[3] = b; + p += 4; + } } else { @@ -223,18 +223,18 @@ renderpath(fz_renderer *gc, fz_pathnode *path, fz_matrix ctm) if (fz_isemptyrect(clip)) return fz_okay; -DEBUG("path %s;\n", path->paint == FZ_STROKE ? "stroke" : "fill"); + DEBUG("path %s;\n", path->paint == FZ_STROKE ? "stroke" : "fill"); if (gc->flag & FRGB) { -DEBUG(" path rgb %d %d %d %d, %d %d %d\n", gc->argb[0], gc->argb[1], gc->argb[2], gc->argb[3], gc->argb[4], gc->argb[5], gc->argb[6]); + DEBUG(" path rgb %d %d %d %d, %d %d %d\n", gc->argb[0], gc->argb[1], gc->argb[2], gc->argb[3], gc->argb[4], gc->argb[5], gc->argb[6]); return fz_scanconvert(gc->gel, gc->ael, path->paint == FZ_EOFILL, - clip, gc->over, gc->argb, 1); + clip, gc->over, gc->argb, 1); } else if (gc->flag & FOVER) { return fz_scanconvert(gc->gel, gc->ael, path->paint == FZ_EOFILL, - clip, gc->over, nil, 1); + clip, gc->over, nil, 1); } else { @@ -243,7 +243,7 @@ DEBUG(" path rgb %d %d %d %d, %d %d %d\n", gc->argb[0], gc->argb[1], gc->argb[2] return error; fz_clearpixmap(gc->dest); return fz_scanconvert(gc->gel, gc->ael, path->paint == FZ_EOFILL, - clip, gc->dest, nil, 0); + clip, gc->dest, nil, 0); } } @@ -319,9 +319,9 @@ rendertext(fz_renderer *gc, fz_textnode *text, fz_matrix ctm) tbox = fz_roundrect(fz_boundnode((fz_node*)text, ctm)); clip = fz_intersectirects(gc->clip, tbox); -DEBUG("text %s n=%d [%g %g %g %g];\n", -text->font->name, text->len, -text->trm.a, text->trm.b, text->trm.c, text->trm.d); + DEBUG("text %s n=%d [%g %g %g %g];\n", + text->font->name, text->len, + text->trm.a, text->trm.b, text->trm.c, text->trm.d); if (fz_isemptyrect(clip)) return fz_okay; @@ -402,15 +402,15 @@ renderimage(fz_renderer *gc, fz_imagenode *node, fz_matrix ctm) int w, h; int tileheight; -DEBUG("image %dx%d %d+%d %s\n{\n", image->w, image->h, image->n, image->a, image->cs?image->cs->name:"(nil)"); + DEBUG("image %dx%d %d+%d %s\n{\n", image->w, image->h, image->n, image->a, image->cs?image->cs->name:"(nil)"); bbox = fz_roundrect(fz_boundnode((fz_node*)node, ctm)); clip = fz_intersectirects(gc->clip, bbox); if (fz_isemptyrect(clip)) return fz_okay; - if (image->w == 0 || image->h == 0) - return fz_okay; + if (image->w == 0 || image->h == 0) + return fz_okay; calcimagescale(ctm, image->w, image->h, &dx, &dy); @@ -424,7 +424,7 @@ DEBUG("image %dx%d %d+%d %s\n{\n", image->w, image->h, image->n, image->a, image DEBUG(" load image tile size = %dx%d\n", image->w, tileheight); error = fz_newpixmap(&tile, 0, 0, image->w, - tileheight, image->n + 1); + tileheight, image->n + 1); if (error) return error; @@ -438,7 +438,7 @@ DEBUG("image %dx%d %d+%d %s\n{\n", image->w, image->h, image->n, image->a, image tile->y = y; tile->h = tileheight; DEBUG(" tile xywh=%d %d %d %d sxsy=1/%d 1/%d\n", - 0, y, image->w, tileheight, dx, dy); + 0, y, image->w, tileheight, dx, dy); error = image->loadtile(image, tile); if (error) goto cleanup1; @@ -456,7 +456,7 @@ DEBUG("image %dx%d %d+%d %s\n{\n", image->w, image->h, image->n, image->a, image else { -DEBUG(" load image\n"); + DEBUG(" load image\n"); error = fz_newpixmap(&tile, 0, 0, image->w, image->h, image->n + 1); if (error) return error; @@ -467,7 +467,7 @@ DEBUG(" load image\n"); if (dx != 1 || dy != 1) { -DEBUG(" scale image 1/%d 1/%d\n", dx, dy); + DEBUG(" scale image 1/%d 1/%d\n", dx, dy); error = fz_scalepixmap(&temp, tile, dx, dy); if (error) goto cleanup; @@ -478,7 +478,7 @@ DEBUG(" scale image 1/%d 1/%d\n", dx, dy); if (image->cs && image->cs != gc->model) { -DEBUG(" convert from %s to %s\n", image->cs->name, gc->model->name); + DEBUG(" convert from %s to %s\n", image->cs->name, gc->model->name); error = fz_newpixmap(&temp, tile->x, tile->y, tile->w, tile->h, gc->model->n + 1); if (error) goto cleanup; @@ -517,7 +517,7 @@ DEBUG(" convert from %s to %s\n", image->cs->name, gc->model->name); { case FNONE: { -DEBUG(" fnone %d x %d\n", w, h); + DEBUG(" fnone %d x %d\n", w, h); if (image->cs) error = fz_newpixmapwithrect(&gc->dest, clip, gc->model->n + 1); else @@ -534,7 +534,7 @@ DEBUG(" fnone %d x %d\n", w, h); case FOVER: { -DEBUG(" fover %d x %d\n", w, h); + DEBUG(" fover %d x %d\n", w, h); if (image->cs) fz_img_4o4(PSRC, PDST(gc->over), PCTM); else @@ -543,7 +543,7 @@ DEBUG(" fover %d x %d\n", w, h); break; case FOVER | FRGB: -DEBUG(" fover+rgb %d x %d\n", w, h); + DEBUG(" fover+rgb %d x %d\n", w, h); fz_img_w4i1o4(gc->argb, PSRC, PDST(gc->over), PCTM); break; @@ -551,7 +551,7 @@ DEBUG(" fover+rgb %d x %d\n", w, h); assert(!"impossible flag in image span function"); } -DEBUG("}\n"); + DEBUG("}\n"); fz_droppixmap(tile); return fz_okay; @@ -693,7 +693,7 @@ renderover(fz_renderer *gc, fz_overnode *over, fz_matrix ctm) if (!gc->over) { -DEBUG("over cluster %d\n{\n", gc->maskonly ? 1 : 4); + DEBUG("over cluster %d\n{\n", gc->maskonly ? 1 : 4); cluster = 1; if (gc->maskonly) error = fz_newpixmapwithrect(&gc->over, gc->clip, 1); @@ -703,7 +703,7 @@ DEBUG("over cluster %d\n{\n", gc->maskonly ? 1 : 4); return error; fz_clearpixmap(gc->over); } -else DEBUG("over\n{\n"); + else DEBUG("over\n{\n"); for (child = over->super.first; child; child = child->next) { @@ -724,7 +724,7 @@ else DEBUG("over\n{\n"); gc->over = nil; } -DEBUG("}\n"); + DEBUG("}\n"); return fz_okay; } @@ -785,15 +785,15 @@ rendermask(fz_renderer *gc, fz_masknode *mask, fz_matrix ctm) if (fz_isemptyrect(clip)) return fz_okay; -DEBUG("mask [%d %d %d %d]\n{\n", clip.x0, clip.y0, clip.x1, clip.y1); + DEBUG("mask [%d %d %d %d]\n{\n", clip.x0, clip.y0, clip.x1, clip.y1); -{ -fz_irect sbox = fz_roundrect(fz_boundnode(shape, ctm)); -fz_irect cbox = fz_roundrect(fz_boundnode(color, ctm)); -if (cbox.x0 >= sbox.x0 && cbox.x1 <= sbox.x1) -if (cbox.y0 >= sbox.y0 && cbox.y1 <= sbox.y1) -DEBUG("potentially useless mask\n"); -} + { + fz_irect sbox = fz_roundrect(fz_boundnode(shape, ctm)); + fz_irect cbox = fz_roundrect(fz_boundnode(color, ctm)); + if (cbox.x0 >= sbox.x0 && cbox.x1 <= sbox.x1) + if (cbox.y0 >= sbox.y0 && cbox.y1 <= sbox.y1) + DEBUG("potentially useless mask\n"); + } gc->clip = clip; gc->over = nil; @@ -837,7 +837,7 @@ DEBUG("potentially useless mask\n"); } } -DEBUG("}\n"); + DEBUG("}\n"); if (shapepix) fz_droppixmap(shapepix); if (colorpix) fz_droppixmap(colorpix); @@ -912,15 +912,15 @@ fz_rendertree(fz_pixmap **outp, else memset(gc->over->samples, 0x00, gc->over->w * gc->over->h * gc->over->n); -DEBUG("tree %d [%d %d %d %d]\n{\n", -gc->maskonly ? 1 : 4, -bbox.x0, bbox.y0, bbox.x1, bbox.y1); + DEBUG("tree %d [%d %d %d %d]\n{\n", + gc->maskonly ? 1 : 4, + bbox.x0, bbox.y0, bbox.x1, bbox.y1); error = rendernode(gc, tree->root, ctm); if (error) return error; -DEBUG("}\n"); + DEBUG("}\n"); if (gc->dest) { diff --git a/mupdf/cmapdump.c b/mupdf/cmapdump.c index 27275360..e3521231 100644 --- a/mupdf/cmapdump.c +++ b/mupdf/cmapdump.c @@ -13,155 +13,155 @@ static char * flagtoname(int flag) { - switch (flag) - { + switch (flag) + { case PDF_CMAP_SINGLE: return "PDF_CMAP_SINGLE,"; - case PDF_CMAP_RANGE: return "PDF_CMAP_RANGE, "; - case PDF_CMAP_TABLE: return "PDF_CMAP_TABLE, "; - case PDF_CMAP_MULTI: return "PDF_CMAP_MULTI, "; - } - return "-1,"; + case PDF_CMAP_RANGE: return "PDF_CMAP_RANGE, "; + case PDF_CMAP_TABLE: return "PDF_CMAP_TABLE, "; + case PDF_CMAP_MULTI: return "PDF_CMAP_MULTI, "; + } + return "-1,"; } static void clean(char *p) { - while (*p) - { - if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-')) - *p = '_'; - p ++; - } + while (*p) + { + if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-')) + *p = '_'; + p ++; + } } int main(int argc, char **argv) { - pdf_cmap *cmap; - fz_error error; - fz_stream *fi; - FILE *fo; - char name[256]; - char *realname; - int i, k; - - if (argc < 3) - { - fprintf(stderr, "usage: cmapdump output.c lots of cmap files\n"); - return 1; - } - - fo = fopen(argv[1], "wb"); - if (!fo) - { - fprintf(stderr, "cmapdump: could not open output file\n"); - return 1; - } - - fprintf(fo, "#include \"fitz.h\"\n"); - fprintf(fo, "#include \"mupdf.h\"\n"); - fprintf(fo, "\n"); - - for (i = 2; i < argc; i++) - { - realname = strrchr(argv[i], '/'); - if (!realname) - realname = strrchr(argv[i], '\\'); - if (realname) - realname ++; - else - realname = argv[i]; - - if (strlen(realname) > (sizeof name - 1)) - { - fprintf(stderr, "cmapdump: file name too long\n"); - return 1; - } - - strcpy(name, realname); - clean(name); - - error = fz_openrfile(&fi, argv[i]); - if (error) - { - fz_catch(error, "cmapdump: could not open input file %s\n", argv[i]); - return 1; - } - - error = pdf_parsecmap(&cmap, fi); - if (error) - { - fz_catch(error, "cmapdump: could not parse input cmap %s\n", argv[i]); - return 1; - } - - fprintf(fo, "/*\n * %s\n */\n\n", cmap->cmapname); - - fprintf(fo, "static const pdf_range pdf_cmap_%s_ranges[] =\n{\n", name); - if (cmap->rlen == 0) - { - fprintf(fo, " /* dummy entry for non-c99 compilers */\n"); - fprintf(fo, " { 0x0, 0x0, PDF_CMAP_RANGE, 0 }\n"); - } - for (k = 0; k < cmap->rlen; k++) + pdf_cmap *cmap; + fz_error error; + fz_stream *fi; + FILE *fo; + char name[256]; + char *realname; + int i, k; + + if (argc < 3) { - fprintf(fo, " { 0x%04x, 0x%04x, %s %d },\n", - cmap->ranges[k].low, cmap->ranges[k].high, - flagtoname(cmap->ranges[k].flag), - cmap->ranges[k].offset); + fprintf(stderr, "usage: cmapdump output.c lots of cmap files\n"); + return 1; } - fprintf(fo, "};\n\n"); - if (cmap->tlen == 0) + fo = fopen(argv[1], "wb"); + if (!fo) { - fprintf(fo, "static const unsigned short pdf_cmap_%s_table[1] = { 0 };\n\n", name); + fprintf(stderr, "cmapdump: could not open output file\n"); + return 1; } - else - { - fprintf(fo, "static const unsigned short pdf_cmap_%s_table[%d] =\n{", - name, cmap->tlen); - for (k = 0; k < cmap->tlen; k++) - { - if (k % 8 == 0) - fprintf(fo, "\n "); - fprintf(fo, "%d, ", cmap->table[k]); - } - fprintf(fo, "\n};\n\n"); - } - - fprintf(fo, "pdf_cmap pdf_cmap_%s =\n", name); - fprintf(fo, "{\n"); - fprintf(fo, " -1, "); - fprintf(fo, "\"%s\", ", cmap->cmapname); - fprintf(fo, "\"%s\", nil, ", cmap->usecmapname); - fprintf(fo, "%d,\n", cmap->wmode); - fprintf(fo, " %d, /* codespace table */\n", cmap->ncspace); - fprintf(fo, " {\n"); + fprintf(fo, "#include \"fitz.h\"\n"); + fprintf(fo, "#include \"mupdf.h\"\n"); + fprintf(fo, "\n"); - if (cmap->ncspace == 0) + for (i = 2; i < argc; i++) { - fprintf(fo, " /* dummy entry for non-c99 compilers */\n"); - fprintf(fo, " { 0, 0x0, 0x0 },\n"); + realname = strrchr(argv[i], '/'); + if (!realname) + realname = strrchr(argv[i], '\\'); + if (realname) + realname ++; + else + realname = argv[i]; + + if (strlen(realname) > (sizeof name - 1)) + { + fprintf(stderr, "cmapdump: file name too long\n"); + return 1; + } + + strcpy(name, realname); + clean(name); + + error = fz_openrfile(&fi, argv[i]); + if (error) + { + fz_catch(error, "cmapdump: could not open input file %s\n", argv[i]); + return 1; + } + + error = pdf_parsecmap(&cmap, fi); + if (error) + { + fz_catch(error, "cmapdump: could not parse input cmap %s\n", argv[i]); + return 1; + } + + fprintf(fo, "/*\n * %s\n */\n\n", cmap->cmapname); + + fprintf(fo, "static const pdf_range pdf_cmap_%s_ranges[] =\n{\n", name); + if (cmap->rlen == 0) + { + fprintf(fo, " /* dummy entry for non-c99 compilers */\n"); + fprintf(fo, " { 0x0, 0x0, PDF_CMAP_RANGE, 0 }\n"); + } + for (k = 0; k < cmap->rlen; k++) + { + fprintf(fo, " { 0x%04x, 0x%04x, %s %d },\n", + cmap->ranges[k].low, cmap->ranges[k].high, + flagtoname(cmap->ranges[k].flag), + cmap->ranges[k].offset); + } + fprintf(fo, "};\n\n"); + + if (cmap->tlen == 0) + { + fprintf(fo, "static const unsigned short pdf_cmap_%s_table[1] = { 0 };\n\n", name); + } + else + { + fprintf(fo, "static const unsigned short pdf_cmap_%s_table[%d] =\n{", + name, cmap->tlen); + for (k = 0; k < cmap->tlen; k++) + { + if (k % 8 == 0) + fprintf(fo, "\n "); + fprintf(fo, "%d, ", cmap->table[k]); + } + fprintf(fo, "\n};\n\n"); + } + + fprintf(fo, "pdf_cmap pdf_cmap_%s =\n", name); + fprintf(fo, "{\n"); + fprintf(fo, " -1, "); + fprintf(fo, "\"%s\", ", cmap->cmapname); + fprintf(fo, "\"%s\", nil, ", cmap->usecmapname); + fprintf(fo, "%d,\n", cmap->wmode); + + fprintf(fo, " %d, /* codespace table */\n", cmap->ncspace); + fprintf(fo, " {\n"); + + if (cmap->ncspace == 0) + { + fprintf(fo, " /* dummy entry for non-c99 compilers */\n"); + fprintf(fo, " { 0, 0x0, 0x0 },\n"); + } + for (k = 0; k < cmap->ncspace; k++) + { + fprintf(fo, "\t{ %d, 0x%04x, 0x%04x },\n", + cmap->cspace[k].n, cmap->cspace[k].low, cmap->cspace[k].high); + } + fprintf(fo, " },\n"); + + fprintf(fo, " %d, %d, (pdf_range*) pdf_cmap_%s_ranges,\n", + cmap->rlen, cmap->rlen, name); + + fprintf(fo, " %d, %d, (unsigned short*) pdf_cmap_%s_table,\n", + cmap->tlen, cmap->tlen, name); + + fprintf(fo, "};\n\n"); + + fz_dropstream(fi); } - for (k = 0; k < cmap->ncspace; k++) - { - fprintf(fo, "\t{ %d, 0x%04x, 0x%04x },\n", - cmap->cspace[k].n, cmap->cspace[k].low, cmap->cspace[k].high); - } - fprintf(fo, " },\n"); - - fprintf(fo, " %d, %d, (pdf_range*) pdf_cmap_%s_ranges,\n", - cmap->rlen, cmap->rlen, name); - - fprintf(fo, " %d, %d, (unsigned short*) pdf_cmap_%s_table,\n", - cmap->tlen, cmap->tlen, name); - - fprintf(fo, "};\n\n"); - - fz_dropstream(fi); - } - return 0; + return 0; } diff --git a/mupdf/fontdump.c b/mupdf/fontdump.c index 6b9077b1..88d75bc5 100644 --- a/mupdf/fontdump.c +++ b/mupdf/fontdump.c @@ -6,80 +6,80 @@ static int hexdump(FILE *fo, FILE *fi) { - int c, n; + int c, n; - n = 0; - c = fgetc(fi); - while (c != -1) - { - fprintf(fo, "0x%02x,", c); - if (n % 16 == 15) - fprintf(fo, "\n"); + n = 0; c = fgetc(fi); - n ++; - } + while (c != -1) + { + fprintf(fo, "0x%02x,", c); + if (n % 16 == 15) + fprintf(fo, "\n"); + c = fgetc(fi); + n ++; + } - return n; + return n; } int main(int argc, char **argv) { - FILE *fo; - FILE *fi; - char name[256]; - char *basename; - char *p; - int i, len; - - if (argc < 3) - { - fprintf(stderr, "usage: fontdump output.c input.dat\n"); - return 1; - } - - fo = fopen(argv[1], "wb"); - if (!fo) - { - fprintf(stderr, "fontdump: could not open output file '%s'\n", argv[1]); - return 1; - } + FILE *fo; + FILE *fi; + char name[256]; + char *basename; + char *p; + int i, len; - for (i = 2; i < argc; i++) - { - fi = fopen(argv[i], "rb"); - if (!fi) + if (argc < 3) { - fprintf(stderr, "fontdump: could not open input file '%s'\n", argv[i]); - return 1; + fprintf(stderr, "usage: fontdump output.c input.dat\n"); + return 1; } - basename = strrchr(argv[i], '/'); - if (!basename) - basename = strrchr(argv[i], '\\'); - if (basename) - basename++; - else - basename = argv[i]; - strcpy(name, basename); - p = name; - while (*p) + fo = fopen(argv[1], "wb"); + if (!fo) { - if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-')) - *p = '_'; - p ++; + fprintf(stderr, "fontdump: could not open output file '%s'\n", argv[1]); + return 1; } - fprintf(fo, "const unsigned char pdf_font_%s_buf[] = {\n", name); + for (i = 2; i < argc; i++) + { + fi = fopen(argv[i], "rb"); + if (!fi) + { + fprintf(stderr, "fontdump: could not open input file '%s'\n", argv[i]); + return 1; + } + + basename = strrchr(argv[i], '/'); + if (!basename) + basename = strrchr(argv[i], '\\'); + if (basename) + basename++; + else + basename = argv[i]; + strcpy(name, basename); + p = name; + while (*p) + { + if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-')) + *p = '_'; + p ++; + } - len = hexdump(fo, fi); + fprintf(fo, "const unsigned char pdf_font_%s_buf[] = {\n", name); - fprintf(fo, "};\n"); - fprintf(fo, "const unsigned int pdf_font_%s_len = %d;\n", name, len); + len = hexdump(fo, fi); - fclose(fi); - } + fprintf(fo, "};\n"); + fprintf(fo, "const unsigned int pdf_font_%s_len = %d;\n", name, len); + + fclose(fi); + } - return 0; + return 0; } diff --git a/mupdf/mupdf.h b/mupdf/mupdf.h index a26f0de1..7b16f438 100644 --- a/mupdf/mupdf.h +++ b/mupdf/mupdf.h @@ -49,15 +49,15 @@ unsigned short * pdf_toucs2(fz_obj *src); */ /* Permission flag bits */ -#define PDF_PERM_PRINT (1<<2) -#define PDF_PERM_CHANGE (1<<3) -#define PDF_PERM_COPY (1<<4) -#define PDF_PERM_NOTES (1<<5) -#define PDF_PERM_FILL_FORM (1<<8) -#define PDF_PERM_ACCESSIBILITY (1<<9) -#define PDF_PERM_ASSEMBLE (1<<10) +#define PDF_PERM_PRINT (1<<2) +#define PDF_PERM_CHANGE (1<<3) +#define PDF_PERM_COPY (1<<4) +#define PDF_PERM_NOTES (1<<5) +#define PDF_PERM_FILL_FORM (1<<8) +#define PDF_PERM_ACCESSIBILITY (1<<9) +#define PDF_PERM_ASSEMBLE (1<<10) #define PDF_PERM_HIGH_RES_PRINT (1<<11) -#define PDF_DEFAULT_PERM_FLAGS 0xfffc +#define PDF_DEFAULT_PERM_FLAGS 0xfffc typedef struct pdf_crypt_s pdf_crypt; typedef struct pdf_cryptfilter_s pdf_cryptfilter; diff --git a/mupdf/pdf_annot.c b/mupdf/pdf_annot.c index b22a4c3d..3aed828b 100644 --- a/mupdf/pdf_annot.c +++ b/mupdf/pdf_annot.c @@ -66,8 +66,8 @@ pdf_loadlink(pdf_xref *xref, fz_obj *dict) { bbox = pdf_torect(obj); pdf_logpage("rect [%g %g %g %g]\n", - bbox.x0, bbox.y0, - bbox.x1, bbox.y1); + bbox.x0, bbox.y0, + bbox.x1, bbox.y1); } else bbox = fz_emptyrect; diff --git a/mupdf/pdf_build.c b/mupdf/pdf_build.c index 4a42c77f..c235e4ee 100644 --- a/mupdf/pdf_build.c +++ b/mupdf/pdf_build.c @@ -47,10 +47,10 @@ pdf_initgstate(pdf_gstate *gs) static fz_error pdf_newovernode(fz_node **nodep, pdf_gstate *gs) { - if (gs->blendmode == FZ_BNORMAL) - return fz_newovernode(nodep); - else - return fz_newblendnode(nodep, gs->blendmode, 0, 0); + if (gs->blendmode == FZ_BNORMAL) + return fz_newovernode(nodep); + else + return fz_newblendnode(nodep, gs->blendmode, 0, 0); } fz_error @@ -309,7 +309,7 @@ static fz_matrix getmatrix(fz_node *node) static fz_error addpatternshape(pdf_gstate *gs, fz_node *shape, - pdf_pattern *pat, fz_colorspace *cs, float *v) + pdf_pattern *pat, fz_colorspace *cs, float *v) { fz_error error; fz_node *xform; @@ -660,7 +660,7 @@ pdf_showimage(pdf_csi *csi, pdf_image *img) fz_error pdf_showpath(pdf_csi *csi, - int doclose, int dofill, int dostroke, int evenodd) + int doclose, int dofill, int dostroke, int evenodd) { pdf_gstate *gstate = csi->gstate + csi->gtop; fz_error error; @@ -870,11 +870,11 @@ showglyph(pdf_csi *csi, int cid) tsm.f = gstate->rise; if (fontdesc->tounicode) - ucs = pdf_lookupcmap(fontdesc->tounicode, cid); + ucs = pdf_lookupcmap(fontdesc->tounicode, cid); else if (cid < fontdesc->ncidtoucs) - ucs = fontdesc->cidtoucs[cid]; + ucs = fontdesc->cidtoucs[cid]; else - ucs = '?'; + ucs = '?'; gid = pdf_fontcidtogid(fontdesc, cid); diff --git a/mupdf/pdf_cmap.c b/mupdf/pdf_cmap.c index 9b154f5a..065cca4e 100644 --- a/mupdf/pdf_cmap.c +++ b/mupdf/pdf_cmap.c @@ -25,132 +25,132 @@ pdf_cmap * pdf_newcmap(void) { - pdf_cmap *cmap; - - cmap = fz_malloc(sizeof(pdf_cmap)); - cmap->refs = 1; - - strcpy(cmap->cmapname, ""); - strcpy(cmap->usecmapname, ""); - cmap->usecmap = nil; - cmap->wmode = 0; - cmap->ncspace = 0; - - cmap->rlen = 0; - cmap->rcap = 0; - cmap->ranges = nil; - - cmap->tlen = 0; - cmap->tcap = 0; - cmap->table = nil; - - return cmap; + pdf_cmap *cmap; + + cmap = fz_malloc(sizeof(pdf_cmap)); + cmap->refs = 1; + + strcpy(cmap->cmapname, ""); + strcpy(cmap->usecmapname, ""); + cmap->usecmap = nil; + cmap->wmode = 0; + cmap->ncspace = 0; + + cmap->rlen = 0; + cmap->rcap = 0; + cmap->ranges = nil; + + cmap->tlen = 0; + cmap->tcap = 0; + cmap->table = nil; + + return cmap; } pdf_cmap * pdf_keepcmap(pdf_cmap *cmap) { - if (cmap->refs >= 0) - cmap->refs ++; - return cmap; + if (cmap->refs >= 0) + cmap->refs ++; + return cmap; } void pdf_dropcmap(pdf_cmap *cmap) { - if (cmap->refs >= 0) - { - if (--cmap->refs == 0) + if (cmap->refs >= 0) { - if (cmap->usecmap) - pdf_dropcmap(cmap->usecmap); - fz_free(cmap->ranges); - fz_free(cmap->table); - fz_free(cmap); + if (--cmap->refs == 0) + { + if (cmap->usecmap) + pdf_dropcmap(cmap->usecmap); + fz_free(cmap->ranges); + fz_free(cmap->table); + fz_free(cmap); + } } - } } pdf_cmap * pdf_getusecmap(pdf_cmap *cmap) { - return cmap->usecmap; + return cmap->usecmap; } void pdf_setusecmap(pdf_cmap *cmap, pdf_cmap *usecmap) { - int i; - - if (cmap->usecmap) - pdf_dropcmap(cmap->usecmap); - cmap->usecmap = pdf_keepcmap(usecmap); - - if (cmap->ncspace == 0) - { - cmap->ncspace = usecmap->ncspace; - for (i = 0; i < usecmap->ncspace; i++) - cmap->cspace[i] = usecmap->cspace[i]; - } + int i; + + if (cmap->usecmap) + pdf_dropcmap(cmap->usecmap); + cmap->usecmap = pdf_keepcmap(usecmap); + + if (cmap->ncspace == 0) + { + cmap->ncspace = usecmap->ncspace; + for (i = 0; i < usecmap->ncspace; i++) + cmap->cspace[i] = usecmap->cspace[i]; + } } int pdf_getwmode(pdf_cmap *cmap) { - return cmap->wmode; + return cmap->wmode; } void pdf_setwmode(pdf_cmap *cmap, int wmode) { - cmap->wmode = wmode; + cmap->wmode = wmode; } void pdf_debugcmap(pdf_cmap *cmap) { - int i, k, n; - - printf("cmap $%p /%s {\n", (void *) cmap, cmap->cmapname); - - if (cmap->usecmapname[0]) - printf(" usecmap /%s\n", cmap->usecmapname); - if (cmap->usecmap) - printf(" usecmap $%p\n", (void *) cmap->usecmap); - - printf(" wmode %d\n", cmap->wmode); - - printf(" codespaces {\n"); - for (i = 0; i < cmap->ncspace; i++) - { - printf(" <%x> <%x>\n", cmap->cspace[i].low, cmap->cspace[i].high); - } - printf(" }\n"); - - printf(" ranges (%d,%d) {\n", cmap->rlen, cmap->tlen); - for (i = 0; i < cmap->rlen; i++) - { - pdf_range *r = &cmap->ranges[i]; - printf(" <%04x> <%04x> ", r->low, r->high); - if (r->flag == PDF_CMAP_TABLE) + int i, k, n; + + printf("cmap $%p /%s {\n", (void *) cmap, cmap->cmapname); + + if (cmap->usecmapname[0]) + printf(" usecmap /%s\n", cmap->usecmapname); + if (cmap->usecmap) + printf(" usecmap $%p\n", (void *) cmap->usecmap); + + printf(" wmode %d\n", cmap->wmode); + + printf(" codespaces {\n"); + for (i = 0; i < cmap->ncspace; i++) { - printf("[ "); - for (k = 0; k < r->high - r->low + 1; k++) - printf("%d ", cmap->table[r->offset + k]); - printf("]\n"); + printf(" <%x> <%x>\n", cmap->cspace[i].low, cmap->cspace[i].high); } - else if (r->flag == PDF_CMAP_MULTI) + printf(" }\n"); + + printf(" ranges (%d,%d) {\n", cmap->rlen, cmap->tlen); + for (i = 0; i < cmap->rlen; i++) { - printf("< "); - n = cmap->table[r->offset]; - for (k = 0; k < n; k++) - printf("%04x ", cmap->table[r->offset + 1 + k]); - printf(">\n"); + pdf_range *r = &cmap->ranges[i]; + printf(" <%04x> <%04x> ", r->low, r->high); + if (r->flag == PDF_CMAP_TABLE) + { + printf("[ "); + for (k = 0; k < r->high - r->low + 1; k++) + printf("%d ", cmap->table[r->offset + k]); + printf("]\n"); + } + else if (r->flag == PDF_CMAP_MULTI) + { + printf("< "); + n = cmap->table[r->offset]; + for (k = 0; k < n; k++) + printf("%04x ", cmap->table[r->offset + 1 + k]); + printf(">\n"); + } + else + printf("%d\n", r->offset); } - else - printf("%d\n", r->offset); - } - printf(" }\n}\n"); + printf(" }\n}\n"); } /* @@ -161,16 +161,16 @@ pdf_debugcmap(pdf_cmap *cmap) void pdf_addcodespace(pdf_cmap *cmap, int low, int high, int n) { - if (cmap->ncspace + 1 == nelem(cmap->cspace)) - { - fz_warn("assert: too many code space ranges"); - return; - } - - cmap->cspace[cmap->ncspace].n = n; - cmap->cspace[cmap->ncspace].low = low; - cmap->cspace[cmap->ncspace].high = high; - cmap->ncspace ++; + if (cmap->ncspace + 1 == nelem(cmap->cspace)) + { + fz_warn("assert: too many code space ranges"); + return; + } + + cmap->cspace[cmap->ncspace].n = n; + cmap->cspace[cmap->ncspace].low = low; + cmap->cspace[cmap->ncspace].high = high; + cmap->ncspace ++; } /* @@ -179,12 +179,12 @@ pdf_addcodespace(pdf_cmap *cmap, int low, int high, int n) static void addtable(pdf_cmap *cmap, int value) { - if (cmap->tlen + 1 > cmap->tcap) - { - cmap->tcap = cmap->tcap == 0 ? 256 : (cmap->tcap * 3) / 2; - cmap->table = fz_realloc(cmap->table, cmap->tcap * sizeof(unsigned short)); - } - cmap->table[cmap->tlen++] = value; + if (cmap->tlen + 1 > cmap->tcap) + { + cmap->tcap = cmap->tcap == 0 ? 256 : (cmap->tcap * 3) / 2; + cmap->table = fz_realloc(cmap->table, cmap->tcap * sizeof(unsigned short)); + } + cmap->table[cmap->tlen++] = value; } /* @@ -193,16 +193,16 @@ addtable(pdf_cmap *cmap, int value) static void addrange(pdf_cmap *cmap, int low, int high, int flag, int offset) { - if (cmap->rlen + 1 > cmap->rcap) - { - cmap->rcap = cmap->rcap == 0 ? 256 : (cmap->rcap * 3) / 2; - cmap->ranges = fz_realloc(cmap->ranges, cmap->rcap * sizeof(pdf_range)); - } - cmap->ranges[cmap->rlen].low = low; - cmap->ranges[cmap->rlen].high = high; - cmap->ranges[cmap->rlen].flag = flag; - cmap->ranges[cmap->rlen].offset = offset; - cmap->rlen ++; + if (cmap->rlen + 1 > cmap->rcap) + { + cmap->rcap = cmap->rcap == 0 ? 256 : (cmap->rcap * 3) / 2; + cmap->ranges = fz_realloc(cmap->ranges, cmap->rcap * sizeof(pdf_range)); + } + cmap->ranges[cmap->rlen].low = low; + cmap->ranges[cmap->rlen].high = high; + cmap->ranges[cmap->rlen].flag = flag; + cmap->ranges[cmap->rlen].offset = offset; + cmap->rlen ++; } /* @@ -211,12 +211,12 @@ addrange(pdf_cmap *cmap, int low, int high, int flag, int offset) void pdf_maprangetotable(pdf_cmap *cmap, int low, int *table, int len) { - int i; - int high = low + len; - int offset = cmap->tlen; - for (i = 0; i < len; i++) - addtable(cmap, table[i]); - addrange(cmap, low, high, PDF_CMAP_TABLE, offset); + int i; + int high = low + len; + int offset = cmap->tlen; + for (i = 0; i < len; i++) + addtable(cmap, table[i]); + addrange(cmap, low, high, PDF_CMAP_TABLE, offset); } /* @@ -225,7 +225,7 @@ pdf_maprangetotable(pdf_cmap *cmap, int low, int *table, int len) void pdf_maprangetorange(pdf_cmap *cmap, int low, int high, int offset) { - addrange(cmap, low, high, high - low == 0 ? PDF_CMAP_SINGLE : PDF_CMAP_RANGE, offset); + addrange(cmap, low, high, high - low == 0 ? PDF_CMAP_SINGLE : PDF_CMAP_RANGE, offset); } /* @@ -234,20 +234,20 @@ pdf_maprangetorange(pdf_cmap *cmap, int low, int high, int offset) void pdf_maponetomany(pdf_cmap *cmap, int low, int *values, int len) { - int offset, i; + int offset, i; - if (len == 1) - { - addrange(cmap, low, low, PDF_CMAP_SINGLE, values[0]); - return; - } + if (len == 1) + { + addrange(cmap, low, low, PDF_CMAP_SINGLE, values[0]); + return; + } - offset = cmap->tlen; - addtable(cmap, len); - for (i = 0; i < len; i++) - addtable(cmap, values[i]); - addrange(cmap, low, low, PDF_CMAP_MULTI, offset); - } + offset = cmap->tlen; + addtable(cmap, len); + for (i = 0; i < len; i++) + addtable(cmap, values[i]); + addrange(cmap, low, low, PDF_CMAP_MULTI, offset); +} /* * Sort the input ranges. @@ -257,100 +257,100 @@ pdf_maponetomany(pdf_cmap *cmap, int low, int *values, int len) static int cmprange(const void *va, const void *vb) { - return ((const pdf_range*)va)->low - ((const pdf_range*)vb)->low; + return ((const pdf_range*)va)->low - ((const pdf_range*)vb)->low; } void pdf_sortcmap(pdf_cmap *cmap) { - pdf_range *a; /* last written range on output */ - pdf_range *b; /* current range examined on input */ - - if (cmap->rlen == 0) - return; + pdf_range *a; /* last written range on output */ + pdf_range *b; /* current range examined on input */ - qsort(cmap->ranges, cmap->rlen, sizeof(pdf_range), cmprange); + if (cmap->rlen == 0) + return; - a = cmap->ranges; - b = cmap->ranges + 1; + qsort(cmap->ranges, cmap->rlen, sizeof(pdf_range), cmprange); - while (b < cmap->ranges + cmap->rlen) - { - /* ignore one-to-many mappings */ - if (b->flag == PDF_CMAP_MULTI) - { - *(++a) = *b; - } + a = cmap->ranges; + b = cmap->ranges + 1; - /* input contiguous */ - else if (a->high + 1 == b->low) + while (b < cmap->ranges + cmap->rlen) { - /* output contiguous */ - if (a->high - a->low + a->offset + 1 == b->offset) - { - /* SR -> R and SS -> R and RR -> R and RS -> R */ - if (a->flag == PDF_CMAP_SINGLE || a->flag == PDF_CMAP_RANGE) - { - a->flag = PDF_CMAP_RANGE; - a->high = b->high; - } - - /* LS -> L */ - else if (a->flag == PDF_CMAP_TABLE && b->flag == PDF_CMAP_SINGLE) - { - a->high = b->high; - addtable(cmap, b->offset); - } - - /* LR -> LR */ - else if (a->flag == PDF_CMAP_TABLE && b->flag == PDF_CMAP_RANGE) + /* ignore one-to-many mappings */ + if (b->flag == PDF_CMAP_MULTI) { - *(++a) = *b; + *(++a) = *b; } - /* XX -> XX */ - else - { - *(++a) = *b; - } - } - - /* output separated */ - else - { - /* SS -> L */ - if (a->flag == PDF_CMAP_SINGLE && b->flag == PDF_CMAP_SINGLE) - { - a->flag = PDF_CMAP_TABLE; - a->high = b->high; - addtable(cmap, a->offset); - addtable(cmap, b->offset); - a->offset = cmap->tlen - 2; - } - - /* LS -> L */ - else if (a->flag == PDF_CMAP_TABLE && b->flag == PDF_CMAP_SINGLE) + /* input contiguous */ + else if (a->high + 1 == b->low) { - a->high = b->high; - addtable(cmap, b->offset); + /* output contiguous */ + if (a->high - a->low + a->offset + 1 == b->offset) + { + /* SR -> R and SS -> R and RR -> R and RS -> R */ + if (a->flag == PDF_CMAP_SINGLE || a->flag == PDF_CMAP_RANGE) + { + a->flag = PDF_CMAP_RANGE; + a->high = b->high; + } + + /* LS -> L */ + else if (a->flag == PDF_CMAP_TABLE && b->flag == PDF_CMAP_SINGLE) + { + a->high = b->high; + addtable(cmap, b->offset); + } + + /* LR -> LR */ + else if (a->flag == PDF_CMAP_TABLE && b->flag == PDF_CMAP_RANGE) + { + *(++a) = *b; + } + + /* XX -> XX */ + else + { + *(++a) = *b; + } + } + + /* output separated */ + else + { + /* SS -> L */ + if (a->flag == PDF_CMAP_SINGLE && b->flag == PDF_CMAP_SINGLE) + { + a->flag = PDF_CMAP_TABLE; + a->high = b->high; + addtable(cmap, a->offset); + addtable(cmap, b->offset); + a->offset = cmap->tlen - 2; + } + + /* LS -> L */ + else if (a->flag == PDF_CMAP_TABLE && b->flag == PDF_CMAP_SINGLE) + { + a->high = b->high; + addtable(cmap, b->offset); + } + + /* XX -> XX */ + else + { + *(++a) = *b; + } + } } - /* XX -> XX */ + /* input separated: XX -> XX */ else { - *(++a) = *b; + *(++a) = *b; } - } - } - /* input separated: XX -> XX */ - else - { - *(++a) = *b; + b ++; } - - b ++; - } } /* @@ -359,32 +359,32 @@ pdf_sortcmap(pdf_cmap *cmap) int pdf_lookupcmap(pdf_cmap *cmap, int cpt) { - int l = 0; - int r = cmap->rlen - 1; - int m; - - while (l <= r) - { - m = (l + r) >> 1; - if (cpt < cmap->ranges[m].low) - r = m - 1; - else if (cpt > cmap->ranges[m].high) - l = m + 1; - else + int l = 0; + int r = cmap->rlen - 1; + int m; + + while (l <= r) { - int i = cpt - cmap->ranges[m].low + cmap->ranges[m].offset; - if (cmap->ranges[m].flag == PDF_CMAP_TABLE) - return cmap->table[i]; - if (cmap->ranges[m].flag == PDF_CMAP_MULTI) - return -1; - return i; + m = (l + r) >> 1; + if (cpt < cmap->ranges[m].low) + r = m - 1; + else if (cpt > cmap->ranges[m].high) + l = m + 1; + else + { + int i = cpt - cmap->ranges[m].low + cmap->ranges[m].offset; + if (cmap->ranges[m].flag == PDF_CMAP_TABLE) + return cmap->table[i]; + if (cmap->ranges[m].flag == PDF_CMAP_MULTI) + return -1; + return i; + } } - } - if (cmap->usecmap) - return pdf_lookupcmap(cmap->usecmap, cpt); + if (cmap->usecmap) + return pdf_lookupcmap(cmap->usecmap, cpt); - return -1; + return -1; } /* @@ -394,26 +394,26 @@ pdf_lookupcmap(pdf_cmap *cmap, int cpt) unsigned char * pdf_decodecmap(pdf_cmap *cmap, unsigned char *buf, int *cpt) { - int k, n, c; + int k, n, c; - c = 0; - for (n = 0; n < 4; n++) - { - c = (c << 8) | buf[n]; - for (k = 0; k < cmap->ncspace; k++) + c = 0; + for (n = 0; n < 4; n++) { - if (cmap->cspace[k].n == n + 1) - { - if (c >= cmap->cspace[k].low && c <= cmap->cspace[k].high) + c = (c << 8) | buf[n]; + for (k = 0; k < cmap->ncspace; k++) { - *cpt = c; - return buf + n + 1; + if (cmap->cspace[k].n == n + 1) + { + if (c >= cmap->cspace[k].low && c <= cmap->cspace[k].high) + { + *cpt = c; + return buf + n + 1; + } + } } - } } - } - *cpt = 0; - return buf + 1; + *cpt = 0; + return buf + 1; } diff --git a/mupdf/pdf_cmap_load.c b/mupdf/pdf_cmap_load.c index 97a7cb3c..c99270f2 100644 --- a/mupdf/pdf_cmap_load.c +++ b/mupdf/pdf_cmap_load.c @@ -7,86 +7,86 @@ fz_error pdf_loadembeddedcmap(pdf_cmap **cmapp, pdf_xref *xref, fz_obj *stmref) { - fz_error error = fz_okay; - fz_obj *stmobj; - fz_stream *file = nil; - pdf_cmap *cmap = nil; - pdf_cmap *usecmap; - fz_obj *wmode; - fz_obj *obj; - - if ((*cmapp = pdf_finditem(xref->store, PDF_KCMAP, stmref))) - { - pdf_keepcmap(*cmapp); - return fz_okay; - } - - pdf_logfont("load embedded cmap (%d %d R) {\n", fz_tonum(stmref), fz_togen(stmref)); - - stmobj = fz_resolveindirect(stmref); - - error = pdf_openstream(&file, xref, fz_tonum(stmref), fz_togen(stmref)); - if (error) - { - error = fz_rethrow(error, "cannot open cmap stream"); - goto cleanup; - } - - error = pdf_parsecmap(&cmap, file); - if (error) - { - error = fz_rethrow(error, "cannot parse cmap stream"); - goto cleanup; - } - - fz_dropstream(file); - - wmode = fz_dictgets(stmobj, "WMode"); - if (fz_isint(wmode)) - { - pdf_logfont("wmode %d\n", wmode); - pdf_setwmode(cmap, fz_toint(wmode)); - } - - obj = fz_dictgets(stmobj, "UseCMap"); - if (fz_isname(obj)) - { - pdf_logfont("usecmap /%s\n", fz_toname(obj)); - error = pdf_loadsystemcmap(&usecmap, fz_toname(obj)); + fz_error error = fz_okay; + fz_obj *stmobj; + fz_stream *file = nil; + pdf_cmap *cmap = nil; + pdf_cmap *usecmap; + fz_obj *wmode; + fz_obj *obj; + + if ((*cmapp = pdf_finditem(xref->store, PDF_KCMAP, stmref))) + { + pdf_keepcmap(*cmapp); + return fz_okay; + } + + pdf_logfont("load embedded cmap (%d %d R) {\n", fz_tonum(stmref), fz_togen(stmref)); + + stmobj = fz_resolveindirect(stmref); + + error = pdf_openstream(&file, xref, fz_tonum(stmref), fz_togen(stmref)); if (error) { - error = fz_rethrow(error, "cannot load system usecmap '%s'", fz_toname(obj)); - goto cleanup; + error = fz_rethrow(error, "cannot open cmap stream"); + goto cleanup; } - pdf_setusecmap(cmap, usecmap); - pdf_dropcmap(usecmap); - } - else if (fz_isindirect(obj)) - { - pdf_logfont("usecmap (%d %d R)\n", fz_tonum(obj), fz_togen(obj)); - error = pdf_loadembeddedcmap(&usecmap, xref, obj); + + error = pdf_parsecmap(&cmap, file); if (error) { - error = fz_rethrow(error, "cannot load embedded usecmap"); - goto cleanup; + error = fz_rethrow(error, "cannot parse cmap stream"); + goto cleanup; } - pdf_setusecmap(cmap, usecmap); - pdf_dropcmap(usecmap); - } - pdf_logfont("}\n"); + fz_dropstream(file); - pdf_storeitem(xref->store, PDF_KCMAP, stmref, cmap); + wmode = fz_dictgets(stmobj, "WMode"); + if (fz_isint(wmode)) + { + pdf_logfont("wmode %d\n", wmode); + pdf_setwmode(cmap, fz_toint(wmode)); + } - *cmapp = cmap; - return fz_okay; + obj = fz_dictgets(stmobj, "UseCMap"); + if (fz_isname(obj)) + { + pdf_logfont("usecmap /%s\n", fz_toname(obj)); + error = pdf_loadsystemcmap(&usecmap, fz_toname(obj)); + if (error) + { + error = fz_rethrow(error, "cannot load system usecmap '%s'", fz_toname(obj)); + goto cleanup; + } + pdf_setusecmap(cmap, usecmap); + pdf_dropcmap(usecmap); + } + else if (fz_isindirect(obj)) + { + pdf_logfont("usecmap (%d %d R)\n", fz_tonum(obj), fz_togen(obj)); + error = pdf_loadembeddedcmap(&usecmap, xref, obj); + if (error) + { + error = fz_rethrow(error, "cannot load embedded usecmap"); + goto cleanup; + } + pdf_setusecmap(cmap, usecmap); + pdf_dropcmap(usecmap); + } + + pdf_logfont("}\n"); + + pdf_storeitem(xref->store, PDF_KCMAP, stmref, cmap); + + *cmapp = cmap; + return fz_okay; cleanup: - if (file) - fz_dropstream(file); - if (cmap) - pdf_dropcmap(cmap); - return error; /* already rethrown */ + if (file) + fz_dropstream(file); + if (cmap) + pdf_dropcmap(cmap); + return error; /* already rethrown */ } /* @@ -95,13 +95,13 @@ cleanup: pdf_cmap * pdf_newidentitycmap(int wmode, int bytes) { - pdf_cmap *cmap = pdf_newcmap(); - sprintf(cmap->cmapname, "Identity-%c", wmode ? 'V' : 'H'); - pdf_addcodespace(cmap, 0x0000, 0xffff, bytes); - pdf_maprangetorange(cmap, 0x0000, 0xffff, 0); - pdf_sortcmap(cmap); - pdf_setwmode(cmap, wmode); - return cmap; + pdf_cmap *cmap = pdf_newcmap(); + sprintf(cmap->cmapname, "Identity-%c", wmode ? 'V' : 'H'); + pdf_addcodespace(cmap, 0x0000, 0xffff, bytes); + pdf_maprangetorange(cmap, 0x0000, 0xffff, 0); + pdf_sortcmap(cmap); + pdf_setwmode(cmap, wmode); + return cmap; } /* @@ -110,30 +110,30 @@ pdf_newidentitycmap(int wmode, int bytes) fz_error pdf_loadsystemcmap(pdf_cmap **cmapp, char *cmapname) { - fz_error error; - pdf_cmap *usecmap; - pdf_cmap *cmap; - int i; + fz_error error; + pdf_cmap *usecmap; + pdf_cmap *cmap; + int i; - pdf_logfont("loading system cmap %s\n", cmapname); + pdf_logfont("loading system cmap %s\n", cmapname); - for (i = 0; pdf_cmaptable[i]; i++) - { - if (!strcmp(cmapname, pdf_cmaptable[i]->cmapname)) + for (i = 0; pdf_cmaptable[i]; i++) { - cmap = pdf_cmaptable[i]; - if (cmap->usecmapname[0] && !cmap->usecmap) - { - error = pdf_loadsystemcmap(&usecmap, cmap->usecmapname); - if (error) - return fz_rethrow(error, "could not load usecmap: %s", cmap->usecmapname); - pdf_setusecmap(cmap, usecmap); - } - *cmapp = cmap; - return fz_okay; + if (!strcmp(cmapname, pdf_cmaptable[i]->cmapname)) + { + cmap = pdf_cmaptable[i]; + if (cmap->usecmapname[0] && !cmap->usecmap) + { + error = pdf_loadsystemcmap(&usecmap, cmap->usecmapname); + if (error) + return fz_rethrow(error, "could not load usecmap: %s", cmap->usecmapname); + pdf_setusecmap(cmap, usecmap); + } + *cmapp = cmap; + return fz_okay; + } } - } - return fz_throw("no builtin cmap file: %s", cmapname); + return fz_throw("no builtin cmap file: %s", cmapname); } diff --git a/mupdf/pdf_cmap_parse.c b/mupdf/pdf_cmap_parse.c index b8f11751..60367626 100644 --- a/mupdf/pdf_cmap_parse.c +++ b/mupdf/pdf_cmap_parse.c @@ -7,474 +7,474 @@ enum { - TUSECMAP = PDF_NTOKENS, - TBEGINCODESPACERANGE, - TENDCODESPACERANGE, - TBEGINBFCHAR, - TENDBFCHAR, - TBEGINBFRANGE, - TENDBFRANGE, - TBEGINCIDCHAR, - TENDCIDCHAR, - TBEGINCIDRANGE, - TENDCIDRANGE + TUSECMAP = PDF_NTOKENS, + TBEGINCODESPACERANGE, + TENDCODESPACERANGE, + TBEGINBFCHAR, + TENDBFCHAR, + TBEGINBFRANGE, + TENDBFRANGE, + TBEGINCIDCHAR, + TENDCIDCHAR, + TBEGINCIDRANGE, + TENDCIDRANGE }; static pdf_token_e pdf_cmaptokenfromkeyword(char *key) { - if (!strcmp(key, "usecmap")) return TUSECMAP; - if (!strcmp(key, "begincodespacerange")) return TBEGINCODESPACERANGE; - if (!strcmp(key, "endcodespacerange")) return TENDCODESPACERANGE; - if (!strcmp(key, "beginbfchar")) return TBEGINBFCHAR; - if (!strcmp(key, "endbfchar")) return TENDBFCHAR; - if (!strcmp(key, "beginbfrange")) return TBEGINBFRANGE; - if (!strcmp(key, "endbfrange")) return TENDBFRANGE; - if (!strcmp(key, "begincidchar")) return TBEGINCIDCHAR; - if (!strcmp(key, "endcidchar")) return TENDCIDCHAR; - if (!strcmp(key, "begincidrange")) return TBEGINCIDRANGE; - if (!strcmp(key, "endcidrange")) return TENDCIDRANGE; - return PDF_TKEYWORD; + if (!strcmp(key, "usecmap")) return TUSECMAP; + if (!strcmp(key, "begincodespacerange")) return TBEGINCODESPACERANGE; + if (!strcmp(key, "endcodespacerange")) return TENDCODESPACERANGE; + if (!strcmp(key, "beginbfchar")) return TBEGINBFCHAR; + if (!strcmp(key, "endbfchar")) return TENDBFCHAR; + if (!strcmp(key, "beginbfrange")) return TBEGINBFRANGE; + if (!strcmp(key, "endbfrange")) return TENDBFRANGE; + if (!strcmp(key, "begincidchar")) return TBEGINCIDCHAR; + if (!strcmp(key, "endcidchar")) return TENDCIDCHAR; + if (!strcmp(key, "begincidrange")) return TBEGINCIDRANGE; + if (!strcmp(key, "endcidrange")) return TENDCIDRANGE; + return PDF_TKEYWORD; } static int codefromstring(char *buf, int len) { - int a = 0; - while (len--) - a = (a << 8) | *(unsigned char *)buf++; - return a; + int a = 0; + while (len--) + a = (a << 8) | *(unsigned char *)buf++; + return a; } static fz_error lexcmap(pdf_token_e *tok, fz_stream *file, char *buf, int n, int *sl) { - fz_error error; + fz_error error; - error = pdf_lex(tok, file, buf, n, sl); - if (error) - return fz_rethrow(error, "cannot parse cmap token"); + error = pdf_lex(tok, file, buf, n, sl); + if (error) + return fz_rethrow(error, "cannot parse cmap token"); - if (*tok == PDF_TKEYWORD) - *tok = pdf_cmaptokenfromkeyword(buf); + if (*tok == PDF_TKEYWORD) + *tok = pdf_cmaptokenfromkeyword(buf); - return fz_okay; + return fz_okay; } static fz_error parsecmapname(pdf_cmap *cmap, fz_stream *file) { - fz_error error; - char buf[256]; - pdf_token_e tok; - int len; - - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - - if (tok == PDF_TNAME) - { - strlcpy(cmap->cmapname, buf, sizeof(cmap->cmapname)); - return fz_okay; - } + fz_error error; + char buf[256]; + pdf_token_e tok; + int len; - return fz_throw("expected name"); + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); + + if (tok == PDF_TNAME) + { + strlcpy(cmap->cmapname, buf, sizeof(cmap->cmapname)); + return fz_okay; + } + + return fz_throw("expected name"); } static fz_error parsewmode(pdf_cmap *cmap, fz_stream *file) { - fz_error error; - char buf[256]; - pdf_token_e tok; - int len; - - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - - if (tok == PDF_TINT) - { - pdf_setwmode(cmap, atoi(buf)); - return fz_okay; - } + fz_error error; + char buf[256]; + pdf_token_e tok; + int len; + + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); - return fz_throw("expected integer"); + if (tok == PDF_TINT) + { + pdf_setwmode(cmap, atoi(buf)); + return fz_okay; + } + + return fz_throw("expected integer"); } static fz_error parsecodespacerange(pdf_cmap *cmap, fz_stream *file) { - fz_error error; - char buf[256]; - pdf_token_e tok; - int len; - int lo, hi; - - while (1) - { - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - - if (tok == TENDCODESPACERANGE) - return fz_okay; + fz_error error; + char buf[256]; + pdf_token_e tok; + int len; + int lo, hi; - else if (tok == PDF_TSTRING) + while (1) { - lo = codefromstring(buf, len); - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - if (tok == PDF_TSTRING) - { - hi = codefromstring(buf, len); - pdf_addcodespace(cmap, lo, hi, len); - } - else break; - } + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); - else break; - } + if (tok == TENDCODESPACERANGE) + return fz_okay; - return fz_throw("expected string or endcodespacerange"); + else if (tok == PDF_TSTRING) + { + lo = codefromstring(buf, len); + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); + if (tok == PDF_TSTRING) + { + hi = codefromstring(buf, len); + pdf_addcodespace(cmap, lo, hi, len); + } + else break; + } + + else break; + } + + return fz_throw("expected string or endcodespacerange"); } static fz_error parsecidrange(pdf_cmap *cmap, fz_stream *file) { - fz_error error; - char buf[256]; - pdf_token_e tok; - int len; - int lo, hi, dst; - - while (1) - { - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); + fz_error error; + char buf[256]; + pdf_token_e tok; + int len; + int lo, hi, dst; - if (tok == TENDCIDRANGE) - return fz_okay; + while (1) + { + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); - else if (tok != PDF_TSTRING) - return fz_throw("expected string or endcidrange"); + if (tok == TENDCIDRANGE) + return fz_okay; - lo = codefromstring(buf, len); + else if (tok != PDF_TSTRING) + return fz_throw("expected string or endcidrange"); - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - if (tok != PDF_TSTRING) - return fz_throw("expected string"); + lo = codefromstring(buf, len); + + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); + if (tok != PDF_TSTRING) + return fz_throw("expected string"); - hi = codefromstring(buf, len); + hi = codefromstring(buf, len); - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - if (tok != PDF_TINT) - return fz_throw("expected integer"); + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); + if (tok != PDF_TINT) + return fz_throw("expected integer"); - dst = atoi(buf); + dst = atoi(buf); - pdf_maprangetorange(cmap, lo, hi, dst); - } + pdf_maprangetorange(cmap, lo, hi, dst); + } } static fz_error parsecidchar(pdf_cmap *cmap, fz_stream *file) { - fz_error error; - char buf[256]; - pdf_token_e tok; - int len; - int src, dst; - - while (1) - { - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); + fz_error error; + char buf[256]; + pdf_token_e tok; + int len; + int src, dst; - if (tok == TENDCIDCHAR) - return fz_okay; + while (1) + { + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); - else if (tok != PDF_TSTRING) - return fz_throw("expected string or endcidchar"); + if (tok == TENDCIDCHAR) + return fz_okay; - src = codefromstring(buf, len); + else if (tok != PDF_TSTRING) + return fz_throw("expected string or endcidchar"); - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - if (tok != PDF_TINT) - return fz_throw("expected integer"); + src = codefromstring(buf, len); + + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); + if (tok != PDF_TINT) + return fz_throw("expected integer"); - dst = atoi(buf); + dst = atoi(buf); - pdf_maprangetorange(cmap, src, src, dst); - } + pdf_maprangetorange(cmap, src, src, dst); + } } static fz_error parsebfrangearray(pdf_cmap *cmap, fz_stream *file, int lo, int hi) { - fz_error error; - char buf[256]; - pdf_token_e tok; - int len; - int dst[256]; - int i; - - while (1) - { - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); + fz_error error; + char buf[256]; + pdf_token_e tok; + int len; + int dst[256]; + int i; + + while (1) + { + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); - if (tok == PDF_TCARRAY) - return fz_okay; + if (tok == PDF_TCARRAY) + return fz_okay; - /* Note: does not handle [ /Name /Name ... ] */ - else if (tok != PDF_TSTRING) - return fz_throw("expected string or ]"); + /* Note: does not handle [ /Name /Name ... ] */ + else if (tok != PDF_TSTRING) + return fz_throw("expected string or ]"); - if (len / 2) - { - for (i = 0; i < len / 2; i++) - dst[i] = codefromstring(buf + i * 2, 2); + if (len / 2) + { + for (i = 0; i < len / 2; i++) + dst[i] = codefromstring(buf + i * 2, 2); - pdf_maponetomany(cmap, lo, dst, len / 2); - } + pdf_maponetomany(cmap, lo, dst, len / 2); + } - lo ++; - } + lo ++; + } } static fz_error parsebfrange(pdf_cmap *cmap, fz_stream *file) { - fz_error error; - char buf[256]; - pdf_token_e tok; - int len; - int lo, hi, dst; - - while (1) - { - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); + fz_error error; + char buf[256]; + pdf_token_e tok; + int len; + int lo, hi, dst; - if (tok == TENDBFRANGE) - return fz_okay; + while (1) + { + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); - else if (tok != PDF_TSTRING) - return fz_throw("expected string or endbfrange"); + if (tok == TENDBFRANGE) + return fz_okay; - lo = codefromstring(buf, len); + else if (tok != PDF_TSTRING) + return fz_throw("expected string or endbfrange"); - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - if (tok != PDF_TSTRING) - return fz_throw("expected string"); + lo = codefromstring(buf, len); - hi = codefromstring(buf, len); + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); + if (tok != PDF_TSTRING) + return fz_throw("expected string"); - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); + hi = codefromstring(buf, len); - if (tok == PDF_TSTRING) - { - if (len == 2) - { - dst = codefromstring(buf, len); - pdf_maprangetorange(cmap, lo, hi, dst); - } - else - { - int dststr[256]; - int i; + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); - if (len / 2) + if (tok == PDF_TSTRING) { - for (i = 0; i < len / 2; i++) - dststr[i] = codefromstring(buf + i * 2, 2); - - while (lo <= hi) - { - dststr[i-1] ++; - pdf_maponetomany(cmap, lo, dststr, i); - lo ++; - } + if (len == 2) + { + dst = codefromstring(buf, len); + pdf_maprangetorange(cmap, lo, hi, dst); + } + else + { + int dststr[256]; + int i; + + if (len / 2) + { + for (i = 0; i < len / 2; i++) + dststr[i] = codefromstring(buf + i * 2, 2); + + while (lo <= hi) + { + dststr[i-1] ++; + pdf_maponetomany(cmap, lo, dststr, i); + lo ++; + } + } + } } - } - } - else if (tok == PDF_TOARRAY) - { - error = parsebfrangearray(cmap, file, lo, hi); - if (error) - return fz_rethrow(error, "cannot map bfrange"); - } + else if (tok == PDF_TOARRAY) + { + error = parsebfrangearray(cmap, file, lo, hi); + if (error) + return fz_rethrow(error, "cannot map bfrange"); + } - else - { - return fz_throw("expected string or array or endbfrange"); + else + { + return fz_throw("expected string or array or endbfrange"); + } } - } } static fz_error parsebfchar(pdf_cmap *cmap, fz_stream *file) { - fz_error error; - char buf[256]; - pdf_token_e tok; - int len; - int dst[256]; - int src; - int i; - - while (1) - { - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); + fz_error error; + char buf[256]; + pdf_token_e tok; + int len; + int dst[256]; + int src; + int i; + + while (1) + { + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); - if (tok == TENDBFCHAR) - return fz_okay; + if (tok == TENDBFCHAR) + return fz_okay; - else if (tok != PDF_TSTRING) - return fz_throw("expected string or endbfchar"); + else if (tok != PDF_TSTRING) + return fz_throw("expected string or endbfchar"); - src = codefromstring(buf, len); + src = codefromstring(buf, len); - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) - return fz_rethrow(error, "syntaxerror in cmap"); - /* Note: does not handle /dstName */ - if (tok != PDF_TSTRING) - return fz_throw("expected string"); + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + return fz_rethrow(error, "syntaxerror in cmap"); + /* Note: does not handle /dstName */ + if (tok != PDF_TSTRING) + return fz_throw("expected string"); - if (len / 2) - { - for (i = 0; i < len / 2; i++) - dst[i] = codefromstring(buf + i * 2, 2); - pdf_maponetomany(cmap, src, dst, i); + if (len / 2) + { + for (i = 0; i < len / 2; i++) + dst[i] = codefromstring(buf + i * 2, 2); + pdf_maponetomany(cmap, src, dst, i); + } } - } } fz_error pdf_parsecmap(pdf_cmap **cmapp, fz_stream *file) { - fz_error error; - pdf_cmap *cmap; - char key[64]; - char buf[256]; - pdf_token_e tok; - int len; + fz_error error; + pdf_cmap *cmap; + char key[64]; + char buf[256]; + pdf_token_e tok; + int len; - cmap = pdf_newcmap(); + cmap = pdf_newcmap(); - strcpy(key, ".notdef"); + strcpy(key, ".notdef"); - while (1) - { - error = lexcmap(&tok, file, buf, sizeof buf, &len); - if (error) + while (1) { - error = fz_rethrow(error, "syntaxerror in cmap"); - goto cleanup; - } + error = lexcmap(&tok, file, buf, sizeof buf, &len); + if (error) + { + error = fz_rethrow(error, "syntaxerror in cmap"); + goto cleanup; + } - if (tok == PDF_TEOF) - break; + if (tok == PDF_TEOF) + break; - else if (tok == PDF_TNAME) - { - if (!strcmp(buf, "CMapName")) - { - error = parsecmapname(cmap, file); - if (error) + else if (tok == PDF_TNAME) { - error = fz_rethrow(error, "syntaxerror in cmap after /CMapName"); - goto cleanup; + if (!strcmp(buf, "CMapName")) + { + error = parsecmapname(cmap, file); + if (error) + { + error = fz_rethrow(error, "syntaxerror in cmap after /CMapName"); + goto cleanup; + } + } + else if (!strcmp(buf, "WMode")) + { + error = parsewmode(cmap, file); + if (error) + { + error = fz_rethrow(error, "syntaxerror in cmap after /WMode"); + goto cleanup; + } + } + else + strlcpy(key, buf, sizeof key); } - } - else if (!strcmp(buf, "WMode")) - { - error = parsewmode(cmap, file); - if (error) + + else if (tok == TUSECMAP) { - error = fz_rethrow(error, "syntaxerror in cmap after /WMode"); - goto cleanup; + strlcpy(cmap->usecmapname, key, sizeof(cmap->usecmapname)); } - } - else - strlcpy(key, buf, sizeof key); - } - else if (tok == TUSECMAP) - { - strlcpy(cmap->usecmapname, key, sizeof(cmap->usecmapname)); - } + else if (tok == TBEGINCODESPACERANGE) + { + error = parsecodespacerange(cmap, file); + if (error) + { + error = fz_rethrow(error, "syntaxerror in cmap codespacerange"); + goto cleanup; + } + } - else if (tok == TBEGINCODESPACERANGE) - { - error = parsecodespacerange(cmap, file); - if (error) - { - error = fz_rethrow(error, "syntaxerror in cmap codespacerange"); - goto cleanup; - } - } + else if (tok == TBEGINBFCHAR) + { + error = parsebfchar(cmap, file); + if (error) + { + error = fz_rethrow(error, "syntaxerror in cmap bfchar"); + goto cleanup; + } + } - else if (tok == TBEGINBFCHAR) - { - error = parsebfchar(cmap, file); - if (error) - { - error = fz_rethrow(error, "syntaxerror in cmap bfchar"); - goto cleanup; - } - } + else if (tok == TBEGINCIDCHAR) + { + error = parsecidchar(cmap, file); + if (error) + { + error = fz_rethrow(error, "syntaxerror in cmap cidchar"); + goto cleanup; + } + } - else if (tok == TBEGINCIDCHAR) - { - error = parsecidchar(cmap, file); - if (error) - { - error = fz_rethrow(error, "syntaxerror in cmap cidchar"); - goto cleanup; - } - } + else if (tok == TBEGINBFRANGE) + { + error = parsebfrange(cmap, file); + if (error) + { + error = fz_rethrow(error, "syntaxerror in cmap bfrange"); + goto cleanup; + } + } - else if (tok == TBEGINBFRANGE) - { - error = parsebfrange(cmap, file); - if (error) - { - error = fz_rethrow(error, "syntaxerror in cmap bfrange"); - goto cleanup; - } - } + else if (tok == TBEGINCIDRANGE) + { + error = parsecidrange(cmap, file); + if (error) + { + error = fz_rethrow(error, "syntaxerror in cmap cidrange"); + goto cleanup; + } + } - else if (tok == TBEGINCIDRANGE) - { - error = parsecidrange(cmap, file); - if (error) - { - error = fz_rethrow(error, "syntaxerror in cmap cidrange"); - goto cleanup; - } + /* ignore everything else */ } - /* ignore everything else */ - } + pdf_sortcmap(cmap); - pdf_sortcmap(cmap); - - *cmapp = cmap; - return fz_okay; + *cmapp = cmap; + return fz_okay; cleanup: - pdf_dropcmap(cmap); - return error; /* already rethrown */ + pdf_dropcmap(cmap); + return error; /* already rethrown */ } diff --git a/mupdf/pdf_cmap_table.c b/mupdf/pdf_cmap_table.c index a1abea3f..7af1548b 100644 --- a/mupdf/pdf_cmap_table.c +++ b/mupdf/pdf_cmap_table.c @@ -82,80 +82,80 @@ extern pdf_cmap pdf_cmap_UniKS_UCS2_V; pdf_cmap *pdf_cmaptable[] = { #ifndef NOCJK - &pdf_cmap_Adobe_GB1_4, - &pdf_cmap_Adobe_GB1_UCS2, - &pdf_cmap_GB_EUC_H, - &pdf_cmap_GB_EUC_V, - &pdf_cmap_GBK_EUC_H, - &pdf_cmap_GBK_EUC_UCS2, - &pdf_cmap_GBK_EUC_V, - &pdf_cmap_GBK2K_H, - &pdf_cmap_GBK2K_V, - &pdf_cmap_GBKp_EUC_H, - &pdf_cmap_GBKp_EUC_V, - &pdf_cmap_GBT_EUC_H, - &pdf_cmap_GBT_EUC_V, - &pdf_cmap_GBpc_EUC_H, - &pdf_cmap_GBpc_EUC_UCS2, - &pdf_cmap_GBpc_EUC_UCS2C, - &pdf_cmap_GBpc_EUC_V, - &pdf_cmap_UniGB_UCS2_H, - &pdf_cmap_UniGB_UCS2_V, - &pdf_cmap_Adobe_CNS1_3, - &pdf_cmap_Adobe_CNS1_UCS2, - &pdf_cmap_B5pc_H, - &pdf_cmap_B5pc_UCS2, - &pdf_cmap_B5pc_UCS2C, - &pdf_cmap_B5pc_V, - &pdf_cmap_CNS_EUC_H, - &pdf_cmap_CNS_EUC_V, - &pdf_cmap_ETen_B5_H, - &pdf_cmap_ETen_B5_UCS2, - &pdf_cmap_ETen_B5_V, - &pdf_cmap_ETenms_B5_H, - &pdf_cmap_ETenms_B5_V, - &pdf_cmap_HKscs_B5_H, - &pdf_cmap_HKscs_B5_V, - &pdf_cmap_UniCNS_UCS2_H, - &pdf_cmap_UniCNS_UCS2_V, - &pdf_cmap_83pv_RKSJ_H, - &pdf_cmap_90ms_RKSJ_H, - &pdf_cmap_90ms_RKSJ_UCS2, - &pdf_cmap_90ms_RKSJ_V, - &pdf_cmap_90msp_RKSJ_H, - &pdf_cmap_90msp_RKSJ_V, - &pdf_cmap_90pv_RKSJ_H, - &pdf_cmap_90pv_RKSJ_UCS2, - &pdf_cmap_90pv_RKSJ_UCS2C, - &pdf_cmap_Add_RKSJ_H, - &pdf_cmap_Add_RKSJ_V, - &pdf_cmap_Adobe_Japan1_4, - &pdf_cmap_Adobe_Japan1_UCS2, - &pdf_cmap_EUC_H, - &pdf_cmap_EUC_V, - &pdf_cmap_Ext_RKSJ_H, - &pdf_cmap_Ext_RKSJ_V, - &pdf_cmap_H, - &pdf_cmap_UniJIS_UCS2_H, - &pdf_cmap_UniJIS_UCS2_HW_H, - &pdf_cmap_UniJIS_UCS2_HW_V, - &pdf_cmap_UniJIS_UCS2_V, - &pdf_cmap_V, - &pdf_cmap_Adobe_Korea1_2, - &pdf_cmap_Adobe_Korea1_UCS2, - &pdf_cmap_KSC_EUC_H, - &pdf_cmap_KSC_EUC_V, - &pdf_cmap_KSCms_UHC_H, - &pdf_cmap_KSCms_UHC_HW_H, - &pdf_cmap_KSCms_UHC_HW_V, - &pdf_cmap_KSCms_UHC_UCS2, - &pdf_cmap_KSCms_UHC_V, - &pdf_cmap_KSCpc_EUC_H, - &pdf_cmap_KSCpc_EUC_UCS2, - &pdf_cmap_KSCpc_EUC_UCS2C, - &pdf_cmap_UniKS_UCS2_H, - &pdf_cmap_UniKS_UCS2_V, + &pdf_cmap_Adobe_GB1_4, + &pdf_cmap_Adobe_GB1_UCS2, + &pdf_cmap_GB_EUC_H, + &pdf_cmap_GB_EUC_V, + &pdf_cmap_GBK_EUC_H, + &pdf_cmap_GBK_EUC_UCS2, + &pdf_cmap_GBK_EUC_V, + &pdf_cmap_GBK2K_H, + &pdf_cmap_GBK2K_V, + &pdf_cmap_GBKp_EUC_H, + &pdf_cmap_GBKp_EUC_V, + &pdf_cmap_GBT_EUC_H, + &pdf_cmap_GBT_EUC_V, + &pdf_cmap_GBpc_EUC_H, + &pdf_cmap_GBpc_EUC_UCS2, + &pdf_cmap_GBpc_EUC_UCS2C, + &pdf_cmap_GBpc_EUC_V, + &pdf_cmap_UniGB_UCS2_H, + &pdf_cmap_UniGB_UCS2_V, + &pdf_cmap_Adobe_CNS1_3, + &pdf_cmap_Adobe_CNS1_UCS2, + &pdf_cmap_B5pc_H, + &pdf_cmap_B5pc_UCS2, + &pdf_cmap_B5pc_UCS2C, + &pdf_cmap_B5pc_V, + &pdf_cmap_CNS_EUC_H, + &pdf_cmap_CNS_EUC_V, + &pdf_cmap_ETen_B5_H, + &pdf_cmap_ETen_B5_UCS2, + &pdf_cmap_ETen_B5_V, + &pdf_cmap_ETenms_B5_H, + &pdf_cmap_ETenms_B5_V, + &pdf_cmap_HKscs_B5_H, + &pdf_cmap_HKscs_B5_V, + &pdf_cmap_UniCNS_UCS2_H, + &pdf_cmap_UniCNS_UCS2_V, + &pdf_cmap_83pv_RKSJ_H, + &pdf_cmap_90ms_RKSJ_H, + &pdf_cmap_90ms_RKSJ_UCS2, + &pdf_cmap_90ms_RKSJ_V, + &pdf_cmap_90msp_RKSJ_H, + &pdf_cmap_90msp_RKSJ_V, + &pdf_cmap_90pv_RKSJ_H, + &pdf_cmap_90pv_RKSJ_UCS2, + &pdf_cmap_90pv_RKSJ_UCS2C, + &pdf_cmap_Add_RKSJ_H, + &pdf_cmap_Add_RKSJ_V, + &pdf_cmap_Adobe_Japan1_4, + &pdf_cmap_Adobe_Japan1_UCS2, + &pdf_cmap_EUC_H, + &pdf_cmap_EUC_V, + &pdf_cmap_Ext_RKSJ_H, + &pdf_cmap_Ext_RKSJ_V, + &pdf_cmap_H, + &pdf_cmap_UniJIS_UCS2_H, + &pdf_cmap_UniJIS_UCS2_HW_H, + &pdf_cmap_UniJIS_UCS2_HW_V, + &pdf_cmap_UniJIS_UCS2_V, + &pdf_cmap_V, + &pdf_cmap_Adobe_Korea1_2, + &pdf_cmap_Adobe_Korea1_UCS2, + &pdf_cmap_KSC_EUC_H, + &pdf_cmap_KSC_EUC_V, + &pdf_cmap_KSCms_UHC_H, + &pdf_cmap_KSCms_UHC_HW_H, + &pdf_cmap_KSCms_UHC_HW_V, + &pdf_cmap_KSCms_UHC_UCS2, + &pdf_cmap_KSCms_UHC_V, + &pdf_cmap_KSCpc_EUC_H, + &pdf_cmap_KSCpc_EUC_UCS2, + &pdf_cmap_KSCpc_EUC_UCS2C, + &pdf_cmap_UniKS_UCS2_H, + &pdf_cmap_UniKS_UCS2_V, #endif - nil + nil }; diff --git a/mupdf/pdf_colorspace1.c b/mupdf/pdf_colorspace1.c index e03aae70..8480d6fe 100644 --- a/mupdf/pdf_colorspace1.c +++ b/mupdf/pdf_colorspace1.c @@ -488,8 +488,8 @@ loadseparation(fz_colorspace **csp, pdf_xref *xref, fz_obj *array) cs = fz_malloc(sizeof(struct separation)); initcs((fz_colorspace*)cs, - n == 1 ? "Separation" : "DeviceN", n, - separationtoxyz, nil, dropseparation); + n == 1 ? "Separation" : "DeviceN", n, + separationtoxyz, nil, dropseparation); cs->base = base; cs->tint = tint; diff --git a/mupdf/pdf_crypt.c b/mupdf/pdf_crypt.c index b1886231..cca0fd10 100644 --- a/mupdf/pdf_crypt.c +++ b/mupdf/pdf_crypt.c @@ -9,207 +9,207 @@ fz_error pdf_newcrypt(pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) { - pdf_crypt *crypt; - fz_error error; - fz_obj *obj; - - crypt = fz_malloc(sizeof(pdf_crypt)); - memset(crypt, 0x00, sizeof(pdf_crypt)); - crypt->cf = nil; - - /* - * Common to all security handlers (PDF 1.7 table 3.18) - */ - - obj = fz_dictgets(dict, "Filter"); - if (!fz_isname(obj)) - { - pdf_freecrypt(crypt); - return fz_throw("unspecified encryption handler"); - } - if (strcmp(fz_toname(obj), "Standard") != 0) - { - pdf_freecrypt(crypt); - return fz_throw("unknown encryption handler: '%s'", fz_toname(obj)); - } - - crypt->v = 0; - obj = fz_dictgets(dict, "V"); - if (fz_isint(obj)) - crypt->v = fz_toint(obj); - if (crypt->v != 1 && crypt->v != 2 && crypt->v != 4) - { - pdf_freecrypt(crypt); - return fz_throw("unknown encryption version: %d", crypt->v); - } - - crypt->length = 40; - if (crypt->v == 2 || crypt->v == 4) - { - obj = fz_dictgets(dict, "Length"); - if (fz_isint(obj)) - crypt->length = fz_toint(obj); + pdf_crypt *crypt; + fz_error error; + fz_obj *obj; + + crypt = fz_malloc(sizeof(pdf_crypt)); + memset(crypt, 0x00, sizeof(pdf_crypt)); + crypt->cf = nil; - /* work-around for pdf generators that assume length is in bytes */ - if (crypt->length < 40) - crypt->length = crypt->length * 8; + /* + * Common to all security handlers (PDF 1.7 table 3.18) + */ - if (crypt->length % 8 != 0) + obj = fz_dictgets(dict, "Filter"); + if (!fz_isname(obj)) { - pdf_freecrypt(crypt); - return fz_throw("invalid encryption key length: %d", crypt->length); + pdf_freecrypt(crypt); + return fz_throw("unspecified encryption handler"); } - if (crypt->length > 256) + if (strcmp(fz_toname(obj), "Standard") != 0) { - pdf_freecrypt(crypt); - return fz_throw("invalid encryption key length: %d", crypt->length); + pdf_freecrypt(crypt); + return fz_throw("unknown encryption handler: '%s'", fz_toname(obj)); } - } - - if (crypt->v == 1 || crypt->v == 2) - { - crypt->stmf.method = PDF_CRYPT_RC4; - crypt->stmf.length = crypt->length; - - crypt->strf.method = PDF_CRYPT_RC4; - crypt->strf.length = crypt->length; - } - if (crypt->v == 4) - { - crypt->stmf.method = PDF_CRYPT_NONE; - crypt->stmf.length = crypt->length; - - crypt->strf.method = PDF_CRYPT_NONE; - crypt->strf.length = crypt->length; + crypt->v = 0; + obj = fz_dictgets(dict, "V"); + if (fz_isint(obj)) + crypt->v = fz_toint(obj); + if (crypt->v != 1 && crypt->v != 2 && crypt->v != 4) + { + pdf_freecrypt(crypt); + return fz_throw("unknown encryption version: %d", crypt->v); + } - obj = fz_dictgets(dict, "CF"); - if (fz_isdict(obj)) + crypt->length = 40; + if (crypt->v == 2 || crypt->v == 4) { - crypt->cf = fz_keepobj(obj); + obj = fz_dictgets(dict, "Length"); + if (fz_isint(obj)) + crypt->length = fz_toint(obj); - obj = fz_dictgets(dict, "StmF"); - if (fz_isname(obj)) - { - /* should verify that it is either Identity or StdCF */ - obj = fz_dictgets(crypt->cf, fz_toname(obj)); - if (fz_isdict(obj)) + /* work-around for pdf generators that assume length is in bytes */ + if (crypt->length < 40) + crypt->length = crypt->length * 8; + + if (crypt->length % 8 != 0) + { + pdf_freecrypt(crypt); + return fz_throw("invalid encryption key length: %d", crypt->length); + } + if (crypt->length > 256) { - error = pdf_parsecryptfilter(&crypt->stmf, obj, crypt->length); - if (error) - { pdf_freecrypt(crypt); - return fz_rethrow(error, "cannot parse stream crypt filter"); - } + return fz_throw("invalid encryption key length: %d", crypt->length); } - } + } + + if (crypt->v == 1 || crypt->v == 2) + { + crypt->stmf.method = PDF_CRYPT_RC4; + crypt->stmf.length = crypt->length; - obj = fz_dictgets(dict, "StrF"); - if (fz_isname(obj)) - { - /* should verify that it is either Identity or StdCF */ - obj = fz_dictgets(crypt->cf, fz_toname(obj)); + crypt->strf.method = PDF_CRYPT_RC4; + crypt->strf.length = crypt->length; + } + + if (crypt->v == 4) + { + crypt->stmf.method = PDF_CRYPT_NONE; + crypt->stmf.length = crypt->length; + + crypt->strf.method = PDF_CRYPT_NONE; + crypt->strf.length = crypt->length; + + obj = fz_dictgets(dict, "CF"); if (fz_isdict(obj)) { - error = pdf_parsecryptfilter(&crypt->strf, obj, crypt->length); - if (error) - { - pdf_freecrypt(crypt); - return fz_rethrow(error, "cannot parse string crypt filter"); - } + crypt->cf = fz_keepobj(obj); + + obj = fz_dictgets(dict, "StmF"); + if (fz_isname(obj)) + { + /* should verify that it is either Identity or StdCF */ + obj = fz_dictgets(crypt->cf, fz_toname(obj)); + if (fz_isdict(obj)) + { + error = pdf_parsecryptfilter(&crypt->stmf, obj, crypt->length); + if (error) + { + pdf_freecrypt(crypt); + return fz_rethrow(error, "cannot parse stream crypt filter"); + } + } + } + + obj = fz_dictgets(dict, "StrF"); + if (fz_isname(obj)) + { + /* should verify that it is either Identity or StdCF */ + obj = fz_dictgets(crypt->cf, fz_toname(obj)); + if (fz_isdict(obj)) + { + error = pdf_parsecryptfilter(&crypt->strf, obj, crypt->length); + if (error) + { + pdf_freecrypt(crypt); + return fz_rethrow(error, "cannot parse string crypt filter"); + } + } + } } - } } - } - - /* - * Standard security handler (PDF 1.7 table 3.19) - */ - - obj = fz_dictgets(dict, "R"); - if (fz_isint(obj)) - crypt->r = fz_toint(obj); - else - { - pdf_freecrypt(crypt); - return fz_throw("encryption dictionary missing revision value"); - } - - obj = fz_dictgets(dict, "O"); - if (fz_isstring(obj) && fz_tostrlen(obj) == 32) - memcpy(crypt->o, fz_tostrbuf(obj), 32); - else - { - pdf_freecrypt(crypt); - return fz_throw("encryption dictionary missing owner password"); - } - - obj = fz_dictgets(dict, "U"); - if (fz_isstring(obj) && fz_tostrlen(obj) == 32) - memcpy(crypt->u, fz_tostrbuf(obj), 32); - else - { - pdf_freecrypt(crypt); - return fz_throw("encryption dictionary missing user password"); - } - - obj = fz_dictgets(dict, "P"); - if (fz_isint(obj)) - crypt->p = fz_toint(obj); - else - { - pdf_freecrypt(crypt); - return fz_throw("encryption dictionary missing permissions value"); - } - - crypt->encryptmetadata = 1; - obj = fz_dictgets(dict, "EncryptMetadata"); - if (fz_isbool(obj)) - crypt->encryptmetadata = fz_tobool(obj); - - /* - * Extract file identifier string - */ - - crypt->idlength = 0; - - if (fz_isarray(id) && fz_arraylen(id) == 2) - { - obj = fz_arrayget(id, 0); - if (fz_isstring(obj)) + + /* + * Standard security handler (PDF 1.7 table 3.19) + */ + + obj = fz_dictgets(dict, "R"); + if (fz_isint(obj)) + crypt->r = fz_toint(obj); + else + { + pdf_freecrypt(crypt); + return fz_throw("encryption dictionary missing revision value"); + } + + obj = fz_dictgets(dict, "O"); + if (fz_isstring(obj) && fz_tostrlen(obj) == 32) + memcpy(crypt->o, fz_tostrbuf(obj), 32); + else + { + pdf_freecrypt(crypt); + return fz_throw("encryption dictionary missing owner password"); + } + + obj = fz_dictgets(dict, "U"); + if (fz_isstring(obj) && fz_tostrlen(obj) == 32) + memcpy(crypt->u, fz_tostrbuf(obj), 32); + else { - if (fz_tostrlen(obj) <= sizeof(crypt->idstring)) - { - memcpy(crypt->idstring, fz_tostrbuf(obj), fz_tostrlen(obj)); - crypt->idlength = fz_tostrlen(obj); - } + pdf_freecrypt(crypt); + return fz_throw("encryption dictionary missing user password"); } - } - else - fz_warn("missing file identifier, may not be able to do decryption"); + + obj = fz_dictgets(dict, "P"); + if (fz_isint(obj)) + crypt->p = fz_toint(obj); + else + { + pdf_freecrypt(crypt); + return fz_throw("encryption dictionary missing permissions value"); + } + + crypt->encryptmetadata = 1; + obj = fz_dictgets(dict, "EncryptMetadata"); + if (fz_isbool(obj)) + crypt->encryptmetadata = fz_tobool(obj); + + /* + * Extract file identifier string + */ + + crypt->idlength = 0; + + if (fz_isarray(id) && fz_arraylen(id) == 2) + { + obj = fz_arrayget(id, 0); + if (fz_isstring(obj)) + { + if (fz_tostrlen(obj) <= sizeof(crypt->idstring)) + { + memcpy(crypt->idstring, fz_tostrbuf(obj), fz_tostrlen(obj)); + crypt->idlength = fz_tostrlen(obj); + } + } + } + else + fz_warn("missing file identifier, may not be able to do decryption"); #if 0 - { - int i; - printf("crypt: v=%d length=%d\n", crypt->v, crypt->length); - printf("crypt: stmf method=%d length=%d\n", crypt->stmf.method, crypt->stmf.length); - printf("crypt: strf method=%d length=%d\n", crypt->strf.method, crypt->strf.length); - printf("crypt: r=%d\n", crypt->r); - printf("crypt: o=<"); for (i = 0; i < 32; i++) printf("%02X", crypt->o[i]); printf(">\n"); - printf("crypt: u=<"); for (i = 0; i < 32; i++) printf("%02X", crypt->u[i]); printf(">\n"); - printf("crypt: p=0x%08X\n", crypt->p); - } + { + int i; + printf("crypt: v=%d length=%d\n", crypt->v, crypt->length); + printf("crypt: stmf method=%d length=%d\n", crypt->stmf.method, crypt->stmf.length); + printf("crypt: strf method=%d length=%d\n", crypt->strf.method, crypt->strf.length); + printf("crypt: r=%d\n", crypt->r); + printf("crypt: o=<"); for (i = 0; i < 32; i++) printf("%02X", crypt->o[i]); printf(">\n"); + printf("crypt: u=<"); for (i = 0; i < 32; i++) printf("%02X", crypt->u[i]); printf(">\n"); + printf("crypt: p=0x%08X\n", crypt->p); + } #endif - *cryptp = crypt; - return fz_okay; + *cryptp = crypt; + return fz_okay; } void pdf_freecrypt(pdf_crypt *crypt) { - if (crypt->cf) fz_dropobj(crypt->cf); - fz_free(crypt); + if (crypt->cf) fz_dropobj(crypt->cf); + fz_free(crypt); } /* @@ -219,32 +219,32 @@ pdf_freecrypt(pdf_crypt *crypt) fz_error pdf_parsecryptfilter(pdf_cryptfilter *cf, fz_obj *dict, int defaultlength) { - fz_obj *obj; - - cf->method = PDF_CRYPT_NONE; - cf->length = defaultlength; - - obj = fz_dictgets(dict, "CFM"); - if (fz_isname(obj)) - { - if (!strcmp(fz_toname(obj), "None")) - cf->method = PDF_CRYPT_NONE; - else if (!strcmp(fz_toname(obj), "V2")) - cf->method = PDF_CRYPT_RC4; - else if (!strcmp(fz_toname(obj), "AESV2")) - cf->method = PDF_CRYPT_AESV2; - else - fz_throw("unknown encryption method: %s", fz_toname(obj)); - } + fz_obj *obj; + + cf->method = PDF_CRYPT_NONE; + cf->length = defaultlength; - obj = fz_dictgets(dict, "Length"); - if (fz_isint(obj)) - cf->length = fz_toint(obj); + obj = fz_dictgets(dict, "CFM"); + if (fz_isname(obj)) + { + if (!strcmp(fz_toname(obj), "None")) + cf->method = PDF_CRYPT_NONE; + else if (!strcmp(fz_toname(obj), "V2")) + cf->method = PDF_CRYPT_RC4; + else if (!strcmp(fz_toname(obj), "AESV2")) + cf->method = PDF_CRYPT_AESV2; + else + fz_throw("unknown encryption method: %s", fz_toname(obj)); + } + + obj = fz_dictgets(dict, "Length"); + if (fz_isint(obj)) + cf->length = fz_toint(obj); - if ((cf->length % 8) != 0) - return fz_throw("invalid key length: %d", cf->length); + if ((cf->length % 8) != 0) + return fz_throw("invalid key length: %d", cf->length); - return fz_okay; + return fz_okay; } /* @@ -253,75 +253,75 @@ pdf_parsecryptfilter(pdf_cryptfilter *cf, fz_obj *dict, int defaultlength) static const unsigned char padding[32] = { - 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, - 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, - 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, - 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a + 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, + 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, + 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, + 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a }; static void pdf_computeencryptionkey(pdf_crypt *crypt, unsigned char *password, int pwlen, unsigned char *key) { - unsigned char buf[32]; - unsigned int p; - int i, n; - fz_md5 md5; - - n = crypt->length / 8; - - /* Step 1 - copy and pad password string */ - if (pwlen > 32) - pwlen = 32; - memcpy(buf, password, pwlen); - memcpy(buf + pwlen, padding, 32 - pwlen); - - /* Step 2 - init md5 and pass value of step 1 */ - fz_md5init(&md5); - fz_md5update(&md5, buf, 32); - - /* Step 3 - pass O value */ - fz_md5update(&md5, crypt->o, 32); - - /* Step 4 - pass P value as unsigned int, low-order byte first */ - p = (unsigned int) crypt->p; - buf[0] = (p) & 0xFF; - buf[1] = (p >> 8) & 0xFF; - buf[2] = (p >> 16) & 0xFF; - buf[3] = (p >> 24) & 0xFF; - fz_md5update(&md5, buf, 4); - - /* Step 5 - pass first element of ID array */ - fz_md5update(&md5, crypt->idstring, crypt->idlength); - - /* Step 6 (revision 4 or greater) - if metadata is not encrypted pass 0xFFFFFFFF */ - if (crypt->r >= 4) - { - if (!crypt->encryptmetadata) + unsigned char buf[32]; + unsigned int p; + int i, n; + fz_md5 md5; + + n = crypt->length / 8; + + /* Step 1 - copy and pad password string */ + if (pwlen > 32) + pwlen = 32; + memcpy(buf, password, pwlen); + memcpy(buf + pwlen, padding, 32 - pwlen); + + /* Step 2 - init md5 and pass value of step 1 */ + fz_md5init(&md5); + fz_md5update(&md5, buf, 32); + + /* Step 3 - pass O value */ + fz_md5update(&md5, crypt->o, 32); + + /* Step 4 - pass P value as unsigned int, low-order byte first */ + p = (unsigned int) crypt->p; + buf[0] = (p) & 0xFF; + buf[1] = (p >> 8) & 0xFF; + buf[2] = (p >> 16) & 0xFF; + buf[3] = (p >> 24) & 0xFF; + fz_md5update(&md5, buf, 4); + + /* Step 5 - pass first element of ID array */ + fz_md5update(&md5, crypt->idstring, crypt->idlength); + + /* Step 6 (revision 4 or greater) - if metadata is not encrypted pass 0xFFFFFFFF */ + if (crypt->r >= 4) { - buf[0] = 0xFF; - buf[1] = 0xFF; - buf[2] = 0xFF; - buf[3] = 0xFF; - fz_md5update(&md5, buf, 4); + if (!crypt->encryptmetadata) + { + buf[0] = 0xFF; + buf[1] = 0xFF; + buf[2] = 0xFF; + buf[3] = 0xFF; + fz_md5update(&md5, buf, 4); + } } - } - /* Step 7 - finish the hash */ - fz_md5final(&md5, buf); + /* Step 7 - finish the hash */ + fz_md5final(&md5, buf); - /* Step 8 (revision 3 or greater) - do some voodoo 50 times */ - if (crypt->r >= 3) - { - for (i = 0; i < 50; i++) + /* Step 8 (revision 3 or greater) - do some voodoo 50 times */ + if (crypt->r >= 3) { - fz_md5init(&md5); - fz_md5update(&md5, buf, n); - fz_md5final(&md5, buf); + for (i = 0; i < 50; i++) + { + fz_md5init(&md5); + fz_md5update(&md5, buf, n); + fz_md5final(&md5, buf); + } } - } - /* Step 9 - the key is the first 'n' bytes of the result */ - memcpy(key, buf, n); + /* Step 9 - the key is the first 'n' bytes of the result */ + memcpy(key, buf, n); } /* @@ -332,45 +332,45 @@ pdf_computeencryptionkey(pdf_crypt *crypt, unsigned char *password, int pwlen, u static void pdf_computeuserpassword(pdf_crypt *crypt, unsigned char *password, int pwlen, unsigned char *output) { - if (crypt->r == 2) - { - fz_arc4 arc4; + if (crypt->r == 2) + { + fz_arc4 arc4; - pdf_computeencryptionkey(crypt, password, pwlen, crypt->key); - fz_arc4init(&arc4, crypt->key, crypt->length / 8); - fz_arc4encrypt(&arc4, output, padding, 32); - } + pdf_computeencryptionkey(crypt, password, pwlen, crypt->key); + fz_arc4init(&arc4, crypt->key, crypt->length / 8); + fz_arc4encrypt(&arc4, output, padding, 32); + } - if (crypt->r >= 3) - { - unsigned char xor[32]; - unsigned char digest[16]; - fz_md5 md5; - fz_arc4 arc4; - int i, x, n; + if (crypt->r >= 3) + { + unsigned char xor[32]; + unsigned char digest[16]; + fz_md5 md5; + fz_arc4 arc4; + int i, x, n; - n = crypt->length / 8; + n = crypt->length / 8; - pdf_computeencryptionkey(crypt, password, pwlen, crypt->key); + pdf_computeencryptionkey(crypt, password, pwlen, crypt->key); - fz_md5init(&md5); - fz_md5update(&md5, padding, 32); - fz_md5update(&md5, crypt->idstring, crypt->idlength); - fz_md5final(&md5, digest); + fz_md5init(&md5); + fz_md5update(&md5, padding, 32); + fz_md5update(&md5, crypt->idstring, crypt->idlength); + fz_md5final(&md5, digest); - fz_arc4init(&arc4, crypt->key, n); - fz_arc4encrypt(&arc4, output, digest, 16); + fz_arc4init(&arc4, crypt->key, n); + fz_arc4encrypt(&arc4, output, digest, 16); - for (x = 1; x <= 19; x++) - { - for (i = 0; i < n; i++) - xor[i] = crypt->key[i] ^ x; - fz_arc4init(&arc4, xor, n); - fz_arc4encrypt(&arc4, output, output, 16); - } + for (x = 1; x <= 19; x++) + { + for (i = 0; i < n; i++) + xor[i] = crypt->key[i] ^ x; + fz_arc4init(&arc4, xor, n); + fz_arc4encrypt(&arc4, output, output, 16); + } - memcpy(output + 16, padding, 16); - } + memcpy(output + 16, padding, 16); + } } /* @@ -382,13 +382,13 @@ pdf_computeuserpassword(pdf_crypt *crypt, unsigned char *password, int pwlen, un static int pdf_authenticateuserpassword(pdf_crypt *crypt, unsigned char *password, int pwlen) { - unsigned char output[32]; - pdf_computeuserpassword(crypt, password, pwlen, output); - if (crypt->r == 2) - return memcmp(output, crypt->u, 32) == 0; - if (crypt->r >= 3) - return memcmp(output, crypt->u, 16) == 0; - return 0; + unsigned char output[32]; + pdf_computeuserpassword(crypt, password, pwlen, output); + if (crypt->r == 2) + return memcmp(output, crypt->u, 32) == 0; + if (crypt->r >= 3) + return memcmp(output, crypt->u, 16) == 0; + return 0; } /* @@ -400,86 +400,86 @@ pdf_authenticateuserpassword(pdf_crypt *crypt, unsigned char *password, int pwle static int pdf_authenticateownerpassword(pdf_crypt *crypt, unsigned char *ownerpass, int pwlen) { - unsigned char pwbuf[32]; - unsigned char key[32]; - unsigned char xor[32]; - unsigned char userpass[32]; - int i, n, x; - fz_md5 md5; - fz_arc4 arc4; - - n = crypt->length / 8; - - /* Step 1 -- steps 1 to 4 of PDF 1.7 algorithm 3.3 */ - - /* copy and pad password string */ - if (pwlen > 32) - pwlen = 32; - memcpy(pwbuf, ownerpass, pwlen); - memcpy(pwbuf + pwlen, padding, 32 - pwlen); - - /* take md5 hash of padded password */ - fz_md5init(&md5); - fz_md5update(&md5, pwbuf, 32); - fz_md5final(&md5, key); - - /* do some voodoo 50 times (Revision 3 or greater) */ - if (crypt->r >= 3) - { - for (i = 0; i < 50; i++) + unsigned char pwbuf[32]; + unsigned char key[32]; + unsigned char xor[32]; + unsigned char userpass[32]; + int i, n, x; + fz_md5 md5; + fz_arc4 arc4; + + n = crypt->length / 8; + + /* Step 1 -- steps 1 to 4 of PDF 1.7 algorithm 3.3 */ + + /* copy and pad password string */ + if (pwlen > 32) + pwlen = 32; + memcpy(pwbuf, ownerpass, pwlen); + memcpy(pwbuf + pwlen, padding, 32 - pwlen); + + /* take md5 hash of padded password */ + fz_md5init(&md5); + fz_md5update(&md5, pwbuf, 32); + fz_md5final(&md5, key); + + /* do some voodoo 50 times (Revision 3 or greater) */ + if (crypt->r >= 3) + { + for (i = 0; i < 50; i++) + { + fz_md5init(&md5); + fz_md5update(&md5, key, 16); + fz_md5final(&md5, key); + } + } + + /* Step 2 (Revision 2) */ + if (crypt->r == 2) { - fz_md5init(&md5); - fz_md5update(&md5, key, 16); - fz_md5final(&md5, key); + fz_arc4init(&arc4, key, n); + fz_arc4encrypt(&arc4, userpass, crypt->o, 32); } - } - - /* Step 2 (Revision 2) */ - if (crypt->r == 2) - { - fz_arc4init(&arc4, key, n); - fz_arc4encrypt(&arc4, userpass, crypt->o, 32); - } - - /* Step 2 (Revision 3 or greater) */ - if (crypt->r >= 3) - { - memcpy(userpass, crypt->o, 32); - for (x = 0; x < 20; x++) + + /* Step 2 (Revision 3 or greater) */ + if (crypt->r >= 3) { - for (i = 0; i < n; i++) - xor[i] = key[i] ^ (19 - x); - fz_arc4init(&arc4, xor, n); - fz_arc4encrypt(&arc4, userpass, userpass, 32); + memcpy(userpass, crypt->o, 32); + for (x = 0; x < 20; x++) + { + for (i = 0; i < n; i++) + xor[i] = key[i] ^ (19 - x); + fz_arc4init(&arc4, xor, n); + fz_arc4encrypt(&arc4, userpass, userpass, 32); + } } - } - return pdf_authenticateuserpassword(crypt, userpass, 32); + return pdf_authenticateuserpassword(crypt, userpass, 32); } int pdf_authenticatepassword(pdf_xref *xref, char *password) { - if (xref->crypt) - { - if (pdf_authenticateuserpassword(xref->crypt, (unsigned char *)password, strlen(password))) - return 1; - if (pdf_authenticateownerpassword(xref->crypt, (unsigned char *)password, strlen(password))) - return 1; - return 0; - } - return 1; + if (xref->crypt) + { + if (pdf_authenticateuserpassword(xref->crypt, (unsigned char *)password, strlen(password))) + return 1; + if (pdf_authenticateownerpassword(xref->crypt, (unsigned char *)password, strlen(password))) + return 1; + return 0; + } + return 1; } int pdf_needspassword(pdf_xref *xref) { - if (!xref->crypt) - return 0; - if (pdf_authenticatepassword(xref, "")) - return 0; - return 1; + if (!xref->crypt) + return 0; + if (pdf_authenticatepassword(xref, "")) + return 0; + return 1; } /* @@ -494,26 +494,26 @@ pdf_needspassword(pdf_xref *xref) static int pdf_computeobjectkey(pdf_crypt *crypt, pdf_cryptfilter *cf, int num, int gen, unsigned char *key) { - fz_md5 md5; - unsigned char message[5]; - - fz_md5init(&md5); - fz_md5update(&md5, crypt->key, crypt->length / 8); - message[0] = (num) & 0xFF; - message[1] = (num >> 8) & 0xFF; - message[2] = (num >> 16) & 0xFF; - message[3] = (gen) & 0xFF; - message[4] = (gen >> 8) & 0xFF; - fz_md5update(&md5, message, 5); - - if (cf->method == PDF_CRYPT_AESV2) - fz_md5update(&md5, (unsigned char *)"sAlT", 4); - - fz_md5final(&md5, key); - - if (crypt->length / 8 + 5 > 16) - return 16; - return crypt->length / 8 + 5; + fz_md5 md5; + unsigned char message[5]; + + fz_md5init(&md5); + fz_md5update(&md5, crypt->key, crypt->length / 8); + message[0] = (num) & 0xFF; + message[1] = (num >> 8) & 0xFF; + message[2] = (num >> 16) & 0xFF; + message[3] = (gen) & 0xFF; + message[4] = (gen >> 8) & 0xFF; + fz_md5update(&md5, message, 5); + + if (cf->method == PDF_CRYPT_AESV2) + fz_md5update(&md5, (unsigned char *)"sAlT", 4); + + fz_md5final(&md5, key); + + if (crypt->length / 8 + 5 > 16) + return 16; + return crypt->length / 8 + 5; } /* @@ -527,67 +527,67 @@ pdf_computeobjectkey(pdf_crypt *crypt, pdf_cryptfilter *cf, int num, int gen, un static void pdf_cryptobjimp(pdf_crypt *crypt, fz_obj *obj, unsigned char *key, int keylen) { - unsigned char *s; - int i, n; - - if (fz_isindirect(obj)) - return; + unsigned char *s; + int i, n; - if (fz_isstring(obj)) - { - s = (unsigned char *) fz_tostrbuf(obj); - n = fz_tostrlen(obj); + if (fz_isindirect(obj)) + return; - if (crypt->strf.method == PDF_CRYPT_RC4) + if (fz_isstring(obj)) { - fz_arc4 arc4; - fz_arc4init(&arc4, key, keylen); - fz_arc4encrypt(&arc4, s, s, n); - } + s = (unsigned char *) fz_tostrbuf(obj); + n = fz_tostrlen(obj); - if (crypt->strf.method == PDF_CRYPT_AESV2) - { - if (n >= 32) - { - unsigned char iv[16]; - fz_aes aes; - memcpy(iv, s, 16); - aes_setkey_dec(&aes, key, keylen * 8); - aes_crypt_cbc(&aes, AES_DECRYPT, n - 16, iv, s + 16, s); - obj->u.s.len -= 16; /* delete space used for iv */ - obj->u.s.len -= s[n - 17]; /* delete padding bytes at end */ - } + if (crypt->strf.method == PDF_CRYPT_RC4) + { + fz_arc4 arc4; + fz_arc4init(&arc4, key, keylen); + fz_arc4encrypt(&arc4, s, s, n); + } + + if (crypt->strf.method == PDF_CRYPT_AESV2) + { + if (n >= 32) + { + unsigned char iv[16]; + fz_aes aes; + memcpy(iv, s, 16); + aes_setkey_dec(&aes, key, keylen * 8); + aes_crypt_cbc(&aes, AES_DECRYPT, n - 16, iv, s + 16, s); + obj->u.s.len -= 16; /* delete space used for iv */ + obj->u.s.len -= s[n - 17]; /* delete padding bytes at end */ + } + } } - } - else if (fz_isarray(obj)) - { - n = fz_arraylen(obj); - for (i = 0; i < n; i++) + else if (fz_isarray(obj)) { - pdf_cryptobjimp(crypt, fz_arrayget(obj, i), key, keylen); + n = fz_arraylen(obj); + for (i = 0; i < n; i++) + { + pdf_cryptobjimp(crypt, fz_arrayget(obj, i), key, keylen); + } } - } - else if (fz_isdict(obj)) - { - n = fz_dictlen(obj); - for (i = 0; i < n; i++) + else if (fz_isdict(obj)) { - pdf_cryptobjimp(crypt, fz_dictgetval(obj, i), key, keylen); + n = fz_dictlen(obj); + for (i = 0; i < n; i++) + { + pdf_cryptobjimp(crypt, fz_dictgetval(obj, i), key, keylen); + } } - } } void pdf_cryptobj(pdf_crypt *crypt, fz_obj *obj, int num, int gen) { - unsigned char key[16]; - int len; + unsigned char key[16]; + int len; - len = pdf_computeobjectkey(crypt, &crypt->strf, num, gen, key); + len = pdf_computeobjectkey(crypt, &crypt->strf, num, gen, key); - pdf_cryptobjimp(crypt, obj, key, len); + pdf_cryptobjimp(crypt, obj, key, len); } /* diff --git a/mupdf/pdf_font.c b/mupdf/pdf_font.c index 0d43aa0c..ffc28c27 100644 --- a/mupdf/pdf_font.c +++ b/mupdf/pdf_font.c @@ -37,21 +37,21 @@ static char *basefontnames[14][7] = static int strcmpignorespace(char *a, char *b) { - while (1) - { - while (*a == ' ') - a++; - while (*b == ' ') - b++; - if (*a != *b) - return 1; - if (*a == 0) - return *a != *b; - if (*b == 0) - return *a != *b; - a++; - b++; - } + while (1) + { + while (*a == ' ') + a++; + while (*b == ' ') + b++; + if (*a != *b) + return 1; + if (*a == 0) + return *a != *b; + if (*b == 0) + return *a != *b; + a++; + b++; + } } static char *cleanfontname(char *fontname) @@ -109,9 +109,9 @@ static inline int ftcidtogid(pdf_fontdesc *fontdesc, int cid) int pdf_fontcidtogid(pdf_fontdesc *fontdesc, int cid) { - if (fontdesc->font->ftface) - return ftcidtogid(fontdesc, cid); - return cid; + if (fontdesc->font->ftface) + return ftcidtogid(fontdesc, cid); + return cid; } static int ftwidth(pdf_fontdesc *fontdesc, int cid) @@ -121,7 +121,7 @@ static int ftwidth(pdf_fontdesc *fontdesc, int cid) gid = ftcidtogid(fontdesc, cid); fterr = FT_Load_Glyph(fontdesc->font->ftface, gid, - FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM); + FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM); if (fterr) { fz_warn("freetype load glyph (gid %d): %s", gid, ft_errorstring(fterr)); @@ -150,31 +150,31 @@ static int mrecode(char *name) pdf_fontdesc * pdf_keepfont(pdf_fontdesc *fontdesc) { - fontdesc->refs ++; - return fontdesc; + fontdesc->refs ++; + return fontdesc; } void pdf_dropfont(pdf_fontdesc *fontdesc) { - if (fontdesc && --fontdesc->refs == 0) - { - if (fontdesc->font) - fz_dropfont(fontdesc->font); - if (fontdesc->buffer) - fz_free(fontdesc->buffer); - if (fontdesc->encoding) - pdf_dropcmap(fontdesc->encoding); - if (fontdesc->tottfcmap) - pdf_dropcmap(fontdesc->tottfcmap); - if (fontdesc->tounicode) - pdf_dropcmap(fontdesc->tounicode); - fz_free(fontdesc->cidtogid); - fz_free(fontdesc->cidtoucs); - fz_free(fontdesc->hmtx); - fz_free(fontdesc->vmtx); - fz_free(fontdesc); - } + if (fontdesc && --fontdesc->refs == 0) + { + if (fontdesc->font) + fz_dropfont(fontdesc->font); + if (fontdesc->buffer) + fz_free(fontdesc->buffer); + if (fontdesc->encoding) + pdf_dropcmap(fontdesc->encoding); + if (fontdesc->tottfcmap) + pdf_dropcmap(fontdesc->tottfcmap); + if (fontdesc->tounicode) + pdf_dropcmap(fontdesc->tounicode); + fz_free(fontdesc->cidtogid); + fz_free(fontdesc->cidtoucs); + fz_free(fontdesc->hmtx); + fz_free(fontdesc->vmtx); + fz_free(fontdesc); + } } pdf_fontdesc * @@ -864,8 +864,8 @@ pdf_loadfontdescriptor(pdf_fontdesc *fontdesc, pdf_xref *xref, fz_obj *dict, cha bbox = pdf_torect(fz_dictgets(dict, "FontBBox")); pdf_logfont("bbox [%g %g %g %g]\n", - bbox.x0, bbox.y0, - bbox.x1, bbox.y1); + bbox.x0, bbox.y0, + bbox.x1, bbox.y1); pdf_logfont("flags %d\n", fontdesc->flags); @@ -879,14 +879,14 @@ pdf_loadfontdescriptor(pdf_fontdesc *fontdesc, pdf_xref *xref, fz_obj *dict, cha if (fz_isindirect(obj)) { - error = pdf_loadembeddedfont(fontdesc, xref, obj); - if (error) - { + error = pdf_loadembeddedfont(fontdesc, xref, obj); + if (error) + { fz_catch(error, "ignored error when loading embedded font, attempting to load system font"); - error = pdf_loadsystemfont(fontdesc, fontname, collection); - if (error) + error = pdf_loadsystemfont(fontdesc, fontname, collection); + if (error) return fz_rethrow(error, "cannot load font descriptor"); - } + } } else { @@ -945,7 +945,7 @@ pdf_loadfont(pdf_fontdesc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict error = loadsimplefont(fontdescp, xref, dict); } if (error) - return fz_rethrow(error, "cannot load font"); + return fz_rethrow(error, "cannot load font"); pdf_storeitem(xref->store, PDF_KFONT, dict, *fontdescp); @@ -955,32 +955,32 @@ pdf_loadfont(pdf_fontdesc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict void pdf_debugfont(pdf_fontdesc *fontdesc) { - int i; - - printf("fontdesc {\n"); - - if (fontdesc->font->ftface) - printf(" freetype font\n"); - if (fontdesc->font->t3procs) - printf(" type3 font\n"); - - printf(" wmode %d\n", fontdesc->wmode); - printf(" DW %d\n", fontdesc->dhmtx.w); - - printf(" W {\n"); - for (i = 0; i < fontdesc->nhmtx; i++) - printf(" <%04x> <%04x> %d\n", - fontdesc->hmtx[i].lo, fontdesc->hmtx[i].hi, fontdesc->hmtx[i].w); - printf(" }\n"); - - if (fontdesc->wmode) - { - printf(" DW2 [%d %d]\n", fontdesc->dvmtx.y, fontdesc->dvmtx.w); - printf(" W2 {\n"); - for (i = 0; i < fontdesc->nvmtx; i++) - printf(" <%04x> <%04x> %d %d %d\n", fontdesc->vmtx[i].lo, fontdesc->vmtx[i].hi, - fontdesc->vmtx[i].x, fontdesc->vmtx[i].y, fontdesc->vmtx[i].w); + int i; + + printf("fontdesc {\n"); + + if (fontdesc->font->ftface) + printf(" freetype font\n"); + if (fontdesc->font->t3procs) + printf(" type3 font\n"); + + printf(" wmode %d\n", fontdesc->wmode); + printf(" DW %d\n", fontdesc->dhmtx.w); + + printf(" W {\n"); + for (i = 0; i < fontdesc->nhmtx; i++) + printf(" <%04x> <%04x> %d\n", + fontdesc->hmtx[i].lo, fontdesc->hmtx[i].hi, fontdesc->hmtx[i].w); printf(" }\n"); - } + + if (fontdesc->wmode) + { + printf(" DW2 [%d %d]\n", fontdesc->dvmtx.y, fontdesc->dvmtx.w); + printf(" W2 {\n"); + for (i = 0; i < fontdesc->nvmtx; i++) + printf(" <%04x> <%04x> %d %d %d\n", fontdesc->vmtx[i].lo, fontdesc->vmtx[i].hi, + fontdesc->vmtx[i].x, fontdesc->vmtx[i].y, fontdesc->vmtx[i].w); + printf(" }\n"); + } } diff --git a/mupdf/pdf_fontfile.c b/mupdf/pdf_fontfile.c index 7339a962..711e827a 100644 --- a/mupdf/pdf_fontfile.c +++ b/mupdf/pdf_fontfile.c @@ -58,53 +58,53 @@ static const struct const char *name; const unsigned char *cff; const unsigned int *len; -} basefonts[] = { - { "Courier", - pdf_font_NimbusMonL_Regu_cff_buf, - &pdf_font_NimbusMonL_Regu_cff_len }, - { "Courier-Bold", - pdf_font_NimbusMonL_Bold_cff_buf, - &pdf_font_NimbusMonL_Bold_cff_len }, - { "Courier-Oblique", - pdf_font_NimbusMonL_ReguObli_cff_buf, - &pdf_font_NimbusMonL_ReguObli_cff_len }, - { "Courier-BoldOblique", - pdf_font_NimbusMonL_BoldObli_cff_buf, - &pdf_font_NimbusMonL_BoldObli_cff_len }, - { "Helvetica", - pdf_font_NimbusSanL_Regu_cff_buf, - &pdf_font_NimbusSanL_Regu_cff_len }, - { "Helvetica-Bold", - pdf_font_NimbusSanL_Bold_cff_buf, - &pdf_font_NimbusSanL_Bold_cff_len }, - { "Helvetica-Oblique", - pdf_font_NimbusSanL_ReguItal_cff_buf, - &pdf_font_NimbusSanL_ReguItal_cff_len }, - { "Helvetica-BoldOblique", - pdf_font_NimbusSanL_BoldItal_cff_buf, - &pdf_font_NimbusSanL_BoldItal_cff_len }, - { "Times-Roman", - pdf_font_NimbusRomNo9L_Regu_cff_buf, - &pdf_font_NimbusRomNo9L_Regu_cff_len }, - { "Times-Bold", - pdf_font_NimbusRomNo9L_Medi_cff_buf, - &pdf_font_NimbusRomNo9L_Medi_cff_len }, - { "Times-Italic", - pdf_font_NimbusRomNo9L_ReguItal_cff_buf, - &pdf_font_NimbusRomNo9L_ReguItal_cff_len }, - { "Times-BoldItalic", - pdf_font_NimbusRomNo9L_MediItal_cff_buf, - &pdf_font_NimbusRomNo9L_MediItal_cff_len }, - { "Symbol", - pdf_font_StandardSymL_cff_buf, - &pdf_font_StandardSymL_cff_len }, - { "ZapfDingbats", - pdf_font_Dingbats_cff_buf, - &pdf_font_Dingbats_cff_len }, - { "Chancery", - pdf_font_URWChanceryL_MediItal_cff_buf, - &pdf_font_URWChanceryL_MediItal_cff_len }, - { nil, nil, nil } + } basefonts[] = { + { "Courier", + pdf_font_NimbusMonL_Regu_cff_buf, + &pdf_font_NimbusMonL_Regu_cff_len }, + { "Courier-Bold", + pdf_font_NimbusMonL_Bold_cff_buf, + &pdf_font_NimbusMonL_Bold_cff_len }, + { "Courier-Oblique", + pdf_font_NimbusMonL_ReguObli_cff_buf, + &pdf_font_NimbusMonL_ReguObli_cff_len }, + { "Courier-BoldOblique", + pdf_font_NimbusMonL_BoldObli_cff_buf, + &pdf_font_NimbusMonL_BoldObli_cff_len }, + { "Helvetica", + pdf_font_NimbusSanL_Regu_cff_buf, + &pdf_font_NimbusSanL_Regu_cff_len }, + { "Helvetica-Bold", + pdf_font_NimbusSanL_Bold_cff_buf, + &pdf_font_NimbusSanL_Bold_cff_len }, + { "Helvetica-Oblique", + pdf_font_NimbusSanL_ReguItal_cff_buf, + &pdf_font_NimbusSanL_ReguItal_cff_len }, + { "Helvetica-BoldOblique", + pdf_font_NimbusSanL_BoldItal_cff_buf, + &pdf_font_NimbusSanL_BoldItal_cff_len }, + { "Times-Roman", + pdf_font_NimbusRomNo9L_Regu_cff_buf, + &pdf_font_NimbusRomNo9L_Regu_cff_len }, + { "Times-Bold", + pdf_font_NimbusRomNo9L_Medi_cff_buf, + &pdf_font_NimbusRomNo9L_Medi_cff_len }, + { "Times-Italic", + pdf_font_NimbusRomNo9L_ReguItal_cff_buf, + &pdf_font_NimbusRomNo9L_ReguItal_cff_len }, + { "Times-BoldItalic", + pdf_font_NimbusRomNo9L_MediItal_cff_buf, + &pdf_font_NimbusRomNo9L_MediItal_cff_len }, + { "Symbol", + pdf_font_StandardSymL_cff_buf, + &pdf_font_StandardSymL_cff_len }, + { "ZapfDingbats", + pdf_font_Dingbats_cff_buf, + &pdf_font_Dingbats_cff_len }, + { "Chancery", + pdf_font_URWChanceryL_MediItal_cff_buf, + &pdf_font_URWChanceryL_MediItal_cff_len }, + { nil, nil, nil } }; fz_error @@ -147,7 +147,7 @@ loadsystemcidfont(pdf_fontdesc *font, int csi, int kind) (unsigned char *)pdf_font_DroidSansFallback_ttf_buf, pdf_font_DroidSansFallback_ttf_len, 0); if (error) - return fz_rethrow(error, "cannot load builtin CJK font"); + return fz_rethrow(error, "cannot load builtin CJK font"); font->font->ftsubstitute = 1; /* substitute font */ return fz_okay; #else @@ -186,7 +186,7 @@ pdf_loadsystemfont(pdf_fontdesc *font, char *fontname, char *collection) isbold = 1; pdf_logfont("fixed-%d serif-%d italic-%d script-%d bold-%d\n", - isfixed, isserif, isitalic, isscript, isbold); + isfixed, isserif, isitalic, isscript, isbold); if (collection) { diff --git a/mupdf/pdf_function.c b/mupdf/pdf_function.c index ec9a0b4c..f563b402 100644 --- a/mupdf/pdf_function.c +++ b/mupdf/pdf_function.c @@ -203,7 +203,7 @@ pspopnum(psstack *st, float *real) if (!pschecktype(st, PSINT) && !pschecktype(st, PSREAL)) return fz_stacktypemismatch; *real = (st->stack[st->sp].type == PSINT) ? - st->stack[st->sp].u.i : st->stack[st->sp].u.f; + st->stack[st->sp].u.i : st->stack[st->sp].u.f; ++st->sp; return fz_okay; } @@ -1071,7 +1071,7 @@ evalsamplefunc(pdf_function *func, float *in, float *out) { x = CLAMP(in[i], func->domain[i][0], func->domain[i][1]); x = LERP(x, func->domain[i][0], func->domain[i][1], - func->u.sa.encode[i][0], func->u.sa.encode[i][1]); + func->u.sa.encode[i][0], func->u.sa.encode[i][1]); x = CLAMP(x, 0, func->u.sa.size[i] - 1); e[0][i] = floor(x); e[1][i] = ceil(x); @@ -1107,7 +1107,7 @@ evalsamplefunc(pdf_function *func, float *in, float *out) /* decode output values */ out[i] = LERP(s0[0], 0, (1 << func->u.sa.bps) - 1, - func->u.sa.decode[i][0], func->u.sa.decode[i][1]); + func->u.sa.decode[i][0], func->u.sa.decode[i][1]); out[i] = CLAMP(out[i], func->range[i][0], func->range[i][1]); } @@ -1271,7 +1271,7 @@ loadstitchingfunc(pdf_function *func, pdf_xref *xref, fz_obj *dict) } if (k != 1 && (func->domain[0][0] > func->u.st.bounds[0] || - func->domain[0][1] < func->u.st.bounds[k-2])) + func->domain[0][1] < func->u.st.bounds[k-2])) fz_warn("malformed shading function bounds (domain mismatch), proceeding anyway."); } diff --git a/mupdf/pdf_image.c b/mupdf/pdf_image.c index ca7a6a83..32cb1b4b 100644 --- a/mupdf/pdf_image.c +++ b/mupdf/pdf_image.c @@ -17,7 +17,7 @@ void pdf_dropimage(fz_image *fzimg) fz_error pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, - fz_obj *rdb, fz_obj *dict, fz_stream *file) + fz_obj *rdb, fz_obj *dict, fz_stream *file) { fz_error error; pdf_image *img; @@ -68,7 +68,7 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, } /* If no colorspace found in resource dictionary, - * assume that reference is a standard name */ + * assume that reference is a standard name */ if (!cso) cso = cs; @@ -112,7 +112,7 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, img->super.n = 0; img->super.a = 1; } - else if (!cs) + else if (!cs) return fz_throw("image is missing colorspace"); if (fz_isarray(d)) @@ -300,12 +300,12 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict) a = 1; } else - { + { if (!cs) return fz_throw("colorspace missing for image"); if (bpc == 0) return fz_throw("image has no bits per component"); - } + } obj = fz_dictgets(dict, "SMask"); if (fz_isindirect(obj)) @@ -393,7 +393,7 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict) if (realsize < expectedsize) { /* don't treat truncated image as fatal - get as much as possible and - fill the rest with 0 */ + fill the rest with 0 */ fz_buffer *buf; buf = fz_newbuffer(expectedsize); memset(buf->bp, 0, expectedsize); @@ -517,8 +517,8 @@ pdf_loadtile(fz_image *img, fz_pixmap *tile) } tilefunc(src->samples->rp + (tile->y * src->stride), src->stride, - tmp->samples, tmp->w, - tmp->w, tmp->h, 0); + tmp->samples, tmp->w, + tmp->w, tmp->h, 0); for (y = 0; y < tile->h; y++) { @@ -549,8 +549,8 @@ pdf_loadtile(fz_image *img, fz_pixmap *tile) else { tilefunc(src->samples->rp + (tile->y * src->stride), src->stride, - tile->samples, tile->w * tile->n, - tile->w * (img->n + img->a), tile->h, img->a ? 0 : img->n); + tile->samples, tile->w * tile->n, + tile->w * (img->n + img->a), tile->h, img->a ? 0 : img->n); if (src->usecolorkey) maskcolorkey(tile, src->colorkey); fz_decodetile(tile, !img->a, src->decode); diff --git a/mupdf/pdf_interpret.c b/mupdf/pdf_interpret.c index 170db8c9..c2602724 100644 --- a/mupdf/pdf_interpret.c +++ b/mupdf/pdf_interpret.c @@ -136,8 +136,8 @@ pdf_dropcsi(pdf_csi *csi) while (csi->gtop) grestore(csi); /* no need to check for impossible errors */ - if (csi->gstate[csi->gtop].fill.cs) - fz_dropcolorspace(csi->gstate[csi->gtop].fill.cs); + if (csi->gstate[csi->gtop].fill.cs) + fz_dropcolorspace(csi->gstate[csi->gtop].fill.cs); if (csi->gstate[csi->gtop].stroke.cs) fz_dropcolorspace(csi->gstate[csi->gtop].stroke.cs); if (csi->gstate[csi->gtop].font) @@ -182,9 +182,9 @@ runxobject(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, pdf_xobject *xobj) /* reset alpha to 1.0 when starting a new Transparency group */ if (xobj->transparency) { - gstate->blendmode = FZ_BNORMAL; - gstate->stroke.alpha = gstate->stroke.parentalpha; - gstate->fill.alpha = gstate->fill.parentalpha; + gstate->blendmode = FZ_BNORMAL; + gstate->stroke.alpha = gstate->stroke.parentalpha; + gstate->fill.alpha = gstate->fill.parentalpha; } /* push transform */ @@ -202,25 +202,25 @@ runxobject(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, pdf_xobject *xobj) if (xobj->isolated || xobj->knockout) { - /* The xobject's contents ought to be blended properly, - but for now, just do over and hope for something - - error = fz_newblendnode(&blend, gstate->blendmode, - xobj->isolated, xobj->knockout); - */ - if (gstate->blendmode != FZ_BNORMAL) - fz_warn("ignoring non-normal blendmode (%d)", gstate->blendmode); - if (xobj->isolated && xobj->knockout) - fz_warn("ignoring that the group is isolated and knockout"); - else if (xobj->isolated) - fz_warn("ignoring that the group is isolated"); - else if (xobj->knockout) - fz_warn("ignoring that the group is knockout"); - error = fz_newovernode(&blend); - if (error) - return fz_rethrow(error, "cannot create blend node"); - fz_insertnodelast(gstate->head, blend); - gstate->head = blend; + /* The xobject's contents ought to be blended properly, + but for now, just do over and hope for something + + error = fz_newblendnode(&blend, gstate->blendmode, + xobj->isolated, xobj->knockout); + */ + if (gstate->blendmode != FZ_BNORMAL) + fz_warn("ignoring non-normal blendmode (%d)", gstate->blendmode); + if (xobj->isolated && xobj->knockout) + fz_warn("ignoring that the group is isolated and knockout"); + else if (xobj->isolated) + fz_warn("ignoring that the group is isolated"); + else if (xobj->knockout) + fz_warn("ignoring that the group is knockout"); + error = fz_newovernode(&blend); + if (error) + return fz_rethrow(error, "cannot create blend node"); + fz_insertnodelast(gstate->head, blend); + gstate->head = blend; } /* run contents */ @@ -387,10 +387,10 @@ runextgstate(pdf_gstate *gstate, pdf_xref *xref, fz_obj *rdb, fz_obj *extgstate) } /* The content stream ought to be blended properly, - but for now, just do over and hope for something + but for now, just do over and hope for something - error = fz_newblendnode(&blend, gstate->blendmode, 0, 0); - */ + error = fz_newblendnode(&blend, gstate->blendmode, 0, 0); + */ error = fz_newovernode(&blend); if (error) return fz_rethrow(error, "cannot create blend node"); @@ -416,16 +416,16 @@ runextgstate(pdf_gstate *gstate, pdf_xref *xref, fz_obj *rdb, fz_obj *extgstate) if (!strcmp(fz_toname(subtype), "Form")) { - error = pdf_loadxobject(&xobj, xref, g); - if (error) - return fz_rethrow(error, "cannot load xobject"); + error = pdf_loadxobject(&xobj, xref, g); + if (error) + return fz_rethrow(error, "cannot load xobject"); } else if (!strcmp(fz_toname(subtype), "Image")) { - error = pdf_loadimage(&img, xref, g); - if (error) - return fz_rethrow(error, "cannot load xobject"); + error = pdf_loadimage(&img, xref, g); + if (error) + return fz_rethrow(error, "cannot load xobject"); } */ puts("we encountered a soft mask"); diff --git a/mupdf/pdf_lex.c b/mupdf/pdf_lex.c index e0425685..350bb1c7 100644 --- a/mupdf/pdf_lex.c +++ b/mupdf/pdf_lex.c @@ -49,7 +49,7 @@ static inline int ishex(int ch) static inline int fromhex(int ch) { if (ch >= '0' && ch <= '9') - return ch - '0'; + return ch - '0'; else if (ch >= 'A' && ch <= 'F') return ch - 'A' + 0xA; else if (ch >= 'a' && ch <= 'f') @@ -343,7 +343,7 @@ pdf_lex(pdf_token_e *tok, fz_stream *f, char *buf, int n, int *sl) goto cleanupokay; } - else if (c == '}') + else if (c == '}') { fz_readbyte(f); *tok = PDF_TCBRACE; diff --git a/mupdf/pdf_open.c b/mupdf/pdf_open.c index ec33414d..6374f3e2 100644 --- a/mupdf/pdf_open.c +++ b/mupdf/pdf_open.c @@ -247,7 +247,7 @@ readoldxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) } /* broken pdfs where size in trailer undershoots - entries in xref sections */ + entries in xref sections */ if ((ofs + len) > xref->cap) { fz_warn("broken xref section, proceeding anyway."); @@ -402,14 +402,14 @@ readnewxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) { if (oid == xref->len && oid < xref->cap) { - /* allow broken pdf files that have off-by-one errors in the xref */ - fz_warn("object id (%d %d R) out of range (0..%d)", oid, gen, xref->len - 1); - xref->len ++; + /* allow broken pdf files that have off-by-one errors in the xref */ + fz_warn("object id (%d %d R) out of range (0..%d)", oid, gen, xref->len - 1); + xref->len ++; } else { - fz_dropobj(trailer); - return fz_throw("object id (%d %d R) out of range (0..%d)", oid, gen, xref->len - 1); + fz_dropobj(trailer); + return fz_throw("object id (%d %d R) out of range (0..%d)", oid, gen, xref->len - 1); } } @@ -733,14 +733,14 @@ pdf_loadxref(pdf_xref *xref, char *filename) } /* broken pdfs where freed objects have offset and gen set to 0 - but still exits */ + but still exits */ for (i = 0; i < xref->len; i++) if (xref->table[i].type == 'n' && xref->table[i].ofs == 0 && - xref->table[i].gen == 0 && xref->table[i].obj == nil) - { - fz_warn("object (%d %d R) has invalid offset, assumed missing", i, xref->table[i].gen); - xref->table[i].type = 'f'; - } + xref->table[i].gen == 0 && xref->table[i].obj == nil) + { + fz_warn("object (%d %d R) has invalid offset, assumed missing", i, xref->table[i].gen); + xref->table[i].type = 'f'; + } return fz_okay; diff --git a/mupdf/pdf_outline.c b/mupdf/pdf_outline.c index 7fe6b886..4e2d5eac 100644 --- a/mupdf/pdf_outline.c +++ b/mupdf/pdf_outline.c @@ -93,9 +93,9 @@ pdf_debugoutline(pdf_outline *outline, int level) putchar(' '); if (outline->title) - printf("%s ", outline->title); + printf("%s ", outline->title); else - printf("<nil> "); + printf("<nil> "); if (outline->link) fz_debugobj(outline->link->dest); diff --git a/mupdf/pdf_page.c b/mupdf/pdf_page.c index 5caca8b3..18d6fb53 100644 --- a/mupdf/pdf_page.c +++ b/mupdf/pdf_page.c @@ -33,55 +33,55 @@ runone(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_obj *stmref) static fz_error runmany(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_obj *list) { - fz_error error; - fz_stream *file; - fz_buffer *big; - fz_buffer *one; - fz_obj *stm; - int i, n; + fz_error error; + fz_stream *file; + fz_buffer *big; + fz_buffer *one; + fz_obj *stm; + int i, n; - pdf_logpage("multiple content streams: %d\n", fz_arraylen(list)); + pdf_logpage("multiple content streams: %d\n", fz_arraylen(list)); - big = fz_newbuffer(32 * 1024); + big = fz_newbuffer(32 * 1024); - for (i = 0; i < fz_arraylen(list); i++) - { - stm = fz_arrayget(list, i); - error = pdf_loadstream(&one, xref, fz_tonum(stm), fz_togen(stm)); - if (error) + for (i = 0; i < fz_arraylen(list); i++) { - fz_dropbuffer(big); - return fz_rethrow(error, "cannot load content stream part %d/%d", i + 1, fz_arraylen(list)); - } + stm = fz_arrayget(list, i); + error = pdf_loadstream(&one, xref, fz_tonum(stm), fz_togen(stm)); + if (error) + { + fz_dropbuffer(big); + return fz_rethrow(error, "cannot load content stream part %d/%d", i + 1, fz_arraylen(list)); + } - n = one->wp - one->rp; + n = one->wp - one->rp; - while (big->wp + n + 1 > big->ep) - { - fz_growbuffer(big); - } + while (big->wp + n + 1 > big->ep) + { + fz_growbuffer(big); + } - memcpy(big->wp, one->rp, n); + memcpy(big->wp, one->rp, n); - big->wp += n; - *big->wp++ = ' '; + big->wp += n; + *big->wp++ = ' '; - fz_dropbuffer(one); - } + fz_dropbuffer(one); + } - file = fz_openrbuffer(big); - - error = pdf_runcsi(csi, xref, rdb, file); - if (error) - { - fz_dropbuffer(big); - fz_dropstream(file); - return fz_rethrow(error, "cannot interpret content buffer"); - } + file = fz_openrbuffer(big); + + error = pdf_runcsi(csi, xref, rdb, file); + if (error) + { + fz_dropbuffer(big); + fz_dropstream(file); + return fz_rethrow(error, "cannot interpret content buffer"); + } - fz_dropstream(file); - fz_dropbuffer(big); - return fz_okay; + fz_dropstream(file); + fz_dropbuffer(big); + return fz_okay; } static fz_error @@ -167,10 +167,10 @@ pdf_loadpage(pdf_page **pagep, pdf_xref *xref, fz_obj *dict) bbox = pdf_torect(obj); pdf_logpage("bbox [%g %g %g %g]\n", - bbox.x0, bbox.y0, bbox.x1, bbox.y1); + bbox.x0, bbox.y0, bbox.x1, bbox.y1); if (bbox.x1 - bbox.x0 < 1 || bbox.y1 - bbox.y0 < 1) - return fz_throw("invalid page size"); + return fz_throw("invalid page size"); obj = fz_dictgets(dict, "Rotate"); if (fz_isint(obj)) diff --git a/mupdf/pdf_parse.c b/mupdf/pdf_parse.c index cbe9c490..75eaa1b5 100644 --- a/mupdf/pdf_parse.c +++ b/mupdf/pdf_parse.c @@ -181,7 +181,7 @@ pdf_parsearray(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap) fz_arraypush(ary, obj); fz_dropobj(obj); break; - + case PDF_TODICT: error = pdf_parsedict(&obj, xref, file, buf, cap); if (error) @@ -293,7 +293,7 @@ skip: return fz_rethrow(error, "cannot parse dict"); } break; - + case PDF_TODICT: error = pdf_parsedict(&val, xref, file, buf, cap); if (error) @@ -303,7 +303,7 @@ skip: return fz_rethrow(error, "cannot parse dict"); } break; - + case PDF_TNAME: val = fz_newname(buf); break; case PDF_TREAL: val = fz_newreal(atof(buf)); break; case PDF_TSTRING: val = fz_newstring(buf, len); break; @@ -397,8 +397,8 @@ pdf_parsestmobj(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap fz_error pdf_parseindobj(fz_obj **op, pdf_xref *xref, - fz_stream *file, char *buf, int cap, - int *onum, int *ogen, int *ostmofs) + fz_stream *file, char *buf, int cap, + int *onum, int *ogen, int *ostmofs) { fz_error error = fz_okay; fz_obj *obj = nil; @@ -444,7 +444,7 @@ pdf_parseindobj(fz_obj **op, pdf_xref *xref, if (error) return fz_rethrow(error, "cannot parse indirect object (%d %d R)", num, gen); break; - + case PDF_TNAME: obj = fz_newname(buf); break; case PDF_TREAL: obj = fz_newreal(atof(buf)); break; case PDF_TSTRING: obj = fz_newstring(buf, len); break; diff --git a/mupdf/pdf_pattern.c b/mupdf/pdf_pattern.c index 01aadd59..8052c356 100644 --- a/mupdf/pdf_pattern.c +++ b/mupdf/pdf_pattern.c @@ -52,8 +52,8 @@ pdf_loadpattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict) pat->bbox = pdf_torect(obj); pdf_logrsrc("bbox [%g %g %g %g]\n", - pat->bbox.x0, pat->bbox.y0, - pat->bbox.x1, pat->bbox.y1); + pat->bbox.x0, pat->bbox.y0, + pat->bbox.x1, pat->bbox.y1); obj = fz_dictgets(dict, "Matrix"); if (obj) @@ -62,9 +62,9 @@ pdf_loadpattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict) pat->matrix = fz_identity(); pdf_logrsrc("matrix [%g %g %g %g %g %g]\n", - pat->matrix.a, pat->matrix.b, - pat->matrix.c, pat->matrix.d, - pat->matrix.e, pat->matrix.f); + pat->matrix.a, pat->matrix.b, + pat->matrix.c, pat->matrix.d, + pat->matrix.e, pat->matrix.f); /* Store pattern now, to avoid possible recursion if objects refer back to this one */ pdf_storeitem(xref->store, PDF_KPATTERN, dict, pat); diff --git a/mupdf/pdf_repair.c b/mupdf/pdf_repair.c index 3be1e98d..f3d7999e 100644 --- a/mupdf/pdf_repair.c +++ b/mupdf/pdf_repair.c @@ -225,7 +225,7 @@ pdf_repairxref(pdf_xref *xref, char *filename) list = fz_realloc(list, listcap * sizeof(struct entry)); } - pdf_logxref("found object: (%d %d R)\n", oid, gen); + pdf_logxref("found object: (%d %d R)\n", oid, gen); list[listlen].oid = oid; list[listlen].gen = gen; @@ -252,8 +252,8 @@ pdf_repairxref(pdf_xref *xref, char *filename) } error = fz_packobj(&xref->trailer, xref, - "<< /Size %i /Root %r >>", - maxoid + 1, rootoid, rootgen); + "<< /Size %i /Root %r >>", + maxoid + 1, rootoid, rootgen); if (error) { error = fz_rethrow(error, "cannot create new trailer"); @@ -293,7 +293,7 @@ pdf_repairxref(pdf_xref *xref, char *filename) fz_obj *dict, *length; pdf_logxref("correct stream length %d %d = %d\n", - list[i].oid, list[i].gen, list[i].stmlen); + list[i].oid, list[i].gen, list[i].stmlen); error = pdf_loadobject(&dict, xref, list[i].oid, list[i].gen); if (error) diff --git a/mupdf/pdf_shade.c b/mupdf/pdf_shade.c index c7e27dc6..70df7482 100644 --- a/mupdf/pdf_shade.c +++ b/mupdf/pdf_shade.c @@ -189,8 +189,8 @@ loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix matrix) { shade->bbox = pdf_torect(obj); pdf_logshade("bbox [%g %g %g %g]\n", - shade->bbox.x0, shade->bbox.y0, - shade->bbox.x1, shade->bbox.y1); + shade->bbox.x0, shade->bbox.y0, + shade->bbox.x1, shade->bbox.y1); } switch(type) @@ -263,7 +263,7 @@ pdf_loadshade(fz_shade **shadep, pdf_xref *xref, fz_obj *dict) { mat = pdf_tomatrix(obj); pdf_logshade("matrix [%g %g %g %g %g %g]\n", - mat.a, mat.b, mat.c, mat.d, mat.e, mat.f); + mat.a, mat.b, mat.c, mat.d, mat.e, mat.f); } else { diff --git a/mupdf/pdf_shade1.c b/mupdf/pdf_shade1.c index fb037725..b14d7c34 100644 --- a/mupdf/pdf_shade1.c +++ b/mupdf/pdf_shade1.c @@ -178,7 +178,7 @@ pdf_loadtype2shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict) dist = hypot(x1 - x0, y1 - y0); /* if the axis has virtually length 0 (a point), - do not extend as there is nothing to extend beyond */ + do not extend as there is nothing to extend beyond */ if (dist < FLT_EPSILON) { e0 = 0; @@ -205,7 +205,7 @@ pdf_loadtype2shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict) n = 0; /* if the axis has virtually length 0 (a point), use the same axis - position t = 0 for all triangle vertices */ + position t = 0 for all triangle vertices */ if (dist < FLT_EPSILON) { pdf_setmeshvalue(shade->mesh, n++, p1.x, p1.y, 0); @@ -262,8 +262,8 @@ pdf_loadtype2shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict) static int buildannulusmesh(float* mesh, int pos, - float x0, float y0, float r0, float x1, float y1, float r1, - float c0, float c1, int nomesh) + float x0, float y0, float r0, float x1, float y1, float r1, + float c0, float c1, int nomesh) { int n = pos * 3; float dist = hypot(x1 - x0, y1 - y0); diff --git a/mupdf/pdf_shade4.c b/mupdf/pdf_shade4.c index 7b2b73f5..d1b7920c 100644 --- a/mupdf/pdf_shade4.c +++ b/mupdf/pdf_shade4.c @@ -7,8 +7,8 @@ typedef struct pdf_tensorpatch_s pdf_tensorpatch; struct pdf_tensorpatch_s { - fz_point pole[4][4]; - float color[4][FZ_MAXCOLORS]; + fz_point pole[4][4]; + float color[4][FZ_MAXCOLORS]; }; static void @@ -19,7 +19,7 @@ growshademesh(fz_shade *shade, int amount) } static fz_error -parsedecode(fz_obj *decode, int ncomp, +parsedecode(fz_obj *decode, int ncomp, float *x0, float *x1, float *y0, float *y1, float *c0, float *c1) { int i; @@ -391,37 +391,37 @@ filltensorinterior(pdf_tensorpatch *p) ((p0 + p3 + p3) / 3.0f) p->pole[1][1].x = lcp1(p->pole[0][1].x, p->pole[3][1].x) + - lcp1(p->pole[1][0].x, p->pole[1][3].x) - - lcp1(lcp1(p->pole[0][0].x, p->pole[0][3].x), + lcp1(p->pole[1][0].x, p->pole[1][3].x) - + lcp1(lcp1(p->pole[0][0].x, p->pole[0][3].x), lcp1(p->pole[3][0].x, p->pole[3][3].x)); p->pole[1][2].x = lcp1(p->pole[0][2].x, p->pole[3][2].x) + - lcp2(p->pole[1][0].x, p->pole[1][3].x) - - lcp1(lcp2(p->pole[0][0].x, p->pole[0][3].x), + lcp2(p->pole[1][0].x, p->pole[1][3].x) - + lcp1(lcp2(p->pole[0][0].x, p->pole[0][3].x), lcp2(p->pole[3][0].x, p->pole[3][3].x)); p->pole[2][1].x = lcp2(p->pole[0][1].x, p->pole[3][1].x) + - lcp1(p->pole[2][0].x, p->pole[2][3].x) - - lcp2(lcp1(p->pole[0][0].x, p->pole[0][3].x), + lcp1(p->pole[2][0].x, p->pole[2][3].x) - + lcp2(lcp1(p->pole[0][0].x, p->pole[0][3].x), lcp1(p->pole[3][0].x, p->pole[3][3].x)); p->pole[2][2].x = lcp2(p->pole[0][2].x, p->pole[3][2].x) + - lcp2(p->pole[2][0].x, p->pole[2][3].x) - - lcp2(lcp2(p->pole[0][0].x, p->pole[0][3].x), + lcp2(p->pole[2][0].x, p->pole[2][3].x) - + lcp2(lcp2(p->pole[0][0].x, p->pole[0][3].x), lcp2(p->pole[3][0].x, p->pole[3][3].x)); p->pole[1][1].y = lcp1(p->pole[0][1].y, p->pole[3][1].y) + - lcp1(p->pole[1][0].y, p->pole[1][3].y) - - lcp1(lcp1(p->pole[0][0].y, p->pole[0][3].y), + lcp1(p->pole[1][0].y, p->pole[1][3].y) - + lcp1(lcp1(p->pole[0][0].y, p->pole[0][3].y), lcp1(p->pole[3][0].y, p->pole[3][3].y)); p->pole[1][2].y = lcp1(p->pole[0][2].y, p->pole[3][2].y) + - lcp2(p->pole[1][0].y, p->pole[1][3].y) - - lcp1(lcp2(p->pole[0][0].y, p->pole[0][3].y), + lcp2(p->pole[1][0].y, p->pole[1][3].y) - + lcp1(lcp2(p->pole[0][0].y, p->pole[0][3].y), lcp2(p->pole[3][0].y, p->pole[3][3].y)); p->pole[2][1].y = lcp2(p->pole[0][1].y, p->pole[3][1].y) + - lcp1(p->pole[2][0].y, p->pole[2][3].y) - - lcp2(lcp1(p->pole[0][0].y, p->pole[0][3].y), + lcp1(p->pole[2][0].y, p->pole[2][3].y) - + lcp2(lcp1(p->pole[0][0].y, p->pole[0][3].y), lcp1(p->pole[3][0].y, p->pole[3][3].y)); p->pole[2][2].y = lcp2(p->pole[0][2].y, p->pole[3][2].y) + - lcp2(p->pole[2][0].y, p->pole[2][3].y) - - lcp2(lcp2(p->pole[0][0].y, p->pole[0][3].y), + lcp2(p->pole[2][0].y, p->pole[2][3].y) - + lcp2(lcp2(p->pole[0][0].y, p->pole[0][3].y), lcp2(p->pole[3][0].y, p->pole[3][3].y)); #undef lcp1 @@ -433,33 +433,33 @@ split_curve_s(const fz_point *pole, fz_point *q0, fz_point *q1, int pole_step) { #define midpoint(a,b)\ ((a)/2.0f + (b)/2.0f) /* to avoid overflow */ - float x12 = midpoint(pole[1 * pole_step].x, pole[2 * pole_step].x); - float y12 = midpoint(pole[1 * pole_step].y, pole[2 * pole_step].y); - - q0[1 * pole_step].x = midpoint(pole[0 * pole_step].x, pole[1 * pole_step].x); - q0[1 * pole_step].y = midpoint(pole[0 * pole_step].y, pole[1 * pole_step].y); - q1[2 * pole_step].x = midpoint(pole[2 * pole_step].x, pole[3 * pole_step].x); - q1[2 * pole_step].y = midpoint(pole[2 * pole_step].y, pole[3 * pole_step].y); - q0[2 * pole_step].x = midpoint(q0[1 * pole_step].x, x12); - q0[2 * pole_step].y = midpoint(q0[1 * pole_step].y, y12); - q1[1 * pole_step].x = midpoint(x12, q1[2 * pole_step].x); - q1[1 * pole_step].y = midpoint(y12, q1[2 * pole_step].y); - q0[0 * pole_step].x = pole[0 * pole_step].x; - q0[0 * pole_step].y = pole[0 * pole_step].y; - q0[3 * pole_step].x = q1[0 * pole_step].x = midpoint(q0[2 * pole_step].x, q1[1 * pole_step].x); - q0[3 * pole_step].y = q1[0 * pole_step].y = midpoint(q0[2 * pole_step].y, q1[1 * pole_step].y); - q1[3 * pole_step].x = pole[3 * pole_step].x; - q1[3 * pole_step].y = pole[3 * pole_step].y; + float x12 = midpoint(pole[1 * pole_step].x, pole[2 * pole_step].x); + float y12 = midpoint(pole[1 * pole_step].y, pole[2 * pole_step].y); + + q0[1 * pole_step].x = midpoint(pole[0 * pole_step].x, pole[1 * pole_step].x); + q0[1 * pole_step].y = midpoint(pole[0 * pole_step].y, pole[1 * pole_step].y); + q1[2 * pole_step].x = midpoint(pole[2 * pole_step].x, pole[3 * pole_step].x); + q1[2 * pole_step].y = midpoint(pole[2 * pole_step].y, pole[3 * pole_step].y); + q0[2 * pole_step].x = midpoint(q0[1 * pole_step].x, x12); + q0[2 * pole_step].y = midpoint(q0[1 * pole_step].y, y12); + q1[1 * pole_step].x = midpoint(x12, q1[2 * pole_step].x); + q1[1 * pole_step].y = midpoint(y12, q1[2 * pole_step].y); + q0[0 * pole_step].x = pole[0 * pole_step].x; + q0[0 * pole_step].y = pole[0 * pole_step].y; + q0[3 * pole_step].x = q1[0 * pole_step].x = midpoint(q0[2 * pole_step].x, q1[1 * pole_step].x); + q0[3 * pole_step].y = q1[0 * pole_step].y = midpoint(q0[2 * pole_step].y, q1[1 * pole_step].y); + q1[3 * pole_step].x = pole[3 * pole_step].x; + q1[3 * pole_step].y = pole[3 * pole_step].y; #undef midpoint } static inline void split_patch(pdf_tensorpatch *s0, pdf_tensorpatch *s1, const pdf_tensorpatch *p) { - split_curve_s(&p->pole[0][0], &s0->pole[0][0], &s1->pole[0][0], 4); - split_curve_s(&p->pole[0][1], &s0->pole[0][1], &s1->pole[0][1], 4); - split_curve_s(&p->pole[0][2], &s0->pole[0][2], &s1->pole[0][2], 4); - split_curve_s(&p->pole[0][3], &s0->pole[0][3], &s1->pole[0][3], 4); + split_curve_s(&p->pole[0][0], &s0->pole[0][0], &s1->pole[0][0], 4); + split_curve_s(&p->pole[0][1], &s0->pole[0][1], &s1->pole[0][1], 4); + split_curve_s(&p->pole[0][2], &s0->pole[0][2], &s1->pole[0][2], 4); + split_curve_s(&p->pole[0][3], &s0->pole[0][3], &s1->pole[0][3], 4); copycolor(s0->color[0], p->color[0]); midcolor(s0->color[1], p->color[0], p->color[1]); @@ -476,10 +476,10 @@ static inline void split_stripe(pdf_tensorpatch *s0, pdf_tensorpatch *s1, const pdf_tensorpatch *p) { - split_curve_s(p->pole[0], s0->pole[0], s1->pole[0], 1); - split_curve_s(p->pole[1], s0->pole[1], s1->pole[1], 1); - split_curve_s(p->pole[2], s0->pole[2], s1->pole[2], 1); - split_curve_s(p->pole[3], s0->pole[3], s1->pole[3], 1); + split_curve_s(p->pole[0], s0->pole[0], s1->pole[0], 1); + split_curve_s(p->pole[1], s0->pole[1], s1->pole[1], 1); + split_curve_s(p->pole[2], s0->pole[2], s1->pole[2], 1); + split_curve_s(p->pole[3], s0->pole[3], s1->pole[3], 1); copycolor(s0->color[0], p->color[0]); copycolor(s0->color[1], p->color[1]); @@ -646,7 +646,7 @@ pdf_loadtype6shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict) { t = getdata(stream, bpcomp); patch.color[i][k] = - c0[k] + (t * (c1[k] - c0[k]) / (pow(2, bpcomp) - 1.0f)); + c0[k] + (t * (c1[k] - c0[k]) / (pow(2, bpcomp) - 1.0f)); } } @@ -754,7 +754,7 @@ pdf_loadtype7shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict) { t = getdata(stream, bpcomp); patch.color[i][k] = - c0[k] + (t * (c1[k] - c0[k]) / (pow(2, bpcomp) - 1.0f)); + c0[k] + (t * (c1[k] - c0[k]) / (pow(2, bpcomp) - 1.0f)); } } diff --git a/mupdf/pdf_store.c b/mupdf/pdf_store.c index 0fe2df54..96d96705 100644 --- a/mupdf/pdf_store.c +++ b/mupdf/pdf_store.c @@ -264,10 +264,10 @@ pdf_finditem(pdf_store *store, pdf_itemkind kind, fz_obj *key) { for (item = store->root; item; item = item->next) if (item->kind == kind && !fz_objcmp(item->key, key)) - { - item->age = 0; - return item->val; - } + { + item->age = 0; + return item->val; + } } return nil; diff --git a/mupdf/pdf_stream.c b/mupdf/pdf_stream.c index be0b5f99..8b56ea2d 100644 --- a/mupdf/pdf_stream.c +++ b/mupdf/pdf_stream.c @@ -119,7 +119,7 @@ buildonefilter(pdf_xref * xref, fz_obj * f, fz_obj * p, int num, int gen) { fz_buffer *globals; fz_filter *dec; - + dec = fz_newjbig2d(p); error = pdf_loadstream(&globals, xref, fz_tonum(obj), fz_togen(obj)); @@ -330,7 +330,7 @@ pdf_openrawstream(fz_stream **stmp, pdf_xref *xref, int num, int gen) if (x->stmofs) { filter = buildrawfilter(xref, x->obj, num, gen); - + error = fz_seek(xref->file, x->stmofs, 0); if (error) return fz_rethrow(error, "cannot seek to stream"); diff --git a/mupdf/pdf_type3.c b/mupdf/pdf_type3.c index 4bf1ec4f..e82df455 100644 --- a/mupdf/pdf_type3.c +++ b/mupdf/pdf_type3.c @@ -67,16 +67,16 @@ pdf_loadtype3font(pdf_fontdesc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_obj matrix = pdf_tomatrix(obj); pdf_logfont("matrix [%g %g %g %g %g %g]\n", - matrix.a, matrix.b, - matrix.c, matrix.d, - matrix.e, matrix.f); + matrix.a, matrix.b, + matrix.c, matrix.d, + matrix.e, matrix.f); obj = fz_dictgets(dict, "FontBBox"); bbox = pdf_torect(obj); pdf_logfont("bbox [%g %g %g %g]\n", - bbox.x0, bbox.y0, - bbox.x1, bbox.y1); + bbox.x0, bbox.y0, + bbox.x1, bbox.y1); bbox = fz_transformaabb(matrix, bbox); bbox.x0 = fz_floor(bbox.x0 * 1000); diff --git a/mupdf/pdf_unicode.c b/mupdf/pdf_unicode.c index d08c7e89..52792be8 100644 --- a/mupdf/pdf_unicode.c +++ b/mupdf/pdf_unicode.c @@ -5,8 +5,8 @@ #include FT_FREETYPE_H #if ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1)) || \ - ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 2)) || \ - ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 3) && (FREETYPE_PATCH < 8)) + ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 2)) || \ + ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 3) && (FREETYPE_PATCH < 8)) int FT_Get_Advance(FT_Face face, int gid, int masks, FT_Fixed *out) { @@ -79,8 +79,8 @@ pdf_loadtounicode(pdf_fontdesc *font, pdf_xref *xref, error = pdf_loadsystemcmap(&font->tounicode, "Adobe-Japan1-UCS2"); else if (!strcmp(collection, "Adobe-Japan2")) error = pdf_loadsystemcmap(&font->tounicode, "Adobe-Japan2-UCS2"); /* where's this? */ - else if (!strcmp(collection, "Adobe-Korea1")) - error = pdf_loadsystemcmap(&font->tounicode, "Adobe-Korea1-UCS2"); + else if (!strcmp(collection, "Adobe-Korea1")) + error = pdf_loadsystemcmap(&font->tounicode, "Adobe-Korea1-UCS2"); if (error) return fz_rethrow(error, "cannot load tounicode system cmap %s-UCS2", collection); @@ -116,9 +116,9 @@ pdf_loadtounicode(pdf_fontdesc *font, pdf_xref *xref, if (!font->tounicode && !font->cidtoucs) { - pdf_logfont("tounicode could not be loaded\n"); - /* TODO: synthesize a ToUnicode if it's a freetype font with - * cmap and/or post tables or if it has glyph names. */ + pdf_logfont("tounicode could not be loaded\n"); + /* TODO: synthesize a ToUnicode if it's a freetype font with + * cmap and/or post tables or if it has glyph names. */ } return fz_okay; diff --git a/mupdf/pdf_xobject.c b/mupdf/pdf_xobject.c index 5f3810c1..831796eb 100644 --- a/mupdf/pdf_xobject.c +++ b/mupdf/pdf_xobject.c @@ -20,7 +20,7 @@ pdf_loadxobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) form->contents = nil; /* Store item immediately, to avoid infinite recursion if contained - objects refer again to this xobject */ + objects refer again to this xobject */ pdf_storeitem(xref->store, PDF_KXOBJECT, dict, form); pdf_logrsrc("load xobject (%d %d R) ptr=%p {\n", fz_tonum(dict), fz_togen(dict), form); @@ -29,8 +29,8 @@ pdf_loadxobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) form->bbox = pdf_torect(obj); pdf_logrsrc("bbox [%g %g %g %g]\n", - form->bbox.x0, form->bbox.y0, - form->bbox.x1, form->bbox.y1); + form->bbox.x0, form->bbox.y0, + form->bbox.x1, form->bbox.y1); obj = fz_dictgets(dict, "Matrix"); if (obj) @@ -39,9 +39,9 @@ pdf_loadxobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) form->matrix = fz_identity(); pdf_logrsrc("matrix [%g %g %g %g %g %g]\n", - form->matrix.a, form->matrix.b, - form->matrix.c, form->matrix.d, - form->matrix.e, form->matrix.f); + form->matrix.a, form->matrix.b, + form->matrix.c, form->matrix.d, + form->matrix.e, form->matrix.f); form->isolated = 0; form->knockout = 0; diff --git a/mupdf/pdf_xref.c b/mupdf/pdf_xref.c index ec6a8d6c..5c365f7f 100644 --- a/mupdf/pdf_xref.c +++ b/mupdf/pdf_xref.c @@ -120,11 +120,11 @@ pdf_debugxref(pdf_xref *xref) for (i = 0; i < xref->len; i++) { printf("%010d %05d %c (ref=%d, ofs=%d)\n", - xref->table[i].ofs, - xref->table[i].gen, - xref->table[i].type, - xref->table[i].obj ? xref->table[i].obj->refs : 0, - xref->table[i].stmofs); + xref->table[i].ofs, + xref->table[i].gen, + xref->table[i].type, + xref->table[i].obj ? xref->table[i].obj->refs : 0, + xref->table[i].stmofs); } } |