64 void *ptr =
calloc( size + 2, 1);
117 if(*str ==
'\"' || *str ==
' ' || *str ==
'\t')
162 if(*str ==
' ' || *str ==
'\t')
196 while(*str && ( *str <= ' ' || *str >= 0x7f) )
225 while(*str >
' ' && *str <= 0x7e && len < max)
249 if( (c >=
'0' && c <=
'9') )
251 else if (c >=
'A' && c <=
'F')
252 return( c -
'A' + 10);
253 else if (c >=
'a' || c <=
'f')
264 while(*str &&
ishex(*str) >= 0)
287 while(*str <= ' ' || *str >= 0x7f)
293 while(*ptr >
' ' && *ptr <= 0x7e )
310 if(
strncmp(str,pat,patlen) == 0)
333 fprintf(out,
" @file %s\n", target);
334 fprintf(out,
" Created using %s (c) 2015 by Mike Gore\n" 351 fprintf(out,
"Font info empty\n");
368 fprintf(out,
"#ifndef MEMSPACE_FONT\n");
369 fprintf(out,
" #define MEMSPACE_FONT /* */\n");
376 fprintf(out,
"extern unsigned char %s_bitmap[];\n",
380 fprintf(out,
"#ifdef FONTSPECS\n");
381 fprintf(out,
" extern _fontspecs %s_specs[];\n",
386 fprintf(out,
"#ifdef FONTINFO\n");
387 fprintf(out,
" extern _fontinfo %s_info[];\n",
392 fprintf(out,
"/* Font %s */\n\n",
416 fprintf(out,
"#ifdef FONTSPECS\n");
419 fprintf(out,
"\tNULL, /* font->specs */\n");
421 fprintf(out,
"#ifdef FONTINFO\n");
424 fprintf(out,
"\tNULL /* font->info */\n");
444 fprintf(out,
"\t/* %s = %d */\n", name, num);
445 fprintf(out,
"\t\t\%d,\n", num);
461 fprintf(out,
"\t/* %s */\n", name);
480 fprintf(out,
"\t/* %s */\n", name);
484 fprintf(out,
"\t\t\"%s\",\n", data);
617 if(
strcmp( BDFnames[i].structname, str) == 0)
635 fprintf(out,
"/* Font BIT DATA , MSB Left to Right (padded to byte alignment), Top Down */\n");
641 for(i=0;i<font->
Glyphs;++i)
662 fprintf(out,
"#ifdef FONTINFO\n");
663 fprintf(out,
"MEMSPACE_FONT _fontinfo %s_info[%d] = /* %s_info */\n",
692 fprintf(out,
"#ifdef FONTSPECS\n");
693 fprintf(out,
"MEMSPACE_FONT _fontspecs %s_specs[%d] = /* %s_specs */\n",
697 fprintf(out,
"\t\t/* Offset, Width, Height, X, Y*/\n");
698 for(i=0;i<font->
Glyphs;++i)
701 fprintf(out,
"\t\t{ % 5d, % 5d, % 5d, % 5d, %5d }, /* [%c]*/\n",
730 unsigned char *ptr = font->
bitmap;
732 if(num < 0 || num >= font->
Glyphs)
741 xoff = font->
specs[num].
X;
742 yoff = font->
specs[num].
Y;
743 bytes = ((w * h) + 7)/8;
752 bytes = ((w * h) + 7)/8;
753 offset = (bytes * num);
757 c = num + font->
First;
759 fprintf(out,
"/* index:%d, [%c] 0x%02x, W:% 3d, H:% 3d, X:% 3d, Y:% 3d */\n",
771 fprintf(out,
"0x%02x,", ptr[i]);
801 int x, addr, hexline;
811 int BitBox_Width = 0;
812 int BitBox_Height = 0;
818 unsigned char *ptr, *save, *bp;
835 bdf =
fopen(name,
"r");
850 while(
fgets(line,
sizeof(line), bdf) !=
NULL)
858 ptr =
get_token(line,token,
sizeof(token)-1);
859 if(
MATCH(token,
"FONTBOUNDINGBOX"))
863 ptr =
get_token(ptr,token,
sizeof(token)-1);
866 ptr =
get_token(ptr,token,
sizeof(token)-1);
870 ptr =
get_token(ptr,token,
sizeof(token)-1);
871 font->
X =
atoi(token);
872 ptr =
get_token(ptr,token,
sizeof(token)-1);
873 font->
Y =
atoi(token);
879 if(
MATCH(token,
"FONT_ASCENT"))
882 ptr =
get_token(ptr,token,
sizeof(token)-1);
886 if(
MATCH(token,
"FONT_DESCENT"))
889 ptr =
get_token(ptr,token,
sizeof(token)-1);
894 if(
MATCH(token,
"FONT"))
901 if(
MATCH(token,
"FAMILY_NAME"))
907 if(
MATCH(token,
"WEIGHT_NAME"))
913 if(
MATCH(token,
"SLANT"))
919 if(
MATCH(token,
"SPACING"))
929 if(c ==
'C' || c ==
'M')
934 if(
MATCH(token,
"COPYRIGHT"))
942 if(
MATCH(token,
"CHARS"))
944 ptr =
get_token(ptr,token,
sizeof(token)-1);
945 Glyphs =
atoi(token);
986 Next = font->
Width-1;
989 while(
fgets(line,
sizeof(line), bdf) !=
NULL)
996 ptr =
get_token(line,token,
sizeof(token)-1);
997 if(
MATCH(token,
"STARTCHAR"))
999 ptr =
get_token(ptr,token,
sizeof(token)-1);
1002 sscanf(token,
"%x", &character);
1013 if(
MATCH(token,
"ENCODING"))
1015 ptr =
get_token(ptr,token,
sizeof(token)-1);
1017 character =
atoi(token);
1029 if(
MATCH(token,
"DWIDTH"))
1031 ptr =
get_token(ptr,token,
sizeof(token)-1);
1037 if(
MATCH(token,
"BBX"))
1040 ptr =
get_token(ptr,token,
sizeof(token)-1);
1041 BitBox_Width =
atoi(token);
1042 ptr =
get_token(ptr,token,
sizeof(token)-1);
1043 BitBox_Height =
atoi(token);
1046 ptr =
get_token(ptr,token,
sizeof(token)-1);
1047 BitBox_X =
atoi(token);
1048 ptr =
get_token(ptr,token,
sizeof(token)-1);
1049 BitBox_Y =
atoi(token);
1069 if(BitBox_Width > font->
Width)
1071 fprintf(
stderr,
"Font:%d, Bit Width(%d) > Font bounding Box Bit Width(%d)!\n", ind, BitBox_Width,font->
Width);
1075 if(BitBox_Height > font->
Height)
1077 fprintf(
stderr,
"Font:%d, Bit Height(%d) > Font bounding Box Bit Height(%d)!\n", ind, BitBox_Height,font->
Height);
1084 if(
MATCH(token,
"BITMAP"))
1086 if(character < lower || character > upper)
1095 font->
Bytes = offset;
1102 while(
fgets(line,
sizeof(line), bdf) !=
NULL)
1109 ptr =
get_token(line,token,
sizeof(token)-1);
1111 if(
MATCH(token,
"ENDCHAR"))
1113 ptr =
get_token(ptr,token,
sizeof(token)-1);
1126 digit =
ishex(*ptr);
1128 while(mask && x < BitBox_Width)
1130 addr = x + BitBox_Width * hexline;
1132 bitsetxy(bp, x,hexline, BitBox_Width, BitBox_Height);
1134 bitclrxy(bp, x,hexline, BitBox_Width, BitBox_Height);
1143 bytes = ((BitBox_Width * BitBox_Height) + 7) / 8;
1150 if (++ind >= Glyphs )
1165 Next = font->
Width-1;
1171 font->
Bytes = offset;
1200 for(i=0;i<font->
Glyphs;++i)
1209 for(i=0;i<font->
Glyphs;++i)
1220 for(i=0;i<font->
Glyphs;++i)
1250 unsigned char *ptr = font->
bitmap;
1252 unsigned char *bp = save;
1255 for(i=0;i<font->
Glyphs;++i)
1269 skip = font->
Height-(yoff+h);
1270 for (y = 0; y <
skip; ++
y)
1272 for (x = 0; x < font->
Width; ++
x)
1276 for (y=0;y < h; ++
y) {
1277 for (x = 0; x < xoff; ++
x)
1279 for (x=0;x < w; ++
x) {
1285 for (x=xoff+w;x < font->
Width; ++
x)
1290 for (y = 0; y < yoff; ++
y)
1292 for (x = 0; x < font->
Width; ++
x)
1308 font->
Bytes = offset;
1342 unsigned char *ptr = font->
bitmap;
1362 for(i=0;i<font->
Glyphs;++i)
1384 offset = i * ((w*h)+7)/8;
1398 for (y=0;y <h; ++
y) {
1399 for (x=0;x < w; ++
x)
1426 width = maxx - minx + 1;
1436 height = maxy - miny + 1;
1447 ydelta = (h-1-maxy);
1456 font->
specs[i].
X += xdelta;
1459 font->
specs[i].
Y += ydelta;
1477 for (y=0;y < h; ++
y) {
1478 for (x=0;x < w ; ++
x)
1482 bitsetxy(
new+newoffset,x-minx,y-miny, width, height);
1493 bytes = ((width * height) + 7) / 8;
1503 font->
Bytes = newoffset;
1546 for(i=0;i<font->
Glyphs;++i)
1560 offset = i * ((w*h)+7)/8;
1565 for (y=0;y <h; ++
y) {
1570 for (x=0;x < w; ++
x)
1585 Width = (maxx - minx + 1);
1625 void bsetv(
unsigned char *ptr,
int addr)
1630 ptr[byte] |= (0x80 >> bit);
1639 void bclrv(
unsigned char *ptr,
int addr)
1644 ptr[byte] &= ~(0x80 >> bit);
1658 return ( ptr[byte] & (0x80 >> bit) );
1686 return( (ptr[byte] & (0x80 >> bit)) );
1714 ptr[byte] |= (0x80 >> bit);
1726 void bitclrxy(
unsigned char *ptr,
int x,
int y,
int width,
int height)
1731 if(y < 0 || y > height)
1735 if(x < 0 || x > width)
1739 addr = y * width +
x;
1742 ptr[byte] &= ~(0x80 >> bit);
1762 unsigned char *ptr = font->
bitmap;
1764 if(num < 0 || num >= font->
Glyphs)
1767 c = num + font->
First;
1775 xoff = font->
specs[num].
X;
1776 yoff = font->
specs[num].
Y;
1777 bytes = ((w * h) + 7)/8;
1786 bytes = ((w * h) + 7)/8;
1787 offset = (bytes * num);
1792 fprintf(out,
"/* index:%d, [%c] 0x%02x, W:% 3d, H:% 3d, X:% 3d, Y:% 3d */\n",
1802 for (x = 0; x < w; ++
x)
1809 for (y = 0; y < h; ++
y) {
1811 for (x = 0; x < w; ++
x) {
1822 for (x = 0; x < w; ++
x)
1845 unsigned char *ptr = font->
bitmap;
1847 if(num < 0 || num >= font->
Glyphs)
1850 c = num + font->
First;
1858 xoff = font->
specs[num].
X;
1859 yoff = font->
specs[num].
Y;
1868 offset = ((w * h) + 7)/8;
1869 ptr += (offset * num);
1872 fprintf(out,
"/* index:%d, [%c] 0x%02x, W:% 3d, H:% 3d, X:% 3d, Y:% 3d */\n",
1882 for (x = 0; x < font->
Width; ++
x)
1890 for (y = 0; y < font->
Height-(yoff+h); ++
y)
1893 for (x = 0; x < font->
Width; ++
x)
1898 for (y=0;y< h; ++
y) {
1900 for (x = 0; x < xoff; ++
x)
1902 for (x=0;x < w; ++
x) {
1908 for (x=xoff+w;x < font->
Width; ++
x)
1914 for (y = 0; y < yoff; ++
y)
1917 for (x = 0; x < font->
Width; ++
x)
1924 for (x = 0; x < font->
Width; ++
x)
1947 unsigned char *ptr = font->
bitmap;
1949 if(num < 0 || num >= font->
Glyphs)
1952 c = num + font->
First;
1960 xoff = font->
specs[num].
X;
1961 yoff = font->
specs[num].
Y;
1962 bytes = ((w * h) + 7)/8;
1971 bytes = ((w * h) + 7)/8;
1972 offset = (bytes * num);
1977 fprintf(out,
"/* index:%d, [%c] 0x%02x, W:% 3d, H:% 3d, X:% 3d, Y:% 3d */\n",
1988 for (x = 0; x < w; ++
x)
1996 for (y = 0; y < font->
Height-(yoff+h); ++
y)
1999 for (x = 0; x < w; ++
x)
2004 for (y=0;y< h; ++
y) {
2006 for (x=0;x < w; ++
x) {
2016 for (y = 0; y < yoff+1; ++
y)
2019 for (x = 0; x < w; ++
x)
2026 for (x = 0; x < w; ++
x)
2045 fprintf(out,
"/* Font BIT DATA , MSB Left to Right (padded to byte alignment), Top Down */\n");
2047 for(i=0;i<font->
Glyphs;++i)
void WriteFontTable(FILE *out, _font *font)
Write Specification Font Table.
MEMSPACE int WEAK_ATR strcmp(const char *str, const char *pat)
Compare two strings.
int ReadBdf(char *name, _font *font, int lower, int upper)
Read and parse a BDF file for specified font and character set range Fills fonts structures.
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
char * remove_quotes(char *str)
STrip quotes from string and leading spaces.
Cordic_T X
Main Cordic routine - used for basic trig and vector rotations We use fixed point numbers...
void FreeFont(_font *font)
Free font data.
par BDF font utils for BDF to C code converter Displays fonts generated by bdffont2c BDF to C code co...
int ishexstr(char *str)
Does a string only contain hex characters ?
MEMSPACE char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices
MEMSPACE FILE * fopen(const char *path, const char *mode)
POSIX Open a file with path name and ascii file mode string.
void FontHeaderInfo(FILE *out, _font *font, char *prog, char *target)
Write Font Header Information Copyright, font family, etc.
static struct ip_info info
MEMSPACE int WEAK_ATR strncmp(const char *str, const char *pat, size_t len)
Compare two strings maximum len bytes in size.
void emit_data(FILE *out, char *name, unsigned char *data, int size)
Write Font Structure element as a uint8_t value.
char * match_token(char *str, char *pat)
Match next token against pattern.
MEMSPACE int fprintf(FILE *fp, const char *format,...)
fprintf function Example user defined printf function using fputc for I/O This method allows I/O to d...
void bitsetxy(unsigned char *ptr, int x, int y, int w, int h)
Set bit in width * height size bit array usng x and y offsets.
void FontPreview(FILE *out, _font *font, int num)
Write Font Preview bit bounding box in ASCII character comments.
#define snprintf(s, size, format, args...)
void * db_calloc(size_t size)
calloc memory or error exit
void emit_number(FILE *out, char *name, int num)
Write Font Structure element as a number.
void WriteFontBits(FILE *out, _font *font)
Write Font bitmap data for all characters in a font.
void trim_tail(char *str)
Remove characters less then or equal to space from end of string.
char * skip_spaces(char *str)
Skip spaces at start of string.
MEMSPACE void * calloc(size_t nmemb, size_t size)
calloc buffer POSIX function
char * stralloc(char *str)
Allocate memory and copy string into it.
MEMSPACE WEAK_ATR char * strcpy(char *dest, const char *src)
copy a string
void WriteFontBitsPreview(FILE *out, _font *font, int preview)
Write all Font characters in a font as ASCII character comments.
int FindFontName(char *str)
Search for a font name.
MEMSPACE void free(void *p)
Free buffer POSIX function We only call os_free() is pointer is not null.
MEMSPACE int token(char *str, char *pat)
Search for token in a string matching user pattern.
void InitFonts(_font *font)
Initialize all font structures to reset states.
void AddFontName(_font *font)
Generate the font name for this font This is based on the BDF FAMILY_NAME,WEIGHT_NAME,SLANT keywords.
void ComputeGapSize(_font *font)
Find a good gap size (inter-character spacing) for any font Currently we searching for the smallest w...
MEMSPACE int WEAK_ATR toupper(int c)
Convert character to upper case, only if it is lower case.
MEMSPACE int fclose(FILE *stream)
POSIX close a file stream.
void bsetv(unsigned char *ptr, int addr)
bit set in byte array
int sscanf(const char *strp, const char *fmt,...)
int ishex(int c)
is a character hex ASCII character
char * get_token(char *str, char *token, int max)
get first non space containing string Skip spaces at start of string
void FontAdjustSmall(_font *font)
Ajust font to use smallest font bounding box for each font Can be used to converting large fixed font...
void bitclrxy(unsigned char *ptr, int x, int y, int width, int height)
Clear bit in width * height size bit array usng x and y offsets.
void FontPreviewProportional(FILE *out, _font *font, int num)
Write Font Preview as proportional format in ASCII character comments.
void bclrv(unsigned char *ptr, int addr)
bit clear in byte array
void FontPreviewFull(FILE *out, _font *font, int num)
Write Font Preview as full format in ASCII character comments.
void * db_free(void *p)
free memory
MEMSPACE char * basename(char *str)
POSIX Basename of filename.
void Convert_Font2c(FILE *out, _font *font)
Convert font to C structure Writes header information, font specification, font bitmap.
_bdffile BDFnames[MAXFONTS]
void InitNames()
Reset File and Structure names.
void FontAdjustFull(_font *font)
Adjust font to full size with no offset.
int btestv(unsigned char *ptr, int addr)
Test bit in byte array.
MEMSPACE int atoi(const char *str)
Convert ASCII string to number in base 10.
int bittestxy(unsigned char *ptr, int x, int y, int w, int h)
Test bit in width * height size bit array usng x and y offsets.
void emit_str(FILE *out, char *name, unsigned char *data)
Write Font Structure string.
void AdjustFontTable(_font *font)
Adjust Font X Y offset, renormalize X Y to 0 0 Also readjust font bounding box.
void WriteFontInfo(FILE *out, _font *font)
Write C Header: Font Information Summary.
void line_wrap(char *str, int max)
Line wrap function ASSUMES we write back into the string (replace space or tab with newlines...
void WriteCharacterBits(FILE *out, _font *font, int num)
Write Font bitmap data for one charactre.