diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-04-26 20:11:49 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-04-27 17:01:06 +0200 |
commit | 9b4acc78d2a56a5f79d69f50e72197930509505e (patch) | |
tree | b30e03bd1e80d859b578324425e2486f122c5ac8 /source | |
parent | ed763d50c7363af5f09d24d0e04b95ca59ff7960 (diff) | |
download | mupdf-9b4acc78d2a56a5f79d69f50e72197930509505e.tar.xz |
Add fz_close_device function.
Garbage collected languages need a way to signal that they are done
with a device other than freeing it.
Call it implicitly on fz_drop_device; so take care not to call it again
in case it has been explicitly called already.
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/bbox-device.c | 4 | ||||
-rw-r--r-- | source/fitz/device.c | 38 | ||||
-rw-r--r-- | source/fitz/draw-device.c | 4 | ||||
-rw-r--r-- | source/fitz/list-device.c | 2 | ||||
-rw-r--r-- | source/fitz/stext-device.c | 4 | ||||
-rw-r--r-- | source/fitz/svg-device.c | 4 | ||||
-rw-r--r-- | source/pdf/pdf-device.c | 4 | ||||
-rw-r--r-- | source/tools/murun.c | 12 |
8 files changed, 59 insertions, 13 deletions
diff --git a/source/fitz/bbox-device.c b/source/fitz/bbox-device.c index 247fdb30..42ca57ad 100644 --- a/source/fitz/bbox-device.c +++ b/source/fitz/bbox-device.c @@ -179,7 +179,7 @@ fz_bbox_end_tile(fz_context *ctx, fz_device *dev) } static void -fz_bbox_drop_imp(fz_context *ctx, fz_device *dev) +fz_bbox_close(fz_context *ctx, fz_device *dev) { fz_bbox_device *bdev = (fz_bbox_device*)dev; if (bdev->top > 0) @@ -191,7 +191,7 @@ fz_new_bbox_device(fz_context *ctx, fz_rect *result) { fz_bbox_device *dev = fz_new_device(ctx, sizeof *dev); - dev->super.drop_imp = fz_bbox_drop_imp; + dev->super.close = fz_bbox_close; dev->super.fill_path = fz_bbox_fill_path; dev->super.stroke_path = fz_bbox_stroke_path; diff --git a/source/fitz/device.c b/source/fitz/device.c index 5a293bce..df2d4f86 100644 --- a/source/fitz/device.c +++ b/source/fitz/device.c @@ -7,12 +7,46 @@ fz_new_device(fz_context *ctx, int size) } void +fz_close_device(fz_context *ctx, fz_device *dev) +{ + if (dev == NULL) + return; + if (dev->close) + dev->close(ctx, dev); + + /* Don't call more than once! */ + dev->close = NULL; + + /* And disable all further device calls. */ + dev->fill_path = NULL; + dev->stroke_path = NULL; + dev->clip_path = NULL; + dev->clip_stroke_path = NULL; + dev->fill_text = NULL; + dev->stroke_text = NULL; + dev->clip_text = NULL; + dev->clip_stroke_text = NULL; + dev->ignore_text = NULL; + dev->fill_shade = NULL; + dev->fill_image = NULL; + dev->fill_image_mask = NULL; + dev->clip_image_mask = NULL; + dev->pop_clip = NULL; + dev->begin_mask = NULL; + dev->end_mask = NULL; + dev->begin_group = NULL; + dev->end_group = NULL; + dev->begin_tile = NULL; + dev->end_tile = NULL; +} + +void fz_drop_device(fz_context *ctx, fz_device *dev) { if (dev == NULL) return; - if (dev->drop_imp) - dev->drop_imp(ctx, dev); + if (dev->close) + dev->close(ctx, dev); fz_free(ctx, dev->container); fz_free(ctx, dev); } diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c index 83195cd1..b9db1558 100644 --- a/source/fitz/draw-device.c +++ b/source/fitz/draw-device.c @@ -2013,7 +2013,7 @@ fz_draw_end_tile(fz_context *ctx, fz_device *devp) } static void -fz_draw_drop_imp(fz_context *ctx, fz_device *devp) +fz_draw_close(fz_context *ctx, fz_device *devp) { fz_draw_device *dev = (fz_draw_device*)devp; fz_gel *gel = dev->gel; @@ -2056,7 +2056,7 @@ fz_new_draw_device(fz_context *ctx, fz_pixmap *dest) { fz_draw_device *dev = fz_new_device(ctx, sizeof *dev); - dev->super.drop_imp = fz_draw_drop_imp; + dev->super.close = fz_draw_close; dev->super.fill_path = fz_draw_fill_path; dev->super.stroke_path = fz_draw_stroke_path; diff --git a/source/fitz/list-device.c b/source/fitz/list-device.c index 156e50f6..5f7d69c8 100644 --- a/source/fitz/list-device.c +++ b/source/fitz/list-device.c @@ -1243,7 +1243,7 @@ fz_new_list_device(fz_context *ctx, fz_display_list *list) dev->super.render_flags = fz_list_render_flags; - dev->super.drop_imp = drop_writer; + dev->super.close = drop_writer; dev->list = list; dev->path = NULL; diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c index 35a6568a..94ff9fd6 100644 --- a/source/fitz/stext-device.c +++ b/source/fitz/stext-device.c @@ -1010,7 +1010,7 @@ fz_bidi_reorder_stext_page(fz_context *ctx, fz_stext_page *page) } static void -fz_stext_drop_imp(fz_context *ctx, fz_device *dev) +fz_stext_close(fz_context *ctx, fz_device *dev) { fz_stext_device *tdev = (fz_stext_device*)dev; @@ -1034,7 +1034,7 @@ fz_new_stext_device(fz_context *ctx, fz_stext_sheet *sheet, fz_stext_page *page) dev->super.hints = FZ_IGNORE_IMAGE | FZ_IGNORE_SHADE; - dev->super.drop_imp = fz_stext_drop_imp; + dev->super.close = fz_stext_close; dev->super.fill_text = fz_stext_fill_text; dev->super.stroke_text = fz_stext_stroke_text; dev->super.clip_text = fz_stext_clip_text; diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c index e57b8f5a..d36a5872 100644 --- a/source/fitz/svg-device.c +++ b/source/fitz/svg-device.c @@ -1057,7 +1057,7 @@ svg_dev_end_tile(fz_context *ctx, fz_device *dev) } static void -svg_dev_drop_imp(fz_context *ctx, fz_device *dev) +svg_dev_close(fz_context *ctx, fz_device *dev) { svg_device *sdev = (svg_device*)dev; fz_output *out = sdev->out; @@ -1073,7 +1073,7 @@ fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, { svg_device *dev = fz_new_device(ctx, sizeof *dev); - dev->super.drop_imp = svg_dev_drop_imp; + dev->super.close = svg_dev_close; dev->super.fill_path = svg_dev_fill_path; dev->super.stroke_path = svg_dev_stroke_path; diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c index 9c38dd41..7ece963d 100644 --- a/source/pdf/pdf-device.c +++ b/source/pdf/pdf-device.c @@ -1037,7 +1037,7 @@ pdf_dev_end_tile(fz_context *ctx, fz_device *dev) } static void -pdf_dev_drop_imp(fz_context *ctx, fz_device *dev) +pdf_dev_close(fz_context *ctx, fz_device *dev) { pdf_device *pdev = (pdf_device*)dev; int i; @@ -1066,7 +1066,7 @@ 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.drop_imp = pdf_dev_drop_imp; + dev->super.close = pdf_dev_close; dev->super.fill_path = pdf_dev_fill_path; dev->super.stroke_path = pdf_dev_stroke_path; diff --git a/source/tools/murun.c b/source/tools/murun.c index 541930eb..b5726770 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -1134,6 +1134,16 @@ static fz_device *new_js_device(fz_context *ctx, js_State *J) /* device calling into c from js */ +static void ffi_Device_close(js_State *J) +{ + fz_context *ctx = js_getcontext(J); + fz_device *dev = js_touserdata(J, 0, "fz_device"); + fz_try(ctx) + fz_close_device(ctx, dev); + fz_catch(ctx) + rethrow(J); +} + static void ffi_Device_fillPath(js_State *J) { fz_context *ctx = js_getcontext(J); @@ -2953,6 +2963,8 @@ int murun_main(int argc, char **argv) js_newobject(J); { + jsB_propfun(J, "Device.close", ffi_Device_close, 0); + jsB_propfun(J, "Device.fillPath", ffi_Device_fillPath, 6); jsB_propfun(J, "Device.strokePath", ffi_Device_strokePath, 6); jsB_propfun(J, "Device.clipPath", ffi_Device_clipPath, 3); |