diff options
-rw-r--r-- | buildtools/Makefile | 10 | ||||
-rw-r--r-- | buildtools/genfontc.c | 119 | ||||
-rw-r--r-- | doc/HISTORY | 3 | ||||
-rw-r--r-- | lib/libpbmfont.c | 8 | ||||
-rw-r--r-- | lib/pbmfont.h | 24 | ||||
-rw-r--r-- | lib/pbmfontdata1.c | 3 | ||||
-rw-r--r-- | lib/pbmfontdata2.c | 3 |
7 files changed, 160 insertions, 10 deletions
diff --git a/buildtools/Makefile b/buildtools/Makefile index 8671c066..a549d962 100644 --- a/buildtools/Makefile +++ b/buildtools/Makefile @@ -33,6 +33,16 @@ libopt.o: libopt.c typegen.o endiangen.o:%.o:%.c $(CC_FOR_BUILD) -c -o $@ $(CFLAGS_FOR_BUILD) $< +# genfontc is strange because it isn't really a build tool; it's a development +# tool. And it uses Netpbm. So we don't even build it by default and the +# developer who builds it explicitly may have to be careful. +genfontc.o:%.o:%.c importinc + $(CC_FOR_BUILD) -c -o $@ $(CFLAGS_FOR_BUILD) \ + $(NETPBM_INCLUDES) \ + $< +genfontc:%:%.o $(NETPBMLIB) + $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $(NETPBMLIB) $< + $(BUILDPROGS):%:%.o $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< diff --git a/buildtools/genfontc.c b/buildtools/genfontc.c new file mode 100644 index 00000000..f8c5c95e --- /dev/null +++ b/buildtools/genfontc.c @@ -0,0 +1,119 @@ +#include "pm_c_util.h" +#include "mallocvar.h" +#include "shhopt.h" +#include "pm.h" +#include "pbmfont.h" + + + +struct CmdlineInfo { + /* All the information the user supplied in the command line, + in a form easy for the program to use. + */ + const char * font; + const char * builtin; + unsigned int verbose; +}; + + + +static void +parseCommandLine(int argc, const char ** argv, + struct CmdlineInfo * const cmdlineP) { +/*---------------------------------------------------------------------------- + Note that the file spec array we return is stored in the storage that + was passed to us as the argv array. +-----------------------------------------------------------------------------*/ + optEntry * option_def; + /* Instructions to OptParseOptions3 on how to parse our options. + */ + optStruct3 opt; + + unsigned int fontSpec, builtinSpec; + + unsigned int option_def_index; + + MALLOCARRAY_NOFAIL(option_def, 100); + + 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, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0); + + opt.opt_table = option_def; + opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ + opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + + pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + /* Uses and sets argc, argv, and some of *cmdlineP and others. */ + + if (!fontSpec) + cmdlineP->font = NULL; + + if (!builtinSpec) + cmdlineP->builtin = NULL; +} + + + +static void +reportFont(struct font * const fontP) { + + unsigned int n; + unsigned int c; + + pm_message("FONT:"); + pm_message(" character dimensions: %uw x %uh", + 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) + if (fontP->glyph[c]) + ++n; + + pm_message(" # characters: %u", n); +} + + + +static void +computeFont(const char * const fontName, + const char * const builtinName, + struct font ** const fontPP) { + + struct font * fontP; + + if (fontName) + fontP = pbm_loadfont(fontName); + else { + if (builtinName) + fontP = pbm_defaultfont(builtinName); + else + fontP = pbm_defaultfont("bdf"); + } + + *fontPP = fontP; +} + + + +int +main(int argc, const char *argv[]) { + + struct CmdlineInfo cmdline; + struct font * fontP; + + pm_proginit(&argc, argv); + + parseCommandLine(argc, argv, &cmdline); + + computeFont(cmdline.font, cmdline.builtin, &fontP); + + if (cmdline.verbose) + reportFont(fontP); + + pbm_dumpfont(fontP, stdout); +} + + + diff --git a/doc/HISTORY b/doc/HISTORY index 86615c98..91e0e073 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -6,6 +6,9 @@ CHANGE HISTORY not yet BJH Release 10.75.00 + pbmtext: remove undocumented -dump option; add 'genfontc' + development tool (buildtools/ directory) to replace it. + pbmtext: Add -dry-run pbmtext: Add -dump-sheet diff --git a/lib/libpbmfont.c b/lib/libpbmfont.c index aecc6226..55d3be0c 100644 --- a/lib/libpbmfont.c +++ b/lib/libpbmfont.c @@ -340,9 +340,11 @@ pbm_loadpbmfont(const char * const filename) { void -pbm_dumpfont(struct font * const fontP) { - /* Dump out font as C source code. */ - +pbm_dumpfont(struct font * const fontP, + FILE * const ofP) { +/*---------------------------------------------------------------------------- + Dump out font as C source code. +-----------------------------------------------------------------------------*/ unsigned int i; unsigned int ng; diff --git a/lib/pbmfont.h b/lib/pbmfont.h index ef06570a..5111a075 100644 --- a/lib/pbmfont.h +++ b/lib/pbmfont.h @@ -76,20 +76,30 @@ struct font { int fcols, frows; }; -struct font* pbm_defaultfont(const char* const which); -struct font* +struct font * +pbm_defaultfont(const char* const which); + +struct font * pbm_dissectfont(const bit ** const font, unsigned int const frows, unsigned int const fcols); -struct font* pbm_loadfont(const char * const filename); -struct font* pbm_loadpbmfont(const char * const filename); -struct font* pbm_loadbdffont(const char * const filename); -void pbm_dumpfont(struct font * const fnP); + +struct font * +pbm_loadfont(const char * const filename); + +struct font * +pbm_loadpbmfont(const char * const filename); + +struct font * +pbm_loadbdffont(const char * const filename); + +void +pbm_dumpfont(struct font * const fontP, + FILE * const ofP); extern struct font pbm_defaultFixedfont; extern struct font pbm_defaultBdffont; - #ifdef __cplusplus } #endif diff --git a/lib/pbmfontdata1.c b/lib/pbmfontdata1.c index 19fca15c..8552d29e 100644 --- a/lib/pbmfontdata1.c +++ b/lib/pbmfontdata1.c @@ -14,6 +14,9 @@ To ensure future compatibility call pbm_defaultfont() before accessing default_fixedfont. + + The Netpbm development tool 'genfontc' generates C source code like this + from a libnetpbm font file or builtin font. */ static struct glyph glFxd[96] = { diff --git a/lib/pbmfontdata2.c b/lib/pbmfontdata2.c index a65b05d8..336fc773 100644 --- a/lib/pbmfontdata2.c +++ b/lib/pbmfontdata2.c @@ -10,6 +10,9 @@ To ensure future compatibility call pbm_defaultfont() before accessing default_bdffont. + + The Netpbm development tool 'genfontc' generates C source code like this + from a libnetpbm font file or builtin font. */ static struct glyph glBdf[190] = { |