summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-12-09 17:51:53 +0000
committerRobin Watts <robin.watts@artifex.com>2015-12-14 16:22:35 +0000
commit3b183d95c919bf56a5ffcecf9717aa5b73db0db6 (patch)
treeb42897f0d2c5cff306be90b2f6f10c31d5bb4bcd
parent1180b61fce77e2c06a0be764605f7fde4aad7ae3 (diff)
downloadmupdf-3b183d95c919bf56a5ffcecf9717aa5b73db0db6.tar.xz
Add fz_clone_text
Will be required for JNI bindings.
-rw-r--r--include/mupdf/fitz/text.h2
-rw-r--r--source/fitz/text.c51
2 files changed, 53 insertions, 0 deletions
diff --git a/include/mupdf/fitz/text.h b/include/mupdf/fitz/text.h
index 01b4667f..302678cd 100644
--- a/include/mupdf/fitz/text.h
+++ b/include/mupdf/fitz/text.h
@@ -52,4 +52,6 @@ void fz_drop_text(fz_context *ctx, fz_text *text);
void fz_add_text(fz_context *ctx, fz_text *text, fz_font *font, int wmode, const fz_matrix *trm, int gid, int ucs);
fz_rect *fz_bound_text(fz_context *ctx, fz_text *text, const fz_stroke_state *stroke, const fz_matrix *ctm, fz_rect *r);
+fz_text *fz_clone_text(fz_context *ctx, fz_text *text);
+
#endif
diff --git a/source/fitz/text.c b/source/fitz/text.c
index f90fee53..5490f72e 100644
--- a/source/fitz/text.c
+++ b/source/fitz/text.c
@@ -138,3 +138,54 @@ fz_bound_text(fz_context *ctx, fz_text *text, const fz_stroke_state *stroke, con
return bbox;
}
+
+fz_text *
+fz_clone_text(fz_context *ctx, fz_text *text)
+{
+ fz_text *new_text;
+ fz_text_span *span;
+ fz_text_span **tail;
+
+ new_text = fz_malloc_struct(ctx, fz_text);
+ new_text->refs = 1;
+ span = text->head;
+ tail = &new_text->head;
+
+ fz_var(span);
+
+ fz_try(ctx)
+ {
+ while (span != NULL)
+ {
+ fz_text_span *new_span = fz_malloc_struct(ctx, fz_text_span);
+ *tail = new_span;
+ tail = &new_span->next;
+ new_text->tail = new_span;
+ new_span->font = fz_keep_font(ctx, span->font);
+ new_span->trm = span->trm;
+ new_span->wmode = span->wmode;
+ new_span->len = span->len;
+ new_span->cap = span->len;
+ new_span->items = fz_malloc(ctx, span->len * sizeof(*span->items));
+ memcpy(new_span->items, span->items, span->len * sizeof(*span->items));
+ span = span->next;
+
+ }
+ }
+ fz_catch(ctx)
+ {
+ span = new_text->head;
+ while (span != NULL)
+ {
+ fz_text_span *next = span->next;
+ fz_drop_font(ctx, span->font);
+ fz_free(ctx, span->items);
+ fz_free(ctx, span);
+ span = next;
+ }
+ fz_free(ctx, new_text);
+ fz_rethrow(ctx);
+ }
+
+ return new_text;
+}