From b98c748a7c71f0a49f41a33411709b7051b9d4e7 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 10 May 2009 22:25:34 +0000 Subject: Pass entire context to freetype binding svn path=/trunk/tools/ttf2f/; revision=7458 --- src/cli.c | 10 +++++----- src/ft.c | 39 +++++++++++++++++++++------------------ src/ft.h | 17 +++++++++-------- src/outlines.c | 2 +- 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/cli.c b/src/cli.c index 128b93c..d1b167f 100644 --- a/src/cli.c +++ b/src/cli.c @@ -48,7 +48,7 @@ int main(int argc, char **argv) return 1; } - ctx.nglyphs = count_glyphs(ctx.face); + ctx.nglyphs = count_glyphs(&ctx); ctx.glyphs = calloc(ctx.nglyphs, sizeof(struct glyph)); if (ctx.glyphs == NULL) { @@ -69,25 +69,25 @@ int main(int argc, char **argv) return 1; } - fail = fnmetrics(ctx.face, ctx.metrics); + fail = fnmetrics(&ctx); if (fail) { fprintf(stderr, "ERROR: failed reading font metrics\n"); return 1; } - fail = glenc(ctx.face, ctx.glyphs); + fail = glenc(&ctx); if (fail) { fprintf(stderr, "ERROR: failed reading glyph encoding\n"); return 1; } - fail = glnames(ctx.face, ctx.glyphs); + fail = glnames(&ctx); if (fail) { fprintf(stderr, "ERROR: failed reading glyph names\n"); return 1; } - glmetrics(ctx.face, ctx.glyphs, progress); + glmetrics(&ctx, progress); mkdir(argv[2], 0755); diff --git a/src/ft.c b/src/ft.c index aa655f0..ccba8a7 100644 --- a/src/ft.c +++ b/src/ft.c @@ -82,9 +82,11 @@ void close_font(void *face) * Get the number of glyphs in font. */ -size_t count_glyphs(void *face) +size_t count_glyphs(ttf2f_ctx *ctx) { - return (size_t) ((FT_Face) face)->num_glyphs; + FT_Face f = (FT_Face) ctx->face; + + return (size_t) f->num_glyphs; } /* @@ -92,13 +94,14 @@ size_t count_glyphs(void *face) * Returns 0 if the names were assigned, non-zero on error */ -int glnames(void *face, struct glyph *glyph_list) +int glnames(ttf2f_ctx *ctx) { + FT_Face f = (FT_Face) ctx->face; int i; - for (i = 0; i != ((FT_Face) face)->num_glyphs; i++) { + for (i = 0; i != f->num_glyphs; i++) { ttf2f_poll(1); - glyph_list[i].name = glyph_name(glyph_list[i].code); + ctx->glyphs[i].name = glyph_name(ctx->glyphs[i].code); } return 0; @@ -108,10 +111,9 @@ int glnames(void *face, struct glyph *glyph_list) * Get the metrics of the glyphs. */ -void glmetrics(void *face, struct glyph *glyph_list, - void (*callback)(int progress)) +void glmetrics(ttf2f_ctx *ctx, void (*callback)(int progress)) { - FT_Face f = (FT_Face) face; + FT_Face f = (FT_Face) ctx->face; struct glyph *g; int i; FT_Glyph_Metrics *met; @@ -119,7 +121,7 @@ void glmetrics(void *face, struct glyph *glyph_list, FT_Glyph gly; for (i = 0; i < f->num_glyphs; i++) { - g = &(glyph_list[i]); + g = &ctx->glyphs[i]; callback(i * 100 / f->num_glyphs); ttf2f_poll(1); @@ -168,9 +170,9 @@ void glmetrics(void *face, struct glyph *glyph_list, * Map charcodes to glyph ids using the unicode encoding */ -int glenc(void *face, struct glyph *glyph_list) +int glenc(ttf2f_ctx *ctx) { - FT_Face f = (FT_Face) face; + FT_Face f = (FT_Face) ctx->face; unsigned charcode, glyphid; if (!f->charmaps || FT_Select_Charmap(f, FT_ENCODING_UNICODE)) { @@ -181,7 +183,7 @@ int glenc(void *face, struct glyph *glyph_list) charcode = FT_Get_First_Char(f, &glyphid); while (glyphid != 0) { ttf2f_poll(1); - glyph_list[glyphid].code = charcode; + ctx->glyphs[glyphid].code = charcode; charcode = FT_Get_Next_Char(f, charcode, &glyphid); } @@ -191,9 +193,10 @@ int glenc(void *face, struct glyph *glyph_list) /* * Get the font metrics */ -int fnmetrics(void *face, struct font_metrics *fm) +int fnmetrics(ttf2f_ctx *ctx) { - FT_Face f = (FT_Face) face; + FT_Face f = (FT_Face) ctx->face; + struct font_metrics *fm = ctx->metrics; char *str; static char *fieldstocheck[3]; FT_SfntName sn; @@ -455,14 +458,14 @@ static FT_Outline_Funcs ft_outl_funcs = { * Get the path of contours for a glyph. */ -void glpath(void *face, int glyphno, struct glyph *glyf_list) +void glpath(ttf2f_ctx *ctx, int glyphno) { - FT_Face f = (FT_Face) face; + FT_Face f = (FT_Face) ctx->face; FT_Outline *ol; FT_Glyph gly; struct outline *o; - curg = &glyf_list[glyphno]; + curg = &ctx->glyphs[glyphno]; cur_outline_entry = 0; if (FT_Load_Glyph(f, glyphno, @@ -512,7 +515,7 @@ void glpath(void *face, int glyphno, struct glyph *glyf_list) * Get the kerning data. */ -void kerning(struct glyph *glyph_list) +void kerning(ttf2f_ctx *ctx) { int i, j, n; int nglyphs = face->num_glyphs; diff --git a/src/ft.h b/src/ft.h index db3db19..fc60c91 100644 --- a/src/ft.h +++ b/src/ft.h @@ -1,6 +1,8 @@ #ifndef _TTF2F_FT_H_ #define _TTF2F_FT_H_ +#include "context.h" + struct font_metrics; struct glyph; @@ -8,14 +10,13 @@ void ft_init(void); void ft_fini(void); void *open_font(char *fname); void close_font(void *face); -size_t count_glyphs(void *face); -int glnames(void *face, struct glyph *glyph_list); -void glmetrics(void *face, struct glyph *glyph_list, - void (*callback)(int progress)); -int glenc(void *face, struct glyph *glyph_list); -int fnmetrics(void *face, struct font_metrics *fm); -void glpath(void *face, int glyphno, struct glyph *glyph_list); -void kerning(void *face, struct glyph *glyph_list); +size_t count_glyphs(ttf2f_ctx *ctx); +int glnames(ttf2f_ctx *ctx); +void glmetrics(ttf2f_ctx *ctx, void (*callback)(int progress)); +int glenc(ttf2f_ctx *ctx); +int fnmetrics(ttf2f_ctx *ctx); +void glpath(ttf2f_ctx *ctx, int glyphno); +void kerning(ttf2f_ctx *ctx); #endif diff --git a/src/outlines.c b/src/outlines.c index 3e27f54..77b8266 100644 --- a/src/outlines.c +++ b/src/outlines.c @@ -236,7 +236,7 @@ ttf2f_result write_chunk(FILE* file, int chunk_no, ttf2f_ctx *ctx, character->xsys[2] = ((g->yMax - g->yMin) >> 4) & 0xFF; /* decompose glyph path */ - glpath(ctx->face, (chunk_no * 32) + i, ctx->glyphs); + glpath(ctx, (chunk_no * 32) + i); for (o = g->outline; o; o = next) { if (!o) -- cgit v1.2.3