summaryrefslogtreecommitdiff
path: root/fitz/res_font.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2012-01-12 19:02:17 +0100
committerTor Andersson <tor.andersson@artifex.com>2012-01-12 19:02:17 +0100
commit2f15b4c15438df7f6b1940a0036cc793be9fd9c3 (patch)
treedff7c41561991be72790beb5fb9645d7b66d8d64 /fitz/res_font.c
parent5fdcd483e8d70452b1bff56f37b9a910ade2eccc (diff)
downloadmupdf-2f15b4c15438df7f6b1940a0036cc793be9fd9c3.tar.xz
Calculate individual glyph bboxes for Type 3 fonts too.
Diffstat (limited to 'fitz/res_font.c')
-rw-r--r--fitz/res_font.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/fitz/res_font.c b/fitz/res_font.c
index 84291fe7..c3e2e0bd 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -36,6 +36,7 @@ fz_new_font(fz_context *ctx, char *name, int use_glyph_bbox, int glyph_count)
font->t3resources = NULL;
font->t3procs = NULL;
font->t3widths = NULL;
+ font->t3flags = NULL;
font->t3xref = NULL;
font->t3run = NULL;
@@ -90,6 +91,7 @@ fz_drop_font(fz_context *ctx, fz_font *font)
fz_drop_buffer(ctx, font->t3procs[i]);
fz_free(ctx, font->t3procs);
fz_free(ctx, font->t3widths);
+ fz_free(ctx, font->t3flags);
}
if (font->ft_face)
@@ -593,12 +595,14 @@ fz_new_type3_font(fz_context *ctx, char *name, fz_matrix matrix)
font = fz_new_font(ctx, name, 1, 256);
font->t3procs = fz_malloc_array(ctx, 256, sizeof(fz_buffer*));
font->t3widths = fz_malloc_array(ctx, 256, sizeof(float));
+ font->t3flags = fz_malloc_array(ctx, 256, sizeof(char));
font->t3matrix = matrix;
for (i = 0; i < 256; i++)
{
font->t3procs[i] = NULL;
font->t3widths[i] = 0;
+ font->t3flags[i] = 0;
}
return font;
@@ -607,9 +611,27 @@ fz_new_type3_font(fz_context *ctx, char *name, fz_matrix matrix)
static fz_rect
fz_bound_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm)
{
- // TODO: run through bbox device here and set d0/d1 flags
- trm = fz_concat(font->t3matrix, trm);
- return fz_transform_rect(trm, font->bbox);
+ fz_matrix ctm;
+ fz_buffer *contents;
+ fz_rect bounds;
+ fz_bbox bbox;
+ fz_device *dev;
+
+ contents = font->t3procs[gid];
+ if (!contents)
+ return fz_transform_rect(trm, fz_empty_rect);
+
+ ctm = fz_concat(font->t3matrix, trm);
+ dev = fz_new_bbox_device(ctx, &bbox);
+ font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
+ font->t3flags[gid] = dev->flags;
+ fz_free_device(dev);
+
+ bounds.x0 = bbox.x0;
+ bounds.y0 = bbox.y0;
+ bounds.x1 = bbox.x1;
+ bounds.y1 = bbox.y1;
+ return bounds;
}
fz_pixmap *
@@ -629,18 +651,13 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co
if (!contents)
return NULL;
- ctm = fz_concat(font->t3matrix, trm);
- dev = fz_new_bbox_device(ctx, &bbox);
- font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
- /* RJW: "cannot draw type3 glyph" */
-
- if (dev->flags & FZ_CHARPROC_MASK)
+ if (font->t3flags[gid] & FZ_CHARPROC_MASK)
{
- if (dev->flags & FZ_CHARPROC_COLOR)
+ if (font->t3flags[gid] & FZ_CHARPROC_COLOR)
fz_warn(ctx, "type3 glyph claims to be both masked and colored");
model = NULL;
}
- else if (dev->flags & FZ_CHARPROC_COLOR)
+ else if (font->t3flags[gid] & FZ_CHARPROC_COLOR)
{
if (!model)
fz_warn(ctx, "colored type3 glyph wanted in masked context");
@@ -651,8 +668,7 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co
model = NULL; /* Treat as masked */
}
- fz_free_device(dev);
-
+ bbox = fz_round_rect(fz_bound_glyph(ctx, font, gid, trm));
bbox.x0--;
bbox.y0--;
bbox.x1++;
@@ -661,6 +677,7 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co
glyph = fz_new_pixmap_with_rect(ctx, model ? model : fz_device_gray, bbox);
fz_clear_pixmap(glyph);
+ ctm = fz_concat(font->t3matrix, trm);
dev = fz_new_draw_device_type3(ctx, glyph);
font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
/* RJW: "cannot draw type3 glyph" */