diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-12-17 22:38:35 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-12-18 15:32:14 +0100 |
commit | 80949d3d6b6320f5643a450c382f19370922e78f (patch) | |
tree | 7e3a6612d9c2985c3c3c493182d4171d017b4456 | |
parent | 02d5b2280db2846e4a683944819eb395ab15b8ce (diff) | |
download | mupdf-80949d3d6b6320f5643a450c382f19370922e78f.tar.xz |
Remove fz_save_document and use pdf_save_document directly instead.
In preparation of adding pdf_write_document that writes a document
to a fz_output stream.
-rw-r--r-- | include/mupdf/fitz.h | 2 | ||||
-rw-r--r-- | include/mupdf/fitz/document.h | 5 | ||||
-rw-r--r-- | include/mupdf/fitz/write-document.h | 59 | ||||
-rw-r--r-- | include/mupdf/pdf/clean.h | 2 | ||||
-rw-r--r-- | include/mupdf/pdf/document.h | 38 | ||||
-rw-r--r-- | include/mupdf/pdf/output-pdf.h | 5 | ||||
-rw-r--r-- | platform/android/jni/mupdf.c | 7 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocumentController.m | 8 | ||||
-rw-r--r-- | platform/win32/libmupdf.vcproj | 4 | ||||
-rw-r--r-- | platform/x11/pdfapp.c | 10 | ||||
-rw-r--r-- | source/fitz/document.c | 7 | ||||
-rw-r--r-- | source/pdf/pdf-clean-file.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-write.c | 142 | ||||
-rw-r--r-- | source/pdf/pdf-xref.c | 1 | ||||
-rw-r--r-- | source/tools/mudraw.c | 4 | ||||
-rw-r--r-- | source/tools/pdfclean.c | 8 | ||||
-rw-r--r-- | source/tools/pdfposter.c | 2 |
17 files changed, 135 insertions, 171 deletions
diff --git a/include/mupdf/fitz.h b/include/mupdf/fitz.h index 02f02dde..11accf6d 100644 --- a/include/mupdf/fitz.h +++ b/include/mupdf/fitz.h @@ -49,8 +49,6 @@ #include "mupdf/fitz/document.h" #include "mupdf/fitz/annotation.h" -#include "mupdf/fitz/write-document.h" - #include "mupdf/fitz/util.h" /* Output formats */ diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index 459a5fbd..32f5bba6 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -26,9 +26,6 @@ typedef enum } fz_permission; -// TODO: move out of this interface (it's pdf specific) -typedef struct fz_save_options_s fz_save_options; - typedef void (fz_document_close_fn)(fz_context *ctx, fz_document *doc); typedef int (fz_document_needs_password_fn)(fz_context *ctx, fz_document *doc); typedef int (fz_document_authenticate_password_fn)(fz_context *ctx, fz_document *doc, const char *password); @@ -38,7 +35,6 @@ typedef void (fz_document_layout_fn)(fz_context *ctx, fz_document *doc, float w, typedef int (fz_document_count_pages_fn)(fz_context *ctx, fz_document *doc); typedef fz_page *(fz_document_load_page_fn)(fz_context *ctx, fz_document *doc, int number); typedef int (fz_document_lookup_metadata_fn)(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size); -typedef void (fz_document_save_fn)(fz_context *ctx, fz_document *doc, char *filename, fz_save_options *opts); typedef fz_link *(fz_page_load_links_fn)(fz_context *ctx, fz_page *page); typedef fz_rect *(fz_page_bound_page_fn)(fz_context *ctx, fz_page *page, fz_rect *); @@ -86,7 +82,6 @@ struct fz_document_s fz_document_count_pages_fn *count_pages; fz_document_load_page_fn *load_page; fz_document_lookup_metadata_fn *lookup_metadata; - fz_document_save_fn *save; int did_layout; }; diff --git a/include/mupdf/fitz/write-document.h b/include/mupdf/fitz/write-document.h deleted file mode 100644 index f3974e71..00000000 --- a/include/mupdf/fitz/write-document.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef MUPDF_FITZ_WRITE_DOCUMENT_H -#define MUPDF_FITZ_WRITE_DOCUMENT_H - -#include "mupdf/fitz/system.h" -#include "mupdf/fitz/context.h" -#include "mupdf/fitz/document.h" - -/* - In calls to fz_save_document, the following options structure can be used - to control aspects of the writing process. This structure may grow - in future, and should be zero-filled to allow forwards compatiblity. -*/ -struct fz_save_options_s -{ - int do_incremental; /* Write just the changed objects */ - int do_ascii; /* If non-zero then attempt (where possible) to make - the output ascii. */ - int do_deflate; /* If non-zero then attempt to compress streams. */ - int do_expand; /* Bitflags; each non zero bit indicates an aspect - of the file that should be 'expanded' on - writing. */ - int do_garbage; /* If non-zero then attempt (where possible) to - garbage collect the file before writing. */ - int do_linear; /* If non-zero then write linearised. */ - int do_clean; /* If non-zero then clean contents */ - int continue_on_error; /* If non-zero, errors are (optionally) - counted and writing continues. */ - int *errors; /* Pointer to a place to store a count of errors */ -}; - -/* An enumeration of bitflags to use in the above 'do_expand' field of - fz_save_options. -*/ -enum -{ - fz_expand_images = 1, - fz_expand_fonts = 2, - fz_expand_all = -1 -}; - -/* - fz_save_document: Write a document out to a file. - - (In development - Subject to change in future versions) - - Save a copy of the current document in its original format. - Internally the document may change. - - doc: The document to save. - - filename: The filename to save to. - - opts: NULL, or a pointer to an options structure. - - May throw exceptions. -*/ -void fz_save_document(fz_context *ctx, fz_document *doc, char *filename, fz_save_options *opts); - -#endif diff --git a/include/mupdf/pdf/clean.h b/include/mupdf/pdf/clean.h index f1068cfb..397964f6 100644 --- a/include/mupdf/pdf/clean.h +++ b/include/mupdf/pdf/clean.h @@ -2,6 +2,6 @@ #define MUPDF_PDF_CLEAN_H /* Read infile, and write selected pages to outfile with the given options. */ -void pdf_clean_file(fz_context *ctx, char *infile, char *outfile, char *password, fz_save_options *opts, char *retainlist[], int retainlen); +void pdf_clean_file(fz_context *ctx, char *infile, char *outfile, char *password, pdf_write_options *opts, char *retainlist[], int retainlen); #endif diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h index e65a7590..f369bafe 100644 --- a/include/mupdf/pdf/document.h +++ b/include/mupdf/pdf/document.h @@ -280,4 +280,42 @@ void pdf_finish_edit(fz_context *ctx, pdf_document *doc); int pdf_recognize(fz_context *doc, const char *magic); +typedef struct pdf_write_options_s pdf_write_options; + +/* An enumeration of bitflags to use in the 'do_expand' field of the options struct. */ +enum +{ + PDF_EXPAND_IMAGES = 1, + PDF_EXPAND_FONTS = 2, + PDF_EXPAND_ALL = -1 +}; + +/* + In calls to fz_save_document, the following options structure can be used + to control aspects of the writing process. This structure may grow + in future, and should be zero-filled to allow forwards compatiblity. +*/ +struct pdf_write_options_s +{ + int do_incremental; /* Write just the changed objects */ + int do_ascii; /* If non-zero then attempt (where possible) to make + the output ascii. */ + int do_deflate; /* If non-zero then attempt to compress streams. */ + int do_expand; /* Bitflags; each non zero bit indicates an aspect + of the file that should be 'expanded' on + writing. */ + int do_garbage; /* If non-zero then attempt (where possible) to + garbage collect the file before writing. */ + int do_linear; /* If non-zero then write linearised. */ + int do_clean; /* If non-zero then clean contents */ + int continue_on_error; /* If non-zero, errors are (optionally) + counted and writing continues. */ + int *errors; /* Pointer to a place to store a count of errors */ +}; + +/* + pdf_save_document: Write out the document to a file with all changes finalised. +*/ +void pdf_save_document(fz_context *ctx, pdf_document *doc, char *filename, pdf_write_options *opts); + #endif diff --git a/include/mupdf/pdf/output-pdf.h b/include/mupdf/pdf/output-pdf.h index a1506dfb..558209b0 100644 --- a/include/mupdf/pdf/output-pdf.h +++ b/include/mupdf/pdf/output-pdf.h @@ -12,11 +12,6 @@ */ fz_device *pdf_new_pdf_device(fz_context *ctx, pdf_document *doc, pdf_obj *contents, pdf_obj *resources, const fz_matrix *ctm, fz_buffer *buf); -/* - pdf_save_document: Write out the document to a file with all changes finalised. -*/ -void pdf_save_document(fz_context *ctx, pdf_document *doc, char *filename, fz_save_options *opts); - void pdf_localise_page_resources(fz_context *ctx, pdf_document *doc); #endif diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c index b927bd57..e91eea70 100644 --- a/platform/android/jni/mupdf.c +++ b/platform/android/jni/mupdf.c @@ -2593,11 +2593,12 @@ JNI_FN(MuPDFCore_saveInternal)(JNIEnv * env, jobject thiz) { globals *glo = get_globals(env, thiz); fz_context *ctx = glo->ctx; + pdf_document *idoc = pdf_specifics(ctx, glo->doc); - if (glo->doc && glo->current_path) + if (idoc && glo->current_path) { char *tmp; - fz_save_options opts; + pdf_write_options opts; opts.do_incremental = 1; opts.do_ascii = 0; opts.do_expand = 0; @@ -2631,7 +2632,7 @@ JNI_FN(MuPDFCore_saveInternal)(JNIEnv * env, jobject thiz) if (!err) { - fz_save_document(ctx, glo->doc, tmp, &opts); + pdf_save_document(ctx, idoc, tmp, &opts); written = 1; } } diff --git a/platform/ios/Classes/MuDocumentController.m b/platform/ios/Classes/MuDocumentController.m index b30d516c..d1c685d0 100644 --- a/platform/ios/Classes/MuDocumentController.m +++ b/platform/ios/Classes/MuDocumentController.m @@ -70,13 +70,17 @@ static char *tmp_path(char *path) static void saveDoc(char *current_path, fz_document *doc) { char *tmp; - fz_write_options opts; + pdf_document *idoc = pdf_specifics(ctx, doc); + pdf_write_options opts; opts.do_incremental = 1; opts.do_ascii = 0; opts.do_expand = 0; opts.do_garbage = 0; opts.do_linear = 0; + if (!idoc) + return; + tmp = tmp_path(current_path); if (tmp) { @@ -105,7 +109,7 @@ static void saveDoc(char *current_path, fz_document *doc) if (!err) { - fz_write_document(ctx, doc, tmp, &opts); + pdf_write_document(ctx, idoc, tmp, &opts); written = 1; } } diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj index 7c4b12be..a5fc9f2d 100644 --- a/platform/win32/libmupdf.vcproj +++ b/platform/win32/libmupdf.vcproj @@ -1558,10 +1558,6 @@ > </File> <File - RelativePath="..\..\include\mupdf\fitz\write-document.h" - > - </File> - <File RelativePath="..\..\include\mupdf\fitz\xml.h" > </File> diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index 314592a1..82c711dc 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -549,9 +549,13 @@ static int pdfapp_save(pdfapp_t *app) { char buf[PATH_MAX]; + pdf_document *idoc = pdf_specifics(app->ctx, app->doc); + if (!idoc) + return 0; + if (wingetsavepath(app, buf, PATH_MAX)) { - fz_save_options opts; + pdf_write_options opts; opts.do_incremental = 1; opts.do_ascii = 0; @@ -562,7 +566,7 @@ static int pdfapp_save(pdfapp_t *app) if (strcmp(buf, app->docpath) != 0) { wincopyfile(app->docpath, buf); - fz_save_document(app->ctx, app->doc, buf, &opts); + pdf_save_document(app->ctx, idoc, buf, &opts); return 1; } @@ -573,7 +577,7 @@ static int pdfapp_save(pdfapp_t *app) fz_try(app->ctx) { wincopyfile(app->docpath, buf); - fz_save_document(app->ctx, app->doc, buf, &opts); + pdf_save_document(app->ctx, idoc, buf, &opts); written = 1; } fz_catch(app->ctx) diff --git a/source/fitz/document.c b/source/fitz/document.c index 588ee71c..61d3091e 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -239,13 +239,6 @@ fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char *buf return -1; } -void -fz_save_document(fz_context *ctx, fz_document *doc, char *filename, fz_save_options *opts) -{ - if (doc && doc->save) - doc->save(ctx, doc, filename, opts); -} - fz_page * fz_load_page(fz_context *ctx, fz_document *doc, int number) { diff --git a/source/pdf/pdf-clean-file.c b/source/pdf/pdf-clean-file.c index 69e796b3..69ca8a36 100644 --- a/source/pdf/pdf-clean-file.c +++ b/source/pdf/pdf-clean-file.c @@ -190,7 +190,7 @@ static void retainpages(fz_context *ctx, globals *glo, int argc, char **argv) } } -void pdf_clean_file(fz_context *ctx, char *infile, char *outfile, char *password, fz_save_options *opts, char *argv[], int argc) +void pdf_clean_file(fz_context *ctx, char *infile, char *outfile, char *password, pdf_write_options *opts, char *argv[], int argc) { globals glo = { 0 }; diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index b321edf7..5d05e496 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -6,7 +6,7 @@ /* #define DEBUG_HEAP_SORT */ /* #define DEBUG_WRITING */ -typedef struct pdf_save_options_s pdf_save_options; +typedef struct pdf_write_state_s pdf_write_state; /* As part of linearization, we need to keep a list of what objects are used @@ -45,9 +45,10 @@ typedef struct { page_objects *page[1]; } page_objects_list; -struct pdf_save_options_s +struct pdf_write_state_s { fz_output *out; + int do_incremental; int do_tight; int do_ascii; @@ -56,6 +57,7 @@ struct pdf_save_options_s int do_garbage; int do_linear; int do_clean; + int *use_list; fz_off_t *ofs_list; int *gen_list; @@ -181,7 +183,7 @@ page_objects_insert(fz_context *ctx, page_objects **ppo, int i) } static void -page_objects_list_insert(fz_context *ctx, pdf_save_options *opts, int page, int object) +page_objects_list_insert(fz_context *ctx, pdf_write_state *opts, int page, int object) { page_objects_list_ensure(ctx, &opts->page_object_lists, page+1); if (opts->page_object_lists->len < page+1) @@ -190,7 +192,7 @@ page_objects_list_insert(fz_context *ctx, pdf_save_options *opts, int page, int } static void -page_objects_list_set_page_object(fz_context *ctx, pdf_save_options *opts, int page, int object) +page_objects_list_set_page_object(fz_context *ctx, pdf_write_state *opts, int page, int object) { page_objects_list_ensure(ctx, &opts->page_object_lists, page+1); opts->page_object_lists->page[page]->page_object_number = object; @@ -472,7 +474,7 @@ page_objects_list_sort_and_dedupe(fz_context *ctx, page_objects_list *pol) #ifdef DEBUG_LINEARIZATION static void -page_objects_dump(pdf_save_options *opts) +page_objects_dump(pdf_write_state *opts) { page_objects_list *pol = opts->page_object_lists; int i, j; @@ -493,7 +495,7 @@ page_objects_dump(pdf_save_options *opts) } static void -objects_dump(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +objects_dump(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { int i; @@ -513,7 +515,7 @@ objects_dump(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) * that we can continue our recursive marking. If it's a duff reference * return the fact so that we can remove the reference at source. */ -static pdf_obj *markref(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *obj, int *duff) +static pdf_obj *markref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *obj, int *duff) { int num = pdf_to_num(ctx, obj); int gen = pdf_to_gen(ctx, obj); @@ -561,7 +563,7 @@ static pdf_obj *markref(fz_context *ctx, pdf_document *doc, pdf_save_options *op /* Recursively mark an object. If any references found are duff, then * replace them with nulls. */ -static int markobj(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *obj) +static int markobj(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *obj) { int i; @@ -596,7 +598,7 @@ static int markobj(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, p * Scan for and remove duplicate objects (slow) */ -static void removeduplicateobjs(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +static void removeduplicateobjs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { int num, other; int xref_len = pdf_xref_len(ctx, doc); @@ -696,7 +698,7 @@ static void removeduplicateobjs(fz_context *ctx, pdf_document *doc, pdf_save_opt * This code assumes that any opts->renumber_map[n] <= n for all n. */ -static void compactxref(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +static void compactxref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { int num, newnum; int xref_len = pdf_xref_len(ctx, doc); @@ -738,7 +740,7 @@ static void compactxref(fz_context *ctx, pdf_document *doc, pdf_save_options *op * removing duplicate objects and compacting the xref. */ -static void renumberobj(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *obj) +static void renumberobj(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *obj) { int i; int xref_len = pdf_xref_len(ctx, doc); @@ -791,7 +793,7 @@ static void renumberobj(fz_context *ctx, pdf_document *doc, pdf_save_options *op } } -static void renumberobjs(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +static void renumberobjs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { pdf_xref_entry *newxref = NULL; int newlen; @@ -877,7 +879,7 @@ static void renumberobjs(fz_context *ctx, pdf_document *doc, pdf_save_options *o } } -static void page_objects_list_renumber(pdf_save_options *opts) +static void page_objects_list_renumber(pdf_write_state *opts) { int i, j; @@ -893,7 +895,7 @@ static void page_objects_list_renumber(pdf_save_options *opts) } static void -mark_all(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *val, int flag, int page) +mark_all(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *val, int flag, int page) { if (pdf_mark_obj(ctx, val)) @@ -943,7 +945,7 @@ mark_all(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *va } static int -mark_pages(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *val, int pagenum) +mark_pages(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *val, int pagenum) { if (pdf_mark_obj(ctx, val)) @@ -1011,7 +1013,7 @@ mark_pages(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj * } static void -mark_root(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *dict) +mark_root(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *dict) { int i, n = pdf_dict_len(ctx, dict); @@ -1063,7 +1065,7 @@ mark_root(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *d } static void -mark_trailer(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *dict) +mark_trailer(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *dict) { int i, n = pdf_dict_len(ctx, dict); @@ -1094,7 +1096,7 @@ mark_trailer(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj } static void -add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { pdf_obj *params_obj = NULL; pdf_obj *params_ref = NULL; @@ -1357,7 +1359,7 @@ pdf_localise_page_resources(fz_context *ctx, pdf_document *doc) } static void -linearize(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +linearize(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { int i; int n = pdf_xref_len(ctx, doc) + 2; @@ -1433,7 +1435,7 @@ linearize(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) } static void -update_linearization_params(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +update_linearization_params(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { fz_off_t offset; pdf_set_int(ctx, opts->linear_l, opts->file_len); @@ -1587,7 +1589,7 @@ static fz_buffer *deflatebuf(fz_context *ctx, unsigned char *p, int n) return buf; } -static void copystream(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *obj_orig, int num, int gen) +static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *obj_orig, int num, int gen) { fz_buffer *buf, *tmp; pdf_obj *newlen; @@ -1631,7 +1633,7 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_save_options *opt pdf_drop_obj(ctx, obj); } -static void expandstream(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *obj_orig, int num, int gen) +static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *obj_orig, int num, int gen) { fz_buffer *buf, *tmp; pdf_obj *newlen; @@ -1708,7 +1710,7 @@ static int filter_implies_image(fz_context *ctx, pdf_document *doc, pdf_obj *o) return 0; } -static void writeobject(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, int num, int gen, int skip_xrefs) +static void writeobject(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int num, int gen, int skip_xrefs) { pdf_xref_entry *entry; pdf_obj *obj; @@ -1767,31 +1769,31 @@ static void writeobject(fz_context *ctx, pdf_document *doc, pdf_save_options *op else { int dontexpand = 0; - if (opts->do_expand != 0 && opts->do_expand != fz_expand_all) + if (opts->do_expand != 0 && opts->do_expand != PDF_EXPAND_ALL) { pdf_obj *o; if ((o = pdf_dict_get(ctx, obj, PDF_NAME_Type), pdf_name_eq(ctx, o, PDF_NAME_XObject)) && (o = pdf_dict_get(ctx, obj, PDF_NAME_Subtype), pdf_name_eq(ctx, o, PDF_NAME_Image))) - dontexpand = !(opts->do_expand & fz_expand_images); + dontexpand = !(opts->do_expand & PDF_EXPAND_IMAGES); if (o = pdf_dict_get(ctx, obj, PDF_NAME_Type), pdf_name_eq(ctx, o, PDF_NAME_Font)) - dontexpand = !(opts->do_expand & fz_expand_fonts); + dontexpand = !(opts->do_expand & PDF_EXPAND_FONTS); if (o = pdf_dict_get(ctx, obj, PDF_NAME_Type), pdf_name_eq(ctx, o, PDF_NAME_FontDescriptor)) - dontexpand = !(opts->do_expand & fz_expand_fonts); + dontexpand = !(opts->do_expand & PDF_EXPAND_FONTS); if (pdf_dict_get(ctx, obj, PDF_NAME_Length1) != NULL) - dontexpand = !(opts->do_expand & fz_expand_fonts); + dontexpand = !(opts->do_expand & PDF_EXPAND_FONTS); if (pdf_dict_get(ctx, obj, PDF_NAME_Length2) != NULL) - dontexpand = !(opts->do_expand & fz_expand_fonts); + dontexpand = !(opts->do_expand & PDF_EXPAND_FONTS); if (pdf_dict_get(ctx, obj, PDF_NAME_Length3) != NULL) - dontexpand = !(opts->do_expand & fz_expand_fonts); + dontexpand = !(opts->do_expand & PDF_EXPAND_FONTS); if (o = pdf_dict_get(ctx, obj, PDF_NAME_Subtype), pdf_name_eq(ctx, o, PDF_NAME_Type1C)) - dontexpand = !(opts->do_expand & fz_expand_fonts); + dontexpand = !(opts->do_expand & PDF_EXPAND_FONTS); if (o = pdf_dict_get(ctx, obj, PDF_NAME_Subtype), pdf_name_eq(ctx, o, PDF_NAME_CIDFontType0C)) - dontexpand = !(opts->do_expand & fz_expand_fonts); + dontexpand = !(opts->do_expand & PDF_EXPAND_FONTS); if (o = pdf_dict_get(ctx, obj, PDF_NAME_Filter), filter_implies_image(ctx, doc, o)) - dontexpand = !(opts->do_expand & fz_expand_images); + dontexpand = !(opts->do_expand & PDF_EXPAND_IMAGES); if (pdf_dict_get(ctx, obj, PDF_NAME_Width) != NULL && pdf_dict_get(ctx, obj, PDF_NAME_Height) != NULL) - dontexpand = !(opts->do_expand & fz_expand_images); + dontexpand = !(opts->do_expand & PDF_EXPAND_IMAGES); } fz_try(ctx) { @@ -1821,7 +1823,7 @@ static void writeobject(fz_context *ctx, pdf_document *doc, pdf_save_options *op pdf_drop_obj(ctx, obj); } -static void writexrefsubsect(fz_context *ctx, pdf_save_options *opts, int from, int to) +static void writexrefsubsect(fz_context *ctx, pdf_write_state *opts, int from, int to) { int num; @@ -1835,7 +1837,7 @@ static void writexrefsubsect(fz_context *ctx, pdf_save_options *opts, int from, } } -static void writexref(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, int from, int to, int first, int main_xref_offset, int startxref) +static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int main_xref_offset, int startxref) { pdf_obj *trailer = NULL; pdf_obj *obj; @@ -1935,7 +1937,7 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_save_options *opts doc->has_xref_streams = 0; } -static void writexrefstreamsubsect(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, pdf_obj *index, fz_buffer *fzbuf, int from, int to) +static void writexrefstreamsubsect(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *index, fz_buffer *fzbuf, int from, int to) { int num; @@ -1952,7 +1954,7 @@ static void writexrefstreamsubsect(fz_context *ctx, pdf_document *doc, pdf_save_ } } -static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, int from, int to, int first, int main_xref_offset, int startxref) +static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int main_xref_offset, int startxref) { int num; pdf_obj *dict = NULL; @@ -2082,7 +2084,7 @@ padto(fz_context *ctx, fz_output *out, fz_off_t target) } static void -dowriteobject(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, int num, int pass) +dowriteobject(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int num, int pass) { pdf_xref_entry *entry = pdf_get_xref_entry(ctx, doc, num); if (entry->type == 'f') @@ -2118,7 +2120,7 @@ dowriteobject(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, int nu } static void -writeobjects(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, int pass) +writeobjects(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int pass) { int num; int xref_len = pdf_xref_len(ctx, doc); @@ -2174,7 +2176,7 @@ my_log2(int x) } static void -make_page_offset_hints(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, fz_buffer *buf) +make_page_offset_hints(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, fz_buffer *buf) { int i, j; int min_objs_per_page, max_objs_per_page; @@ -2444,7 +2446,7 @@ make_page_offset_hints(fz_context *ctx, pdf_document *doc, pdf_save_options *opt } static void -make_hint_stream(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +make_hint_stream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { fz_buffer *buf = fz_new_buffer(ctx, 100); @@ -2463,7 +2465,7 @@ make_hint_stream(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) } #ifdef DEBUG_WRITING -static void dump_object_details(fz_context *ctx, pdf_document *doc, pdf_save_options *opts) +static void dump_object_details(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { int i; @@ -2511,7 +2513,7 @@ static void presize_unsaved_signature_byteranges(fz_context *ctx, pdf_document * } } -static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_save_options *opts, char *filename) +static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, char *filename) { pdf_unsaved_sig *usig; char buf[5120]; @@ -2615,21 +2617,21 @@ static void sanitize(fz_context *ctx, pdf_document *doc, int ascii) } } -/* Initialise the pdf_save_options, used dynamically during the write, from the static - * fz_save_options, passed into pdf_save_document */ -static void initialise_write_options(fz_context *ctx, pdf_document *doc, const fz_save_options *fz_opts, pdf_save_options *opts) +/* Initialise the pdf_write_state, used dynamically during the write, from the static + * pdf_write_options, passed into pdf_save_document */ +static void initialise_write_state(fz_context *ctx, pdf_document *doc, const pdf_write_options *in_opts, pdf_write_state *opts) { int num; int xref_len = pdf_xref_len(ctx, doc); - opts->do_incremental = fz_opts->do_incremental; - opts->do_tight = (fz_opts->do_expand == 0) || fz_opts->do_deflate; - opts->do_expand = fz_opts->do_expand; - opts->do_garbage = fz_opts->do_garbage; - opts->do_ascii = fz_opts->do_ascii; - opts->do_deflate = fz_opts->do_deflate; - opts->do_linear = fz_opts->do_linear; - opts->do_clean = fz_opts->do_clean; + opts->do_incremental = in_opts->do_incremental; + opts->do_tight = (in_opts->do_expand == 0) || in_opts->do_deflate; + opts->do_expand = in_opts->do_expand; + opts->do_garbage = in_opts->do_garbage; + opts->do_ascii = in_opts->do_ascii; + opts->do_deflate = in_opts->do_deflate; + opts->do_linear = in_opts->do_linear; + opts->do_clean = in_opts->do_clean; opts->start = 0; opts->main_xref_offset = INT_MIN; /* We deliberately make these arrays long enough to cope with @@ -2641,8 +2643,8 @@ static void initialise_write_options(fz_context *ctx, pdf_document *doc, const f opts->renumber_map = fz_malloc_array(ctx, xref_len + 3, sizeof(int)); opts->rev_renumber_map = fz_malloc_array(ctx, xref_len + 3, sizeof(int)); opts->rev_gen_list = fz_malloc_array(ctx, xref_len + 3, sizeof(int)); - opts->continue_on_error = fz_opts->continue_on_error; - opts->errors = fz_opts->errors; + opts->continue_on_error = in_opts->continue_on_error; + opts->errors = in_opts->errors; for (num = 0; num < xref_len; num++) { @@ -2655,7 +2657,7 @@ static void initialise_write_options(fz_context *ctx, pdf_document *doc, const f } /* Free the resources held by the dynamic write options */ -static void finalise_write_options(fz_context *ctx, pdf_save_options *opts) +static void finalise_write_state(fz_context *ctx, pdf_write_state *opts) { fz_free(ctx, opts->use_list); fz_free(ctx, opts->ofs_list); @@ -2676,10 +2678,10 @@ static void finalise_write_options(fz_context *ctx, pdf_save_options *opts) fz_drop_output(ctx, opts->out); } -void pdf_save_document(fz_context *ctx, pdf_document *doc, char *filename, fz_save_options *fz_opts) +void pdf_save_document(fz_context *ctx, pdf_document *doc, char *filename, pdf_write_options *in_opts) { - fz_save_options opts_defaults = { 0 }; - pdf_save_options opts = { 0 }; + pdf_write_options opts_defaults = { 0 }; + pdf_write_state opts = { 0 }; int lastfree; int num; @@ -2688,26 +2690,26 @@ void pdf_save_document(fz_context *ctx, pdf_document *doc, char *filename, fz_sa if (!doc) return; - if (!fz_opts) - fz_opts = &opts_defaults; + if (!in_opts) + in_opts = &opts_defaults; - if (fz_opts->do_incremental && fz_opts->do_garbage) + if (in_opts->do_incremental && in_opts->do_garbage) fz_throw(ctx, FZ_ERROR_GENERIC, "Can't do incremental writes with garbage collection"); - if (fz_opts->do_incremental && fz_opts->do_linear) + if (in_opts->do_incremental && in_opts->do_linear) fz_throw(ctx, FZ_ERROR_GENERIC, "Can't do incremental writes with linearisation"); doc->freeze_updates = 1; /* Sanitize the operator streams */ - if (fz_opts->do_clean) - sanitize(ctx, doc, fz_opts->do_ascii); + if (in_opts->do_clean) + sanitize(ctx, doc, in_opts->do_ascii); pdf_finish_edit(ctx, doc); presize_unsaved_signature_byteranges(ctx, doc); xref_len = pdf_xref_len(ctx, doc); - if (fz_opts->do_incremental) + if (in_opts->do_incremental) { /* If no changes, nothing to write */ if (doc->num_incremental_sections == 0) @@ -2729,7 +2731,7 @@ void pdf_save_document(fz_context *ctx, pdf_document *doc, char *filename, fz_sa fz_try(ctx) { - initialise_write_options(ctx, doc, fz_opts, &opts); + initialise_write_state(ctx, doc, in_opts, &opts); /* Make sure any objects hidden in compressed streams have been loaded */ if (!opts.do_incremental) @@ -2865,7 +2867,7 @@ void pdf_save_document(fz_context *ctx, pdf_document *doc, char *filename, fz_sa page_objects_dump(&opts); objects_dump(ctx, doc, &opts); #endif - finalise_write_options(ctx, &opts); + finalise_write_state(ctx, &opts); doc->freeze_updates = 0; } diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index 960c1c34..cb927725 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -2336,7 +2336,6 @@ pdf_new_document(fz_context *ctx, fz_stream *file) doc->super.count_pages = (fz_document_count_pages_fn *)pdf_count_pages; doc->super.load_page = (fz_document_load_page_fn *)pdf_load_page; doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)pdf_lookup_metadata; - doc->super.save = (fz_document_save_fn *)pdf_save_document; doc->update_appearance = pdf_update_appearance; pdf_lexbuf_init(ctx, &doc->lexbuf.base, PDF_LEXBUF_LARGE); diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index b1ccc38b..47aab044 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -1130,9 +1130,7 @@ int mudraw_main(int argc, char **argv) if (pdfout) { - fz_save_options opts = { 0 }; - - pdf_save_document(ctx, pdfout, output, &opts); + pdf_save_document(ctx, pdfout, output, NULL); pdf_close_document(ctx, pdfout); } diff --git a/source/tools/pdfclean.c b/source/tools/pdfclean.c index 93ec762d..8d599de9 100644 --- a/source/tools/pdfclean.c +++ b/source/tools/pdfclean.c @@ -37,7 +37,7 @@ int pdfclean_main(int argc, char **argv) char *outfile = "out.pdf"; char *password = ""; int c; - fz_save_options opts; + pdf_write_options opts; int errors = 0; fz_context *ctx; @@ -57,9 +57,9 @@ int pdfclean_main(int argc, char **argv) { case 'p': password = fz_optarg; break; case 'g': opts.do_garbage ++; break; - case 'd': opts.do_expand ^= fz_expand_all; break; - case 'f': opts.do_expand ^= fz_expand_fonts; break; - case 'i': opts.do_expand ^= fz_expand_images; break; + case 'd': opts.do_expand ^= PDF_EXPAND_ALL; break; + case 'f': opts.do_expand ^= PDF_EXPAND_FONTS; break; + case 'i': opts.do_expand ^= PDF_EXPAND_IMAGES; break; case 'l': opts.do_linear ++; break; case 'a': opts.do_ascii ++; break; case 'z': opts.do_deflate ++; break; diff --git a/source/tools/pdfposter.c b/source/tools/pdfposter.c index 16bbc080..5a5a5948 100644 --- a/source/tools/pdfposter.c +++ b/source/tools/pdfposter.c @@ -157,7 +157,7 @@ int pdfposter_main(int argc, char **argv) char *outfile = "out.pdf"; char *password = ""; int c; - fz_save_options opts = { 0 }; + pdf_write_options opts = { 0 }; pdf_document *doc; fz_context *ctx; |