summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/buffer.h9
-rw-r--r--include/mupdf/fitz/font.h4
-rw-r--r--source/fitz/font.c14
-rw-r--r--source/pdf/pdf-device.c2
-rw-r--r--source/pdf/pdf-font.c7
-rw-r--r--source/xps/xps-glyphs.c8
6 files changed, 25 insertions, 19 deletions
diff --git a/include/mupdf/fitz/buffer.h b/include/mupdf/fitz/buffer.h
index 8a6805a5..a96f7603 100644
--- a/include/mupdf/fitz/buffer.h
+++ b/include/mupdf/fitz/buffer.h
@@ -57,9 +57,14 @@ struct fz_buffer_s
fz_buffer *fz_new_buffer(fz_context *ctx, int capacity);
/*
- fz_new_buffer: Create a new buffer.
+ fz_new_buffer_from_data: Create a new buffer with existing data.
- capacity: Initial capacity.
+ data: Pointer to existing data.
+ size: Size of existing data.
+
+ Takes ownership of data. Does not make a copy. Calls fz_free on the
+ data when the buffer is deallocated. Do not use 'data' after passing
+ to this function.
Returns pointer to new buffer. Throws exception on allocation
failure.
diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h
index f83c3885..29a87f48 100644
--- a/include/mupdf/fitz/font.h
+++ b/include/mupdf/fitz/font.h
@@ -36,8 +36,7 @@ struct fz_font_s
int ft_hint; /* ... force hinting for DynaLab fonts */
/* origin of font data */
- char *ft_file;
- unsigned char *ft_data;
+ fz_buffer *ft_buffer;
int ft_size;
fz_matrix t3matrix;
@@ -69,6 +68,7 @@ void fz_drop_font_context(fz_context *ctx);
fz_font *fz_new_type3_font(fz_context *ctx, char *name, const fz_matrix *matrix);
fz_font *fz_new_font_from_memory(fz_context *ctx, char *name, unsigned char *data, int len, int index, int use_glyph_bbox);
+fz_font *fz_new_font_from_buffer(fz_context *ctx, char *name, fz_buffer *buffer, int index, int use_glyph_bbox);
fz_font *fz_new_font_from_file(fz_context *ctx, char *name, char *path, int index, int use_glyph_bbox);
fz_font *fz_keep_font(fz_context *ctx, fz_font *font);
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);
}