From 1dd2a1ae1f1cb7d93ec2edcc5a6c7e7fd4f0e2ec Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 31 Oct 2013 16:27:12 +0100 Subject: Allow stroke states to be kept on the stack. Add a function to clone stroke states, a magic number to keep in the reference count to signal that a stroke state is stack-stored, and automatically clone stack stored stroke states in the keep function. Use fz_default_stroke_state to initialise stack stored stroke states. --- source/fitz/path.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'source/fitz') diff --git a/source/fitz/path.c b/source/fitz/path.c index 811db282..04a3a7bc 100644 --- a/source/fitz/path.c +++ b/source/fitz/path.c @@ -364,12 +364,24 @@ fz_print_path(fz_context *ctx, FILE *out, fz_path *path, int indent) } #endif +const fz_stroke_state fz_default_stroke_state = { + -2, /* -2 is the magic number we use when we have stroke states stored on the stack */ + FZ_LINECAP_BUTT, FZ_LINECAP_BUTT, FZ_LINECAP_BUTT, + FZ_LINEJOIN_MITER, + 1, 10, + 0, 0, { 0 } +}; + fz_stroke_state * fz_keep_stroke_state(fz_context *ctx, fz_stroke_state *stroke) { if (!stroke) return NULL; + /* -2 is the magic number we use when we have stroke states stored on the stack */ + if (stroke->refs == -2) + return fz_clone_stroke_state(ctx, stroke); + fz_lock(ctx, FZ_LOCK_ALLOC); if (stroke->refs > 0) stroke->refs++; @@ -422,6 +434,17 @@ fz_new_stroke_state(fz_context *ctx) return fz_new_stroke_state_with_dash_len(ctx, 0); } +fz_stroke_state * +fz_clone_stroke_state(fz_context *ctx, fz_stroke_state *stroke) +{ + fz_stroke_state *clone = fz_new_stroke_state_with_dash_len(ctx, stroke->dash_len); + int extra = stroke->dash_len - nelem(stroke->dash_list); + int size = sizeof(*stroke) + sizeof(stroke->dash_list[0]) * extra; + memcpy(clone, stroke, size); + clone->refs = 1; + return clone; +} + fz_stroke_state * fz_unshare_stroke_state_with_dash_len(fz_context *ctx, fz_stroke_state *shared, int len) { -- cgit v1.2.3