diff options
-rw-r--r-- | include/mupdf/fitz/font.h | 2 | ||||
-rw-r--r-- | include/mupdf/pdf/document.h | 4 | ||||
-rw-r--r-- | source/fitz/font.c | 40 | ||||
-rw-r--r-- | source/pdf/pdf-type3.c | 14 | ||||
-rw-r--r-- | source/pdf/pdf-xref.c | 7 |
5 files changed, 62 insertions, 5 deletions
diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h index 00588d13..38f6c697 100644 --- a/include/mupdf/fitz/font.h +++ b/include/mupdf/fitz/font.h @@ -78,6 +78,8 @@ void fz_set_font_bbox(fz_context *ctx, fz_font *font, float xmin, float ymin, fl fz_rect *fz_bound_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, fz_rect *r); int fz_glyph_cacheable(fz_context *ctx, fz_font *font, int gid); +void fz_decouple_type3_font(fz_context *ctx, fz_font *font, void *t3doc); + #ifndef NDEBUG void fz_print_font(fz_context *ctx, FILE *out, fz_font *font); #endif diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h index 736ae4e5..c65fe893 100644 --- a/include/mupdf/pdf/document.h +++ b/include/mupdf/pdf/document.h @@ -206,6 +206,10 @@ struct pdf_document_s pdf_doc_event_cb *event_cb; void *event_cb_data; + + int num_type3_fonts; + int max_type3_fonts; + fz_font **type3_fonts; }; /* diff --git a/source/fitz/font.c b/source/fitz/font.c index e8613f84..cb369c0f 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -82,6 +82,39 @@ fz_keep_font(fz_context *ctx, fz_font *font) return font; } +static void +free_resources(fz_context *ctx, fz_font *font) +{ + int i; + + if (font->t3resources) + { + font->t3freeres(font->t3doc, font->t3resources); + font->t3resources = NULL; + } + + if (font->t3procs) + { + for (i = 0; i < 256; i++) + if (font->t3procs[i]) + fz_drop_buffer(ctx, font->t3procs[i]); + } + fz_free(ctx, font->t3procs); + font->t3procs = NULL; +} + +void fz_decouple_type3_font(fz_context *ctx, fz_font *font, void *t3doc) +{ + if (!ctx || !font || !t3doc || font->t3doc == NULL) + return; + + if (font->t3doc != t3doc) + fz_throw(ctx, FZ_ERROR_GENERIC, "can't decouple type3 font from a different doc"); + + font->t3doc = NULL; + free_resources(ctx, font); +} + void fz_drop_font(fz_context *ctx, fz_font *font) { @@ -94,14 +127,11 @@ fz_drop_font(fz_context *ctx, fz_font *font) if (!drop) return; - if (font->t3procs) + free_resources(ctx, font); + if (font->t3lists) { - if (font->t3resources) - font->t3freeres(font->t3doc, font->t3resources); for (i = 0; i < 256; i++) { - if (font->t3procs[i]) - fz_drop_buffer(ctx, font->t3procs[i]); if (font->t3lists[i]) fz_drop_display_list(ctx, font->t3lists[i]); } diff --git a/source/pdf/pdf-type3.c b/source/pdf/pdf-type3.c index d136b6f5..d4c9b31a 100644 --- a/source/pdf/pdf-type3.c +++ b/source/pdf/pdf-type3.c @@ -31,6 +31,17 @@ pdf_load_type3_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict) fz_var(fontdesc); + /* Make a new type3 font entry in the document */ + if (doc->num_type3_fonts == doc->max_type3_fonts) + { + int new_max = doc->max_type3_fonts * 2; + + if (new_max == 0) + new_max = 4; + doc->type3_fonts = fz_resize_array(doc->ctx, doc->type3_fonts, new_max, sizeof(*doc->type3_fonts)); + doc->max_type3_fonts = new_max; + } + fz_try(ctx) { obj = pdf_dict_gets(dict, "Name"); @@ -163,6 +174,9 @@ pdf_load_type3_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict) pdf_drop_font(ctx, fontdesc); fz_rethrow_message(ctx, "cannot load type3 font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } + + doc->type3_fonts[doc->num_type3_fonts++] = fz_keep_font(ctx, fontdesc->font); + return fontdesc; } diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index 970a83aa..ee9f8ea1 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -1102,6 +1102,13 @@ pdf_close_document(pdf_document *doc) if (doc->crypt) pdf_free_crypt(ctx, doc->crypt); + for (i=0; i < doc->num_type3_fonts; i++) + { + fz_decouple_type3_font(ctx, doc->type3_fonts[i], (void *)doc); + fz_drop_font(ctx, doc->type3_fonts[i]); + } + fz_free(ctx, doc->type3_fonts); + pdf_free_ocg(ctx, doc->ocg); fz_empty_store(ctx); |