summaryrefslogtreecommitdiff
path: root/source/tools
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-03-25 16:42:46 +0000
committerRobin Watts <robin.watts@artifex.com>2013-06-21 17:39:41 +0100
commit0afe72e5fc386aa0ebceec9618f2b681f9bfdc3d (patch)
tree1e294cef2b4b01e1311b90286c7675a87ca3a9f4 /source/tools
parent82131246a46ed4547c978b0081d4e0db9d6f3942 (diff)
downloadmupdf-0afe72e5fc386aa0ebceec9618f2b681f9bfdc3d.tar.xz
Initial PDF editing/page creation commit
Diffstat (limited to 'source/tools')
-rw-r--r--source/tools/mudraw.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index 57bd4be2..1803447b 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -14,7 +14,7 @@
enum { TEXT_PLAIN = 1, TEXT_HTML = 2, TEXT_XML = 3 };
-enum { OUT_PNG, OUT_PPM, OUT_PNM, OUT_PAM, OUT_PGM, OUT_PBM, OUT_SVG, OUT_PWG, OUT_PCL };
+enum { OUT_PNG, OUT_PPM, OUT_PNM, OUT_PAM, OUT_PGM, OUT_PBM, OUT_SVG, OUT_PWG, OUT_PCL, OUT_PDF };
enum { CS_INVALID, CS_UNSET, CS_MONO, CS_GRAY, CS_GRAYALPHA, CS_RGB, CS_RGBA };
@@ -34,7 +34,8 @@ static const suffix_t suffix_table[] =
{ ".pbm", OUT_PBM },
{ ".svg", OUT_SVG },
{ ".pwg", OUT_PWG },
- { ".pcl", OUT_PCL }
+ { ".pcl", OUT_PCL },
+ { ".pdf", OUT_PDF },
};
typedef struct
@@ -75,7 +76,8 @@ static const format_cs_table_t format_cs_table[] =
{ OUT_PBM, CS_MONO, { CS_MONO } },
{ OUT_SVG, CS_RGB, { CS_RGB } },
{ OUT_PWG, CS_RGB, { CS_MONO, CS_GRAY, CS_RGB } },
- { OUT_PCL, CS_MONO, { CS_MONO } }
+ { OUT_PCL, CS_MONO, { CS_MONO } },
+ { OUT_PDF, CS_RGB, { CS_RGB } }
};
/*
@@ -137,6 +139,7 @@ static int showxml = 0;
static int showtext = 0;
static int showtime = 0;
static int showmd5 = 0;
+static pdf_document *pdfout = NULL;
static int showoutline = 0;
static int uselist = 1;
static int alphabits = 8;
@@ -473,6 +476,44 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
if (showmd5 || showtime)
printf("page %s %d", filename, pagenum);
+ if (pdfout)
+ {
+ fz_matrix ctm;
+ fz_rect bounds, tbounds;
+ pdf_page *newpage;
+
+ fz_bound_page(doc, page, &bounds);
+ fz_rotate(&ctm, rotation);
+ tbounds = bounds;
+ fz_transform_rect(&tbounds, &ctm);
+
+ newpage = pdf_create_page(pdfout, bounds, 72, 0);
+
+ fz_try(ctx)
+ {
+ dev = pdf_page_write(pdfout, newpage);
+ if (list)
+ fz_run_display_list(list, dev, &ctm, &tbounds, &cookie);
+ else
+ fz_run_page(doc, page, dev, &ctm, &cookie);
+ fz_free_device(dev);
+ dev = NULL;
+ }
+ fz_always(ctx)
+ {
+ fz_free_device(dev);
+ dev = NULL;
+ }
+ fz_catch(ctx)
+ {
+ fz_drop_display_list(ctx, list);
+ fz_free_page(doc, page);
+ fz_rethrow(ctx);
+ }
+ pdf_insert_page(pdfout, newpage, INT_MAX);
+ pdf_free_page(pdfout, newpage);
+ }
+
if (output && output_format == OUT_SVG)
{
float zoom;
@@ -519,7 +560,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
}
}
- if ((output && output_format != OUT_SVG)|| showmd5 || showtime)
+ if ((output && output_format != OUT_SVG && !pdfout)|| showmd5 || showtime)
{
float zoom;
fz_matrix ctm;
@@ -936,6 +977,11 @@ int main(int argc, char **argv)
break;
}
+ if (output_format == OUT_PDF)
+ {
+ pdfout = pdf_create_document(ctx);
+ }
+
timing.count = 0;
timing.total = 0;
timing.min = 1 << 30;
@@ -1037,6 +1083,14 @@ int main(int argc, char **argv)
errored = 1;
}
+ if (pdfout)
+ {
+ fz_write_options opts = { 0 };
+
+ pdf_write_document(pdfout, output, &opts);
+ pdf_close_document(pdfout);
+ }
+
if (showtext == TEXT_HTML)
{
fz_printf(out, "</body>\n");