Option to remove advance deleted on grounds of minimal savings

pull/3/merge
Peter Hinch 2016-10-22 13:34:00 +01:00
rodzic e7c2fdf7d5
commit 5fd6f42305
1 zmienionych plików z 18 dodań i 25 usunięć

Wyświetl plik

@ -40,11 +40,11 @@ required height in pixels and outputs a Python 3 source file. The pixel layout
is determined by command arguments. Arguments also define whether the font is to is determined by command arguments. Arguments also define whether the font is to
be stored in proportional or fixed width form. be stored in proportional or fixed width form.
Further arguments will be specified by the documentation for the specific Further arguments ensure that the byte contents and layout are correct for the
device driver in use. They ensure that the byte contents and layout are correct target display hardware. Their usage should be defined in the documentation for
for the target display hardware. the device driver.
Example usage to produce a file ``myfont.py`` with height of 23 pixels Example usage to produce a file ``myfont.py`` with height of 23 pixels:
``font_to_py.py FreeSans.ttf 23 -o myfont.py`` ``font_to_py.py FreeSans.ttf 23 -o myfont.py``
## Arguments ## Arguments
@ -61,8 +61,6 @@ Example usage to produce a file ``myfont.py`` with height of 23 pixels
default fonts are assumed to be variable pitch. default fonts are assumed to be variable pitch.
* -h Specifies horizontal mapping (default is vertical). * -h Specifies horizontal mapping (default is vertical).
* -b Specifies big-endian bytes (default little endian). * -b Specifies big-endian bytes (default little endian).
* -n For variable pitch fonts specifies that blank advance bits should be
omitted from the character map.
Optional arguments other than the fixed pitch argument will be specified in the Optional arguments other than the fixed pitch argument will be specified in the
device driver documentation. device driver documentation.
@ -106,15 +104,13 @@ The user program imports a Python font file. This instantiates a ``PyFont``
object with appropriate constructor arguments such as the metrics of the object with appropriate constructor arguments such as the metrics of the
specific font. When the user program needs to display a string it passes the specific font. When the user program needs to display a string it passes the
instance to the device driver. The instance exposes appropriate font metrics instance to the device driver. The instance exposes appropriate font metrics
defined in pixels and a ``get_ch()`` method. The latter provides fast access to (defined in pixels) and a ``get_ch()`` method. The latter provides fast access
the bytes corresponding to an individual character together with character to the bytes corresponding to an individual character together with character
specific metrics. specific metrics.
All fixed width characters include blank bits after the character bits to define Fixed width characters include blank bits after the character bits to pad out
the width. By default variable pitch characters include blank "advance" bits to the width. Variable pitch characters include a small number of blank "advance"
provide correct spacing between characters. These may optionally be omitted from bits to provide correct spacing between characters.
the data with the -n argument. In this instance the driver may supply them: the
number of bits to be supplied is stored in byte 1 of the character data.
## The PyFont class ## The PyFont class
@ -124,24 +120,22 @@ as follows:
```python ```python
class PyFont(object): class PyFont(object):
def __init__(self, font, index, vert, horiz): def __init__(self, font, index, vert, horiz):
self.bits_horiz = horiz # Width of monospaced char or 0 if variable self._bits_horiz = horiz # Width of monospaced char or 0 if variable
self.bits_vert = vert # Height of all chars self._bits_vert = vert # Height of all chars
self._index = index self._index = index
self._font = font self._font = font
def get_ch(self, ch): def get_ch(self, ch):
from uctypes import addressof from uctypes import addressof
# Replace out of range characters with a default # Replace out of range characters with a default
# compute offset of current character bitmap and get char metrics # compute offset of current character bitmap and char width
return addressof(self._font) + offset, self.bits_vert, char_width, advance) return addressof(self._font) + offset, self._bits_vert, char_width)
def get_properties(self): def get_properties(self):
return self.bits_vert, self.bits_horiz return self._bits_vert, self._bits_horiz
``` ```
The device driver calls the ``get_ch`` method for each character. If the driver The device driver calls the ``get_ch`` method for each character in a string.
is to provide the advance (user told to use the -n option) the ``advance`` value
is the number of bits to supply. Otherwise its value will be 0.
## Font files ## Font files
@ -165,10 +159,9 @@ Python source file is a lesser consideration, with readability being prioritised
over size. Hence they will be "pretty printed" with the large bytes objects over size. Hence they will be "pretty printed" with the large bytes objects
split over multiple lines for readability. split over multiple lines for readability.
The bytes object for the font will store the character width in byte 0 and the The ``get_ch`` method will determine the character width from the difference
advance in byte 1. This will be transparent to the device driver, the pointer between current and next index values and the font's vertical size: it does not
returned by ``get_ch`` will be to the raw font data. This implies that the width require explicit storage.
will be restricted to 256 pixels: huge in the context of realistic hardware.
This general approach has been tested on a Pyboard connected to LCD hardware This general approach has been tested on a Pyboard connected to LCD hardware
having an onboard frame buffer. The visual performance is good. having an onboard frame buffer. The visual performance is good.