summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-10 21:38:00 (GMT)
committer John Mark Bell <jmb@netsurf-browser.org>2009-05-10 21:38:00 (GMT)
commit9270294d7d5de0dcfb680596a3f8e51365062358 (patch)
tree2deb3e75e9e3c8f26788d8a4324c82218608d89e
parent952ede7bafced5370174a837c2aa18d01a5a30bd (diff)
downloadttf2f-9270294d7d5de0dcfb680596a3f8e51365062358.tar.gz
ttf2f-9270294d7d5de0dcfb680596a3f8e51365062358.tar.bz2
Introduce a conversion context.
svn path=/trunk/tools/ttf2f/; revision=7456
-rw-r--r--src/cli.c47
-rw-r--r--src/context.h18
2 files changed, 43 insertions, 22 deletions
diff --git a/src/cli.c b/src/cli.c
index 1be69c4..5ec85ff 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -1,8 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
+#include "context.h"
#include "encoding.h"
#include "fm.h"
#include "ft.h"
@@ -24,17 +26,17 @@ void ttf2f_poll(int active)
int main(int argc, char **argv)
{
+ ttf2f_ctx ctx;
int fail;
ttf2f_result err = TTF2F_RESULT_OK;
- int nglyphs;
- struct glyph *glist = NULL;
- struct font_metrics *metrics = NULL;
if (argc != 3) {
fprintf(stderr, "Usage: %s <input.ttf> <output>\n", argv[0]);
return 1;
}
+ memset(&ctx, 0, sizeof(ctx));
+
ft_init();
if ((err = glyph_load_list()) != TTF2F_RESULT_OK)
@@ -46,55 +48,56 @@ int main(int argc, char **argv)
return 1;
}
- nglyphs = count_glyphs();
+ ctx.nglyphs = count_glyphs();
- glist = calloc(nglyphs, sizeof(struct glyph));
- if (glist == NULL) {
+ ctx.glyphs = calloc(ctx.nglyphs, sizeof(struct glyph));
+ if (ctx.glyphs == NULL) {
fprintf(stderr, "ERROR: insufficient memory for glyphs\n");
return 1;
}
- for (int i = 0; i != nglyphs; i++) {
- struct glyph *g = &glist[i];
+ for (size_t i = 0; i != ctx.nglyphs; i++) {
+ struct glyph *g = &ctx.glyphs[i];
g->code = -1;
}
- metrics = calloc(1, sizeof(struct font_metrics));
- if (metrics == NULL) {
- fprintf(stderr, "ERROR: insufficient memory for font metrics\n");
+ ctx.metrics = calloc(1, sizeof(struct font_metrics));
+ if (ctx.metrics == NULL) {
+ fprintf(stderr,
+ "ERROR: insufficient memory for font metrics\n");
return 1;
}
- fail = fnmetrics(metrics);
+ fail = fnmetrics(ctx.metrics);
if (fail) {
fprintf(stderr, "ERROR: failed reading font metrics\n");
return 1;
}
- fail = glenc(glist);
+ fail = glenc(ctx.glyphs);
if (fail) {
fprintf(stderr, "ERROR: failed reading glyph encoding\n");
return 1;
}
- fail = glnames(glist);
+ fail = glnames(ctx.glyphs);
if (fail) {
fprintf(stderr, "ERROR: failed reading glyph names\n");
return 1;
}
- glmetrics(glist, progress);
+ glmetrics(ctx.glyphs, progress);
mkdir(argv[2], 0755);
- if ((err = intmetrics_write(argv[2], argv[2], glist, nglyphs,
- metrics, progress)) != TTF2F_RESULT_OK) goto error_out;
+ if ((err = intmetrics_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], glist, nglyphs,
- metrics, 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 = encoding_write(argv[2], argv[2], glist, nglyphs,
+ if ((err = encoding_write(argv[2], argv[2], ctx.glyphs, ctx.nglyphs,
0, progress)) != TTF2F_RESULT_OK) goto error_out;
error_out:
@@ -118,8 +121,8 @@ error_out:
}
}
- free(metrics);
- free(glist);
+ free(ctx.metrics);
+ free(ctx.glyphs);
close_font();
diff --git a/src/context.h b/src/context.h
new file mode 100644
index 0000000..b89fa7f
--- a/dev/null
+++ b/src/context.h
@@ -0,0 +1,18 @@
+#ifndef ttf2f_context_h_
+#define ttf2f_context_h_
+
+#include "fm.h"
+#include "glyph.h"
+
+typedef struct ttf2f_ctx ttf2f_ctx;
+
+struct ttf2f_ctx {
+ struct font_metrics *metrics;
+
+ size_t nglyphs;
+ struct glyph *glyphs;
+
+ struct glyph *latin1tab[256];
+};
+
+#endif