From 4aed351e3376d70cedf1dfbcf4f396cc904e2703 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 7 May 2009 16:50:17 +0000 Subject: Command line interface svn path=/trunk/tools/ttf2f/; revision=7430 --- src/Makefile | 2 +- src/cli.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/cli.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 4f16a84..0bd3fb2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ # Sources -DIR_SOURCES := encoding.c ft.c glyphs.c intmetrics.c outlines.c utils.c +DIR_SOURCES := cli.c encoding.c ft.c glyphs.c intmetrics.c outlines.c utils.c include build/makefiles/Makefile.subdir diff --git a/src/cli.c b/src/cli.c new file mode 100644 index 0000000..269cf34 --- /dev/null +++ b/src/cli.c @@ -0,0 +1,100 @@ +#include +#include + +#include "encoding.h" +#include "fm.h" +#include "ft.h" +#include "glyph.h" +#include "glyphs.h" +#include "intmetrics.h" +#include "outlines.h" +#include "utils.h" + +static void progress(int value) +{ + UNUSED(value); +} + +void ttf2f_poll(int active) +{ + UNUSED(active); +} + +int main(int argc, char **argv) +{ + int fail; + int nglyphs; + struct glyph *glist; + struct font_metrics *metrics; + + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + ft_init(); + load_glyph_list(); + + fail = open_font(argv[1]); + if (fail) { + fprintf(stderr, "ERROR: Failed opening font %s\n", argv[1]); + return 1; + } + + nglyphs = count_glyphs(); + + glist = calloc(nglyphs, sizeof(struct glyph)); + if (glist == NULL) { + fprintf(stderr, "ERROR: insufficient memory for glyphs\n"); + return 1; + } + + for (int i = 0; i != nglyphs; i++) { + struct glyph *g = &glist[i]; + + g->code = -1; + } + + metrics = calloc(1, sizeof(struct font_metrics)); + if (metrics == NULL) { + fprintf(stderr, "ERROR: insufficient memory for font metrics\n"); + return 1; + } + + fail = fnmetrics(metrics); + if (fail) { + fprintf(stderr, "ERROR: failed reading font metrics\n"); + return 1; + } + + fail = glenc(glist); + if (fail) { + fprintf(stderr, "ERROR: failed reading glyph encoding\n"); + return 1; + } + + fail = glnames(glist); + if (fail) { + fprintf(stderr, "ERROR: failed reading glyph names\n"); + return 1; + } + + glmetrics(glist, NULL); + + write_intmetrics("", argv[2], glist, nglyphs, metrics, progress); + + write_outlines("", argv[2], glist, nglyphs, metrics, progress); + + write_encoding("", argv[2], glist, nglyphs, 0, progress); + + free(metrics); + free(glist); + + close_font(); + + ft_fini(); + destroy_glyphs(); + + return 0; +} + -- cgit v1.2.3