tools/sfnt2fnt: Add getopt option parsing.

This commit is contained in:
Alexandre Julliard 2008-03-22 21:00:56 +01:00
parent f5c49b210a
commit f2734a1a64
2 changed files with 128 additions and 65 deletions

View File

@ -61,121 +61,121 @@ all: $(FONTS)
@MAKE_RULES@
coure.fon: courier.ttf
$(LDPATH) $(SFNT2FNT) courier.ttf $@ 13,1252,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 courier.ttf 13,1252,8
couree.fon: courier.ttf
$(LDPATH) $(SFNT2FNT) courier.ttf $@ 13,1250,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 courier.ttf 13,1250,8
courer.fon: courier.ttf
$(LDPATH) $(SFNT2FNT) courier.ttf $@ 13,1251,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 courier.ttf 13,1251,8
coureg.fon: courier.ttf
$(LDPATH) $(SFNT2FNT) courier.ttf $@ 13,1253,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 courier.ttf 13,1253,8
couret.fon: courier.ttf
$(LDPATH) $(SFNT2FNT) courier.ttf $@ 13,1254,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 courier.ttf 13,1254,8
coue1255.fon: courier.ttf
$(LDPATH) $(SFNT2FNT) courier.ttf $@ 13,1255,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 courier.ttf 13,1255,8
coue1256.fon: courier.ttf
$(LDPATH) $(SFNT2FNT) courier.ttf $@ 13,1256,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 courier.ttf 13,1256,8
coue1257.fon: courier.ttf
$(LDPATH) $(SFNT2FNT) courier.ttf $@ 13,1257,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 courier.ttf 13,1257,8
sserife.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,1252,96,129,5 16,1252,96,129,7 20,1252,96,129,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,1252,5 16,1252,7 20,1252,8
sserifee.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,1250,96,129,5 16,1250,96,129,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,1250,5 16,1250,7
sserifer.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,1251,96,129,5 16,1251,96,129,7 20,1251,96,129,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,1251,5 16,1251,7 20,1251,8
sserifeg.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,1253,96,129,5 16,1253,96,129,7 20,1253,96,129,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,1253,5 16,1253,7 20,1253,8
sserifet.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,1254,96,129,5 16,1254,96,129,7 20,1254,96,129,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,1254,5 16,1254,7 20,1254,8
ssee1255.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,1255,96,129,5 16,1255,96,129,7 20,1255,96,129,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,1255,5 16,1255,7 20,1255,8
ssee1256.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,1256,96,129,5 16,1256,96,129,7 20,1256,96,129,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,1256,5 16,1256,7 20,1256,8
ssee1257.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,1257,96,129,5 16,1257,96,129,7 20,1257,96,129,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,1257,5 16,1257,7 20,1257,8
ssee874.fon: ms_sans_serif.ttf
$(LDPATH) $(SFNT2FNT) ms_sans_serif.ttf $@ 13,874,96,129,5 16,874,96,129,7 20,874,96,129,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 129 ms_sans_serif.ttf 13,874,5 16,874,7 20,874,8
smalle.fon: small_fonts.ttf
$(LDPATH) $(SFNT2FNT) small_fonts.ttf $@ 11,1252,96,128,5
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts.ttf 11,1252,5
smallee.fon: small_fonts.ttf
$(LDPATH) $(SFNT2FNT) small_fonts.ttf $@ 11,1250,96,128,5
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts.ttf 11,1250,5
smaller.fon: small_fonts.ttf
$(LDPATH) $(SFNT2FNT) small_fonts.ttf $@ 11,1251,96,128,5
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts.ttf 11,1251,5
smalleg.fon: small_fonts.ttf
$(LDPATH) $(SFNT2FNT) small_fonts.ttf $@ 11,1253,96,128,5
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts.ttf 11,1253,5
smallet.fon: small_fonts.ttf
$(LDPATH) $(SFNT2FNT) small_fonts.ttf $@ 11,1254,96,128,5
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts.ttf 11,1254,5
smae1255.fon: small_fonts.ttf
$(LDPATH) $(SFNT2FNT) small_fonts.ttf $@ 11,1255,96,128,5
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts.ttf 11,1255,5
smae1256.fon: small_fonts.ttf
$(LDPATH) $(SFNT2FNT) small_fonts.ttf $@ 11,1256,96,128,5
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts.ttf 11,1256,5
smae1257.fon: small_fonts.ttf
$(LDPATH) $(SFNT2FNT) small_fonts.ttf $@ 11,1257,96,128,5
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts.ttf 11,1257,5
jsmalle.fon: small_fonts_jp.ttf
$(LDPATH) $(SFNT2FNT) small_fonts_jp.ttf $@ 11,932,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 small_fonts_jp.ttf 11,932,7
vgasys.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,1252,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,1252,7
vgasyse.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,1250,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,1250,7
vgasysr.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,1251,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,1251,7
vgasysg.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,1253,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,1253,7
vgasyst.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,1254,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,1254,7
vgas1255.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,1255,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,1255,7
vgas1256.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,1256,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,1256,7
vgas1257.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,1257,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,1257,7
vgas874.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,874,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,874,7
jvgasys.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 18,932,96,128,8
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 18,932,8
svgasys.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,936,96,128,7 16,1252,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,936,7 16,1252,7
hvgasys.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,949,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,949,7
cvgasys.fon: system.ttf
$(LDPATH) $(SFNT2FNT) system.ttf $@ 16,950,96,128,7 16,1252,96,128,7
$(LDPATH) $(SFNT2FNT) -o $@ -d 128 system.ttf 16,950,7 16,1252,7
$(BITMAP_FONTS): $(SFNT2FNT)

View File

@ -27,6 +27,9 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#endif
#ifdef HAVE_FREETYPE
@ -128,14 +131,26 @@ static const BYTE MZ_hdr[] =
'm', 'o', 'd', 'e', 0x0d, 0x0a, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static char *option_output;
static int option_defchar = ' ';
static int option_dpi = 96;
static int option_fnt_mode = 0;
static int option_quiet = 0;
static const char *output_name;
static FT_Library ft_library;
static void usage(char **argv)
{
fprintf(stderr, "%s foo.ttf ppem enc dpi def_char avg_width\n", argv[0]);
return;
fprintf(stderr, "%s [options] input.ttf ppem,enc,avg_width ...\n", argv[0]);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -h Display help\n" );
fprintf(stderr, " -d char Set the font default char\n" );
fprintf(stderr, " -o file Set output file name\n" );
fprintf(stderr, " -q Quiet mode\n" );
fprintf(stderr, " -r dpi Set resolution in DPI (default: 96)\n" );
fprintf(stderr, " -s Single .fnt file mode\n" );
}
#ifndef __GNUC__
@ -376,7 +391,7 @@ static struct fontinfo *fill_fontinfo( const char *face_name, int ppem, int enc,
for(i = first_char; i < 0x100; i++) {
int c = get_char(cptable, enc, i);
gi = FT_Get_Char_Index(face, c);
if(gi == 0)
if(gi == 0 && !option_quiet)
fprintf(stderr, "warning: %s %u: missing glyph for char %04x\n",
face->family_name, ppem, cptable->sbcs.cp2uni[i]);
if(FT_Load_Char(face, c, FT_LOAD_DEFAULT)) {
@ -513,6 +528,41 @@ static void write_fontinfo( const struct fontinfo *info, FILE *fp )
fwrite( info->data, info->hdr.dfSize - info->hdr.fi.dfBitsOffset, 1, fp );
}
/* parse options from the argv array and remove all the recognized ones */
static char **parse_options( int argc, char **argv )
{
int optc;
while ((optc = getopt( argc, argv, "d:ho:qr:s" )) != -1)
{
switch(optc)
{
case 'd':
option_defchar = atoi( optarg );
break;
case 'o':
option_output = strdup( optarg );
break;
case 'q':
option_quiet = 1;
break;
case 'r':
option_dpi = atoi( optarg );
break;
case 's':
option_fnt_mode = 1;
break;
case 'h':
usage(argv);
exit(0);
case '?':
usage(argv);
exit(1);
}
}
return &argv[optind];
}
int main(int argc, char **argv)
{
int i, j;
@ -528,9 +578,14 @@ int main(int argc, char **argv)
NE_TYPEINFO rc_type;
NE_NAMEINFO rc_name;
struct fontinfo **info;
char *p;
char *input_file;
char **args;
if(argc <= 3) {
args = parse_options( argc, argv );
input_file = *args++;
if (!input_file || !*args)
{
usage(argv);
exit(1);
}
@ -541,19 +596,25 @@ int main(int argc, char **argv)
FT_Version.major=FT_Version.minor=FT_Version.patch=-1;
FT_Library_Version(ft_library,&FT_Version.major,&FT_Version.minor,&FT_Version.patch);
num_files = argc - 3;
num_files = 0;
while (args[num_files]) num_files++;
if (option_fnt_mode && num_files > 1)
error( "can only specify one font in .fnt mode\n" );
info = malloc( num_files * sizeof(*info) );
for (i = 0; i < num_files; i++)
{
int ppem, enc, dpi, def_char, avg_width;
int ppem, enc, avg_width;
const char *name;
if (sscanf( argv[i+3], "%d,%d,%d,%d,%d", &ppem, &enc, &dpi, &def_char, &avg_width ) != 5)
if (sscanf( args[i], "%d,%d,%d", &ppem, &enc, &avg_width ) != 3)
{
usage(argv);
exit(1);
}
if (!(info[i] = fill_fontinfo( argv[1], ppem, enc, dpi, def_char, avg_width ))) exit(1);
if (!(info[i] = fill_fontinfo( input_file, ppem, enc, option_dpi, option_defchar, avg_width )))
exit(1);
name = get_face_name( info[i] );
fontdir_len += 0x74 + strlen(name) + 1;
@ -567,7 +628,7 @@ int main(int argc, char **argv)
}
}
if(info[0]->hdr.fi.dfVertRes <= 108)
if (option_dpi <= 108)
strcat(non_resident_name, " (VGA res)");
else
strcat(non_resident_name, " (8514 res)");
@ -611,28 +672,29 @@ int main(int argc, char **argv)
signal( SIGHUP, exit_on_signal );
#endif
/* check for .fnt extension on output file (FIXME: should be a cmdline option instead) */
if ((p = strrchr( argv[2], '.' )) && !strcmp( p, ".fnt" ))
if (!option_output) /* build a default output name */
{
if (num_files > 1) error( ".fnt generation mode can only contain one font\n" );
output_name = argv[2];
if (!(ofp = fopen(output_name, "wb")))
{
perror( output_name );
exit(1);
}
write_fontinfo( info[0], ofp );
fclose( ofp );
output_name = NULL;
exit(0);
char *p = strrchr( input_file, '/' );
if (p) p++;
else p = input_file;
option_output = malloc( strlen(p) + sizeof(".fon") );
strcpy( option_output, p );
p = strrchr( option_output, '.' );
if (!p) p = option_output + strlen(option_output);
strcpy( p, option_fnt_mode ? ".fnt" : ".fon" );
}
output_name = argv[2];
if (!(ofp = fopen(output_name, "wb")))
if (!(ofp = fopen(option_output, "wb")))
{
perror( output_name );
perror( option_output );
exit(1);
}
output_name = option_output;
if (option_fnt_mode)
{
write_fontinfo( info[0], ofp );
goto done;
}
fwrite(MZ_hdr, sizeof(MZ_hdr), 1, ofp);
fwrite(&NE_hdr, sizeof(NE_hdr), 1, ofp);
@ -724,6 +786,7 @@ int main(int argc, char **argv)
for(j = 0; j < pad; j++)
fputc(0x00, ofp);
}
done:
fclose(ofp);
output_name = NULL;
exit(0);