ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts
1.0
ESP8266ILI9341DisplayProject
|
BDF to C code converter Copyright © 2015 Mike Gore 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...
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <stdint.h>
#include <ctype.h>
#include "font.h"
#include "bdffontutil.h"
Go to the source code of this file.
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 memory and copy string into it. 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) |
Remove characters less then or equal to space 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) |
get first non space containing string Skip spaces at start of string 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 () |
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 width * height 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 | |
_bdffile | BDFnames [MAXFONTS] |
char * | fnames [MAXFONTS] |
char * | EMPTY = "" |
BDF to C code converter Copyright © 2015 Mike Gore 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.
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.c.
void AddFontName | ( | _font * | font | ) |
Generate the font name for this font This is based on the BDF FAMILY_NAME,WEIGHT_NAME,SLANT keywords.
[in] | *font | Font pointer |
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.
[in] | *font | Font pointer |
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
[in] | *ptr | byte array |
[in] | addr | bit offset to clear |
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.
[in] | *ptr | byte array |
[in] | x | bit x offset |
[in] | y | bit y offset |
[in] | width | width of bit array |
[in] | height | height of bit array |
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.
[in] | *ptr | byte array |
[in] | x | bit x offset |
[in] | y | bit y offset |
[in] | w | width of bit array |
[in] | h | height of bit array |
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 width * height size bit array usng x and y offsets.
Test bit in w * h size bit array usng x and y offsets.
[in] | *ptr | byte array |
[in] | x | bit x offset |
[in] | y | bit y offset |
[in] | w | the width of bit array |
[in] | h | the height of bit array |
Definition at line 1670 of file bdffontutil.c.
Referenced by ComputeGapSize(), FontAdjustFull(), FontAdjustSmall(), FontPreview(), FontPreviewFull(), and FontPreviewProportional().
void bsetv | ( | unsigned char * | ptr, |
int | addr | ||
) |
bit set in byte array
[in] | *ptr | byte array |
[in] | addr | bit offset to clear |
Definition at line 1625 of file bdffontutil.c.
int btestv | ( | unsigned char * | ptr, |
int | addr | ||
) |
Test bit in byte array.
[in] | *ptr | byte array |
[in] | addr | bit offset to clear |
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.
[in] | *font | Font pointer |
Definition at line 1524 of file bdffontutil.c.
Convert font to C structure Writes header information, font specification, font bitmap.
[in] | *out | File handle |
[in] | *font | Font handle |
Definition at line 365 of file bdffontutil.c.
Referenced by main().
void* db_calloc | ( | size_t | size | ) |
calloc memory or error exit
[in] | size | memory size to calloc |
Definition at line 62 of file bdffontutil.c.
Referenced by FontAdjustFull(), FontAdjustSmall(), InitFonts(), ReadBdf(), and stralloc().
void* db_free | ( | void * | p | ) |
free memory
[in] | *p | memory pointer to free |
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.
[in] | *out | File handle |
[in] | *name | structure name |
[in] | *data | data |
[in] | size | size of data to write |
Definition at line 457 of file bdffontutil.c.
void emit_number | ( | FILE * | out, |
char * | name, | ||
int | num | ||
) |
Write Font Structure element as a number.
[in] | *out | File output handle |
[in] | *name | number structure name |
[in] | num | number to display |
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.
[in] | *out | File handle |
[in] | *name | structure name |
[in] | *data | string |
Definition at line 478 of file bdffontutil.c.
Referenced by WriteFontInfo().
int FindFontName | ( | char * | str | ) |
Search for a font name.
Definition at line 611 of file bdffontutil.c.
Referenced by main().
void FontAdjustFull | ( | _font * | font | ) |
Adjust font to full size with no offset.
[in] | *font | Font pointer |
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.
[in] | *font | Font pointer |
Definition at line 1325 of file bdffontutil.c.
Referenced by main().
Write Font Header Information Copyright, font family, etc.
[in] | *out | File handle |
[in] | *font | Font handle |
[in] | *prog | program name |
[in] | *target | file name comments |
Definition at line 323 of file bdffontutil.c.
Referenced by main().
Write Font Preview bit bounding box in ASCII character comments.
[in] | *out | File handle |
[in] | *font | Font pointer |
[in] | num | Font character |
Definition at line 1753 of file bdffontutil.c.
Referenced by WriteFontBitsPreview().
Write Font Preview as full format in ASCII character comments.
[in] | *out | File handle |
[in] | *font | Font pointer |
[in] | num | Font character |
Definition at line 1836 of file bdffontutil.c.
Referenced by WriteFontBitsPreview().
Write Font Preview as proportional format in ASCII character comments.
[in] | *out | File handle |
[in] | *font | Font pointer |
[in] | num | Font character |
Definition at line 1938 of file bdffontutil.c.
Referenced by WriteFontBitsPreview().
void FreeFont | ( | _font * | font | ) |
Free font data.
[in] | *font | Font pointer |
Definition at line 554 of file bdffontutil.c.
Referenced by main().
char* get_token | ( | char * | str, |
char * | token, | ||
int | max | ||
) |
get first non space containing string Skip spaces at start of string
return next token
[in] | *str | string |
[out] | *token | token characters greter then space less then 0x7f |
[in] | max | maximum length of token |
Definition at line 209 of file bdffontutil.c.
Referenced by ReadBdf().
void InitFonts | ( | _font * | font | ) |
Initialize all font structures to reset states.
[in] | *font | Font pointer |
Definition at line 512 of file bdffontutil.c.
Referenced by ReadBdf().
void InitNames | ( | void | ) |
int ishex | ( | int | c | ) |
is a character hex ASCII character
[in] | c | character to test |
Definition at line 247 of file bdffontutil.c.
Referenced by ishexstr(), and ReadBdf().
int ishexstr | ( | char * | str | ) |
Does a string only contain hex characters ?
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.
[in] | *str | string to remove quotes from |
[in] | max | Maximum string length |
Definition at line 141 of file bdffontutil.c.
char* match_token | ( | char * | str, |
char * | pat | ||
) |
Match next token against pattern.
[in] | str | string to search |
[in] | pat | pattern Skips spaces at start of string A token is any string with caracters greter then space less then 0x7f |
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.
[in] | *name | BDF File name |
[in] | *font | Font pointer |
[in] | lower | First character |
[in] | upper | Last character |
Definition at line 790 of file bdffontutil.c.
Referenced by main().
char* remove_quotes | ( | char * | str | ) |
STrip quotes from string and leading spaces.
[in] | *str | string to remove quotes from |
Definition at line 109 of file bdffontutil.c.
Referenced by ReadBdf().
char* skip_spaces | ( | char * | str | ) |
Skip spaces at start of string.
[in] | *str | string to remove quotes from |
Definition at line 193 of file bdffontutil.c.
Referenced by get_token().
char* stralloc | ( | char * | str | ) |
Allocate memory and copy string into it.
Allocate space for string.
[in] | *str | string to allocate and copy memory for |
Definition at line 93 of file bdffontutil.c.
Referenced by AddFontName(), and ReadBdf().
void trim_tail | ( | char * | str | ) |
Remove characters less then or equal to space from end of string.
Trim White space and control characters from end of string.
[in] | *str | string to remove quotes from |
Definition at line 177 of file bdffontutil.c.
Referenced by ReadBdf(), and remove_quotes().
Write Font bitmap data for one charactre.
[in] | *out | File handle |
[in] | *font | Font pointer |
[in] | num | character number |
Definition at line 721 of file bdffontutil.c.
Referenced by WriteFontBits().
Write Font bitmap data for all characters in a font.
[in] | *out | File handle |
[in] | *font | Font pointer |
Definition at line 631 of file bdffontutil.c.
Referenced by Convert_Font2c(), and main().
Write all Font characters in a font as ASCII character comments.
[in] | *out | File handle |
[in] | *font | Font pointer |
[in] | preview | 1 bit bounding box, 2 Full size, 3 proportional |
Definition at line 2040 of file bdffontutil.c.
Referenced by main().
Write C Header: Font Information Summary.
[in] | *out | File handle |
[in] | *font | Font pointer |
Definition at line 654 of file bdffontutil.c.
Referenced by Convert_Font2c(), and main().
Write Specification Font Table.
[in] | *out | File handle |
[in] | *font | Font pointer |
Definition at line 684 of file bdffontutil.c.
Referenced by Convert_Font2c(), and main().
BDF = Glyph Bitmap Distribution Format
Definition at line 51 of file bdffontutil.c.
Referenced by main().
char* EMPTY = "" |
Definition at line 55 of file bdffontutil.c.
Referenced by db_free(), and InitFonts().
char* fnames[MAXFONTS] |
Definition at line 53 of file bdffontutil.c.
Referenced by InitNames(), and main().