Skip to content

Commit bc0aa57

Browse files
committed
Binary fonts: Fix bug and improve docs (iss 59).
1 parent 5f585e7 commit bc0aa57

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

FONT_TO_PY.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ $ font_to_py.py -k extended FreeSans.ttf 23 my_extended_font.py
105105
* -e or --errchar Ordinal value of character to be rendered if an attempt is
106106
made to display an out-of-range character. Default 63 (ord("?")).
107107
* -i or --iterate Specialist use. See below.
108+
* -b or --binary Create a binary font file. See below.
108109
* -c or --charset Option to restrict the characters in the font to a specific
109110
set. See below.
110111
* -k or --charset_file Obtain the character set from a file. Typical use is
@@ -136,7 +137,7 @@ Any requirement for arguments -xr will be specified in the device driver
136137
documentation. Bit reversal is required by some display hardware.
137138

138139
Using the -f argument with a variable pitch source font will produce a fixed
139-
pitch result. A better apearance would be achieved by using a font designed as
140+
pitch result. A better appearance would be achieved by using a font designed as
140141
monospaced.
141142

142143
There have been reports that producing fonts with Unicode characters outside
@@ -208,22 +209,27 @@ for an explanation of `baseline`.
208209

209210
There is an option to create a binary font file, specified with a `-b` or
210211
`--binary` command line argument. In this instance the output filename must
211-
not have a `.py` extension. This is primarily intended for the e-paper driver
212-
in applications where the file is to be stored on the display's internal flash
213-
memory rather than using frozen Python modules.
214-
215-
The technique of accessing character data from a random access file is slow
216-
and thus probably only applicable to devices such as e-paper where the update
217-
time is slow.
212+
not have a `.py` extension. This format was developed for an e-paper driver
213+
where the file was stored on the display's internal flash memory; it is not
214+
clear if there is a current use case.
218215

219216
Binary files currently support only the standard ASCII character set. There is
220217
no error character: the device driver must ensure that seeks are within range.
218+
Conversion of bdf and pcf font files is currently unsupported.
219+
221220
Only the following optional arguments are valid:
222221

223222
* -f or --fixed.
224223
* -x or --xmap.
224+
* -y or --ymap
225225
* -r or --reverse.
226226

227+
The format of binary font files is described [here](./writer/DRIVERS.md).
228+
229+
An alternative implementation of binary fonts may be found in
230+
[this repo](https://github.com/antirez/microfont). It provides for rotated
231+
rendering to a `FrameBuffer`.
232+
227233
# 6. Dependencies, links and licence
228234

229235
The code is released under the MIT licence. The `font_to_py.py` utility

font_to_py.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def write_data(stream, fnt, font_path, hmap, reverse, iterate, charset):
591591
# 1 1 0x42 0xe7
592592
def write_binary_font(op_path, font_path, height, hmap, reverse):
593593
try:
594-
fnt = Font(font_path, height, 32, 126, True, None, "") # All chars have same width
594+
fnt = Font(font_path, height, 32, 126, True, None, "", False) # All chars have same width
595595
except freetype.ft_errors.FT_Exception:
596596
print("Can't open", font_path)
597597
return False

0 commit comments

Comments
 (0)