kopia lustrzana https://github.com/peterhinch/micropython-font-to-py
Improvements to docs.
rodzic
93e42c4dd9
commit
24cc715c73
|
@ -13,7 +13,7 @@ is known as frozen bytecode.
|
|||
|
||||
17 Oct 2019 V0.33 With thanks to Stephen Irons (@ironss).
|
||||
1. Fix bug where input rather than output filename was checked.
|
||||
2. Add `baseline()` to ouput file returning the maximum descent.
|
||||
2. Add `baseline()` to ouput file returning the maximum ascent.
|
||||
3. Correct left position of rendered glyph.
|
||||
|
||||
21 Sept 2019 V0.22
|
||||
|
@ -116,6 +116,10 @@ character set.
|
|||
Any requirement for arguments -xr will be specified in the device driver
|
||||
documentation. Bit reversal is required by some display hardware.
|
||||
|
||||
Using the -f argument with a variable pitch source font will produce a fixed
|
||||
pitch result. A better apearance would be achieved by using a font designed as
|
||||
monospaced.
|
||||
|
||||
There have been reports that producing fonts with Unicode characters outside
|
||||
the ASCII set from ttf files is unreliable. If expected results are not
|
||||
achieved, use an otf font. I have successfully created Cyrillic and extended
|
||||
|
@ -150,6 +154,26 @@ to render strings on demand. A practical example may be studied
|
|||
[here](./writer/writer_demo.py).
|
||||
The detailed layout of the Python file may be seen [here](./writer/DRIVERS.md).
|
||||
|
||||
### Python font files
|
||||
|
||||
These start with a comment which is the command line used to create the font.
|
||||
|
||||
They include the following functions:
|
||||
1. `height()` Height of bitmaps in pixels (all are the same height).
|
||||
2. `max_width()` Width of widest glyph in pixels.
|
||||
3. `baseline()` Offset from top of the bitmap to the baseline. This is a
|
||||
notional "ruler line" where glyphs are drawn. Enables rendering different
|
||||
fonts on a common baseline. It is a positive number of pixels.
|
||||
4. `hmap()` `True` if bitmaps are horizonataly mapped.
|
||||
5. `reverse()` `True` if bit reversal is used.
|
||||
6. `monospaced()` `True` if bitmaps were created with fixed pitch.
|
||||
7. `min_ch()` Returns smallest ordinal value in font.
|
||||
8. `max_ch()` Largest ordinal value in font.
|
||||
9. `get_ch()` Arg: a Unicode character. Returns three items:
|
||||
1. A memoryview into the bitmap for that character.
|
||||
2. Bitmap height in pixels. Equal to `height()` above.
|
||||
3. Bitmap width in pixels.
|
||||
|
||||
### Binary font files
|
||||
|
||||
There is an option to create a binary font file, specified with a `-b` or
|
||||
|
|
25
README.md
25
README.md
|
@ -45,8 +45,8 @@ This comprises three components, links to docs below:
|
|||
|
||||
This command line utility is written in Python 3 and runs on a PC. It takes
|
||||
as input a font file in `ttf` or `otf` form together with a height in pixels
|
||||
and outputs a Python source file containing the font data. Fixed and variable
|
||||
pitch rendering are supported. The design has the following aims:
|
||||
and outputs a Python source file containing the font as a bitmap. Fixed and
|
||||
variable pitch rendering are supported. The design has the following aims:
|
||||
|
||||
* Independence of specific display hardware.
|
||||
* The path from font file to Python code to be fully open source.
|
||||
|
@ -71,35 +71,36 @@ size.
|
|||
|
||||
By default the `font_to_py.py` utility produces the ASCII character set from
|
||||
`chr(32)` to `chr(126)` inclusive. Command line options enable the character
|
||||
set to be modified to include extended ASCII. Alternative sets may be specified
|
||||
such as non-English languages or limited, non-contiguous sets for specialist
|
||||
applications.
|
||||
set to be modified to include arbitrary Unicode characters. Alternative sets
|
||||
may be specified such as for non-English languages. Efficient support is now
|
||||
provided for sparse character sets.
|
||||
|
||||
# Font file interface
|
||||
|
||||
A font file is imported in the usual way e.g. `import font14`. It contains
|
||||
the following methods which return values defined by the arguments which were
|
||||
provided to `font_to_py.py`:
|
||||
A font file is imported in the usual way e.g. `import font14`. Python font
|
||||
files contain the following functions. These return values defined by the
|
||||
arguments which were provided to `font_to_py.py`:
|
||||
|
||||
`height` Returns height in pixels.
|
||||
`max_width` Returns maximum width of a glyph in pixels.
|
||||
`baseline` Offset from top of glyph to the baseline.
|
||||
`hmap` Returns `True` if font is horizontally mapped.
|
||||
`reverse` Returns `True` if bit reversal was specified.
|
||||
`monospaced` Returns `True` if monospaced rendering was specified.
|
||||
`min_ch` Returns the ordinal value of the lowest character in the file.
|
||||
`max_ch` Returns the ordinal value of the highest character in the file.
|
||||
|
||||
Glyphs are returned with the `get_ch` method. Its argument is a character
|
||||
and it returns the following values:
|
||||
Glyphs are returned with the `get_ch` function. Its argument is a Unicode
|
||||
character and it returns the following values:
|
||||
|
||||
* A `memoryview` object containg the glyph bytes.
|
||||
* A `memoryview` object containing the glyph bytes.
|
||||
* The height in pixels.
|
||||
* The character width in pixels.
|
||||
|
||||
The `font_to_py.py` utility allows a default glyph to be specified (typically
|
||||
`?`). If called with an undefined character, this glyph will be returned.
|
||||
|
||||
The `min_ch` and `max_ch` methods are mainly relevant to contiguous character
|
||||
The `min_ch` and `max_ch` functions are mainly relevant to contiguous character
|
||||
sets.
|
||||
|
||||
# Licence
|
||||
|
|
Ładowanie…
Reference in New Issue