From 4f193de66cf672ea408a829bd5233d180cf72bba Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 23 Apr 2016 18:58:59 +0000 Subject: Don't use pbm_dumpfont, add -header, -varname git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2713 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- buildtools/Makefile | 4 +-- buildtools/genfontc.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 5 deletions(-) (limited to 'buildtools') diff --git a/buildtools/Makefile b/buildtools/Makefile index a549d962..0490865b 100644 --- a/buildtools/Makefile +++ b/buildtools/Makefile @@ -41,7 +41,7 @@ genfontc.o:%.o:%.c importinc $(NETPBM_INCLUDES) \ $< genfontc:%:%.o $(NETPBMLIB) - $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $(NETPBMLIB) $< + $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< $(NETPBMLIB) $(BUILDPROGS):%:%.o $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< @@ -49,4 +49,4 @@ $(BUILDPROGS):%:%.o distclean clean: cleanlocal .PHONY: cleanlocal cleanlocal: - rm -f $(BUILDPROGS) + rm -f $(BUILDPROGS) genfontc diff --git a/buildtools/genfontc.c b/buildtools/genfontc.c index f8c5c95e..ce6b8c9c 100644 --- a/buildtools/genfontc.c +++ b/buildtools/genfontc.c @@ -12,6 +12,8 @@ struct CmdlineInfo { */ const char * font; const char * builtin; + const char * header; + const char * varname; unsigned int verbose; }; @@ -29,7 +31,7 @@ parseCommandLine(int argc, const char ** argv, */ optStruct3 opt; - unsigned int fontSpec, builtinSpec; + unsigned int fontSpec, builtinSpec, headerSpec, varnameSpec; unsigned int option_def_index; @@ -38,6 +40,8 @@ parseCommandLine(int argc, const char ** argv, option_def_index = 0; /* incremented by OPTENTRY */ OPTENT3(0, "font", OPT_STRING, &cmdlineP->font, &fontSpec, 0); OPTENT3(0, "builtin", OPT_STRING, &cmdlineP->builtin, &builtinSpec, 0); + OPTENT3(0, "header", OPT_STRING, &cmdlineP->header, &headerSpec, 0); + OPTENT3(0, "varname", OPT_STRING, &cmdlineP->varname, &varnameSpec, 0); OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0); opt.opt_table = option_def; @@ -52,6 +56,12 @@ parseCommandLine(int argc, const char ** argv, if (!builtinSpec) cmdlineP->builtin = NULL; + + if (!headerSpec) + cmdlineP->header = NULL; + + if (!varnameSpec) + cmdlineP->varname = NULL; } @@ -67,9 +77,10 @@ reportFont(struct font * const fontP) { fontP->maxwidth, fontP->maxheight); pm_message(" Additional vert white space: %d pixels", fontP->y); - for (c = 0, n = 0; c < ARRAY_SIZE(fontP->glyph); ++c) + for (c = 0, n = 0; c < ARRAY_SIZE(fontP->glyph); ++c) { if (fontP->glyph[c]) ++n; + } pm_message(" # characters: %u", n); } @@ -97,6 +108,75 @@ computeFont(const char * const fontName, + +static void +dumpfont(struct font * const fontP, + const char * const header, + const char * const varname, + FILE * const ofP) { +/*---------------------------------------------------------------------------- + Dump out font as C source code. +-----------------------------------------------------------------------------*/ + unsigned int i; + unsigned int ng; + + for (i = 0, ng = 0; i < 256; ++i) { + if (fontP->glyph[i]) + ++ng; + } + + if (header != NULL) + printf("#include \"%s\"\n\n", header); + + printf("static struct glyph _g[%d] = {\n", ng); + + for (i = 0; i < 256; ++i) { + struct glyph * const glyphP = fontP->glyph[i]; + + if (glyphP) { + unsigned int j; + + printf(" { %d, %d, %d, %d, %d, \"", + glyphP->width, glyphP->height, + glyphP->x, glyphP->y, glyphP->xadd); + + for (j = 0; j < glyphP->width * glyphP->height; ++j) { + if (glyphP->bmap[j]) + printf("\\1"); + else + printf("\\0"); + } + --ng; + printf("\" }%s\n", ng ? "," : ""); + } + } + printf("};\n"); + + printf("struct font %s = { %d, %d, %d, %d, {\n", + (varname == NULL) ? "XXX_font" : varname, + fontP->maxwidth, fontP->maxheight, fontP->x, fontP->y); + + { + unsigned int i; + + for (i = 0; i < 256; ++i) { + if (fontP->glyph[i]) + printf(" _g + %d", ng++); + else + printf(" NULL"); + + if (i != 255) + printf(","); + + printf("\n"); + } + } + + printf(" }\n};\n"); +} + + + int main(int argc, const char *argv[]) { @@ -112,7 +192,7 @@ main(int argc, const char *argv[]) { if (cmdline.verbose) reportFont(fontP); - pbm_dumpfont(fontP, stdout); + dumpfont(fontP, cmdline.header, cmdline.varname, stdout); } -- cgit 1.4.1