diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-11-10 01:52:40 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-11-10 01:52:40 +0100 |
commit | 97d00440c043b712a2d16134e3b52850c7b36d47 (patch) | |
tree | e7b838f3b7c714037bb238b0c4d17ab4aaa3e0ed /apps | |
parent | c445538b312a45435df87086eed2e19b68ed5bc1 (diff) | |
download | mupdf-97d00440c043b712a2d16134e3b52850c7b36d47.tar.xz |
Add XPS outline parsing and move outline data struct to fz_outline.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/pdfapp.c | 2 | ||||
-rw-r--r-- | apps/pdfapp.h | 2 | ||||
-rw-r--r-- | apps/pdfdraw.c | 50 | ||||
-rw-r--r-- | apps/xpsdraw.c | 31 |
4 files changed, 32 insertions, 53 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 3050145f..ab29fcb9 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -235,7 +235,7 @@ void pdfapp_close(pdfapp_t *app) app->image = NULL; if (app->outline) - pdf_free_outline(app->outline); + fz_free_outline(app->outline); app->outline = NULL; if (app->xref) diff --git a/apps/pdfapp.h b/apps/pdfapp.h index a3829b3e..270c450a 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -31,7 +31,7 @@ struct pdfapp_s /* current document params */ char *doctitle; pdf_xref *xref; - pdf_outline *outline; + fz_outline *outline; xps_context *xps; int pagecount; diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 90db4c1b..d79cd75c 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -297,54 +297,14 @@ static void drawrange(pdf_xref *xref, char *range) } } -static int get_page_number(pdf_xref *xref, pdf_link *link) -{ - if (link->kind == PDF_LINK_GOTO) - return pdf_find_page_number(xref, fz_array_get(link->dest, 0)); - return 0; -} - -static void print_outline_xml(pdf_xref *xref, pdf_outline *outline, int level) -{ - int page; - printf("<outline>\n"); - while (outline) - { - page = get_page_number(xref, outline->link); - printf("<link title=\"%s\" page=\"%d\" />\n", - outline->title ? outline->title : "<null>", page); - if (outline->child) - print_outline_xml(xref, outline->child, level + 1); - outline = outline->next; - } - printf("</outline>\n"); -} - -static void print_outline_plain(pdf_xref *xref, pdf_outline *outline, int level) -{ - int i, page; - while (outline) - { - page = get_page_number(xref, outline->link); - for (i = 0; i < level; i++) - putchar('\t'); - printf("%s %d\n", outline->title ? outline->title : "<null>", page); - if (outline->child) - print_outline_plain(xref, outline->child, level + 1); - outline = outline->next; - } -} - static void drawoutline(pdf_xref *xref) { - pdf_outline *outline = pdf_load_outline(xref); - if (showoutline > 2) - pdf_debug_outline(outline, 0); - else if (showoutline > 1) - print_outline_xml(xref, outline, 0); + fz_outline *outline = pdf_load_outline(xref); + if (showoutline > 1) + fz_debug_outline_xml(outline, 0); else - print_outline_plain(xref, outline, 0); - pdf_free_outline(outline); + fz_debug_outline(outline, 0); + fz_free_outline(outline); } int main(int argc, char **argv) diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c index 29738e6b..1d2992bc 100644 --- a/apps/xpsdraw.c +++ b/apps/xpsdraw.c @@ -14,6 +14,7 @@ int showxml = 0; int showtext = 0; int showtime = 0; int showmd5 = 0; +int showoutline = 0; int savealpha = 0; int uselist = 1; @@ -47,6 +48,7 @@ static void usage(void) "\t-x\tshow display list\n" "\t-d\tdisable use of display list\n" "\t-5\tshow md5 checksums\n" + "\t-l\tprint outline\n" "\tpages\tcomma separated list of ranges\n"); exit(1); } @@ -272,6 +274,16 @@ static void drawrange(xps_context *ctx, char *range) } } +static void drawoutline(xps_context *ctx) +{ + fz_outline *outline = xps_load_outline(ctx); + if (showoutline > 1) + fz_debug_outline_xml(outline, 0); + else + fz_debug_outline(outline, 0); + fz_free_outline(outline); +} + int main(int argc, char **argv) { int grayscale = 0; @@ -280,7 +292,7 @@ int main(int argc, char **argv) int code; int c; - while ((c = fz_getopt(argc, argv, "o:p:r:Aadgmtx5")) != -1) + while ((c = fz_getopt(argc, argv, "o:p:r:Aadglmtx5")) != -1) { switch (c) { @@ -288,6 +300,7 @@ int main(int argc, char **argv) case 'r': resolution = atof(fz_optarg); break; case 'A': accelerate = 0; break; case 'a': savealpha = 1; break; + case 'l': showoutline++; break; case 'm': showtime++; break; case 't': showtext++; break; case 'x': showxml++; break; @@ -301,7 +314,7 @@ int main(int argc, char **argv) if (fz_optind == argc) usage(); - if (!showtext && !showxml && !showtime && !showmd5 && !output) + if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output) { printf("nothing to do\n"); exit(0); @@ -341,10 +354,16 @@ int main(int argc, char **argv) if (showxml) printf("<document name=\"%s\">\n", filename); - if (fz_optind == argc || !isrange(argv[fz_optind])) - drawrange(ctx, "1-"); - if (fz_optind < argc && isrange(argv[fz_optind])) - drawrange(ctx, argv[fz_optind++]); + if (showoutline) + drawoutline(ctx); + + if (showtext || showxml || showtime || showmd5 || output) + { + if (fz_optind == argc || !isrange(argv[fz_optind])) + drawrange(ctx, "1-"); + if (fz_optind < argc && isrange(argv[fz_optind])) + drawrange(ctx, argv[fz_optind++]); + } if (showxml) printf("</document>\n"); |