mirror of
https://github.com/zyphlar/bdf2c.git
synced 2024-03-08 13:47:46 +00:00
The name of the C font structure can be given on the command line.
Fixed small bugs: missing '=' in structure initializer, missing const.
This commit is contained in:
parent
2f475e8fde
commit
2fac095727
5
bdf2c.1
5
bdf2c.1
|
@ -10,6 +10,7 @@ bdf2c \- converts bdf font files into C include files
|
||||||
.I [-b file]
|
.I [-b file]
|
||||||
.I [-c]
|
.I [-c]
|
||||||
.I [-C file]
|
.I [-C file]
|
||||||
|
.I [-n name]
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
|
|
||||||
|
@ -30,6 +31,10 @@ Creates C header file 'file'.
|
||||||
.TP
|
.TP
|
||||||
.B -b file
|
.B -b file
|
||||||
Read and convert bdf font 'file'.
|
Read and convert bdf font 'file'.
|
||||||
|
.TP
|
||||||
|
.B -n name
|
||||||
|
Name of the C font structure. 'name' should contain only valid identifier characters. f.e. font9x15b
|
||||||
|
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Johns (2009) <johns98@gmx.net>.
|
Johns (2009) <johns98@gmx.net>.
|
||||||
|
|
63
bdf2c.c
63
bdf2c.c
|
@ -48,14 +48,14 @@ void CreateFontHeaderFile(FILE * out)
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
fprintf(out, "// (c) 2009 Johns, License: AGPLv3\n\n");
|
fprintf(out, "// (c) 2009 Johns, License: AGPLv3\n\n");
|
||||||
fprintf(out, "\t/// bitmap font structure\n"
|
fprintf(out,
|
||||||
"struct bitmap_font {\n"
|
"\t/// bitmap font structure\n" "struct bitmap_font {\n"
|
||||||
"\tunsigned char Width;\t\t///< max. character width\n"
|
"\tunsigned char Width;\t\t///< max. character width\n"
|
||||||
"\tunsigned char Height;\t\t///< character height\n"
|
"\tunsigned char Height;\t\t///< character height\n"
|
||||||
"\tunsigned short Chars;\t\t///< number of characters in font\n"
|
"\tunsigned short Chars;\t\t///< number of characters in font\n"
|
||||||
"\tunsigned char *Widths;\t\t///< width of each character\n"
|
"\tconst unsigned char *Widths;\t///< width of each character\n"
|
||||||
"\tunsigned short *Index;\t\t///< encoding to character index\n"
|
"\tconst unsigned short *Index;\t///< encoding to character index\n"
|
||||||
"\tunsigned char *Bitmap;\t\t///< bitmap of each character\n"
|
"\tconst unsigned char *Bitmap;\t///< bitmap of each character\n"
|
||||||
"};\n\n");
|
"};\n\n");
|
||||||
|
|
||||||
fprintf(out, "\t/// @{ defines to have human readable font files\n");
|
fprintf(out, "\t/// @{ defines to have human readable font files\n");
|
||||||
|
@ -124,20 +124,21 @@ void EncodingTable(FILE * out, const char *name,
|
||||||
void Footer(FILE * out, const char *name, int width, int height, int chars)
|
void Footer(FILE * out, const char *name, int width, int height, int chars)
|
||||||
{
|
{
|
||||||
fprintf(out, "};\n\n");
|
fprintf(out, "};\n\n");
|
||||||
fprintf(out, "\t/// bitmap font structure\n"
|
fprintf(out,
|
||||||
"struct bitmap_font %s = {\n", name);
|
"\t/// bitmap font structure\n" "const struct bitmap_font %s = {\n",
|
||||||
fprintf(out, "\t.Width %d, .Height %d,\n", width, height);
|
name);
|
||||||
fprintf(out, "\t.Chars %d,\n", chars);
|
fprintf(out, "\t.Width = %d, .Height = %d,\n", width, height);
|
||||||
fprintf(out, "\t.Widths __%s_widths__,\n", name);
|
fprintf(out, "\t.Chars = %d,\n", chars);
|
||||||
fprintf(out, "\t.Index __%s_index__,\n", name);
|
fprintf(out, "\t.Widths = __%s_widths__,\n", name);
|
||||||
fprintf(out, "\t.Bitmap __%s_bitmap__,\n", name);
|
fprintf(out, "\t.Index = __%s_index__,\n", name);
|
||||||
|
fprintf(out, "\t.Bitmap = __%s_bitmap__,\n", name);
|
||||||
fprintf(out, "};\n\n");
|
fprintf(out, "};\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read BDF font file.
|
// Read BDF font file.
|
||||||
//
|
//
|
||||||
void ReadBdf(FILE * bdf)
|
void ReadBdf(FILE * bdf, const char *name)
|
||||||
{
|
{
|
||||||
char linebuf[1024];
|
char linebuf[1024];
|
||||||
char *s;
|
char *s;
|
||||||
|
@ -157,9 +158,7 @@ void ReadBdf(FILE * bdf)
|
||||||
int width;
|
int width;
|
||||||
unsigned *width_table;
|
unsigned *width_table;
|
||||||
unsigned *encoding_table;
|
unsigned *encoding_table;
|
||||||
const char *name;
|
|
||||||
|
|
||||||
name = "font";
|
|
||||||
fontboundingbox_width = 0;
|
fontboundingbox_width = 0;
|
||||||
fontboundingbox_height = 0;
|
fontboundingbox_height = 0;
|
||||||
chars = 0;
|
chars = 0;
|
||||||
|
@ -183,9 +182,9 @@ void ReadBdf(FILE * bdf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
printf("%d * %dx%d\n", chars, fontboundingbox_width,
|
printf("%d * %dx%d\n", chars, fontboundingbox_width,
|
||||||
fontboundingbox_height);
|
fontboundingbox_height);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (chars <= 0) {
|
if (chars <= 0) {
|
||||||
fprintf(stderr, "Need to know the number of characters\n");
|
fprintf(stderr, "Need to know the number of characters\n");
|
||||||
|
@ -309,10 +308,10 @@ void PrintVersion(void)
|
||||||
//
|
//
|
||||||
void PrintUsage(void)
|
void PrintUsage(void)
|
||||||
{
|
{
|
||||||
printf("Usage: bdf2c [OPTIONs]\n"
|
printf("Usage: bdf2c [OPTIONs]\n" "\t-b\tRead bdf file from stdin\n"
|
||||||
"\t-b\tRead bdf file from stdin\n"
|
"\t-c\tCreate font header on stdout\n"
|
||||||
"\t-c\tCreate font header on stdout\n"
|
"\t-C file\tCreate font header file\n"
|
||||||
"\t-C file\tCreate font header file\n");
|
"\t-n name\tName of c font variable (place it before -b)\n");
|
||||||
printf("\tOnly idiots print usage on stderr\n");
|
printf("\tOnly idiots print usage on stderr\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,14 +320,17 @@ void PrintUsage(void)
|
||||||
//
|
//
|
||||||
int main(int argc, char *const argv[])
|
int main(int argc, char *const argv[])
|
||||||
{
|
{
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
name = "font";
|
||||||
//
|
//
|
||||||
// Parse arguments.
|
// Parse arguments.
|
||||||
//
|
//
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (getopt(argc, argv, "bcC:h?-")) {
|
switch (getopt(argc, argv, "bcC:n:h?-")) {
|
||||||
case 'b':
|
case 'b':
|
||||||
ReadBdf(stdin);
|
ReadBdf(stdin, name);
|
||||||
break;
|
continue;
|
||||||
case 'c':
|
case 'c':
|
||||||
CreateFontHeaderFile(stdout);
|
CreateFontHeaderFile(stdout);
|
||||||
break;
|
break;
|
||||||
|
@ -344,7 +346,10 @@ int main(int argc, char *const argv[])
|
||||||
CreateFontHeaderFile(out);
|
CreateFontHeaderFile(out);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
}
|
}
|
||||||
break;
|
continue;
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
continue;
|
||||||
|
|
||||||
case EOF:
|
case EOF:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user