From 4839427ab02dcebcc4c7703d7a04c4bdea6fac18 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 27 Feb 2018 19:48:01 +0100 Subject: Distinguish between simple and CID font resources in cache. --- source/pdf/pdf-font.c | 4 ++-- source/pdf/pdf-resources.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index 8ca89e93..9e8a50dc 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -2099,7 +2099,7 @@ pdf_add_cid_font(fz_context *ctx, pdf_document *doc, fz_font *font) /* Before we add this font as a resource check if the same font * already exists in our resources for this doc. If yes, then * hand back that reference */ - fref = pdf_find_font_resource(ctx, doc, font->buffer, digest); + fref = pdf_find_font_resource(ctx, doc, PDF_CID_FONT_RESOURCE, font->buffer, digest); if (fref == NULL) { /* Set up desc, width, and font file */ @@ -2174,7 +2174,7 @@ pdf_add_simple_font(fz_context *ctx, pdf_document *doc, fz_font *font) /* Before we add this font as a resource check if the same font * already exists in our resources for this doc. If yes, then * hand back that reference */ - fref = pdf_find_font_resource(ctx, doc, font->buffer, digest); + fref = pdf_find_font_resource(ctx, doc, PDF_SIMPLE_FONT_RESOURCE, font->buffer, digest); if (fref == NULL) { fobj = pdf_new_dict(ctx, doc, 10); diff --git a/source/pdf/pdf-resources.c b/source/pdf/pdf-resources.c index 3a0ddbce..72adf081 100644 --- a/source/pdf/pdf-resources.c +++ b/source/pdf/pdf-resources.c @@ -109,15 +109,24 @@ pdf_insert_image_resource(fz_context *ctx, pdf_document *doc, unsigned char dige * it may be more problematic. */ pdf_obj * -pdf_find_font_resource(fz_context *ctx, pdf_document *doc, fz_buffer *item, unsigned char digest[16]) +pdf_find_font_resource(fz_context *ctx, pdf_document *doc, int type, fz_buffer *item, unsigned char digest[16]) { + fz_md5 state; + unsigned char *data; + size_t size; pdf_obj *res; if (!doc->resources.fonts) doc->resources.fonts = fz_new_hash_table(ctx, 4096, 16, -1, pdf_drop_obj_as_void); + size = fz_buffer_storage(ctx, item, &data); + /* Create md5 and see if we have the item in our table */ - fz_md5_buffer(ctx, item, digest); + fz_md5_init(&state); + fz_md5_update(&state, (unsigned char*)&type, sizeof type); + fz_md5_update(&state, data, size); + fz_md5_final(&state, digest); + res = fz_hash_find(ctx, doc->resources.fonts, digest); if (res) pdf_keep_obj(ctx, res); -- cgit v1.2.3