diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-16 17:36:18 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-16 17:36:18 +0000 |
commit | df5b15a77321cc3626d0907bd86a2445af379489 (patch) | |
tree | 98793fa1913b782151fcafa07b24bb8359fcce52 | |
parent | 2e8a58ecce2d509c891e774d7cd1145514328d00 (diff) | |
download | mupdf-df5b15a77321cc3626d0907bd86a2445af379489.tar.xz |
More memsqueezing fixes.
-rw-r--r-- | fitz/dev_list.c | 167 | ||||
-rw-r--r-- | fitz/res_path.c | 18 | ||||
-rw-r--r-- | pdf/pdf_interpret.c | 150 |
3 files changed, 221 insertions, 114 deletions
diff --git a/fitz/dev_list.c b/fitz/dev_list.c index 03c65f49..376cdac8 100644 --- a/fitz/dev_list.c +++ b/fitz/dev_list.c @@ -230,10 +230,19 @@ fz_list_fill_path(fz_device *dev, fz_path *path, int even_odd, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_FILL_PATH, ctm, colorspace, color, alpha); - node->rect = fz_bound_path(path, NULL, ctm); - node->item.path = fz_clone_path(dev->ctx, path); - node->flag = even_odd; + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_FILL_PATH, ctm, colorspace, color, alpha); + fz_try(ctx) + { + node->rect = fz_bound_path(path, NULL, ctm); + node->item.path = fz_clone_path(dev->ctx, path); + node->flag = even_odd; + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -242,10 +251,19 @@ fz_list_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, fz_m fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_STROKE_PATH, ctm, colorspace, color, alpha); - node->rect = fz_bound_path(path, stroke, ctm); - node->item.path = fz_clone_path(dev->ctx, path); - node->stroke = fz_clone_stroke_state(dev->ctx, stroke); + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_STROKE_PATH, ctm, colorspace, color, alpha); + fz_try(ctx) + { + node->rect = fz_bound_path(path, stroke, ctm); + node->item.path = fz_clone_path(dev->ctx, path); + node->stroke = fz_clone_stroke_state(dev->ctx, stroke); + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -253,12 +271,21 @@ static void fz_list_clip_path(fz_device *dev, fz_path *path, fz_rect *rect, int even_odd, fz_matrix ctm) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_CLIP_PATH, ctm, NULL, NULL, 0); - node->rect = fz_bound_path(path, NULL, ctm); - if (rect) - node->rect = fz_intersect_rect(node->rect, *rect); - node->item.path = fz_clone_path(dev->ctx, path); - node->flag = even_odd; + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_CLIP_PATH, ctm, NULL, NULL, 0); + fz_try(ctx) + { + node->rect = fz_bound_path(path, NULL, ctm); + if (rect) + node->rect = fz_intersect_rect(node->rect, *rect); + node->item.path = fz_clone_path(dev->ctx, path); + node->flag = even_odd; + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -266,12 +293,21 @@ static void fz_list_clip_stroke_path(fz_device *dev, fz_path *path, fz_rect *rect, fz_stroke_state *stroke, fz_matrix ctm) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_CLIP_STROKE_PATH, ctm, NULL, NULL, 0); - node->rect = fz_bound_path(path, stroke, ctm); - if (rect) - node->rect = fz_intersect_rect(node->rect, *rect); - node->item.path = fz_clone_path(dev->ctx, path); - node->stroke = fz_clone_stroke_state(dev->ctx, stroke); + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_CLIP_STROKE_PATH, ctm, NULL, NULL, 0); + fz_try(ctx) + { + node->rect = fz_bound_path(path, stroke, ctm); + if (rect) + node->rect = fz_intersect_rect(node->rect, *rect); + node->item.path = fz_clone_path(dev->ctx, path); + node->stroke = fz_clone_stroke_state(dev->ctx, stroke); + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -280,9 +316,18 @@ fz_list_fill_text(fz_device *dev, fz_text *text, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_FILL_TEXT, ctm, colorspace, color, alpha); - node->rect = fz_bound_text(text, ctm); - node->item.text = fz_clone_text(dev->ctx, text); + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_FILL_TEXT, ctm, colorspace, color, alpha); + fz_try(ctx) + { + node->rect = fz_bound_text(text, ctm); + node->item.text = fz_clone_text(dev->ctx, text); + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -291,10 +336,20 @@ fz_list_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_m fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_STROKE_TEXT, ctm, colorspace, color, alpha); - node->rect = fz_bound_text(text, ctm); - node->item.text = fz_clone_text(dev->ctx, text); - node->stroke = fz_clone_stroke_state(dev->ctx, stroke); + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_STROKE_TEXT, ctm, colorspace, color, alpha); + node->item.text = NULL; + fz_try(ctx) + { + node->rect = fz_bound_text(text, ctm); + node->item.text = fz_clone_text(dev->ctx, text); + node->stroke = fz_clone_stroke_state(dev->ctx, stroke); + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -302,13 +357,22 @@ static void fz_list_clip_text(fz_device *dev, fz_text *text, fz_matrix ctm, int accumulate) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_CLIP_TEXT, ctm, NULL, NULL, 0); - node->rect = fz_bound_text(text, ctm); - node->item.text = fz_clone_text(dev->ctx, text); - node->flag = accumulate; - /* when accumulating, be conservative about culling */ - if (accumulate) - node->rect = fz_infinite_rect; + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_CLIP_TEXT, ctm, NULL, NULL, 0); + fz_try(ctx) + { + node->rect = fz_bound_text(text, ctm); + node->item.text = fz_clone_text(dev->ctx, text); + node->flag = accumulate; + /* when accumulating, be conservative about culling */ + if (accumulate) + node->rect = fz_infinite_rect; + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -316,10 +380,19 @@ static void fz_list_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_CLIP_STROKE_TEXT, ctm, NULL, NULL, 0); - node->rect = fz_bound_text(text, ctm); - node->item.text = fz_clone_text(dev->ctx, text); - node->stroke = fz_clone_stroke_state(dev->ctx, stroke); + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_CLIP_STROKE_TEXT, ctm, NULL, NULL, 0); + fz_try(ctx) + { + node->rect = fz_bound_text(text, ctm); + node->item.text = fz_clone_text(dev->ctx, text); + node->stroke = fz_clone_stroke_state(dev->ctx, stroke); + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -327,9 +400,18 @@ static void fz_list_ignore_text(fz_device *dev, fz_text *text, fz_matrix ctm) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_IGNORE_TEXT, ctm, NULL, NULL, 0); - node->rect = fz_bound_text(text, ctm); - node->item.text = fz_clone_text(dev->ctx, text); + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_IGNORE_TEXT, ctm, NULL, NULL, 0); + fz_try(ctx) + { + node->rect = fz_bound_text(text, ctm); + node->item.text = fz_clone_text(dev->ctx, text); + } + fz_catch(ctx) + { + fz_free_display_node(ctx, node); + fz_rethrow(ctx); + } fz_append_display_node(dev->user, node); } @@ -345,7 +427,8 @@ static void fz_list_fill_shade(fz_device *dev, fz_shade *shade, fz_matrix ctm, float alpha) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_FILL_SHADE, ctm, NULL, NULL, alpha); + fz_context *ctx = dev->ctx; + node = fz_new_display_node(ctx, FZ_CMD_FILL_SHADE, ctm, NULL, NULL, alpha); node->rect = fz_bound_shade(shade, ctm); node->item.shade = fz_keep_shade(shade); fz_append_display_node(dev->user, node); diff --git a/fitz/res_path.c b/fitz/res_path.c index 995afc57..054b3c1f 100644 --- a/fitz/res_path.c +++ b/fitz/res_path.c @@ -21,10 +21,18 @@ fz_clone_path(fz_context *ctx, fz_path *old) assert(old); path = fz_malloc_struct(ctx, fz_path); - path->len = old->len; - path->cap = old->len; - path->items = fz_malloc_array(ctx, path->cap, sizeof(fz_path_item)); - memcpy(path->items, old->items, sizeof(fz_path_item) * path->len); + fz_try(ctx) + { + path->len = old->len; + path->cap = old->len; + path->items = fz_malloc_array(ctx, path->cap, sizeof(fz_path_item)); + memcpy(path->items, old->items, sizeof(fz_path_item) * path->len); + } + fz_catch(ctx) + { + fz_free(ctx, path); + fz_rethrow(ctx); + } return path; } @@ -32,6 +40,8 @@ fz_clone_path(fz_context *ctx, fz_path *old) void fz_free_path(fz_context *ctx, fz_path *path) { + if (path == NULL) + return; fz_free(ctx, path->items); fz_free(ctx, path); } diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 14d91d23..a6c1714d 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -431,88 +431,95 @@ pdf_show_path(pdf_csi *csi, int doclose, int dofill, int dostroke, int even_odd) path = csi->path; csi->path = fz_new_path(ctx); - if (doclose) - fz_closepath(ctx, path); + fz_try(ctx) + { + if (doclose) + fz_closepath(ctx, path); - if (dostroke) - bbox = fz_bound_path(path, &gstate->stroke_state, gstate->ctm); - else - bbox = fz_bound_path(path, NULL, gstate->ctm); + if (dostroke) + bbox = fz_bound_path(path, &gstate->stroke_state, gstate->ctm); + else + bbox = fz_bound_path(path, NULL, gstate->ctm); - if (csi->clip) - { - gstate->clip_depth++; - fz_clip_path(csi->dev, path, NULL, csi->clip_even_odd, gstate->ctm); - csi->clip = 0; - } + if (csi->clip) + { + gstate->clip_depth++; + fz_clip_path(csi->dev, path, NULL, csi->clip_even_odd, gstate->ctm); + csi->clip = 0; + } - if (csi->in_hidden_ocg > 0) - dostroke = dofill = 0; + if (csi->in_hidden_ocg > 0) + dostroke = dofill = 0; - if (dofill || dostroke) - pdf_begin_group(csi, bbox); + if (dofill || dostroke) + pdf_begin_group(csi, bbox); - if (dofill) - { - switch (gstate->fill.kind) + if (dofill) { - case PDF_MAT_NONE: - break; - case PDF_MAT_COLOR: - fz_fill_path(csi->dev, path, even_odd, gstate->ctm, - gstate->fill.colorspace, gstate->fill.v, gstate->fill.alpha); - break; - case PDF_MAT_PATTERN: - if (gstate->fill.pattern) + switch (gstate->fill.kind) { - fz_clip_path(csi->dev, path, NULL, even_odd, gstate->ctm); - pdf_show_pattern(csi, gstate->fill.pattern, bbox, PDF_FILL); - fz_pop_clip(csi->dev); - } - break; - case PDF_MAT_SHADE: - if (gstate->fill.shade) - { - fz_clip_path(csi->dev, path, NULL, even_odd, gstate->ctm); - fz_fill_shade(csi->dev, gstate->fill.shade, csi->top_ctm, gstate->fill.alpha); - fz_pop_clip(csi->dev); + case PDF_MAT_NONE: + break; + case PDF_MAT_COLOR: + fz_fill_path(csi->dev, path, even_odd, gstate->ctm, + gstate->fill.colorspace, gstate->fill.v, gstate->fill.alpha); + break; + case PDF_MAT_PATTERN: + if (gstate->fill.pattern) + { + fz_clip_path(csi->dev, path, NULL, even_odd, gstate->ctm); + pdf_show_pattern(csi, gstate->fill.pattern, bbox, PDF_FILL); + fz_pop_clip(csi->dev); + } + break; + case PDF_MAT_SHADE: + if (gstate->fill.shade) + { + fz_clip_path(csi->dev, path, NULL, even_odd, gstate->ctm); + fz_fill_shade(csi->dev, gstate->fill.shade, csi->top_ctm, gstate->fill.alpha); + fz_pop_clip(csi->dev); + } + break; } - break; } - } - if (dostroke) - { - switch (gstate->stroke.kind) + if (dostroke) { - case PDF_MAT_NONE: - break; - case PDF_MAT_COLOR: - fz_stroke_path(csi->dev, path, &gstate->stroke_state, gstate->ctm, - gstate->stroke.colorspace, gstate->stroke.v, gstate->stroke.alpha); - break; - case PDF_MAT_PATTERN: - if (gstate->stroke.pattern) - { - fz_clip_stroke_path(csi->dev, path, &bbox, &gstate->stroke_state, gstate->ctm); - pdf_show_pattern(csi, gstate->stroke.pattern, bbox, PDF_FILL); - fz_pop_clip(csi->dev); - } - break; - case PDF_MAT_SHADE: - if (gstate->stroke.shade) + switch (gstate->stroke.kind) { - fz_clip_stroke_path(csi->dev, path, &bbox, &gstate->stroke_state, gstate->ctm); - fz_fill_shade(csi->dev, gstate->stroke.shade, csi->top_ctm, gstate->stroke.alpha); - fz_pop_clip(csi->dev); + case PDF_MAT_NONE: + break; + case PDF_MAT_COLOR: + fz_stroke_path(csi->dev, path, &gstate->stroke_state, gstate->ctm, + gstate->stroke.colorspace, gstate->stroke.v, gstate->stroke.alpha); + break; + case PDF_MAT_PATTERN: + if (gstate->stroke.pattern) + { + fz_clip_stroke_path(csi->dev, path, &bbox, &gstate->stroke_state, gstate->ctm); + pdf_show_pattern(csi, gstate->stroke.pattern, bbox, PDF_FILL); + fz_pop_clip(csi->dev); + } + break; + case PDF_MAT_SHADE: + if (gstate->stroke.shade) + { + fz_clip_stroke_path(csi->dev, path, &bbox, &gstate->stroke_state, gstate->ctm); + fz_fill_shade(csi->dev, gstate->stroke.shade, csi->top_ctm, gstate->stroke.alpha); + fz_pop_clip(csi->dev); + } + break; } - break; } - } - - if (dofill || dostroke) - pdf_end_group(csi); + if (dofill || dostroke) + pdf_end_group(csi); + } + fz_catch(ctx) + { + fz_free_path(ctx, path); + fz_rethrow(ctx); + } fz_free_path(ctx, path); } @@ -975,7 +982,14 @@ pdf_grestore(pdf_csi *csi) gs = csi->gstate + csi->gtop; while (clip_depth > gs->clip_depth) { - fz_pop_clip(csi->dev); + fz_try(ctx) + { + fz_pop_clip(csi->dev); + } + fz_catch(ctx) + { + /* Silently swallow the problem */ + } clip_depth--; } } |