diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/font.c | 14 | ||||
-rw-r--r-- | source/pdf/pdf-device.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-font.c | 7 | ||||
-rw-r--r-- | source/xps/xps-glyphs.c | 8 |
4 files changed, 16 insertions, 15 deletions
diff --git a/source/fitz/font.c b/source/fitz/font.c index 06ecab76..d78ccd6d 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -31,8 +31,7 @@ fz_new_font(fz_context *ctx, char *name, int use_glyph_bbox, int glyph_count) font->ft_italic = 0; font->ft_hint = 0; - font->ft_file = NULL; - font->ft_data = NULL; + font->ft_buffer = NULL; font->ft_size = 0; font->t3matrix = fz_identity; @@ -151,8 +150,7 @@ fz_drop_font(fz_context *ctx, fz_font *font) fz_drop_freetype(ctx); } - fz_free(ctx, font->ft_file); - fz_free(ctx, font->ft_data); + fz_drop_buffer(ctx, font->ft_buffer); fz_free(ctx, font->bbox_table); fz_free(ctx, font->width_table); fz_free(ctx, font); @@ -365,6 +363,14 @@ fz_new_font_from_memory(fz_context *ctx, char *name, unsigned char *data, int le return font; } +fz_font * +fz_new_font_from_buffer(fz_context *ctx, char *name, fz_buffer *buffer, int index, int use_glyph_bbox) +{ + fz_font *font = fz_new_font_from_memory(ctx, name, buffer->data, buffer->len, index, use_glyph_bbox); + font->ft_buffer = fz_keep_buffer(ctx, buffer); /* remember buffer so we can drop it when we free the font */ + return font; +} + static fz_matrix * fz_adjust_ft_glyph_width(fz_context *ctx, fz_font *font, int gid, fz_matrix *trm) { diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c index f825872b..9877782f 100644 --- a/source/pdf/pdf-device.c +++ b/source/pdf/pdf-device.c @@ -549,7 +549,7 @@ pdf_dev_font(pdf_device *pdev, fz_font *font, float size) if (gs->font >= 0 && pdev->fonts[gs->font].font == font) return; - if (font->ft_data != NULL || font->ft_substitute) + if (font->ft_buffer != NULL || font->ft_substitute) fz_throw(pdev->ctx, FZ_ERROR_GENERIC, "pdf device supports only base 14 fonts currently"); /* Have we sent such a font before? */ diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index e0664b13..78ee7f18 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -292,7 +292,7 @@ pdf_load_embedded_font(pdf_document *doc, pdf_font_desc *fontdesc, char *fontnam fz_try(ctx) { - fontdesc->font = fz_new_font_from_memory(ctx, fontname, buf->data, buf->len, 0, 1); + fontdesc->font = fz_new_font_from_buffer(ctx, fontname, buf, 0, 1); } fz_catch(ctx) { @@ -301,11 +301,6 @@ pdf_load_embedded_font(pdf_document *doc, pdf_font_desc *fontdesc, char *fontnam } fontdesc->size += buf->len; - /* save the buffer so we can free it later */ - fontdesc->font->ft_data = buf->data; - fontdesc->font->ft_size = buf->len; - fz_free(ctx, buf); /* only free the fz_buffer struct, not the contained data */ - fontdesc->is_embedded = 1; } diff --git a/source/xps/xps-glyphs.c b/source/xps/xps-glyphs.c index 02ed6fee..b26e18dc 100644 --- a/source/xps/xps-glyphs.c +++ b/source/xps/xps-glyphs.c @@ -522,7 +522,9 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm, fz_try(doc->ctx) { - font = fz_new_font_from_memory(doc->ctx, NULL, part->data, part->size, subfontid, 1); + fz_buffer *buf = fz_new_buffer_from_data(doc->ctx, part->data, part->size); + font = fz_new_font_from_buffer(doc->ctx, NULL, buf, subfontid, 1); + fz_drop_buffer(doc->ctx, buf); } fz_catch(doc->ctx) { @@ -542,9 +544,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm, xps_insert_font(doc, fakename, font); - /* NOTE: we keep part->data in the font */ - font->ft_data = part->data; - font->ft_size = part->size; + /* NOTE: we already saved part->data in the buffer in the font */ fz_free(doc->ctx, part->name); fz_free(doc->ctx, part); } |