diff options
-rw-r--r-- | apps/pdfdraw.c | 69 | ||||
-rw-r--r-- | debian/pdfdraw.1 | 10 | ||||
-rw-r--r-- | fitz/dev_trace.c | 157 | ||||
-rw-r--r-- | fitz/fitz_draw.h | 1 | ||||
-rw-r--r-- | fitz/res_path.c | 40 | ||||
-rw-r--r-- | mupdf/pdf_interpret.c | 1 |
6 files changed, 166 insertions, 112 deletions
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 876e895a..14ec4afd 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -50,8 +50,6 @@ struct benchmark int maxpage; }; -static fz_renderer *drawgc = nil; - static int drawmode = DRAWPNM; static char *drawpattern = nil; static pdf_page *drawpage = nil; @@ -69,24 +67,19 @@ static void local_cleanup(void) 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" + " -p -\tpassword for decryption\n" " -o -\tpattern (%%d for page number) for output file\n" " -r -\tresolution in dpi\n" - " -m \tprint benchmark results\n" - " -s \tprint MD5 checksum of page pixel data\n" + " -m\tprint benchmark results\n" + " -s\tprint MD5 checksum of page pixel data\n" + " -t\ttext extraction made\n" + " -x\txml trace mode\n" " example:\n" " pdfdraw -o output%%03d.pnm input.pdf 1-3,5,9-\n"); exit(1); @@ -218,23 +211,10 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark * for (b = 0; b < drawbands; b++) { - if (drawbands > 1) - fprintf(stdout, "drawing band %d / %d\n", b + 1, drawbands); - -#if 0 - printf("\nRESOURCES:\n"); - fz_debugobj(fz_resolveindirect(drawpage->resources)); - printf("CONTENTS:\n"); - showsafe(drawpage->contents->rp, - drawpage->contents->wp - drawpage->contents->rp); - printf("END.\n"); -#endif - fz_device *dev; -// dev = fz_newtracedevice(); -// drawpage->contents->rp = drawpage->contents->bp; -// pdf_runcontentstream(dev, ctm, xref, drawpage->resources, drawpage->contents); + if (drawbands > 1) + fprintf(stdout, "drawing band %d / %d\n", b + 1, drawbands); dev = fz_newdrawdevice(pix); drawpage->contents->rp = drawpage->contents->bp; @@ -341,6 +321,34 @@ static void drawtxt(int pagenum) fz_freetextspan(text); } +static void drawxml(int pagenum) +{ + fz_error error; + fz_obj *pageobj; + fz_matrix ctm; + fz_device *dev; + + pageobj = pdf_getpageobject(xref, pagenum); + error = pdf_loadpage(&drawpage, xref, pageobj); + if (error) + die(error); + + ctm = fz_identity(); + + dev = fz_newtracedevice(); + printf("<?xml version=\"1.0\"?>\n"); + printf("<page number=\"%d\">\n", pagenum); + + drawpage->contents->rp = drawpage->contents->bp; + error = pdf_runcontentstream(dev, ctm, xref, drawpage->resources, drawpage->contents); + if (error) + die(error); + + fz_freedevice(dev); + + printf("</page>\n"); +} + static void drawpages(char *pagelist) { int page, spage, epage; @@ -384,14 +392,13 @@ static void drawpages(char *pagelist) if (epage > pagecount) epage = pagecount; - 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; + case DRAWXML: drawxml(page); break; } } @@ -426,12 +433,12 @@ int main(int argc, char **argv) fz_cpudetect(); fz_accelerate(); - while ((c = fz_getopt(argc, argv, "b:d:o:r:txms")) != -1) + while ((c = fz_getopt(argc, argv, "b:p:o:r:txms")) != -1) { switch (c) { case 'b': drawbands = atoi(fz_optarg); break; - case 'd': password = fz_optarg; break; + case 'p': password = fz_optarg; break; case 'o': drawpattern = fz_optarg; checksum = 1; break; case 'r': drawzoom = atof(fz_optarg) / 72.0; break; case 't': drawmode = DRAWTXT; break; diff --git a/debian/pdfdraw.1 b/debian/pdfdraw.1 index 839d1f52..004a2cb7 100644 --- a/debian/pdfdraw.1 +++ b/debian/pdfdraw.1 @@ -1,4 +1,4 @@ -.TH PDFDRAW 1 "March 21, 2010" +.TH PDFDRAW 1 "April 15, 2010" .\" Please adjust this date whenever revising the manpage. .SH NAME pdfdraw \- renderer tool to convert a PDF file to PNM image files @@ -29,7 +29,7 @@ A description of each of the supported options is included below. Each page is rendered in the given number of separate bands. The default is to render the entire page in one go. .TP -.B \-d password +.B \-p password Uses the given password during decryption of an encrypted PDF file. The password is tried both as user and owner password. .TP @@ -46,6 +46,12 @@ inch. The deafult is 72dpi. Enables benchmarking, causing rendering time to be printed for each page as well as summary statistics after all pages in each PDF file have been rendered. +.TP +.B \-t +Print the text on the page in UTF-8. +.TP +.B \-x +Print an XML representation of the page graphics. .SH SEE ALSO .BR mupdf (1), .BR pdfclean (1). diff --git a/fitz/dev_trace.c b/fitz/dev_trace.c index 834aee5c..2a477709 100644 --- a/fitz/dev_trace.c +++ b/fitz/dev_trace.c @@ -3,7 +3,7 @@ static void fz_tracematrix(fz_matrix ctm) { - printf("%g %g %g %g %g %g setmatrix\n", + printf("matrix=\"%g %g %g %g %g %g\" ", ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f); } @@ -11,22 +11,67 @@ static void fz_tracecolor(fz_colorspace *colorspace, float *color, float alpha) { int i; - printf("/%s setcolorspace\n", colorspace->name); + printf("colorspace=\"%s\" color=\"", colorspace->name); for (i = 0; i < colorspace->n; i++) - printf("%g ", color[i]); - printf("setcolor\n"); - printf("%g setalpha\n", alpha); + printf("%s%g", i == 0 ? "" : " ", color[i]); + printf("\" "); + if (alpha != 1.0) + printf("alpha=\"%g\" ", alpha); +} + +static void +fz_tracepath(fz_path *path, int indent) +{ + float x, y; + int i = 0; + int n; + while (i < path->len) + { + for (n = 0; n < indent; n++) + putchar(' '); + switch (path->els[i++].k) + { + case FZ_MOVETO: + x = path->els[i++].v; + y = path->els[i++].v; + printf("<moveto x=\"%g\" y=\"%g\" />\n", x, y); + break; + case FZ_LINETO: + x = path->els[i++].v; + y = path->els[i++].v; + printf("<lineto x=\"%g\" y=\"%g\" />\n", x, y); + break; + case FZ_CURVETO: + x = path->els[i++].v; + y = path->els[i++].v; + printf("<curveto x1=\"%g\" y1=\"%g\" ", x, y); + x = path->els[i++].v; + y = path->els[i++].v; + printf("x2=\"%g\" y2=\"%g\" ", x, y); + x = path->els[i++].v; + y = path->els[i++].v; + printf("x3=\"%g\" y3=\"%g\" />\n", x, y); + break; + case FZ_CLOSEPATH: + printf("<closepath />\n"); + } + } } static void fz_tracefillpath(void *user, fz_path *path, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) { - fz_printpath(path, 0); + printf("<fillpath "); if (path->evenodd) - printf("eofill\n"); + printf("winding=\"eofill\" "); else - printf("fill\n"); + printf("winding=\"nonzero\" "); + fz_tracecolor(colorspace, color, alpha); + fz_tracematrix(ctm); + printf(">\n"); + fz_tracepath(path, 0); + printf("</fillpath>\n"); } static void @@ -35,94 +80,128 @@ fz_tracestrokepath(void *user, fz_path *path, fz_matrix ctm, { int i; - fz_tracecolor(colorspace, color, alpha); - - printf("%g setlinewidth\n", path->linewidth); - printf("%g setmiterlimit\n", path->miterlimit); - printf("%d setlinecap\n", path->linecap); - printf("%d setlinejoin\n", path->linejoin); + printf("<strokepath "); + printf("linewidth=\"%g\" ", path->linewidth); + printf("miterlimit=\"%g\" ", path->miterlimit); + printf("linecap=\"%d\" ", path->linecap); + printf("linejoin=\"%d\" ", path->linejoin); if (path->dashlen) { - printf("%g [ ", path->dashphase); + printf("dashphase=\"%g\" dash=\"", path->dashphase); for (i = 0; i < path->dashlen; i++) printf("%g ", path->dashlist[i]); - printf("] setdash\n"); + printf("\""); } - fz_printpath(path, 0); + fz_tracecolor(colorspace, color, alpha); + fz_tracematrix(ctm); + printf(">\n"); + + fz_tracepath(path, 0); - printf("stroke\n"); + printf("</strokepath>\n"); } static void fz_traceclippath(void *user, fz_path *path, fz_matrix ctm) { - printf("gsave\n"); - fz_printpath(path, 0); + printf("<gsave>\n"); + printf("<clippath "); if (path->evenodd) - printf("eoclip\n"); + printf("winding=\"eofill\" "); else - printf("clip\n"); + printf("winding=\"nonzero\" "); + fz_tracematrix(ctm); + printf(">\n"); + fz_tracepath(path, 0); + printf("</clippath>\n"); } static void fz_tracefilltext(void *user, fz_text *text, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) { - printf("/%s setfont\n", text->font->name); - fz_tracematrix(text->trm); + printf("<filltext font=\"%s\" ", text->font->name); + fz_tracecolor(colorspace, color, alpha); + fz_tracematrix(fz_concat(ctm, text->trm)); + printf(">\n"); fz_debugtext(text, 0); - printf("show\n"); + printf("</filltext>\n"); } static void fz_tracestroketext(void *user, fz_text *text, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) { - printf("/%s setfont\n", text->font->name); - fz_tracematrix(text->trm); + printf("<stroketext font=\"%s\" ", text->font->name); + fz_tracecolor(colorspace, color, alpha); + fz_tracematrix(fz_concat(ctm, text->trm)); + printf(">\n"); fz_debugtext(text, 0); - printf("charpath stroke\n"); + printf("</stroketext>\n"); } static void fz_tracecliptext(void *user, fz_text *text, fz_matrix ctm) { - printf("gsave\n"); - printf("/%s setfont\n", text->font->name); - fz_tracematrix(text->trm); + printf("<gsave>\n"); + printf("<cliptext font=\"%s\" ", text->font->name); + fz_tracematrix(fz_concat(ctm, text->trm)); + printf(">\n"); fz_debugtext(text, 0); - printf("charpath clip\n"); + printf("</cliptext>\n"); } static void fz_traceignoretext(void *user, fz_text *text, fz_matrix ctm) { - printf("/%s setfont\n", text->font->name); - fz_tracematrix(text->trm); + printf("<ignoretext font=\"%s\" ", text->font->name); + fz_tracematrix(fz_concat(ctm, text->trm)); + printf(">\n"); fz_debugtext(text, 0); - printf("invisibletext\n"); + printf("</ignoretext>\n"); } static void fz_tracefillimage(void *user, fz_pixmap *image, fz_matrix ctm) { + printf("<fillimage "); fz_tracematrix(ctm); - printf("fillimage\n"); + printf("/>\n"); } static void fz_tracefillshade(void *user, fz_shade *shade, fz_matrix ctm) { + printf("<fillshade "); + fz_tracematrix(ctm); + printf("/>\n"); +} + +static void +fz_tracefillimagemask(void *user, fz_pixmap *image, fz_matrix ctm, +fz_colorspace *colorspace, float *color, float alpha) +{ + printf("<fillimagemask "); + fz_tracematrix(ctm); + fz_tracecolor(colorspace, color, alpha); + printf("/>\n"); +} + +static void +fz_traceclipimagemask(void *user, fz_pixmap *image, fz_matrix ctm) +{ + printf("<gsave>\n"); + printf("<clipimagemask "); fz_tracematrix(ctm); - printf("fillshade\n"); + printf("/>\n"); } static void fz_tracepopclip(void *user) { - printf("grestore\n"); + printf("</gsave>\n"); } fz_device *fz_newtracedevice(void) @@ -140,6 +219,8 @@ fz_device *fz_newtracedevice(void) dev->fillshade = fz_tracefillshade; dev->fillimage = fz_tracefillimage; + dev->fillimagemask = fz_tracefillimagemask; + dev->clipimagemask = fz_traceclipimagemask; dev->popclip = fz_tracepopclip; diff --git a/fitz/fitz_draw.h b/fitz/fitz_draw.h index 8076f0aa..389c9387 100644 --- a/fitz/fitz_draw.h +++ b/fitz/fitz_draw.h @@ -1,4 +1,3 @@ -typedef struct fz_renderer_s fz_renderer; #define FZ_BYTE unsigned char diff --git a/fitz/res_path.c b/fitz/res_path.c index a7de4da9..dcf026c0 100644 --- a/fitz/res_path.c +++ b/fitz/res_path.c @@ -189,7 +189,7 @@ fz_boundpath(fz_path *path, fz_matrix ctm, int dostroke) } void -fz_printpath(fz_path *path, int indent) +fz_debugpath(fz_path *path, int indent) { float x, y; int i = 0; @@ -227,41 +227,3 @@ fz_printpath(fz_path *path, int indent) } } -void -fz_debugpath(fz_path *path, int indent) -{ - float x, y; - int i = 0; - int n; - while (i < path->len) - { - for (n = 0; n < indent; n++) - putchar(' '); - switch (path->els[i++].k) - { - case FZ_MOVETO: - x = path->els[i++].v; - y = path->els[i++].v; - printf("<moveto x=\"%g\" y=\"%g\" />\n", x, y); - break; - case FZ_LINETO: - x = path->els[i++].v; - y = path->els[i++].v; - printf("<lineto x=\"%g\" y=\"%g\" />\n", x, y); - break; - case FZ_CURVETO: - x = path->els[i++].v; - y = path->els[i++].v; - printf("<curveto x1=\"%g\" y1=\"%g\" ", x, y); - x = path->els[i++].v; - y = path->els[i++].v; - printf("x2=\"%g\" y2=\"%g\" ", x, y); - x = path->els[i++].v; - y = path->els[i++].v; - printf("x3=\"%g\" y3=\"%g\" />\n", x, y); - break; - case FZ_CLOSEPATH: - printf("<closepath />\n"); - } - } -} diff --git a/mupdf/pdf_interpret.c b/mupdf/pdf_interpret.c index eda61156..c31ec908 100644 --- a/mupdf/pdf_interpret.c +++ b/mupdf/pdf_interpret.c @@ -381,7 +381,6 @@ pdf_runextgstate(pdf_gstate *gstate, pdf_xref *xref, fz_obj *rdb, fz_obj *extgst return fz_rethrow(error, "cannot load xobject"); } */ - puts("we encountered a soft mask"); } } |