diff options
author | Robin Watts <robin.watts@artifex.com> | 2015-12-14 14:44:06 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2015-12-14 16:22:34 +0000 |
commit | 143ace7d86324a2f7bf6e3f42b503b3274c8784a (patch) | |
tree | 2e264f43172fa2263fc5571779d717c0b4bcd95a | |
parent | 4f425a3ac7bb9e810995dfba814c1d024c0ebf70 (diff) | |
download | mupdf-143ace7d86324a2f7bf6e3f42b503b3274c8784a.tar.xz |
Add user context field.
This may help the MuPDF JNI code, so it's likely to be useful for
other users too.
-rw-r--r-- | include/mupdf/fitz/context.h | 19 | ||||
-rw-r--r-- | source/fitz/context.c | 16 |
2 files changed, 35 insertions, 0 deletions
diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index 67b16b00..0dce749c 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -101,6 +101,7 @@ void fz_flush_warnings(fz_context *ctx); struct fz_context_s { + void *user; fz_alloc_context *alloc; fz_locks_context *locks; fz_id_context *id; @@ -190,6 +191,24 @@ fz_context *fz_clone_context(fz_context *ctx); void fz_drop_context(fz_context *ctx); /* + fz_set_user_context: Set the user field in the context. + + NULL initially, this field can be set to any opaque value + required by the user. It is copied on clones. + + Does not throw exceptions. +*/ +void fz_set_user_context(fz_context *ctx, void *user); + +/* + fz_user_context: Read the user field from the context. + + Does not throw exceptions. +*/ +void *fz_user_context(fz_context *ctx); + + +/* fz_aa_level: Get the number of bits of antialiasing we are using. Between 0 and 8. */ diff --git a/source/fitz/context.c b/source/fitz/context.c index 44f96993..53f820a1 100644 --- a/source/fitz/context.c +++ b/source/fitz/context.c @@ -120,6 +120,7 @@ new_context_phase1(fz_alloc_context *alloc, fz_locks_context *locks) if (!ctx) return NULL; memset(ctx, 0, sizeof *ctx); + ctx->user = NULL; ctx->alloc = alloc; ctx->locks = locks; @@ -223,6 +224,7 @@ fz_clone_context_internal(fz_context *ctx) fz_copy_aa_context(new_ctx, ctx); /* Keep thread lock checking happy by copying pointers first and locking under new context */ + new_ctx->user = ctx->user; new_ctx->store = ctx->store; new_ctx->store = fz_keep_store_context(new_ctx); new_ctx->glyph_cache = ctx->glyph_cache; @@ -253,3 +255,17 @@ fz_gen_id(fz_context *ctx) fz_unlock(ctx, FZ_LOCK_ALLOC); return id; } + +void fz_set_user_context(fz_context *ctx, void *user) +{ + if (ctx != NULL) + ctx->user = user; +} + +void *fz_user_context(fz_context *ctx) +{ + if (ctx == NULL) + return NULL; + + return ctx->user; +} |