summaryrefslogtreecommitdiff
path: root/fitz/res_font.c
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2011-10-04 18:44:19 +0100
committerRobin Watts <Robin.Watts@artifex.com>2011-10-04 18:44:19 +0100
commitd208be26537db558edb70236ae517cea31b7ebab (patch)
tree57da95b97e354a53bd4517a42010e90968f007d9 /fitz/res_font.c
parentba46cad4b09bb957085900a203206c8fa5868cd4 (diff)
downloadmupdf-d208be26537db558edb70236ae517cea31b7ebab.tar.xz
Move to exception handling rather than error passing throughout.
This frees us from passing errors back everywhere, and hence enables us to pass results back as return values. Rather than having to explicitly check for errors everywhere and bubble them, we now allow exception handling to do the work for us; the downside to this is that we no longer emit as much debugging information as we did before (though this could be put back in). For now, the debugging information we have lost has been retained in comments with 'RJW:' at the start. This code needs fuller testing, but is being committed as a work in progress.
Diffstat (limited to 'fitz/res_font.c')
-rw-r--r--fitz/res_font.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/fitz/res_font.c b/fitz/res_font.c
index 47e22ff1..a9a1fdf4 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -179,8 +179,8 @@ fz_finalize_freetype(fz_context *ctx)
}
}
-fz_error
-fz_new_font_from_file(fz_context *ctx, fz_font **fontp, char *path, int index)
+fz_font *
+fz_new_font_from_file(fz_context *ctx, char *path, int index)
{
FT_Face face;
fz_error error;
@@ -189,11 +189,11 @@ fz_new_font_from_file(fz_context *ctx, fz_font **fontp, char *path, int index)
error = fz_init_freetype(ctx);
if (error)
- return fz_error_note(error, "cannot init freetype library");
+ fz_throw(ctx, "cannot init freetype library");
fterr = FT_New_Face(fz_ftlib, path, index, &face);
if (fterr)
- return fz_error_make("freetype: cannot load font: %s", ft_error_string(fterr));
+ fz_throw(ctx, "freetype: cannot load font: %s", ft_error_string(fterr));
font = fz_new_font(ctx, face->family_name);
font->ft_face = face;
@@ -202,12 +202,11 @@ fz_new_font_from_file(fz_context *ctx, fz_font **fontp, char *path, int index)
font->bbox.x1 = face->bbox.xMax * 1000 / face->units_per_EM;
font->bbox.y1 = face->bbox.yMax * 1000 / face->units_per_EM;
- *fontp = font;
- return fz_okay;
+ return font;
}
-fz_error
-fz_new_font_from_memory(fz_context *ctx, fz_font **fontp, unsigned char *data, int len, int index)
+fz_font *
+fz_new_font_from_memory(fz_context *ctx, unsigned char *data, int len, int index)
{
FT_Face face;
fz_error error;
@@ -216,11 +215,11 @@ fz_new_font_from_memory(fz_context *ctx, fz_font **fontp, unsigned char *data, i
error = fz_init_freetype(ctx);
if (error)
- return fz_error_note(error, "cannot init freetype library");
+ fz_throw(ctx, "cannot init freetype library");
fterr = FT_New_Memory_Face(fz_ftlib, data, len, index, &face);
if (fterr)
- return fz_error_make("freetype: cannot load font: %s", ft_error_string(fterr));
+ fz_throw(ctx, "freetype: cannot load font: %s", ft_error_string(fterr));
font = fz_new_font(ctx, face->family_name);
font->ft_face = face;
@@ -229,8 +228,7 @@ fz_new_font_from_memory(fz_context *ctx, fz_font **fontp, unsigned char *data, i
font->bbox.x1 = face->bbox.xMax * 1000 / face->units_per_EM;
font->bbox.y1 = face->bbox.yMax * 1000 / face->units_per_EM;
- *fontp = font;
- return fz_okay;
+ return font;
}
static fz_matrix
@@ -514,7 +512,6 @@ fz_new_type3_font(fz_context *ctx, char *name, fz_matrix matrix)
fz_pixmap *
fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_colorspace *model)
{
- fz_error error;
fz_matrix ctm;
fz_buffer *contents;
fz_bbox bbox;
@@ -532,9 +529,8 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co
ctm = fz_concat(font->t3matrix, trm);
dev = fz_new_bbox_device(ctx, &bbox);
- error = font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
- if (error)
- fz_error_handle(error, "cannot draw type3 glyph");
+ font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
+ /* RJW: "cannot draw type3 glyph" */
if (dev->flags & FZ_CHARPROC_MASK)
{
@@ -565,9 +561,8 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co
cache = fz_new_glyph_cache(ctx);
dev = fz_new_draw_device_type3(ctx, cache, glyph);
- error = font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
- if (error)
- fz_error_handle(error, "cannot draw type3 glyph");
+ font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
+ /* RJW: "cannot draw type3 glyph" */
fz_free_device(dev);
fz_free_glyph_cache(ctx, cache);