summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/writer.h20
-rw-r--r--source/fitz/output-cbz.c15
-rw-r--r--source/fitz/output-svg.c7
-rw-r--r--source/fitz/writer.c13
-rw-r--r--source/pdf/pdf-write.c8
5 files changed, 33 insertions, 30 deletions
diff --git a/include/mupdf/fitz/writer.h b/include/mupdf/fitz/writer.h
index fc005f76..608850e9 100644
--- a/include/mupdf/fitz/writer.h
+++ b/include/mupdf/fitz/writer.h
@@ -9,19 +9,31 @@
typedef struct fz_document_writer_s fz_document_writer;
+typedef fz_device *(fz_document_writer_begin_page_fn)(fz_context *ctx, fz_document_writer *wri, const fz_rect *mediabox);
+typedef void (fz_document_writer_end_page_fn)(fz_context *ctx, fz_document_writer *wri, fz_device *dev);
+typedef void (fz_document_writer_close_writer_fn)(fz_context *ctx, fz_document_writer *wri);
+typedef void (fz_document_writer_drop_writer_fn)(fz_context *ctx, fz_document_writer *wri);
+
struct fz_document_writer_s
{
- fz_device *(*begin_page)(fz_context *ctx, fz_document_writer *wri, const fz_rect *mediabox);
- void (*end_page)(fz_context *ctx, fz_document_writer *wri, fz_device *dev);
- void (*close_writer)(fz_context *ctx, fz_document_writer *wri);
- void (*drop_writer)(fz_context *ctx, fz_document_writer *wri);
+ fz_document_writer_begin_page_fn *begin_page;
+ fz_document_writer_end_page_fn *end_page;
+ fz_document_writer_close_writer_fn *close_writer;
+ fz_document_writer_drop_writer_fn *drop_writer;
};
+fz_document_writer *fz_new_writer_of_size(fz_context *ctx, size_t size, fz_document_writer_begin_page_fn *begin_page,
+ fz_document_writer_end_page_fn *end_page, fz_document_writer_close_writer_fn *close, fz_document_writer_drop_writer_fn *drop);
+
+#define fz_new_writer(CTX,TYPE,BEGIN_PAGE,END_PAGE,CLOSE,DROP) \
+ ((TYPE *)Memento_label(fz_new_writer_of_size(CTX,sizeof(TYPE),BEGIN_PAGE,END_PAGE,CLOSE,DROP),#TYPE))
+
int fz_has_option(fz_context *ctx, const char *opts, const char *key, const char **val);
int fz_option_eq(const char *a, const char *b);
fz_document_writer *fz_new_document_writer(fz_context *ctx, const char *path, const char *format, const char *options);
+
fz_device *fz_begin_page(fz_context *ctx, fz_document_writer *wri, const fz_rect *mediabox);
void fz_end_page(fz_context *ctx, fz_document_writer *wri, fz_device *dev);
void fz_close_document_writer(fz_context *ctx, fz_document_writer *wri);
diff --git a/source/fitz/output-cbz.c b/source/fitz/output-cbz.c
index 7268a805..73cc1195 100644
--- a/source/fitz/output-cbz.c
+++ b/source/fitz/output-cbz.c
@@ -66,13 +66,7 @@ cbz_drop_writer(fz_context *ctx, fz_document_writer *wri_)
fz_document_writer *
fz_new_cbz_writer(fz_context *ctx, const char *path, const char *options)
{
- fz_cbz_writer *wri;
-
- wri = fz_malloc_struct(ctx, fz_cbz_writer);
- wri->super.begin_page = cbz_begin_page;
- wri->super.end_page = cbz_end_page;
- wri->super.close_writer = cbz_close_writer;
- wri->super.drop_writer = cbz_drop_writer;
+ fz_cbz_writer *wri = fz_new_writer(ctx, fz_cbz_writer, cbz_begin_page, cbz_end_page, cbz_close_writer, cbz_drop_writer);
fz_try(ctx)
{
@@ -139,12 +133,7 @@ fz_new_pixmap_writer(fz_context *ctx, const char *path, const char *options,
const char *default_path, int n,
void (*save)(fz_context *ctx, fz_pixmap *pix, const char *filename))
{
- fz_pixmap_writer *wri;
-
- wri = fz_malloc_struct(ctx, fz_pixmap_writer);
- wri->super.begin_page = pixmap_begin_page;
- wri->super.end_page = pixmap_end_page;
- wri->super.drop_writer = pixmap_drop_writer;
+ fz_pixmap_writer *wri = fz_new_writer(ctx, fz_pixmap_writer, pixmap_begin_page, pixmap_end_page, NULL, pixmap_drop_writer);
fz_try(ctx)
{
diff --git a/source/fitz/output-svg.c b/source/fitz/output-svg.c
index f8711031..0758b843 100644
--- a/source/fitz/output-svg.c
+++ b/source/fitz/output-svg.c
@@ -58,13 +58,8 @@ svg_drop_writer(fz_context *ctx, fz_document_writer *wri_)
fz_document_writer *
fz_new_svg_writer(fz_context *ctx, const char *path, const char *args)
{
- fz_svg_writer *wri;
const char *val;
-
- wri = fz_malloc_struct(ctx, fz_svg_writer);
- wri->super.begin_page = svg_begin_page;
- wri->super.end_page = svg_end_page;
- wri->super.drop_writer = svg_drop_writer;
+ fz_svg_writer *wri = fz_new_writer(ctx, fz_svg_writer, svg_begin_page, svg_end_page, NULL, svg_drop_writer);
wri->text_format = FZ_SVG_TEXT_AS_PATH;
wri->reuse_images = 1;
diff --git a/source/fitz/writer.c b/source/fitz/writer.c
index 3c53f633..c89ee4e0 100644
--- a/source/fitz/writer.c
+++ b/source/fitz/writer.c
@@ -48,6 +48,19 @@ fz_option_eq(const char *a, const char *b)
return !strncmp(a, b, n) && (a[n] == ',' || a[n] == 0);
}
+fz_document_writer *fz_new_writer_of_size(fz_context *ctx, size_t size, fz_document_writer_begin_page_fn *begin_page,
+ fz_document_writer_end_page_fn *end_page, fz_document_writer_close_writer_fn *close, fz_document_writer_drop_writer_fn *drop)
+{
+ fz_document_writer *wri = Memento_label(fz_calloc(ctx, 1, size), "fz_document_writer");
+
+ wri->begin_page = begin_page;
+ wri->end_page = end_page;
+ wri->close_writer = close;
+ wri->drop_writer = drop;
+
+ return wri;
+}
+
fz_document_writer *
fz_new_document_writer(fz_context *ctx, const char *path, const char *format, const char *options)
{
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index d0ff2f76..9af70bb4 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -3273,13 +3273,7 @@ pdf_writer_drop_writer(fz_context *ctx, fz_document_writer *wri_)
fz_document_writer *
fz_new_pdf_writer(fz_context *ctx, const char *path, const char *options)
{
- pdf_writer *wri;
-
- 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_writer = pdf_writer_close_writer;
- wri->super.drop_writer = pdf_writer_drop_writer;
+ pdf_writer *wri = fz_new_writer(ctx, pdf_writer, pdf_writer_begin_page, pdf_writer_end_page, pdf_writer_close_writer, pdf_writer_drop_writer);
fz_try(ctx)
{