summaryrefslogtreecommitdiff
path: root/apps/pdfclean.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-12-12 20:20:31 +0000
committerRobin Watts <robin.watts@artifex.com>2011-12-12 21:01:15 +0000
commit09c8ebeea83f11ccac07bad76e516460e2c8e0f7 (patch)
tree86522aa3117baa0511776040042ee41f25b4ee67 /apps/pdfclean.c
parentb5220176e550c8c6ff92f8eb556ad734e42bebe2 (diff)
downloadmupdf-09c8ebeea83f11ccac07bad76e516460e2c8e0f7.tar.xz
Add -i and -f flags to pdfclean.
Update pdfclean with some new decompression options; -d changes it's definition (though not it's behaviour) to mean "decompress all streams". New flags, -i and -f toggle the decompression of image and font streams respectively.
Diffstat (limited to 'apps/pdfclean.c')
-rw-r--r--apps/pdfclean.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/apps/pdfclean.c b/apps/pdfclean.c
index 56d78082..e13ad0f6 100644
--- a/apps/pdfclean.c
+++ b/apps/pdfclean.c
@@ -14,6 +14,13 @@
static FILE *out = NULL;
+enum
+{
+ expand_images = 1,
+ expand_fonts = 2,
+ expand_all = -1
+};
+
static char *uselist = NULL;
static int *ofslist = NULL;
static int *genlist = NULL;
@@ -34,7 +41,9 @@ static void usage(void)
"\t-g\tgarbage collect unused objects\n"
"\t-gg\tin addition to -g compact xref table\n"
"\t-ggg\tin addition to -gg merge duplicate objects\n"
- "\t-d\tdecompress streams\n"
+ "\t-d\tdecompress all streams\n"
+ "\t-i\ttoggle decompression of image streams\n"
+ "\t-f\ttoggle decompression of font streams\n"
"\t-a\tascii hex encode binary streams\n"
"\tpages\tcomma separated list of ranges\n");
exit(1);
@@ -530,7 +539,7 @@ static void copystream(fz_obj *obj, int num, int gen)
}
fprintf(out, "%d %d obj\n", num, gen);
- fz_fprint_obj(out, obj, !doexpand);
+ fz_fprint_obj(out, obj, doexpand == 0);
fprintf(out, "stream\n");
fwrite(buf->data, 1, buf->len, out);
fprintf(out, "endstream\nendobj\n\n");
@@ -562,7 +571,7 @@ static void expandstream(fz_obj *obj, int num, int gen)
fz_drop_obj(newlen);
fprintf(out, "%d %d obj\n", num, gen);
- fz_fprint_obj(out, obj, !doexpand);
+ fz_fprint_obj(out, obj, doexpand == 0);
fprintf(out, "stream\n");
fwrite(buf->data, 1, buf->len, out);
fprintf(out, "endstream\nendobj\n\n");
@@ -598,12 +607,35 @@ static void writeobject(int num, int gen)
if (!pdf_is_stream(xref, num, gen))
{
fprintf(out, "%d %d obj\n", num, gen);
- fz_fprint_obj(out, obj, !doexpand);
+ fz_fprint_obj(out, obj, doexpand == 0);
fprintf(out, "endobj\n\n");
}
else
{
- if (doexpand && !pdf_is_jpx_image(ctx, obj))
+ int dontexpand = 0;
+ if (doexpand != 0 && doexpand != expand_all)
+ {
+ fz_obj *o;
+
+ if ((o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "XObject")) &&
+ (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "Image")))
+ dontexpand = !(doexpand & expand_images);
+ if (o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "Font"))
+ dontexpand = !(doexpand & expand_fonts);
+ if (o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "FontDescriptor"))
+ dontexpand = !(doexpand & expand_fonts);
+ if ((o = fz_dict_gets(obj, "Length1")) != NULL)
+ dontexpand = !(doexpand & expand_fonts);
+ if ((o = fz_dict_gets(obj, "Length2")) != NULL)
+ dontexpand = !(doexpand & expand_fonts);
+ if ((o = fz_dict_gets(obj, "Length3")) != NULL)
+ dontexpand = !(doexpand & expand_fonts);
+ if (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "Type1C"))
+ dontexpand = !(doexpand & expand_fonts);
+ if (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "CIDFontType0C"))
+ dontexpand = !(doexpand & expand_fonts);
+ }
+ if (doexpand && !dontexpand && !pdf_is_jpx_image(ctx, obj))
expandstream(obj, num, gen);
else
copystream(obj, num, gen);
@@ -650,7 +682,7 @@ static void writexref(void)
fz_dict_puts(trailer, "ID", obj);
fprintf(out, "trailer\n");
- fz_fprint_obj(out, trailer, !doexpand);
+ fz_fprint_obj(out, trailer, doexpand != 0);
fprintf(out, "\n");
fz_drop_obj(trailer);
@@ -706,13 +738,15 @@ int main(int argc, char **argv)
int c, num;
int subset;
- while ((c = fz_getopt(argc, argv, "adgp:")) != -1)
+ while ((c = fz_getopt(argc, argv, "adfgip:")) != -1)
{
switch (c)
{
case 'p': password = fz_optarg; break;
case 'g': dogarbage ++; break;
- case 'd': doexpand ++; break;
+ case 'd': doexpand ^= expand_all; break;
+ case 'f': doexpand ^= expand_fonts; break;
+ case 'i': doexpand ^= expand_images; break;
case 'a': doascii ++; break;
default: usage(); break;
}