diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-11-28 19:44:02 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-11-28 19:44:02 +0000 |
commit | 3a207e707b352b8031409f3851705fbc7eccff36 (patch) | |
tree | 534de121baa1b2a662acecda38bc4a4e536fb2df | |
parent | bdf5c8848a2de071c8380fab86a1a49215ed5ee7 (diff) | |
download | mupdf-3a207e707b352b8031409f3851705fbc7eccff36.tar.xz |
Move Freetype globals into context.
Freetype globals are not shared between threads currently - to do that
we'll need to introduce a lock.
-rw-r--r-- | fitz/base_context.c | 9 | ||||
-rw-r--r-- | fitz/fitz.h | 5 | ||||
-rw-r--r-- | fitz/res_font.c | 48 | ||||
-rw-r--r-- | scripts/cmapdump.c | 8 |
4 files changed, 56 insertions, 14 deletions
diff --git a/fitz/base_context.c b/fitz/base_context.c index c64d09e7..2986a8f8 100644 --- a/fitz/base_context.c +++ b/fitz/base_context.c @@ -15,6 +15,7 @@ fz_free_context(fz_context *ctx) return; /* Other finalisation calls go here (in reverse order) */ + fz_free_font_context(ctx); if (ctx->error) { @@ -50,6 +51,14 @@ fz_new_context(fz_alloc_context *alloc) ctx->warn->count = 0; /* New initialisation calls for context entries go here */ + fz_try(ctx) + { + fz_new_font_context(ctx); + } + fz_catch(ctx) + { + goto cleanup; + } return ctx; diff --git a/fitz/fitz.h b/fitz/fitz.h index ae2c9105..1ae803a4 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -138,6 +138,7 @@ char *fz_get_error_line(int n); typedef struct fz_alloc_context_s fz_alloc_context; typedef struct fz_error_context_s fz_error_context; typedef struct fz_warn_context_s fz_warn_context; +typedef struct fz_font_context_s fz_font_context; typedef struct fz_context_s fz_context; struct fz_alloc_context_s @@ -189,6 +190,7 @@ struct fz_context_s fz_alloc_context *alloc; fz_error_context *error; fz_warn_context *warn; + fz_font_context *font; }; fz_context *fz_new_context(fz_alloc_context *alloc); @@ -829,6 +831,9 @@ struct fz_font_s int *width_table; }; +void fz_new_font_context(fz_context *ctx); +void fz_free_font_context(fz_context *ctx); + fz_font *fz_new_type3_font(fz_context *ctx, char *name, fz_matrix matrix); fz_font *fz_new_font_from_memory(fz_context *ctx, unsigned char *data, int len, int index); diff --git a/fitz/res_font.c b/fitz/res_font.c index a9a1fdf4..fa011d24 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -106,8 +106,10 @@ fz_set_font_bbox(fz_font *font, float xmin, float ymin, float xmax, float ymax) * Freetype hooks */ -static FT_Library fz_ftlib = NULL; -static int fz_ftlib_refs = 0; +struct fz_font_context_s { + FT_Library ftlib; + int ftlib_refs; +}; #undef __FTERRORS_H__ #define FT_ERRORDEF(e, v, s) { (e), (s) }, @@ -120,6 +122,22 @@ struct ft_error char *str; }; +void fz_new_font_context(fz_context *ctx) +{ + ctx->font = fz_malloc(ctx, sizeof(*ctx->font)); + ctx->font->ftlib = NULL; + ctx->font->ftlib_refs = 0; +} + +void fz_free_font_context(fz_context *ctx) +{ + if (ctx->font == NULL) + return; + /* assert(ctx->ftlib == NULL); */ + /* assert(ctx->ftlib_refs == 0); */ + fz_free(ctx, ctx->font); +} + static const struct ft_error ft_errors[] = { #include FT_ERRORS_H @@ -141,27 +159,28 @@ fz_init_freetype(fz_context *ctx) { int fterr; int maj, min, pat; + fz_font_context *fct = ctx->font; - if (fz_ftlib) + if (fct->ftlib) { - fz_ftlib_refs++; + fct->ftlib_refs++; return fz_okay; } - fterr = FT_Init_FreeType(&fz_ftlib); + fterr = FT_Init_FreeType(&fct->ftlib); if (fterr) return fz_error_make("cannot init freetype: %s", ft_error_string(fterr)); - FT_Library_Version(fz_ftlib, &maj, &min, &pat); + FT_Library_Version(fct->ftlib, &maj, &min, &pat); if (maj == 2 && min == 1 && pat < 7) { - fterr = FT_Done_FreeType(fz_ftlib); + fterr = FT_Done_FreeType(fct->ftlib); if (fterr) fz_warn(ctx, "freetype finalizing: %s", ft_error_string(fterr)); return fz_error_make("freetype version too old: %d.%d.%d", maj, min, pat); } - fz_ftlib_refs++; + fct->ftlib_refs++; return fz_okay; } @@ -169,13 +188,14 @@ static void fz_finalize_freetype(fz_context *ctx) { int fterr; + fz_font_context *fct = ctx->font; - if (--fz_ftlib_refs == 0) + if (--fct->ftlib_refs == 0) { - fterr = FT_Done_FreeType(fz_ftlib); + fterr = FT_Done_FreeType(fct->ftlib); if (fterr) fz_warn(ctx, "freetype finalizing: %s", ft_error_string(fterr)); - fz_ftlib = NULL; + fct->ftlib = NULL; } } @@ -191,7 +211,7 @@ fz_new_font_from_file(fz_context *ctx, char *path, int index) if (error) fz_throw(ctx, "cannot init freetype library"); - fterr = FT_New_Face(fz_ftlib, path, index, &face); + fterr = FT_New_Face(ctx->font->ftlib, path, index, &face); if (fterr) fz_throw(ctx, "freetype: cannot load font: %s", ft_error_string(fterr)); @@ -217,7 +237,7 @@ fz_new_font_from_memory(fz_context *ctx, unsigned char *data, int len, int index if (error) fz_throw(ctx, "cannot init freetype library"); - fterr = FT_New_Memory_Face(fz_ftlib, data, len, index, &face); + fterr = FT_New_Memory_Face(ctx->font->ftlib, data, len, index, &face); if (fterr) fz_throw(ctx, "freetype: cannot load font: %s", ft_error_string(fterr)); @@ -442,7 +462,7 @@ fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix tr return NULL; } - fterr = FT_Stroker_New(fz_ftlib, &stroker); + fterr = FT_Stroker_New(ctx->font->ftlib, &stroker); if (fterr) { fz_warn(ctx, "FT_Stroker_New: %s", ft_error_string(fterr)); diff --git a/scripts/cmapdump.c b/scripts/cmapdump.c index 9f75a401..af148765 100644 --- a/scripts/cmapdump.c +++ b/scripts/cmapdump.c @@ -172,3 +172,11 @@ main(int argc, char **argv) fz_free_context(ctx); return 0; } + +void fz_new_font_context(fz_context *ctx) +{ +} + +void fz_free_font_context(fz_context *ctx) +{ +} |