add -p option
This commit is contained in:
parent
494cf3dbb0
commit
e70dde2a44
|
@ -1,17 +1,37 @@
|
|||
|
||||
.SUFFIXES: .bmf .bdf .png
|
||||
|
||||
CFLAGS = -g -Wall -Wno-unused-but-set-variable
|
||||
#CFLAGS = -O4 -Wall
|
||||
|
||||
SRC = bmf2bdf.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
BMF:=$(wildcard *.bmf)
|
||||
PNG:=$(BMF:.bmf=.png)
|
||||
|
||||
|
||||
bmf2bdf: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o bmf2bdf
|
||||
|
||||
png: bmf2bdf $(PNG)
|
||||
|
||||
clean:
|
||||
-rm $(OBJ) bmf2bdf
|
||||
-rm $(OBJ) bmf2bdf *.bdf *.png *.tga
|
||||
|
||||
test:
|
||||
./bmf2bdf 24sans-t.bmf >24sans_t.bdf
|
||||
./bmf2bdf -p 24sans-t.bmf >24sans_t.bdf
|
||||
../bdfconv/bdfconv -f 1 -v 24sans_t.bdf -n 24sans_t -d ../bdf/7x14.bdf
|
||||
convert -trim -flip bdf.tga 24sans_t.png
|
||||
|
||||
.bmf.png:
|
||||
./bmf2bdf $< > $*.bdf
|
||||
- ../bdfconv/bdfconv -f 1 -v $*.bdf -n $* -d ../bdf/7x14.bdf -a -t
|
||||
- convert -trim -flip bdf.tga $@
|
||||
- rm bdf.tga
|
||||
./bmf2bdf -p $< > $*-p.bdf
|
||||
- ../bdfconv/bdfconv -f 1 -v $*-p.bdf -n $*-p -d ../bdf/7x14.bdf -a -t
|
||||
- convert -trim -flip bdf.tga $*-p.png
|
||||
- rm bdf.tga
|
||||
|
||||
|
||||
|
|
|
@ -46,6 +46,14 @@ uint8_t threshold = 128; // gray level threshold
|
|||
|
||||
FILE *bdf_fp = NULL;
|
||||
|
||||
/*
|
||||
option "-p"
|
||||
default: Use the shift value from bmf format for the BDF DWIDTH property
|
||||
"-p": Calculate the bdf DWIDTH from width, relx and addSpace vales.
|
||||
This will force a none-fixed = proportional font
|
||||
*/
|
||||
int optionForceProportional = 0;
|
||||
|
||||
int16_t lineHeight;
|
||||
int16_t sizeOver;
|
||||
int16_t sizeUnder;
|
||||
|
@ -65,6 +73,10 @@ char title[256+2];
|
|||
int8_t tablo[5];
|
||||
uint8_t bitmap[256*256];
|
||||
|
||||
int totalGlyphSize = 0;
|
||||
int cntGlyphSize = 0;
|
||||
int averageGlyphSize = 0;
|
||||
|
||||
|
||||
void write_bdf_header(void)
|
||||
{
|
||||
|
@ -140,17 +152,31 @@ void write_byte(int x)
|
|||
void write_bdf_bitmap(uint32_t encoding)
|
||||
{
|
||||
int x, y;
|
||||
int width, height;
|
||||
int width, height, relx, rely;
|
||||
int dwidth;
|
||||
width = (uint8_t)tablo[0];
|
||||
height = (uint8_t)tablo[1];
|
||||
relx = (int8_t)tablo[2];
|
||||
rely = (int8_t)tablo[3];
|
||||
|
||||
dwidth = tablo[4]+addSpace;
|
||||
if ( optionForceProportional )
|
||||
{
|
||||
if ( width == 0 )
|
||||
dwidth = averageGlyphSize + relx + addSpace;
|
||||
else
|
||||
dwidth = width + relx + addSpace +1;
|
||||
}
|
||||
|
||||
if ( bdf_fp == NULL )
|
||||
return;
|
||||
|
||||
fprintf(bdf_fp, "STARTCHAR %u\n", encoding);
|
||||
fprintf(bdf_fp, "ENCODING %u\n", encoding);
|
||||
fprintf(bdf_fp, "DWIDTH %d 0\n", tablo[4]);
|
||||
fprintf(bdf_fp, "BBX %d %d 0 0\n", width, height);
|
||||
fprintf(bdf_fp, "DWIDTH %d 0\n", dwidth);
|
||||
//fprintf(bdf_fp, "BBX %d %d %d %d\n", width, height, relx, sizeOver+rely);
|
||||
fprintf(bdf_fp, "BBX %d %d %d %d\n",
|
||||
width, height, relx, -(sizeOver+height+rely));
|
||||
fprintf(bdf_fp, "BITMAP\n");
|
||||
|
||||
for( y = 0; y < height; y++ )
|
||||
|
@ -175,7 +201,7 @@ uint16_t readWord(FILE *file)
|
|||
return h*256+l;
|
||||
}
|
||||
|
||||
int processBMF(const char *filename)
|
||||
int processBMF(const char *filename, int isAnalyze)
|
||||
{
|
||||
FILE *file = fopen(filename, "rb");
|
||||
static int8_t buffer[18];
|
||||
|
@ -230,8 +256,10 @@ int processBMF(const char *filename)
|
|||
|
||||
//printf("asciiChars=%d\n", (int)asciiChars);
|
||||
|
||||
|
||||
write_bdf_header();
|
||||
if ( isAnalyze == 0 )
|
||||
{
|
||||
write_bdf_header();
|
||||
}
|
||||
for (i = 0; i < asciiChars; i++)
|
||||
{
|
||||
whichChar = (uint8_t)fgetc(file);
|
||||
|
@ -273,8 +301,19 @@ int processBMF(const char *filename)
|
|||
}
|
||||
*/
|
||||
|
||||
write_bdf_bitmap(whichChar);
|
||||
|
||||
if ( isAnalyze )
|
||||
{
|
||||
if ( (whichChar >= 'A' && whichChar <= 'Z') || (whichChar >= 'a' && whichChar <= 'z') )
|
||||
{
|
||||
totalGlyphSize += w;
|
||||
cntGlyphSize++;
|
||||
averageGlyphSize = ((totalGlyphSize*2) / (cntGlyphSize*3));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
write_bdf_bitmap(whichChar);
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (version >= 0x12) { // next goes for version 1.2 only
|
||||
|
@ -300,17 +339,47 @@ int processBMF(const char *filename)
|
|||
|
||||
void help(void)
|
||||
{
|
||||
puts("bmf2bdf <file.bmf>");
|
||||
puts("bmf2bdf [options] <file.bmf>");
|
||||
puts(" -p Ignore the BMF shift value and try to recalculate it (creates a proportional font)");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *bmf_name = NULL;
|
||||
bdf_fp = stdout;
|
||||
if ( argc < 2 )
|
||||
{
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
processBMF(argv[1]);
|
||||
|
||||
argv++;
|
||||
argc--;
|
||||
while( argv != NULL && argc > 0)
|
||||
{
|
||||
if ( (*argv)[0] != '-' )
|
||||
{
|
||||
bmf_name = *argv;
|
||||
}
|
||||
else if ( strcmp(*argv, "-p") == 0 )
|
||||
{
|
||||
optionForceProportional = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Wrong option %s\n", *argv);
|
||||
return 1;
|
||||
}
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
|
||||
|
||||
if ( bmf_name != NULL )
|
||||
{
|
||||
processBMF(bmf_name, 1);
|
||||
processBMF(bmf_name, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue