diff options
Diffstat (limited to 'fitz/base_context.c')
-rw-r--r-- | fitz/base_context.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/fitz/base_context.c b/fitz/base_context.c new file mode 100644 index 00000000..d828509e --- /dev/null +++ b/fitz/base_context.c @@ -0,0 +1,77 @@ +#include "fitz.h" + +static fz_obj * +fz_resolve_indirect_null(fz_obj *ref) +{ + return ref; +} + +fz_obj *(*fz_resolve_indirect)(fz_obj*) = fz_resolve_indirect_null; + +void +fz_free_context(fz_context *ctx) +{ + if (ctx == NULL) + return; + + /* Other finalisation calls go here (in reverse order) */ + fz_free_aa_context(ctx); + fz_free_font_context(ctx); + + if (ctx->error) + { + assert(ctx->error->top == -1); + fz_free(ctx, ctx->error); + } + + /* Free the context itself */ + ctx->alloc->free(ctx->alloc->user, ctx); +} + +fz_context * +fz_new_context(fz_alloc_context *alloc) +{ + fz_context *ctx; + + ctx = alloc->malloc(alloc->user, sizeof(fz_context)); + if (!ctx) + return NULL; + memset(ctx, 0, sizeof *ctx); + ctx->alloc = alloc; + + ctx->error = fz_malloc_no_throw(ctx, sizeof(fz_error_context)); + if (!ctx->error) + goto cleanup; + ctx->error->top = -1; + ctx->error->message[0] = 0; + + ctx->warn = fz_malloc_no_throw(ctx, sizeof(fz_warn_context)); + if (!ctx->warn) + goto cleanup; + ctx->warn->message[0] = 0; + ctx->warn->count = 0; + + /* New initialisation calls for context entries go here */ + fz_try(ctx) + { + fz_new_font_context(ctx); + fz_new_aa_context(ctx); + } + fz_catch(ctx) + { + goto cleanup; + } + + return ctx; + +cleanup: + fprintf(stderr, "cannot create context\n"); + fz_free_context(ctx); + return NULL; +} + +fz_context * +fz_clone_context(fz_context *ctx) +{ + return fz_new_context(ctx->alloc); +} |