ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Macros | Functions | Variables
bdffontutil.h File Reference

par BDF font utils for BDF to C code converter Displays fonts generated by bdffont2c BDF to C code converter BDF = Glyph Bitmap Distribution Format The code handles fixed, proportional and bounding box format fonts More...

Go to the source code of this file.

Macros

#define MATCH(a, b)   ( ( strcmp(a,b) == 0 ) ? 1 : 0 )
 
#define MAXLINE   1024
 

Functions

void * db_calloc (size_t size)
 calloc memory or error exit More...
 
void * db_free (void *p)
 free memory More...
 
char * stralloc (char *str)
 Allocate space for string. More...
 
char * remove_quotes (char *str)
 STrip quotes from string and leading spaces. More...
 
void line_wrap (char *str, int max)
 Line wrap function ASSUMES we write back into the string (replace space or tab with newlines. More...
 
void trim_tail (char *str)
 Trim White space and control characters from end of string. More...
 
char * skip_spaces (char *str)
 Skip spaces at start of string. More...
 
char * get_token (char *str, char *token, int max)
 return next token More...
 
int ishex (int c)
 is a character hex ASCII character More...
 
int ishexstr (char *str)
 Does a string only contain hex characters ? More...
 
char * match_token (char *str, char *pat)
 Match next token against pattern. More...
 
void FontHeaderInfo (FILE *out, _font *font, char *prog, char *target)
 Write Font Header Information Copyright, font family, etc. More...
 
void Convert_Font2c (FILE *out, _font *font)
 Convert font to C structure Writes header information, font specification, font bitmap. More...
 
void emit_number (FILE *out, char *name, int num)
 Write Font Structure element as a number. More...
 
void emit_data (FILE *out, char *name, unsigned char *data, int size)
 Write Font Structure element as a uint8_t value. More...
 
void emit_str (FILE *out, char *name, unsigned char *data)
 Write Font Structure string. More...
 
void InitNames (void)
 Reset File and Structure names. More...
 
void InitFonts (_font *font)
 Initialize all font structures to reset states. More...
 
void FreeFont (_font *font)
 Free font data. More...
 
void AddFontName (_font *font)
 Generate the font name for this font This is based on the BDF FAMILY_NAME,WEIGHT_NAME,SLANT keywords. More...
 
int FindFontName (char *str)
 Search for a font name. More...
 
void WriteFontBits (FILE *out, _font *font)
 Write Font bitmap data for all characters in a font. More...
 
void WriteFontInfo (FILE *out, _font *font)
 Write C Header: Font Information Summary. More...
 
void WriteFontTable (FILE *out, _font *font)
 Write Specification Font Table. More...
 
void WriteCharacterBits (FILE *out, _font *font, int num)
 Write Font bitmap data for one charactre. More...
 
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. More...
 
void AdjustFontTable (_font *font)
 Adjust Font X Y offset, renormalize X Y to 0 0 Also readjust font bounding box. More...
 
void FontAdjustFull (_font *font)
 Adjust font to full size with no offset. More...
 
void FontAdjustSmall (_font *font)
 Ajust font to use smallest font bounding box for each font Can be used to converting large fixed fonts to more compact form Creates font->specs if missing. Updates font->specs with new font size and offsets Can convert fixed to proportional or optimize bounding box to smallest size for space savings. More...
 
void ComputeGapSize (_font *font)
 Find a good gap size (inter-character spacing) for any font Currently we searching for the smallest width feature in a font set and use it as the gap Set update font->gap FIXME Alternatively we may wish to consider scanning characters only in their middle (virtically) center. More...
 
void bsetv (unsigned char *ptr, int addr)
 bit set in byte array More...
 
void bclrv (unsigned char *ptr, int addr)
 bit clear in byte array More...
 
int btestv (unsigned char *ptr, int addr)
 Test bit in byte array. More...
 
int bittestxy (unsigned char *ptr, int x, int y, int w, int h)
 Test bit in w * h size bit array usng x and y offsets. More...
 
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. More...
 
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. More...
 
void FontPreview (FILE *out, _font *font, int num)
 Write Font Preview bit bounding box in ASCII character comments. More...
 
void FontPreviewFull (FILE *out, _font *font, int num)
 Write Font Preview as full format in ASCII character comments. More...
 
void FontPreviewProportional (FILE *out, _font *font, int num)
 Write Font Preview as proportional format in ASCII character comments. More...
 
void WriteFontBitsPreview (FILE *out, _font *font, int preview)
 Write all Font characters in a font as ASCII character comments. More...
 

Variables

_font font
 
_bdffile BDFnames [MAXFONTS]
 
char * fnames [MAXFONTS]
 

Detailed Description

par BDF font utils for BDF to C code converter Displays fonts generated by bdffont2c BDF to C code converter BDF = Glyph Bitmap Distribution Format The code handles fixed, proportional and bounding box format fonts

See also
http://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format
Copyright © 2015 Mike Gore, GPL License
You are free to use this code under the terms of GPL
please retain a copy of this notice in any code you use it in.

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file bdffontutil.h.

Macro Definition Documentation

#define MATCH (   a,
 
)    ( ( strcmp(a,b) == 0 ) ? 1 : 0 )

BDF = Glyph Bitmap Distribution Format See: http://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format

Definition at line 39 of file bdffontutil.h.

Referenced by fatfs_tests(), ls(), mkfs(), posix_tests(), and ReadBdf().

#define MAXLINE   1024

Definition at line 40 of file bdffontutil.h.

Referenced by AddFontName(), main(), and ReadBdf().

Function Documentation

void AddFontName ( _font font)

Generate the font name for this font This is based on the BDF FAMILY_NAME,WEIGHT_NAME,SLANT keywords.

Parameters
[in]*fontFont pointer
Returns
: void

Definition at line 582 of file bdffontutil.c.

Referenced by ReadBdf().

void AdjustFontTable ( _font font)

Adjust Font X Y offset, renormalize X Y to 0 0 Also readjust font bounding box.

Parameters
[in]*fontFont pointer
Returns
: void

Definition at line 1191 of file bdffontutil.c.

Referenced by FontAdjustSmall(), and ReadBdf().

void bclrv ( unsigned char *  ptr,
int  addr 
)

bit clear in byte array

Parameters
[in]*ptrbyte array
[in]addrbit offset to clear
Returns
void

Definition at line 1639 of file bdffontutil.c.

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.

Parameters
[in]*ptrbyte array
[in]xbit x offset
[in]ybit y offset
[in]widthwidth of bit array
[in]heightheight of bit array
Returns
void

Definition at line 1726 of file bdffontutil.c.

Referenced by FontAdjustFull(), and ReadBdf().

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.

Parameters
[in]*ptrbyte array
[in]xbit x offset
[in]ybit y offset
[in]wwidth of bit array
[in]hheight of bit array
Returns
void

Definition at line 1698 of file bdffontutil.c.

Referenced by FontAdjustFull(), FontAdjustSmall(), and ReadBdf().

int bittestxy ( unsigned char *  ptr,
int  x,
int  y,
int  w,
int  h 
)

Test bit in w * h size bit array usng x and y offsets.

Parameters
[in]*ptrbyte array
[in]xbit x offset
[in]ybit y offset
[in]wbit array wide
[in]hbit array high
Returns
1 if bit is set, 0 if not

Test bit in w * h size bit array usng x and y offsets.

Parameters
[in]*ptrbyte array
[in]xbit x offset
[in]ybit y offset
[in]wthe width of bit array
[in]hthe height of bit array
Returns
1 if bit is set, 0 if not

Definition at line 166 of file flash.c.

Referenced by ComputeGapSize(), FontAdjustFull(), FontAdjustSmall(), FontPreview(), FontPreviewFull(), and FontPreviewProportional().

void bsetv ( unsigned char *  ptr,
int  addr 
)

bit set in byte array

Parameters
[in]*ptrbyte array
[in]addrbit offset to clear
Returns
void

Definition at line 1625 of file bdffontutil.c.

int btestv ( unsigned char *  ptr,
int  addr 
)

Test bit in byte array.

Parameters
[in]*ptrbyte array
[in]addrbit offset to clear
Returns
1 if bit is set, 0 if not

Definition at line 1653 of file bdffontutil.c.

void ComputeGapSize ( _font font)

Find a good gap size (inter-character spacing) for any font Currently we searching for the smallest width feature in a font set and use it as the gap Set update font->gap FIXME Alternatively we may wish to consider scanning characters only in their middle (virtically) center.

Parameters
[in]*fontFont pointer
Returns
: void

Definition at line 1524 of file bdffontutil.c.

Referenced by main(), and ReadBdf().

void Convert_Font2c ( FILE out,
_font font 
)

Convert font to C structure Writes header information, font specification, font bitmap.

Parameters
[in]*outFile handle
[in]*fontFont handle
Returns
: void

Definition at line 365 of file bdffontutil.c.

Referenced by main().

void* db_calloc ( size_t  size)

calloc memory or error exit

Parameters
[in]sizememory size to calloc
Returns
: void * pointer

Definition at line 62 of file bdffontutil.c.

Referenced by FontAdjustFull(), FontAdjustSmall(), InitFonts(), ReadBdf(), and stralloc().

void* db_free ( void *  p)

free memory

Parameters
[in]*pmemory pointer to free
Returns
: void * pointer

Definition at line 78 of file bdffontutil.c.

Referenced by FontAdjustFull(), FontAdjustSmall(), and FreeFont().

void emit_data ( FILE out,
char *  name,
unsigned char *  data,
int  size 
)

Write Font Structure element as a uint8_t value.

Parameters
[in]*outFile handle
[in]*namestructure name
[in]*datadata
[in]sizesize of data to write
Returns
: void

Definition at line 457 of file bdffontutil.c.

void emit_number ( FILE out,
char *  name,
int  num 
)

Write Font Structure element as a number.

Parameters
[in]*outFile output handle
[in]*namenumber structure name
[in]numnumber to display
Returns
: void

Definition at line 442 of file bdffontutil.c.

Referenced by Convert_Font2c().

void emit_str ( FILE out,
char *  name,
unsigned char *  data 
)

Write Font Structure string.

Parameters
[in]*outFile handle
[in]*namestructure name
[in]*datastring
Returns
: void

Definition at line 478 of file bdffontutil.c.

Referenced by WriteFontInfo().

int FindFontName ( char *  str)

Search for a font name.

Returns
: index into BDFnames[]

Definition at line 611 of file bdffontutil.c.

Referenced by main().

void FontAdjustFull ( _font font)

Adjust font to full size with no offset.

Parameters
[in]*fontFont pointer
Returns
: void

Definition at line 1240 of file bdffontutil.c.

Referenced by main().

void FontAdjustSmall ( _font font)

Ajust font to use smallest font bounding box for each font Can be used to converting large fixed fonts to more compact form Creates font->specs if missing. Updates font->specs with new font size and offsets Can convert fixed to proportional or optimize bounding box to smallest size for space savings.

Parameters
[in]*fontFont pointer
Returns
: void

Definition at line 1325 of file bdffontutil.c.

Referenced by main().

void FontHeaderInfo ( FILE out,
_font font,
char *  prog,
char *  target 
)

Write Font Header Information Copyright, font family, etc.

Parameters
[in]*outFile handle
[in]*fontFont handle
[in]*progprogram name
[in]*targetfile name comments
Returns
: void

Definition at line 323 of file bdffontutil.c.

Referenced by main().

void FontPreview ( FILE out,
_font font,
int  num 
)

Write Font Preview bit bounding box in ASCII character comments.

Parameters
[in]*outFile handle
[in]*fontFont pointer
[in]numFont character
Returns
: void

Definition at line 1753 of file bdffontutil.c.

Referenced by WriteFontBitsPreview().

void FontPreviewFull ( FILE out,
_font font,
int  num 
)

Write Font Preview as full format in ASCII character comments.

Parameters
[in]*outFile handle
[in]*fontFont pointer
[in]numFont character
Returns
: void

Definition at line 1836 of file bdffontutil.c.

Referenced by WriteFontBitsPreview().

void FontPreviewProportional ( FILE out,
_font font,
int  num 
)

Write Font Preview as proportional format in ASCII character comments.

Parameters
[in]*outFile handle
[in]*fontFont pointer
[in]numFont character
Returns
: void

Definition at line 1938 of file bdffontutil.c.

Referenced by WriteFontBitsPreview().

void FreeFont ( _font font)

Free font data.

Parameters
[in]*fontFont pointer
Returns
: void

Definition at line 554 of file bdffontutil.c.

Referenced by main().

char* get_token ( char *  str,
char *  token,
int  max 
)

return next token

  • Skips all non printable ASCII characters before token
  • Token returns only printable ASCII
Parameters
[in]strstring to search.
[out]tokentoken to return
[in]maxmaximum token size
Returns
pointer past token on success .
NULL if no token found

return next token

Parameters
[in]*strstring
[out]*tokentoken characters greter then space less then 0x7f
[in]maxmaximum length of token
Returns
: string pointer to character after token

Definition at line 628 of file stringsup.c.

Referenced by ReadBdf().

void InitFonts ( _font font)

Initialize all font structures to reset states.

Parameters
[in]*fontFont pointer
Returns
: void

Definition at line 512 of file bdffontutil.c.

Referenced by ReadBdf().

void InitNames ( void  )

Reset File and Structure names.

Returns
: void

Definition at line 491 of file bdffontutil.c.

int ishex ( int  c)

is a character hex ASCII character

Parameters
[in]ccharacter to test
Returns
: 0 .. 15 or -1 on error

Definition at line 247 of file bdffontutil.c.

Referenced by ishexstr(), and ReadBdf().

int ishexstr ( char *  str)

Does a string only contain hex characters ?

Returns
: 1 if hex , 0 if not

Definition at line 262 of file bdffontutil.c.

Referenced by ReadBdf().

void line_wrap ( char *  str,
int  max 
)

Line wrap function ASSUMES we write back into the string (replace space or tab with newlines.

Parameters
[in]*strstring to remove quotes from
[in]maxMaximum string length
Returns
: void

Definition at line 141 of file bdffontutil.c.

char* match_token ( char *  str,
char *  pat 
)

Match next token against pattern.

Parameters
[in]strstring to search
[in]patpattern Skips spaces at start of string A token is any string with caracters greter then space less then 0x7f
Returns
: length of match on sucess

Definition at line 279 of file bdffontutil.c.

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.

See also
: http://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format
Parameters
[in]*nameBDF File name
[in]*fontFont pointer
[in]lowerFirst character
[in]upperLast character
Returns
: number of characters processed

Definition at line 790 of file bdffontutil.c.

Referenced by main().

char* remove_quotes ( char *  str)

STrip quotes from string and leading spaces.

Parameters
[in]*strstring to remove quotes from
Returns
: char * pointer to first non-space character

Definition at line 109 of file bdffontutil.c.

Referenced by ReadBdf().

char* skip_spaces ( char *  str)

Skip spaces at start of string.

Parameters
[in]*strstring to remove quotes from
Returns
: first non space character

Definition at line 193 of file bdffontutil.c.

Referenced by get_token().

char* stralloc ( char *  str)

Allocate space for string.

  • Copies tring into allocated space.
Parameters
[in]struser string.
Returns
pointer to alocated string.
NULL on out of memory.

Allocate space for string.

Parameters
[in]*strstring to allocate and copy memory for
Returns
: char * pointer to allocated string

Definition at line 774 of file stringsup.c.

Referenced by AddFontName(), main(), and ReadBdf().

void trim_tail ( char *  str)

Trim White space and control characters from end of string.

Parameters
[in]strstring
Returns
void
Warning
Overwrites White space and control characters with EOS.

Trim White space and control characters from end of string.

Parameters
[in]*strstring to remove quotes from
Returns
: void

Definition at line 271 of file stringsup.c.

Referenced by cat(), match_headers(), ReadBdf(), and remove_quotes().

void WriteCharacterBits ( FILE out,
_font font,
int  num 
)

Write Font bitmap data for one charactre.

Parameters
[in]*outFile handle
[in]*fontFont pointer
[in]numcharacter number
Returns
: void

Definition at line 721 of file bdffontutil.c.

Referenced by WriteFontBits().

void WriteFontBits ( FILE out,
_font font 
)

Write Font bitmap data for all characters in a font.

Parameters
[in]*outFile handle
[in]*fontFont pointer
Returns
: void

Definition at line 631 of file bdffontutil.c.

Referenced by Convert_Font2c(), and main().

void WriteFontBitsPreview ( FILE out,
_font font,
int  preview 
)

Write all Font characters in a font as ASCII character comments.

Parameters
[in]*outFile handle
[in]*fontFont pointer
[in]preview1 bit bounding box, 2 Full size, 3 proportional
Returns
: void

Definition at line 2040 of file bdffontutil.c.

Referenced by main().

void WriteFontInfo ( FILE out,
_font font 
)

Write C Header: Font Information Summary.

Parameters
[in]*outFile handle
[in]*fontFont pointer
Returns
: void

Definition at line 654 of file bdffontutil.c.

Referenced by Convert_Font2c(), and main().

void WriteFontTable ( FILE out,
_font font 
)

Write Specification Font Table.

Parameters
[in]*outFile handle
[in]*fontFont pointer
Returns
: void

Definition at line 684 of file bdffontutil.c.

Referenced by Convert_Font2c(), and main().

Variable Documentation

_bdffile BDFnames[MAXFONTS]

BDF = Glyph Bitmap Distribution Format

See also
http://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format

Definition at line 51 of file bdffontutil.c.

Referenced by main().

char* fnames[MAXFONTS]

Definition at line 53 of file bdffontutil.c.

Referenced by InitNames(), and main().

_font font

Referenced by font_H(), and font_W().