summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-annot.c2
-rw-r--r--source/pdf/pdf-appearance.c16
-rw-r--r--source/pdf/pdf-device.c14
-rw-r--r--source/pdf/pdf-interpret.c19
-rw-r--r--source/pdf/pdf-op-buffer.c4
-rw-r--r--source/pdf/pdf-op-filter.c4
-rw-r--r--source/pdf/pdf-op-run.c4
-rw-r--r--source/pdf/pdf-page.c2
-rw-r--r--source/pdf/pdf-write.c27
-rw-r--r--source/pdf/pdf-xref.c8
10 files changed, 65 insertions, 35 deletions
diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c
index 4a34e945..acf81961 100644
--- a/source/pdf/pdf-annot.c
+++ b/source/pdf/pdf-annot.c
@@ -491,7 +491,7 @@ pdf_annot *pdf_new_annot(fz_context *ctx, pdf_page *page)
{
pdf_annot *annot = fz_new_annot(ctx, sizeof(pdf_annot));
- annot->super.drop_annot_imp = (fz_annot_drop_imp_fn*)pdf_drop_annot_imp;
+ annot->super.drop_annot = (fz_annot_drop_fn*)pdf_drop_annot_imp;
annot->super.bound_annot = (fz_annot_bound_fn*)pdf_bound_annot;
annot->super.run_annot = (fz_annot_run_fn*)pdf_run_annot;
annot->super.next_annot = (fz_annot_next_fn*)pdf_next_annot;
diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c
index e275ca56..ed8a6f4a 100644
--- a/source/pdf/pdf-appearance.c
+++ b/source/pdf/pdf-appearance.c
@@ -1612,7 +1612,7 @@ void pdf_set_annot_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *ann
dev = pdf_new_pdf_device(ctx, doc, &fz_identity, &trect, resources, contents);
fz_run_display_list(ctx, disp_list, dev, &inv_page_ctm, &fz_infinite_rect, NULL);
- fz_drop_device(ctx, dev);
+ fz_close_device(ctx, dev);
pdf_update_stream(ctx, doc, ap_obj, contents, 0);
fz_drop_buffer(ctx, contents);
@@ -1627,11 +1627,10 @@ void pdf_set_annot_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *ann
doc->dirty = 1;
}
- fz_catch(ctx)
- {
+ fz_always(ctx)
fz_drop_device(ctx, dev);
+ fz_catch(ctx)
fz_rethrow(ctx);
- }
}
static fz_point *
@@ -1745,6 +1744,8 @@ void pdf_set_markup_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *an
fz_stroke_path(ctx, dev, path, stroke, &page_ctm, fz_device_rgb(ctx), color, alpha);
}
+ fz_close_device(ctx, dev);
+
fz_transform_rect(&rect, &page_ctm);
pdf_set_annot_appearance(ctx, doc, annot, &rect, strike_list);
}
@@ -1879,6 +1880,8 @@ void pdf_update_ink_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *an
rect.y1 += width;
}
+ fz_close_device(ctx, dev);
+
fz_transform_rect(&rect, &page_ctm);
pdf_set_annot_appearance(ctx, doc, annot, &rect, strike_list);
}
@@ -2126,6 +2129,8 @@ void pdf_update_text_annot_appearance(fz_context *ctx, pdf_document *doc, pdf_an
fz_fill_path(ctx, dev, path, 0, &tm, cs, white, 1.0f);
fz_stroke_path(ctx, dev, path, stroke, &tm, cs, black, 1.0f);
+ fz_close_device(ctx, dev);
+
fz_transform_rect(&rect, &page_ctm);
pdf_set_annot_appearance(ctx, doc, annot, &rect, dlist);
@@ -2198,6 +2203,7 @@ void pdf_update_free_text_annot_appearance(fz_context *ctx, pdf_document *doc, p
dlist = fz_new_display_list(ctx, NULL);
dev = fz_new_list_device(ctx, dlist);
fz_fill_text(ctx, dev, text, &page_ctm, cs, font_rec.da_rec.col, 1.0f);
+ fz_close_device(ctx, dev);
fz_transform_rect(&rect, &page_ctm);
pdf_set_annot_appearance(ctx, doc, annot, &rect, dlist);
@@ -2415,6 +2421,8 @@ void pdf_set_signature_appearance(fz_context *ctx, pdf_document *doc, pdf_annot
text = fit_text(ctx, &font_rec, (char *)bufstr, &rect);
fz_fill_text(ctx, dev, text, &page_ctm, cs, font_rec.da_rec.col, 1.0f);
+ fz_close_device(ctx, dev);
+
rect = annot_rect;
fz_transform_rect(&rect, &page_ctm);
pdf_set_annot_appearance(ctx, doc, annot, &rect, dlist);
diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c
index 5c243e8f..4af09b0e 100644
--- a/source/pdf/pdf-device.c
+++ b/source/pdf/pdf-device.c
@@ -1037,12 +1037,17 @@ pdf_dev_end_tile(fz_context *ctx, fz_device *dev)
}
static void
-pdf_dev_close(fz_context *ctx, fz_device *dev)
+pdf_dev_close_device(fz_context *ctx, fz_device *dev)
{
pdf_device *pdev = (pdf_device*)dev;
- int i;
-
pdf_dev_end_text(ctx, pdev);
+}
+
+static void
+pdf_dev_drop_device(fz_context *ctx, fz_device *dev)
+{
+ pdf_device *pdev = (pdf_device*)dev;
+ int i;
for (i = pdev->num_gstates-1; i >= 0; i--)
fz_drop_stroke_state(ctx, pdev->gstates[i].stroke_state);
@@ -1066,7 +1071,8 @@ fz_device *pdf_new_pdf_device(fz_context *ctx, pdf_document *doc, const fz_matri
{
pdf_device *dev = fz_new_device(ctx, sizeof *dev);
- dev->super.close = pdf_dev_close;
+ dev->super.close_device = pdf_dev_close_device;
+ dev->super.drop_device = pdf_dev_drop_device;
dev->super.fill_path = pdf_dev_fill_path;
dev->super.stroke_path = pdf_dev_stroke_path;
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c
index c895478f..f3840794 100644
--- a/source/pdf/pdf-interpret.c
+++ b/source/pdf/pdf-interpret.c
@@ -7,10 +7,25 @@ pdf_new_processor(fz_context *ctx, int size)
}
void
+pdf_close_processor(fz_context *ctx, pdf_processor *proc)
+{
+ if (proc && proc->close_processor)
+ {
+ proc->close_processor(ctx, proc);
+ proc->close_processor = NULL;
+ }
+}
+
+void
pdf_drop_processor(fz_context *ctx, pdf_processor *proc)
{
- if (proc && proc->drop_imp)
- proc->drop_imp(ctx, proc);
+ if (proc)
+ {
+ if (proc->close_processor)
+ fz_warn(ctx, "dropping unclosed PDF processor");
+ if (proc->drop_processor)
+ proc->drop_processor(ctx, proc);
+ }
fz_free(ctx, proc);
}
diff --git a/source/pdf/pdf-op-buffer.c b/source/pdf/pdf-op-buffer.c
index 5b37e6a5..2eb4323a 100644
--- a/source/pdf/pdf-op-buffer.c
+++ b/source/pdf/pdf-op-buffer.c
@@ -761,7 +761,7 @@ pdf_out_EX(fz_context *ctx, pdf_processor *proc)
}
static void
-pdf_drop_imp_output_processor(fz_context *ctx, pdf_processor *proc)
+pdf_drop_output_processor(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
fz_drop_output(ctx, out);
@@ -772,7 +772,7 @@ pdf_new_output_processor(fz_context *ctx, fz_output *out, int ahxencode)
{
pdf_output_processor *proc = pdf_new_processor(ctx, sizeof *proc);
{
- proc->super.drop_imp = pdf_drop_imp_output_processor;
+ proc->super.drop_processor = pdf_drop_output_processor;
/* general graphics state */
proc->super.op_w = pdf_out_w;
diff --git a/source/pdf/pdf-op-filter.c b/source/pdf/pdf-op-filter.c
index 8eebe5cd..f5a0958d 100644
--- a/source/pdf/pdf-op-filter.c
+++ b/source/pdf/pdf-op-filter.c
@@ -1113,7 +1113,7 @@ pdf_filter_END(fz_context *ctx, pdf_processor *proc)
}
static void
-pdf_drop_imp_filter_processor(fz_context *ctx, pdf_processor *proc)
+pdf_drop_filter_processor(fz_context *ctx, pdf_processor *proc)
{
pdf_filter_processor *p = (pdf_filter_processor*)proc;
fz_free(ctx, p->gstate);
@@ -1125,7 +1125,7 @@ pdf_new_filter_processor(fz_context *ctx, pdf_processor *chain, pdf_document *do
pdf_filter_processor *proc = pdf_new_processor(ctx, sizeof *proc);
{
- proc->super.drop_imp = pdf_drop_imp_filter_processor;
+ proc->super.drop_processor = pdf_drop_filter_processor;
/* general graphics state */
proc->super.op_w = pdf_filter_w;
diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c
index a0f28008..96084cdf 100644
--- a/source/pdf/pdf-op-run.c
+++ b/source/pdf/pdf-op-run.c
@@ -1999,7 +1999,7 @@ static void pdf_run_END(fz_context *ctx, pdf_processor *proc)
}
static void
-pdf_run_drop_imp(fz_context *ctx, pdf_processor *proc)
+pdf_drop_run_processor(fz_context *ctx, pdf_processor *proc)
{
pdf_run_processor *pr = (pdf_run_processor *)proc;
@@ -2030,7 +2030,7 @@ pdf_new_run_processor(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, con
{
proc->super.event = event;
- proc->super.drop_imp = pdf_run_drop_imp;
+ proc->super.drop_processor = pdf_drop_run_processor;
/* general graphics state */
proc->super.op_w = pdf_run_w;
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c
index e3b68378..dae0d49d 100644
--- a/source/pdf/pdf-page.c
+++ b/source/pdf/pdf-page.c
@@ -538,7 +538,7 @@ pdf_new_page(fz_context *ctx, pdf_document *doc)
page->doc = (pdf_document*) fz_keep_document(ctx, &doc->super);
- page->super.drop_page_imp = (fz_page_drop_page_imp_fn *)pdf_drop_page_imp;
+ page->super.drop_page = (fz_page_drop_page_fn *)pdf_drop_page_imp;
page->super.load_links = (fz_page_load_links_fn *)pdf_load_links;
page->super.bound_page = (fz_page_bound_page_fn *)pdf_bound_page;
page->super.first_annot = (fz_page_first_annot_fn *)pdf_first_annot;
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 0a7a0f2f..3f2c2cda 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -3221,20 +3221,20 @@ pdf_writer_end_page(fz_context *ctx, fz_document_writer *wri_, fz_device *dev)
}
static void
-pdf_writer_close(fz_context *ctx, fz_document_writer *wri_)
+pdf_writer_close_writer(fz_context *ctx, fz_document_writer *wri_)
{
pdf_writer *wri = (pdf_writer*)wri_;
- fz_try(ctx)
- pdf_save_document(ctx, wri->pdf, wri->filename, &wri->opts);
- fz_always(ctx)
- {
- fz_drop_buffer(ctx, wri->contents);
- pdf_drop_obj(ctx, wri->resources);
- pdf_drop_document(ctx, wri->pdf);
- fz_free(ctx, wri->filename);
- }
- fz_catch(ctx)
- fz_rethrow(ctx);
+ pdf_save_document(ctx, wri->pdf, wri->filename, &wri->opts);
+}
+
+static void
+pdf_writer_drop_writer(fz_context *ctx, fz_document_writer *wri_)
+{
+ pdf_writer *wri = (pdf_writer*)wri_;
+ fz_drop_buffer(ctx, wri->contents);
+ pdf_drop_obj(ctx, wri->resources);
+ pdf_drop_document(ctx, wri->pdf);
+ fz_free(ctx, wri->filename);
}
fz_document_writer *
@@ -3245,7 +3245,8 @@ fz_new_pdf_writer(fz_context *ctx, const char *path, const char *options)
wri = fz_malloc_struct(ctx, pdf_writer);
wri->super.begin_page = pdf_writer_begin_page;
wri->super.end_page = pdf_writer_end_page;
- wri->super.close = pdf_writer_close;
+ wri->super.close_writer = pdf_writer_close_writer;
+ wri->super.drop_writer = pdf_writer_drop_writer;
fz_try(ctx)
{
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index 48a5d316..f9f2f576 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -1556,7 +1556,7 @@ pdf_init_document(fz_context *ctx, pdf_document *doc)
}
static void
-pdf_close_document(fz_context *ctx, pdf_document *doc)
+pdf_drop_document_imp(fz_context *ctx, pdf_document *doc)
{
int i;
@@ -2299,7 +2299,7 @@ pdf_new_document(fz_context *ctx, fz_stream *file)
{
pdf_document *doc = fz_new_document(ctx, pdf_document);
- doc->super.close = (fz_document_close_fn *)pdf_close_document;
+ doc->super.drop_document = (fz_document_drop_fn *)pdf_drop_document_imp;
doc->super.needs_password = (fz_document_needs_password_fn *)pdf_needs_password;
doc->super.authenticate_password = (fz_document_authenticate_password_fn *)pdf_authenticate_password;
doc->super.has_permission = (fz_document_has_permission_fn *)pdf_has_permission;
@@ -2325,7 +2325,7 @@ pdf_open_document_with_stream(fz_context *ctx, fz_stream *file)
}
fz_catch(ctx)
{
- pdf_close_document(ctx, doc);
+ pdf_drop_document_imp(ctx, doc);
fz_rethrow(ctx);
}
return doc;
@@ -2352,7 +2352,7 @@ pdf_open_document(fz_context *ctx, const char *filename)
}
fz_catch(ctx)
{
- pdf_close_document(ctx, doc);
+ pdf_drop_document_imp(ctx, doc);
fz_rethrow(ctx);
}
return doc;