diff options
Diffstat (limited to 'source/fitz/text.c')
-rw-r--r-- | source/fitz/text.c | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/source/fitz/text.c b/source/fitz/text.c index 81e2e1d0..466c869a 100644 --- a/source/fitz/text.c +++ b/source/fitz/text.c @@ -6,6 +6,7 @@ fz_new_text(fz_context *ctx, fz_font *font, const fz_matrix *trm, int wmode) fz_text *text; text = fz_malloc_struct(ctx, fz_text); + text->refs = 1; text->font = fz_keep_font(ctx, font); text->trm = *trm; text->wmode = wmode; @@ -16,40 +17,21 @@ fz_new_text(fz_context *ctx, fz_font *font, const fz_matrix *trm, int wmode) return text; } -void -fz_free_text(fz_context *ctx, fz_text *text) +fz_text * +fz_keep_text(fz_context *ctx, fz_text *text) { - if (text != NULL) - { - fz_drop_font(ctx, text->font); - fz_free(ctx, text->items); - } - fz_free(ctx, text); + return fz_keep_imp(ctx, text, &text->refs); } -fz_text * -fz_clone_text(fz_context *ctx, fz_text *old) +void +fz_drop_text(fz_context *ctx, fz_text *text) { - fz_text *text; - - text = fz_malloc_struct(ctx, fz_text); - text->len = old->len; - fz_try(ctx) - { - text->items = fz_malloc_array(ctx, text->len, sizeof(fz_text_item)); - } - fz_catch(ctx) + if (fz_drop_imp(ctx, text, &text->refs)) { + fz_drop_font(ctx, text->font); + fz_free(ctx, text->items); fz_free(ctx, text); - fz_rethrow(ctx); } - memcpy(text->items, old->items, text->len * sizeof(fz_text_item)); - text->font = fz_keep_font(ctx, old->font); - text->trm = old->trm; - text->wmode = old->wmode; - text->cap = text->len; - - return text; } fz_rect * @@ -91,7 +73,7 @@ fz_bound_text(fz_context *ctx, fz_text *text, const fz_stroke_state *stroke, con } if (stroke) - fz_adjust_rect_for_stroke(bbox, stroke, ctm); + fz_adjust_rect_for_stroke(ctx, bbox, stroke, ctm); /* Compensate for the glyph cache limited positioning precision */ bbox->x0 -= 1; @@ -117,6 +99,9 @@ fz_grow_text(fz_context *ctx, fz_text *text, int n) void fz_add_text(fz_context *ctx, fz_text *text, int gid, int ucs, float x, float y) { + if (text->refs != 1) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot modify shared text objects"); + fz_grow_text(ctx, text, 1); text->items[text->len].ucs = ucs; text->items[text->len].gid = gid; |