diff options
Diffstat (limited to 'tools/genfont')
-rw-r--r-- | tools/genfont/Makefile | 48 | ||||
-rw-r--r-- | tools/genfont/genfont.c | 167 |
2 files changed, 215 insertions, 0 deletions
diff --git a/tools/genfont/Makefile b/tools/genfont/Makefile new file mode 100644 index 0000000..584e433 --- /dev/null +++ b/tools/genfont/Makefile @@ -0,0 +1,48 @@ +# +# Makefile for the GraphLCD tool crtfont +# + +-include ../../Make.config + +PRGNAME = genfont + +OBJS = genfont.o + +INCLUDES += -I../../ +INCLUDES += `freetype-config --cflags` + +LIBDIRS += -L../../glcdgraphics/ +LIBS += `freetype-config --libs` + +all: $(PRGNAME) +.PHONY: all + +# Implicit rules: + +%.o: %.c + $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + +# Dependencies: + +MAKEDEP = $(CXX) -MM -MG +DEPFILE = .dependencies +$(DEPFILE): Makefile + @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ + +-include $(DEPFILE) + +# The main program: + +$(PRGNAME): $(OBJS) + $(CXX) $(CXXFLAGS) -rdynamic $(OBJS) $(LIBDIRS) $(LIBS) -lglcdgraphics -lstdc++ -o $(PRGNAME) + +install: $(PRGNAME) + install -d $(BINDIR) + install -m 755 -o root -g root -s $(PRGNAME) $(BINDIR) + +uninstall: + rm -f $(BINDIR)/$(PRGNAME) + +clean: + @-rm -f $(OBJS) $(DEPFILE) $(PRGNAME) *~ + diff --git a/tools/genfont/genfont.c b/tools/genfont/genfont.c new file mode 100644 index 0000000..7553e4c --- /dev/null +++ b/tools/genfont/genfont.c @@ -0,0 +1,167 @@ +/* + * GraphLCD tool genfont + * + * genfont.c - a tool to create *.fnt files for use with the GraphLCD + * graphics library + * + * This file is released under the GNU General Public License. Refer + * to the COPYING file distributed with this package. + * + * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + */ + +#include <getopt.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <glcdgraphics/bitmap.h> +#include <glcdgraphics/font.h> + +static const char *prgname = "genfont"; +static const char *version = "0.0.2"; + +void usage(void) +{ + fprintf(stdout, "\n"); + fprintf(stdout, "%s v%s\n", prgname, version); + fprintf(stdout, "%s is a tool to create *.fnt files that are used by the\n", prgname); + fprintf(stdout, " graphlcd plugin for VDR.\n\n"); + fprintf(stdout, " Usage: %s -f <format> -i infile -o outfile -s size\n\n", prgname); + fprintf(stdout, " -f --format specifies the format of the output files:\n"); + fprintf(stdout, " 0 - fnt (default)\n"); + fprintf(stdout, " 1 - pbm & desc\n"); + fprintf(stdout, " -i --input specifies the name of the input font file (*.ttf)\n"); + fprintf(stdout, " -o --output specifies the base name of the output files\n"); + fprintf(stdout, " -s --size font size of the generated font file\n"); + fprintf(stdout, "\n" ); + fprintf(stdout, " example: %s -i verdana.ttf -o verdana20 -s 20\n", prgname); + fprintf(stdout, " %s -f 1 -i verdana.ttf -o verdana20 -s 20\n", prgname); +} + + +int main(int argc, char *argv[]) +{ + static struct option long_options[] = + { + { "format", required_argument, NULL, 'f'}, + { "input", required_argument, NULL, 'i'}, + { "output", required_argument, NULL, 'o'}, + { "size", required_argument, NULL, 's'}, + { NULL} + }; + + int c; + int option_index = 0; + int format = 0; + std::string inputFontFile = ""; + std::string outputName = ""; + int size = 30; + + while ((c = getopt_long(argc, argv, "f:i:o:s:", long_options, &option_index)) != -1) + { + switch (c) + { + case 'f': + format = atoi(optarg); + break; + + case 'i': + inputFontFile = optarg; + break; + + case 'o': + outputName = optarg; + break; + + case 's': + size = atoi(optarg); + break; + + default: + usage(); + break; + } + } + if (format > 1) + { + usage(); + return 1; + } + if (inputFontFile == "") + { + usage(); + return 1; + } + if (outputName == "") + { + outputName = inputFontFile; + } + + GLCD::cFont font; + if (!font.LoadFT2(inputFontFile, "iso-8859-1", size, false)) + { + return 1; + } + + GLCD::cBitmap * bitmap = NULL; + std::string fileName; + FILE * descFile = NULL; + int posX = 0; + int posY = 0; + + if (format == 0) + { + fileName = outputName + ".fnt"; + if (!font.SaveFNT(fileName)) + { + return 1; + } + } + else + { + fileName = outputName + ".desc"; + descFile = fopen(fileName.c_str(), "wb"); + if (!descFile) + { + fprintf(stderr, "Cannot open file: %s\n", fileName.c_str()); + return 1; + } + bitmap = new GLCD::cBitmap(32 * font.TotalWidth(), 8 * font.TotalHeight()); + bitmap->Clear(); + fprintf(descFile, "version:1\n"); + fprintf(descFile, "fontheight:%d\n", font.TotalHeight()); + fprintf(descFile, "fontascent:%d\n", font.TotalAscent()); + fprintf(descFile, "lineheight:%d\n", font.LineHeight()); + fprintf(descFile, "spacebetween:%d\n", 0); + fprintf(descFile, "spacewidth:%d\n", 0); + + for (unsigned int i = 0; i < 256; i++) + { + const GLCD::cBitmap * charBitmap = font.GetCharacter((char) i); + if (charBitmap == NULL) + continue; + + bitmap->DrawBitmap(posX, posY, *charBitmap, GLCD::clrBlack); + fprintf(descFile, "%d %d ", posX, i); + posX += charBitmap->Width(); + if ((i % 32) == 31) + { + fprintf(descFile, "%d\n", posX); + posY += font.TotalHeight(); + posX = 0; + } + } + + if (posX > 0) // write last end marker + fprintf(descFile, "%d\n", posX); + fileName = outputName + ".pbm"; + bitmap->SavePBM(fileName); + delete bitmap; + fclose(descFile); + } + + fprintf(stdout, "Font successfully generated.\n"); + + return 0; +} |