summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-10 22:11:32 (GMT)
committer John Mark Bell <jmb@netsurf-browser.org>2009-05-10 22:11:32 (GMT)
commitbf56a5b19e6019b0f0b2bafe5388737da17f5224 (patch)
treeb4802abbc53509bcffc659f3fbdd6da5827ecc77
parent9270294d7d5de0dcfb680596a3f8e51365062358 (diff)
downloadttf2f-bf56a5b19e6019b0f0b2bafe5388737da17f5224.tar.gz
ttf2f-bf56a5b19e6019b0f0b2bafe5388737da17f5224.tar.bz2
Make proper use of conversion context
svn path=/trunk/tools/ttf2f/; revision=7457
-rw-r--r--src/cli.c28
-rw-r--r--src/context.h2
-rw-r--r--src/encoding.c19
-rw-r--r--src/encoding.h3
-rw-r--r--src/ft.c191
-rw-r--r--src/ft.h19
-rw-r--r--src/intmetrics.c18
-rw-r--r--src/intmetrics.h4
-rw-r--r--src/outlines.c47
-rw-r--r--src/outlines.h6
10 files changed, 162 insertions, 175 deletions
diff --git a/src/cli.c b/src/cli.c
index 5ec85ff..128b93c 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -42,13 +42,13 @@ int main(int argc, char **argv)
if ((err = glyph_load_list()) != TTF2F_RESULT_OK)
goto error_out;
- fail = open_font(argv[1]);
- if (fail) {
+ ctx.face = open_font(argv[1]);
+ if (ctx.face == NULL) {
fprintf(stderr, "ERROR: Failed opening font %s\n", argv[1]);
return 1;
}
- ctx.nglyphs = count_glyphs();
+ ctx.nglyphs = count_glyphs(ctx.face);
ctx.glyphs = calloc(ctx.nglyphs, sizeof(struct glyph));
if (ctx.glyphs == NULL) {
@@ -69,36 +69,36 @@ int main(int argc, char **argv)
return 1;
}
- fail = fnmetrics(ctx.metrics);
+ fail = fnmetrics(ctx.face, ctx.metrics);
if (fail) {
fprintf(stderr, "ERROR: failed reading font metrics\n");
return 1;
}
- fail = glenc(ctx.glyphs);
+ fail = glenc(ctx.face, ctx.glyphs);
if (fail) {
fprintf(stderr, "ERROR: failed reading glyph encoding\n");
return 1;
}
- fail = glnames(ctx.glyphs);
+ fail = glnames(ctx.face, ctx.glyphs);
if (fail) {
fprintf(stderr, "ERROR: failed reading glyph names\n");
return 1;
}
- glmetrics(ctx.glyphs, progress);
+ glmetrics(ctx.face, ctx.glyphs, progress);
mkdir(argv[2], 0755);
- if ((err = intmetrics_write(argv[2], argv[2], ctx.glyphs, ctx.nglyphs,
- ctx.metrics, progress)) != TTF2F_RESULT_OK) goto error_out;
+ if ((err = intmetrics_write(argv[2], argv[2], &ctx, progress)) !=
+ TTF2F_RESULT_OK) goto error_out;
- if ((err = outlines_write(argv[2], argv[2], ctx.glyphs, ctx.nglyphs,
- ctx.metrics, progress)) != TTF2F_RESULT_OK) goto error_out;
+ if ((err = outlines_write(argv[2], argv[2], &ctx, progress)) !=
+ TTF2F_RESULT_OK) goto error_out;
- if ((err = encoding_write(argv[2], argv[2], ctx.glyphs, ctx.nglyphs,
- 0, progress)) != TTF2F_RESULT_OK) goto error_out;
+ if ((err = encoding_write(argv[2], argv[2], &ctx, 0, progress)) !=
+ TTF2F_RESULT_OK) goto error_out;
error_out:
if (err != TTF2F_RESULT_OK) {
@@ -124,7 +124,7 @@ error_out:
free(ctx.metrics);
free(ctx.glyphs);
- close_font();
+ close_font(ctx.face);
ft_fini();
glyph_destroy_list();
diff --git a/src/context.h b/src/context.h
index b89fa7f..f854f5e 100644
--- a/src/context.h
+++ b/src/context.h
@@ -7,6 +7,8 @@
typedef struct ttf2f_ctx ttf2f_ctx;
struct ttf2f_ctx {
+ void *face;
+
struct font_metrics *metrics;
size_t nglyphs;
diff --git a/src/encoding.c b/src/encoding.c
index 2b65da3..ae4b43c 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -11,18 +11,17 @@
*
* \param savein Location to save in
* \param name The font name
- * \param glyph_list List of all glyphs in the font
- * \param list_size Size of glyph list
+ * \param ctx Conversion context
* \param type File format to use - 0 = full; 1 = sparse
* \param callback Progress callback function
*/
ttf2f_result encoding_write(const char *savein, const char *name,
- struct glyph *glyph_list, int list_size, encoding_type type,
+ ttf2f_ctx *ctx, encoding_type type,
void (*callback)(int progress))
{
FILE *output;
struct glyph *g;
- int i;
+ size_t i;
char out[1024];
snprintf(out, 1024, "%s" DIR_SEP "Encoding", savein);
@@ -38,10 +37,10 @@ ttf2f_result encoding_write(const char *savein, const char *name,
}
}
- for (i = 0; i != list_size; i++) {
- g = &glyph_list[i];
+ for (i = 0; i != ctx->nglyphs; i++) {
+ g = &ctx->glyphs[i];
- callback(i * 100 / list_size);
+ callback(i * 100 / ctx->nglyphs);
ttf2f_poll(1);
if (type == ENCODING_TYPE_SPARSE) {
@@ -49,13 +48,13 @@ ttf2f_result encoding_write(const char *savein, const char *name,
/* .notdef is implicit */
if (strcmp(g->name, ".notdef") == 0)
continue;
- fprintf(output, "%4.4X;%s;COMMENT\n", i+32,
+ fprintf(output, "%4.4zX;%s;COMMENT\n", i+32,
g->name);
} else if (g->code != (unsigned int) -1) {
- fprintf(output, "%4.4X;uni%04X;COMMENT\n",
+ fprintf(output, "%4.4zX;uni%04X;COMMENT\n",
i+32, g->code);
} else {
- fprintf(output, "# Skipping %4.4X\n", i+32);
+ fprintf(output, "# Skipping %4.4zX\n", i+32);
}
} else {
if (g->name != 0) {
diff --git a/src/encoding.h b/src/encoding.h
index 49b4e29..3f7ccf0 100644
--- a/src/encoding.h
+++ b/src/encoding.h
@@ -1,6 +1,7 @@
#ifndef _TTF2F_ENCODING_H_
#define _TTF2F_ENCODING_H_
+#include "context.h"
#include "utils.h"
typedef enum encoding_type {
@@ -11,7 +12,7 @@ typedef enum encoding_type {
struct glyph;
ttf2f_result encoding_write(const char *savein, const char *name,
- struct glyph *glyph_list, int list_size, encoding_type type,
+ ttf2f_ctx *ctx, encoding_type type,
void (*callback)(int progress));
#endif
diff --git a/src/ft.c b/src/ft.c
index 4e48aeb..aa655f0 100644
--- a/src/ft.c
+++ b/src/ft.c
@@ -27,7 +27,6 @@
/* statics */
static FT_Library library;
-static FT_Face face;
void ft_init(void)
{
@@ -39,9 +38,6 @@ void ft_init(void)
void ft_fini(void)
{
- if (face)
- close_font();
-
if (FT_Done_FreeType(library)) {
fprintf(stderr, "Errors when stopping FreeType, ignored\n");
}
@@ -52,8 +48,9 @@ void ft_fini(void)
* May print error and warning messages.
*/
-int open_font(char *fname)
+void *open_font(char *fname)
{
+ FT_Face face;
FT_Error error;
if ((error = FT_New_Face(library, fname, 0, &face)) != 0) {
@@ -63,10 +60,10 @@ int open_font(char *fname)
fname);
} else
fprintf(stderr, "**** Cannot access %s ****\n", fname);
- return 1;
+ return NULL;
}
- return 0;
+ return face;
}
/*
@@ -74,22 +71,20 @@ int open_font(char *fname)
* Exit on error.
*/
-void close_font(void)
+void close_font(void *face)
{
- if (FT_Done_Face(face)) {
+ if (FT_Done_Face((FT_Face) face)) {
fprintf(stderr, "Errors when closing the font file, ignored\n");
}
-
- face = 0;
}
/*
* Get the number of glyphs in font.
*/
-int count_glyphs(void)
+size_t count_glyphs(void *face)
{
- return (int) face->num_glyphs;
+ return (size_t) ((FT_Face) face)->num_glyphs;
}
/*
@@ -97,11 +92,11 @@ int count_glyphs(void)
* Returns 0 if the names were assigned, non-zero on error
*/
-int glnames(struct glyph *glyph_list)
+int glnames(void *face, struct glyph *glyph_list)
{
int i;
- for (i = 0; i != face->num_glyphs; i++) {
+ for (i = 0; i != ((FT_Face) face)->num_glyphs; i++) {
ttf2f_poll(1);
glyph_list[i].name = glyph_name(glyph_list[i].code);
}
@@ -113,43 +108,44 @@ int glnames(struct glyph *glyph_list)
* Get the metrics of the glyphs.
*/
-void glmetrics(struct glyph *glyph_list, void (*callback)(int progress))
+void glmetrics(void *face, struct glyph *glyph_list,
+ void (*callback)(int progress))
{
+ FT_Face f = (FT_Face) face;
struct glyph *g;
int i;
FT_Glyph_Metrics *met;
FT_BBox bbox;
FT_Glyph gly;
- for (i = 0; i < face->num_glyphs; i++) {
+ for (i = 0; i < f->num_glyphs; i++) {
g = &(glyph_list[i]);
- callback(i * 100 / face->num_glyphs);
+ callback(i * 100 / f->num_glyphs);
ttf2f_poll(1);
- if (FT_Load_Glyph(face, i,
- FT_LOAD_NO_BITMAP|FT_LOAD_NO_SCALE)) {
+ if (FT_Load_Glyph(f, i, FT_LOAD_NO_BITMAP|FT_LOAD_NO_SCALE)) {
fprintf(stderr, "Can't load glyph %s, skipped\n",
g->name);
continue;
}
- met = &face->glyph->metrics;
+ met = &f->glyph->metrics;
- if (FT_HAS_HORIZONTAL(face)) {
+ if (FT_HAS_HORIZONTAL(f)) {
g->width = convert_units(met->horiAdvance,
- face->units_per_EM);
+ f->units_per_EM);
g->lsb = convert_units(met->horiBearingX,
- face->units_per_EM);
+ f->units_per_EM);
} else {
fprintf(stderr, "Glyph %s has no horizontal metrics\n",
g->name);
g->width = convert_units(met->width,
- face->units_per_EM);
+ f->units_per_EM);
g->lsb = 0;
}
- if (FT_Get_Glyph(face->glyph, &gly)) {
+ if (FT_Get_Glyph(f->glyph, &gly)) {
fprintf(stderr,
"Can't access glyph %s bbox, skipped\n",
g->name);
@@ -157,12 +153,12 @@ void glmetrics(struct glyph *glyph_list, void (*callback)(int progress))
}
FT_Glyph_Get_CBox(gly, ft_glyph_bbox_unscaled, &bbox);
- g->xMin = convert_units(bbox.xMin, face->units_per_EM);
- g->yMin = convert_units(bbox.yMin, face->units_per_EM);
- g->xMax = convert_units(bbox.xMax, face->units_per_EM);
- g->yMax = convert_units(bbox.yMax, face->units_per_EM);
+ g->xMin = convert_units(bbox.xMin, f->units_per_EM);
+ g->yMin = convert_units(bbox.yMin, f->units_per_EM);
+ g->xMax = convert_units(bbox.xMax, f->units_per_EM);
+ g->yMax = convert_units(bbox.yMax, f->units_per_EM);
- g->ttf_pathlen = face->glyph->outline.n_points;
+ g->ttf_pathlen = f->glyph->outline.n_points;
FT_Done_Glyph(gly);
}
@@ -172,20 +168,21 @@ void glmetrics(struct glyph *glyph_list, void (*callback)(int progress))
* Map charcodes to glyph ids using the unicode encoding
*/
-int glenc(struct glyph *glyph_list)
+int glenc(void *face, struct glyph *glyph_list)
{
+ FT_Face f = (FT_Face) face;
unsigned charcode, glyphid;
- if (!face->charmaps || FT_Select_Charmap(face, FT_ENCODING_UNICODE)) {
+ if (!f->charmaps || FT_Select_Charmap(f, FT_ENCODING_UNICODE)) {
fprintf(stderr, "**** Cannot set charmap in FreeType ****\n");
return 1;
}
- charcode = FT_Get_First_Char(face, &glyphid);
+ charcode = FT_Get_First_Char(f, &glyphid);
while (glyphid != 0) {
ttf2f_poll(1);
glyph_list[glyphid].code = charcode;
- charcode = FT_Get_Next_Char(face, charcode, &glyphid);
+ charcode = FT_Get_Next_Char(f, charcode, &glyphid);
}
return 0;
@@ -194,52 +191,53 @@ int glenc(struct glyph *glyph_list)
/*
* Get the font metrics
*/
-int fnmetrics(struct font_metrics *fm)
+int fnmetrics(void *face, struct font_metrics *fm)
{
+ FT_Face f = (FT_Face) face;
char *str;
static char *fieldstocheck[3];
FT_SfntName sn;
TT_Postscript *post;
int i, j, len;
- fm->underline_position = convert_units(face->underline_position,
- face->units_per_EM);
- fm->underline_thickness = convert_units(face->underline_thickness,
- face->units_per_EM);
- fm->is_fixed_pitch = FT_IS_FIXED_WIDTH(face);
+ fm->underline_position = convert_units(f->underline_position,
+ f->units_per_EM);
+ fm->underline_thickness = convert_units(f->underline_thickness,
+ f->units_per_EM);
+ fm->is_fixed_pitch = FT_IS_FIXED_WIDTH(f);
- fm->ascender = convert_units(face->ascender, face->units_per_EM);
- fm->descender = convert_units(face->descender, face->units_per_EM);
+ fm->ascender = convert_units(f->ascender, f->units_per_EM);
+ fm->descender = convert_units(f->descender, f->units_per_EM);
- fm->units_per_em = face->units_per_EM;
+ fm->units_per_em = f->units_per_EM;
- fm->bbox[0] = convert_units(face->bbox.xMin, face->units_per_EM);
- fm->bbox[1] = convert_units(face->bbox.yMin, face->units_per_EM);
- fm->bbox[2] = convert_units(face->bbox.xMax, face->units_per_EM);
- fm->bbox[3] = convert_units(face->bbox.yMax, face->units_per_EM);
+ fm->bbox[0] = convert_units(f->bbox.xMin, f->units_per_EM);
+ fm->bbox[1] = convert_units(f->bbox.yMin, f->units_per_EM);
+ fm->bbox[2] = convert_units(f->bbox.xMax, f->units_per_EM);
+ fm->bbox[3] = convert_units(f->bbox.yMax, f->units_per_EM);
- if ((post = (TT_Postscript*)FT_Get_Sfnt_Table(face,
- ft_sfnt_post)) != NULL) {
+ if ((post = (TT_Postscript*) FT_Get_Sfnt_Table(f,
+ ft_sfnt_post)) != NULL) {
fm->italic_angle = post->italicAngle;
} else {
fprintf(stderr, "hidden");
fm->italic_angle = 0.0; /* FreeType hides the angle */
}
- if (FT_Get_Sfnt_Name(face, TT_NAME_ID_COPYRIGHT, &sn)) {
+ if (FT_Get_Sfnt_Name(f, TT_NAME_ID_COPYRIGHT, &sn)) {
fm->name_copyright = (char *) "";
} else {
fm->name_copyright = strndup((const char*)sn.string,
sn.string_len);
}
- fm->name_family = face->family_name;
+ fm->name_family = f->family_name;
- fm->name_style = face->style_name;
+ fm->name_style = f->style_name;
if (fm->name_style == NULL)
fm->name_style = (char *) "";
- if (FT_Get_Sfnt_Name(face, TT_NAME_ID_FULL_NAME, &sn)) {
+ if (FT_Get_Sfnt_Name(f, TT_NAME_ID_FULL_NAME, &sn)) {
int len;
len = strlen(fm->name_family) + strlen(fm->name_style) + 2;
@@ -256,14 +254,14 @@ int fnmetrics(struct font_metrics *fm)
} else
fm->name_full = strndup((const char*)sn.string, sn.string_len);
- if (FT_Get_Sfnt_Name(face, TT_NAME_ID_VERSION_STRING, &sn)) {
+ if (FT_Get_Sfnt_Name(f, TT_NAME_ID_VERSION_STRING, &sn)) {
fm->name_version = (char *) "1.0";
} else {
fm->name_version = strndup((const char*)sn.string,
sn.string_len);
}
- if (FT_Get_Sfnt_Name(face, TT_NAME_ID_PS_NAME , &sn)) {
+ if (FT_Get_Sfnt_Name(f, TT_NAME_ID_PS_NAME , &sn)) {
if ((fm->name_ps = strdup(fm->name_full)) == NULL) {
fprintf(stderr, "****malloc failed %s line %d\n",
__FILE__, __LINE__);
@@ -314,12 +312,11 @@ static struct glyph *curg;
static struct outline *cur_outline_entry;
static long lastx, lasty;
-static int outl_moveto(const FT_Vector *to, void *unused)
+static int outl_moveto(const FT_Vector *to, void *face)
{
+ FT_Face f = (FT_Face) face;
struct outline *o;
- UNUSED(unused);
-
o = calloc(1, sizeof(struct outline));
if (!o) {
fprintf(stderr, "malloc failed\n");
@@ -327,8 +324,8 @@ static int outl_moveto(const FT_Vector *to, void *unused)
}
o->type = MOVE_TO;
- o->data.move_to.x = convert_units(to->x, face->units_per_EM);
- o->data.move_to.y = convert_units(to->y, face->units_per_EM);
+ o->data.move_to.x = convert_units(to->x, f->units_per_EM);
+ o->data.move_to.y = convert_units(to->y, f->units_per_EM);
if (cur_outline_entry)
cur_outline_entry->next = o;
@@ -336,18 +333,17 @@ static int outl_moveto(const FT_Vector *to, void *unused)
curg->outline = o;
cur_outline_entry = o;
- lastx = convert_units(to->x, face->units_per_EM);
- lasty = convert_units(to->y, face->units_per_EM);
+ lastx = convert_units(to->x, f->units_per_EM);
+ lasty = convert_units(to->y, f->units_per_EM);
return 0;
}
-static int outl_lineto(const FT_Vector *to, void *unused)
+static int outl_lineto(const FT_Vector *to, void *face)
{
+ FT_Face f = (FT_Face) face;
struct outline *o;
- UNUSED(unused);
-
o = calloc(1, sizeof(struct outline));
if (!o) {
fprintf(stderr, "malloc failed\n");
@@ -355,8 +351,8 @@ static int outl_lineto(const FT_Vector *to, void *unused)
}
o->type = LINE_TO;
- o->data.line_to.x = convert_units(to->x, face->units_per_EM);
- o->data.line_to.y = convert_units(to->y, face->units_per_EM);
+ o->data.line_to.x = convert_units(to->x, f->units_per_EM);
+ o->data.line_to.y = convert_units(to->y, f->units_per_EM);
if (cur_outline_entry)
cur_outline_entry->next = o;
@@ -364,20 +360,19 @@ static int outl_lineto(const FT_Vector *to, void *unused)
curg->outline = o;
cur_outline_entry = o;
- lastx = convert_units(to->x, face->units_per_EM);
- lasty = convert_units(to->y, face->units_per_EM);
+ lastx = convert_units(to->x, f->units_per_EM);
+ lasty = convert_units(to->y, f->units_per_EM);
return 0;
}
static int outl_conicto(const FT_Vector *control1, const FT_Vector *to,
- void *unused)
+ void *face)
{
+ FT_Face f = (FT_Face) face;
struct outline *o;
double c1x, c1y;
- UNUSED(unused);
-
o = calloc(1, sizeof(struct outline));
if (!o) {
fprintf(stderr, "malloc failed\n");
@@ -385,23 +380,23 @@ static int outl_conicto(const FT_Vector *control1, const FT_Vector *to,
}
c1x = (double)lastx + 2.0 *
- ((double)convert_units(control1->x, face->units_per_EM) -
+ ((double)convert_units(control1->x, f->units_per_EM) -
(double)lastx) / 3.0;
c1y = (double)lasty + 2.0 *
- ((double)convert_units(control1->y, face->units_per_EM) -
+ ((double)convert_units(control1->y, f->units_per_EM) -
(double)lasty) / 3.0;
o->type = CURVE;
o->data.curve.x1 = (int)c1x;
o->data.curve.y1 = (int)c1y;
o->data.curve.x2 = (int)(c1x +
- ((double)convert_units(to->x, face->units_per_EM) -
+ ((double)convert_units(to->x, f->units_per_EM) -
(double)lastx) / 3.0);
o->data.curve.y2 = (int)(c1y +
- ((double)convert_units(to->y, face->units_per_EM) -
+ ((double)convert_units(to->y, f->units_per_EM) -
(double)lasty) / 3.0);
- o->data.curve.x3 = convert_units(to->x, face->units_per_EM);
- o->data.curve.y3 = convert_units(to->y, face->units_per_EM);
+ o->data.curve.x3 = convert_units(to->x, f->units_per_EM);
+ o->data.curve.y3 = convert_units(to->y, f->units_per_EM);
if (cur_outline_entry)
cur_outline_entry->next = o;
@@ -409,19 +404,18 @@ static int outl_conicto(const FT_Vector *control1, const FT_Vector *to,
curg->outline = o;
cur_outline_entry = o;
- lastx = convert_units(to->x, face->units_per_EM);
- lasty = convert_units(to->y, face->units_per_EM);
+ lastx = convert_units(to->x, f->units_per_EM);
+ lasty = convert_units(to->y, f->units_per_EM);
return 0;
}
static int outl_cubicto(const FT_Vector *control1, const FT_Vector *control2,
- const FT_Vector *to, void *unused)
+ const FT_Vector *to, void *face)
{
+ FT_Face f = (FT_Face) face;
struct outline *o;
- UNUSED(unused);
-
o = calloc(1, sizeof(struct outline));
if (!o) {
fprintf(stderr, "malloc failed\n");
@@ -429,12 +423,12 @@ static int outl_cubicto(const FT_Vector *control1, const FT_Vector *control2,
}
o->type = CURVE;
- o->data.curve.x1 = convert_units(control1->x, face->units_per_EM);
- o->data.curve.y1 = convert_units(control1->y, face->units_per_EM);
- o->data.curve.x2 = convert_units(control2->x, face->units_per_EM);
- o->data.curve.y2 = convert_units(control2->y, face->units_per_EM);
- o->data.curve.x3 = convert_units(to->x, face->units_per_EM);
- o->data.curve.y3 = convert_units(to->y, face->units_per_EM);
+ o->data.curve.x1 = convert_units(control1->x, f->units_per_EM);
+ o->data.curve.y1 = convert_units(control1->y, f->units_per_EM);
+ o->data.curve.x2 = convert_units(control2->x, f->units_per_EM);
+ o->data.curve.y2 = convert_units(control2->y, f->units_per_EM);
+ o->data.curve.x3 = convert_units(to->x, f->units_per_EM);
+ o->data.curve.y3 = convert_units(to->y, f->units_per_EM);
if (cur_outline_entry)
cur_outline_entry->next = o;
@@ -442,8 +436,8 @@ static int outl_cubicto(const FT_Vector *control1, const FT_Vector *control2,
curg->outline = o;
cur_outline_entry = o;
- lastx = convert_units(to->x, face->units_per_EM);
- lasty = convert_units(to->y, face->units_per_EM);
+ lastx = convert_units(to->x, f->units_per_EM);
+ lasty = convert_units(to->y, f->units_per_EM);
return 0;
}
@@ -461,8 +455,9 @@ static FT_Outline_Funcs ft_outl_funcs = {
* Get the path of contours for a glyph.
*/
-void glpath(int glyphno, struct glyph *glyf_list)
+void glpath(void *face, int glyphno, struct glyph *glyf_list)
{
+ FT_Face f = (FT_Face) face;
FT_Outline *ol;
FT_Glyph gly;
struct outline *o;
@@ -470,17 +465,17 @@ void glpath(int glyphno, struct glyph *glyf_list)
curg = &glyf_list[glyphno];
cur_outline_entry = 0;
- if (FT_Load_Glyph(face, glyphno,
+ if (FT_Load_Glyph(f, glyphno,
FT_LOAD_NO_BITMAP|FT_LOAD_NO_SCALE|FT_LOAD_NO_HINTING)
- || face->glyph->format != ft_glyph_format_outline) {
+ || f->glyph->format != ft_glyph_format_outline) {
fprintf(stderr, "Can't load glyph %s, skipped\n", curg->name);
return;
}
- ol = &face->glyph->outline;
+ ol = &f->glyph->outline;
lastx = 0; lasty = 0;
- if (FT_Outline_Decompose(ol, &ft_outl_funcs, NULL)) {
+ if (FT_Outline_Decompose(ol, &ft_outl_funcs, f)) {
fprintf(stderr,
"Can't decompose outline of glyph %s, skipped\n",
curg->name);
@@ -503,7 +498,7 @@ void glpath(int glyphno, struct glyph *glyf_list)
curg->outline = o;
cur_outline_entry = o;
- if (FT_Get_Glyph(face->glyph, &gly)) {
+ if (FT_Get_Glyph(f->glyph, &gly)) {
fprintf(stderr, "Can't access glyph %s bbox, skipped\n",
curg->name);
return;
diff --git a/src/ft.h b/src/ft.h
index eb9c9ad..db3db19 100644
--- a/src/ft.h
+++ b/src/ft.h
@@ -6,15 +6,16 @@ struct glyph;
void ft_init(void);
void ft_fini(void);
-int open_font(char *fname);
-void close_font(void);
-int count_glyphs(void);
-int glnames(struct glyph *glyph_list);
-void glmetrics(struct glyph *glyph_list, void (*callback)(int progress));
-int glenc(struct glyph *glyph_list);
-int fnmetrics(struct font_metrics *fm);
-void glpath(int glyphno, struct glyph *glyph_list);
-void kerning(struct glyph *glyph_list);
+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);
#endif
diff --git a/src/intmetrics.c b/src/intmetrics.c
index 1f9f4aa..6b9c297 100644
--- a/src/intmetrics.c
+++ b/src/intmetrics.c
@@ -68,26 +68,20 @@ struct kern_pair_16 {
*
* \param savein Location to save in
* \param name Font name
- * \param glyph_list List of all glyphs in font
- * \param list_size Size of glyph list
- * \param metrics Global font metrics
+ * \param context Conversion context
*/
ttf2f_result intmetrics_write(const char *savein, const char *name,
- const struct glyph *glyph_list, int list_size,
- const struct font_metrics *metrics,
- void (*callback)(int progress))
+ ttf2f_ctx *ctx, void (*callback)(int progress))
{
struct intmetrics_header header;
short *xwidthtab = NULL;
unsigned int xwidthtab_size = 0;
short mapsize;
- int i, name_len;
+ size_t i, name_len;
const struct glyph *g;
char out[1024];
FILE *output;
- UNUSED(metrics);
-
/* allow for chunk 0 */
xwidthtab = calloc(33, sizeof(short));
if (xwidthtab == NULL)
@@ -96,12 +90,12 @@ ttf2f_result intmetrics_write(const char *savein, const char *name,
xwidthtab_size = 32;
/* create xwidthtab - char code is now the index */
- for (i = 0; i != list_size; i++) {
+ for (i = 0; i != ctx->nglyphs; i++) {
short *temp;
- g = &glyph_list[i];
+ g = &ctx->glyphs[i];
- callback((i * 100) / list_size);
+ callback((i * 100) / ctx->nglyphs);
ttf2f_poll(1);
xwidthtab_size++;
diff --git a/src/intmetrics.h b/src/intmetrics.h
index ec1caf0..3d5add2 100644
--- a/src/intmetrics.h
+++ b/src/intmetrics.h
@@ -1,14 +1,14 @@
#ifndef _TTF2F_INTMETRICS_H_
#define _TTF2F_INTMETRICS_H_
+#include "context.h"
#include "utils.h"
struct glyph;
struct font_metrics;
ttf2f_result intmetrics_write(const char *savein,
- const char *name, const struct glyph *glyph_list,
- int list_size, const struct font_metrics *metrics,
+ const char *name, ttf2f_ctx *ctx,
void (*callback)(int progress));
#endif
diff --git a/src/outlines.c b/src/outlines.c
index 8a0d0ec..3e27f54 100644
--- a/src/outlines.c
+++ b/src/outlines.c
@@ -12,8 +12,7 @@
#include "outlines.h"
#include "utils.h"
-ttf2f_result write_chunk(FILE* file, int chunk_no,
- struct glyph *glyph_list, int list_size,
+ttf2f_result write_chunk(FILE* file, int chunk_no, ttf2f_ctx *ctx,
unsigned int *out_chunk_size);
/**
@@ -21,13 +20,10 @@ ttf2f_result write_chunk(FILE* file, int chunk_no,
*
* \param savein Location to save in
* \param name Font name
- * \param glyph_list List of all glyphs in font
- * \param list_size Size of glyph list
- * \param metrics Global font metrics
+ * \param ctx Conversion context
*/
ttf2f_result outlines_write(const char *savein, const char *name,
- struct glyph *glyph_list, int list_size,
- const struct font_metrics *metrics,
+ ttf2f_ctx *ctx,
void (*callback)(int progress))
{
struct outlines_header header;
@@ -45,13 +41,13 @@ ttf2f_result outlines_write(const char *savein, const char *name,
header.bpp = 0;
header.version = 8;
header.flags = 1000; /* design size of converted font */
- header.x0 = metrics->bbox[0];
- header.y0 = metrics->bbox[1];
- header.X = metrics->bbox[2] - metrics->bbox[0];
- header.Y = metrics->bbox[3] - metrics->bbox[1];
+ header.x0 = ctx->metrics->bbox[0];
+ header.y0 = ctx->metrics->bbox[1];
+ header.X = ctx->metrics->bbox[2] - ctx->metrics->bbox[0];
+ header.Y = ctx->metrics->bbox[3] - ctx->metrics->bbox[1];
header.chunk_data.chunk_table_offset =
sizeof(struct outlines_header) + ((table_end_len + 6) & ~3);
- header.chunk_data.nchunks = (list_size / 32) + 2;
+ header.chunk_data.nchunks = (ctx->nglyphs / 32) + 2;
header.chunk_data.num_scaffold = 1; /* no scaffold lines */
header.chunk_data.scaffold_flags = OUTLINES_SCAFFOLD_16BIT |
OUTLINES_SCAFFOLD_NON_ZERO_WINDING;
@@ -100,10 +96,11 @@ ttf2f_result outlines_write(const char *savein, const char *name,
if (fputc(0x0, output) == EOF) goto error_write;
if (fprintf(output,
"\n\n\n%s is %s\nConverted to RISC OS by TTF2F\n\n\n",
- metrics->name_full, metrics->name_copyright) < 0) goto error_write;
+ ctx->metrics->name_full,
+ ctx->metrics->name_copyright) < 0) goto error_write;
if (fputc(0x0, output) == EOF) goto error_write;
- current_chunk_offset += 42 + strlen(metrics->name_full) +
- strlen(metrics->name_copyright);
+ current_chunk_offset += 42 + strlen(ctx->metrics->name_full) +
+ strlen(ctx->metrics->name_copyright);
while(current_chunk_offset % 4) {
if (fputc(0x0, output) == EOF) goto error_write;
@@ -122,15 +119,15 @@ ttf2f_result outlines_write(const char *savein, const char *name,
unsigned int chunk_size;
ttf2f_result err;
- callback((chunk_table_entry * 100) / ((list_size / 32) + 2));
+ callback((chunk_table_entry * 100) / ((ctx->nglyphs / 32) + 2));
ttf2f_poll(1);
/* seek to start of current chunk */
fseek(output, current_chunk_offset, SEEK_SET);
/* write chunk */
- err = write_chunk(output, chunk_table_entry - 1, glyph_list,
- list_size, &chunk_size);
+ err = write_chunk(output, chunk_table_entry - 1, ctx,
+ &chunk_size);
if (err != TTF2F_RESULT_OK) {
fclose(output);
@@ -172,12 +169,10 @@ error_write:
*
* \param file Stream handle
* \param chunk_no The current chunk number (0..nchunks-1)
- * \param glyph_list List of all glyphs in font
- * \param list_size Size of glyph list
+ * \param ctx Conversion context
* \return Size of this chunk, or 0 on failure
*/
-ttf2f_result write_chunk(FILE* file, int chunk_no,
- struct glyph *glyph_list, int list_size,
+ttf2f_result write_chunk(FILE* file, int chunk_no, ttf2f_ctx *ctx,
unsigned int *out_chunk_size)
{
const struct glyph *g;
@@ -185,7 +180,7 @@ ttf2f_result write_chunk(FILE* file, int chunk_no,
unsigned int chunk_size;
struct outline *o, *next;
struct char_data *character;
- int i;
+ size_t i;
*out_chunk_size = 0;
@@ -203,12 +198,12 @@ ttf2f_result write_chunk(FILE* file, int chunk_no,
ttf2f_poll(1);
- if ((chunk_no * 32) + i >= list_size)
+ if ((chunk_no * 32) + i >= ctx->nglyphs)
/* exit if we've reached the end of the input */
break;
/* get glyph */
- g = &glyph_list[(chunk_no * 32) + i];
+ g = &ctx->glyphs[(chunk_no * 32) + i];
/* no path => skip character */
if (g->ttf_pathlen == 0) {
@@ -241,7 +236,7 @@ ttf2f_result write_chunk(FILE* file, int chunk_no,
character->xsys[2] = ((g->yMax - g->yMin) >> 4) & 0xFF;
/* decompose glyph path */
- glpath((chunk_no * 32) + i, glyph_list);
+ glpath(ctx->face, (chunk_no * 32) + i, ctx->glyphs);
for (o = g->outline; o; o = next) {
if (!o)
diff --git a/src/outlines.h b/src/outlines.h
index d849106..9f2bf91 100644
--- a/src/outlines.h
+++ b/src/outlines.h
@@ -1,6 +1,7 @@
#ifndef _TTF2F_OUTLINES_H_
#define _TTF2F_OUTLINES_H_
+#include "context.h"
#include "utils.h"
struct chunk_data {
@@ -52,9 +53,8 @@ struct char_data {
struct glyph;
struct font_metrics;
-ttf2f_result outlines_write(const char *savein, const char *name,
- struct glyph *glyph_list, int list_size,
- const struct font_metrics *metrics,
+ttf2f_result outlines_write(const char *savein,
+ const char *name, ttf2f_ctx *ctx,
void (*callback)(int progress));
#endif