diff options
-rw-r--r-- | fitz/fitz.h | 1 | ||||
-rw-r--r-- | fitz/res_font.c | 43 |
2 files changed, 31 insertions, 13 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h index d38945b8..6aebdf61 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -1047,6 +1047,7 @@ struct fz_font_s fz_obj *t3resources; fz_buffer **t3procs; /* has 256 entries if used */ float *t3widths; /* has 256 entries if used */ + char *t3flags; /* has 256 entries if used */ void *t3xref; /* a pdf_xref for the callback */ void (*t3run)(void *xref, fz_obj *resources, fz_buffer *contents, struct fz_device_s *dev, fz_matrix ctm); 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" */ |