libdrawtext

diff tools/font2glyphmap/src/font2glyphmap.c @ 44:35675c3e16b4

improvements in font2glyphmap
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 07 Aug 2014 07:02:41 +0300
parents 49a190d62271
children
line diff
     1.1 --- a/tools/font2glyphmap/src/font2glyphmap.c	Sun Jun 08 06:40:30 2014 +0300
     1.2 +++ b/tools/font2glyphmap/src/font2glyphmap.c	Thu Aug 07 07:02:41 2014 +0300
     1.3 @@ -4,17 +4,19 @@
     1.4  #include "drawtext.h"
     1.5  
     1.6  #define SUFFIX	"glyphmap"
     1.7 +#define DEF_SIZE	12
     1.8  
     1.9  struct coderange {
    1.10  	int start, end;
    1.11  	struct coderange *next;
    1.12  };
    1.13  
    1.14 +void print_usage(const char *argv0);
    1.15  int font2glyphmap(struct dtx_font *font, const char *infname, const char *outfname, int size, int rstart, int rend);
    1.16  
    1.17  int main(int argc, char **argv)
    1.18  {
    1.19 -	int i, font_size = 12, suffix_len = strlen(SUFFIX);
    1.20 +	int i, font_size = DEF_SIZE, suffix_len = strlen(SUFFIX);
    1.21  	struct coderange *clist = 0;
    1.22  
    1.23  	for(i=1; i<argc; i++) {
    1.24 @@ -45,11 +47,14 @@
    1.25  					return 1;
    1.26  				}
    1.27  			} else {
    1.28 -				fprintf(stderr, "invalid option: %s\n", argv[i]);
    1.29 +				if(strcmp(argv[i], "-help") != 0 && strcmp(argv[i], "-h") != 0) {
    1.30 +					fprintf(stderr, "invalid option: %s\n", argv[i]);
    1.31 +				}
    1.32 +				print_usage(argv[0]);
    1.33  				return 1;
    1.34  			}
    1.35  		} else {
    1.36 -			char *basename, *dotptr, *outfile;
    1.37 +			char *basename, *dotptr, *outfile, *lastslash;
    1.38  			struct dtx_font *font;
    1.39  
    1.40  			if(!(font = dtx_open_font(argv[i], clist ? 0 : font_size))) {
    1.41 @@ -63,6 +68,9 @@
    1.42  			if((dotptr = strrchr(basename, '.'))) {
    1.43  				*dotptr = 0;
    1.44  			}
    1.45 +			if((lastslash = strrchr(basename, '/'))) {
    1.46 +				basename = lastslash + 1;
    1.47 +			}
    1.48  
    1.49  			outfile = alloca(strlen(basename) + 64);
    1.50  
    1.51 @@ -87,6 +95,15 @@
    1.52  	return 0;
    1.53  }
    1.54  
    1.55 +void print_usage(const char *argv0)
    1.56 +{
    1.57 +	printf("usage: %s [options] <font-1> [<font-2> ... <font-n>]\n", argv0);
    1.58 +	printf("options:\n");
    1.59 +	printf("  -size <pt>: point size (default: %d)\n", DEF_SIZE);
    1.60 +	printf("  -range <low>-<high>: unicode range (default: ascii)\n");
    1.61 +	printf("  -help: print usage information and exit\n");
    1.62 +}
    1.63 +
    1.64  int font2glyphmap(struct dtx_font *font, const char *infname, const char *outfname, int size, int rstart, int rend)
    1.65  {
    1.66  	struct dtx_glyphmap *gmap;