# HG changeset patch # User John Tsiombikas # Date 1397522019 -10800 # Node ID 850335344428b9c3fe1dd0339f90d96c2afc2e33 # Parent 9fd4bf11cc1e467afea2d70272000aa7c0762dca font2glyphmap tool diff -r 9fd4bf11cc1e -r 850335344428 src/drawtext.h --- a/src/drawtext.h Mon Mar 18 06:06:26 2013 +0200 +++ b/src/drawtext.h Tue Apr 15 03:33:39 2014 +0300 @@ -82,7 +82,7 @@ int dtx_get_glyphmap_height(struct dtx_glyphmap *gmap); /* The following functions can be used even when the library is compiled without - * freetype support. (TODO) + * freetype support. */ struct dtx_glyphmap *dtx_load_glyphmap(const char *fname); struct dtx_glyphmap *dtx_load_glyphmap_stream(FILE *fp); diff -r 9fd4bf11cc1e -r 850335344428 tools/font2glyphmap/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/font2glyphmap/Makefile Tue Apr 15 03:33:39 2014 +0300 @@ -0,0 +1,24 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +bin = font2glyphmap + +CC = gcc +CFLAGS = -pedantic -Wall -g -I../../src -I/usr/local/include +LDFLAGS = -L. -L/usr/local/lib -ldrawtext + +ifeq ($(shell uname -s), Darwin) + lib_so = libdrawtext.dylib +else + lib_so = libdrawtext.so.0.0 +endif + +$(bin): $(obj) $(lib_so) $(font) + $(CC) -o $@ $(obj) $(LDFLAGS) + +$(lib_so): ../../$(lib_so) + rm -f $@ + ln -s $< $@ + +.PHONY: clean +clean: + rm -f $(obj) $(bin) $(lib_so) diff -r 9fd4bf11cc1e -r 850335344428 tools/font2glyphmap/src/font2glyphmap.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/font2glyphmap/src/font2glyphmap.c Tue Apr 15 03:33:39 2014 +0300 @@ -0,0 +1,114 @@ +#include +#include +#include +#include "drawtext.h" + +#define SUFFIX "glyphmap" + +struct coderange { + int start, end; + struct coderange *next; +}; + +int font2glyphmap(struct dtx_font *font, const char *infname, const char *outfname, int size, int rstart, int rend); + +int main(int argc, char **argv) +{ + int i, font_size = 12, suffix_len = strlen(SUFFIX); + struct coderange *clist = 0; + + for(i=1; istart = start; + node->end = end; + node->next = clist; + clist = node; + } else if(strcmp(argv[i], "-size") == 0) { + char *endp; + + font_size = strtol(argv[++i], &endp, 10); + if(endp == argv[i]) { + fprintf(stderr, "-size must be followed by the font size\n"); + return 1; + } + } else { + fprintf(stderr, "invalid option: %s\n", argv[i]); + return 1; + } + } else { + char *basename, *dotptr, *outfile; + struct dtx_font *font; + + if(!(font = dtx_open_font(argv[i], clist ? 0 : font_size))) { + fprintf(stderr, "failed to open font file: %s\n", argv[i]); + return -1; + } + + basename = alloca(strlen(argv[i]) + suffix_len + 1); + strcpy(basename, argv[i]); + + if((dotptr = strrchr(basename, '.'))) { + *dotptr = 0; + } + + outfile = alloca(strlen(basename) + 64); + + if(clist) { + while(clist) { + struct coderange *r = clist; + clist = clist->next; + + sprintf(outfile, "%s_s%d_r%d-%d.%s", basename, font_size, r->start, r->end, SUFFIX); + font2glyphmap(font, argv[i], outfile, font_size, r->start, r->end); + + free(r); + } + clist = 0; + } else { + sprintf(outfile, "%s_s%d.%s", basename, font_size, SUFFIX); + font2glyphmap(font, argv[i], outfile, font_size, -1, -1); + } + } + } + + return 0; +} + +int font2glyphmap(struct dtx_font *font, const char *infname, const char *outfname, int size, int rstart, int rend) +{ + struct dtx_glyphmap *gmap; + + if(rstart != -1) { + dtx_prepare_range(font, size, rstart, rend); + if(!(gmap = dtx_get_font_glyphmap(font, size, rstart))) { + fprintf(stderr, "failed to retrieve unicode glyphmap (code range: %d-%d)\n", rstart, rend); + return -1; + } + } else { + dtx_prepare(font, size); + if(!(gmap = dtx_get_font_glyphmap(font, size, ' '))) { + fprintf(stderr, "failed to retrieve ASCII glyphmap!\n"); + return -1; + } + } + + if(dtx_save_glyphmap(outfname, gmap) == -1) { + fprintf(stderr, "failed to save glyphmap to: %s\n", outfname); + return -1; + } + + return 0; +}