kopia lustrzana https://github.com/peterhinch/micropython-font-to-py
Tidy up docs
rodzic
1bcf06c531
commit
ba0b85d22f
38
DRIVERS.md
38
DRIVERS.md
|
@ -58,6 +58,12 @@ of characters is maintained regardless of the font in use.
|
||||||
1. ``printstring`` Arg: a text string. Outputs a text string at the current
|
1. ``printstring`` Arg: a text string. Outputs a text string at the current
|
||||||
insertion point. Newline characters are honoured.
|
insertion point. Newline characters are honoured.
|
||||||
|
|
||||||
|
## Note on the Writer class
|
||||||
|
|
||||||
|
This is more a proof of concept than a final implementation. Obvious
|
||||||
|
enhancements include rendering to a rectangular area, support for proper word
|
||||||
|
wrap and support for format control characters such as tabs.
|
||||||
|
|
||||||
# Device Driver Implementation
|
# Device Driver Implementation
|
||||||
|
|
||||||
Display devices comprise two varieties, depending on whether the framebuffer is
|
Display devices comprise two varieties, depending on whether the framebuffer is
|
||||||
|
@ -65,7 +71,8 @@ located on the controlling system or on the physical display device. In the
|
||||||
former case the ``Writer`` class simplifies the design of the driver. It merely
|
former case the ``Writer`` class simplifies the design of the driver. It merely
|
||||||
has to expose certin attributes and methods with ``Writer`` instances taking
|
has to expose certin attributes and methods with ``Writer`` instances taking
|
||||||
care of text rendering. It is strongly recommended that such device drivers use
|
care of text rendering. It is strongly recommended that such device drivers use
|
||||||
the oficial ``framebuf`` module, as per the official SSD1306 driver.
|
the oficial ``framebuf`` module, as per the official SSD1306 driver which
|
||||||
|
exposes the required components.
|
||||||
|
|
||||||
Where the buffer is located on the display device the means of controlling the
|
Where the buffer is located on the display device the means of controlling the
|
||||||
text insertion point will be device dependent. The driver will need to
|
text insertion point will be device dependent. The driver will need to
|
||||||
|
@ -104,26 +111,21 @@ buffer/device.
|
||||||
Each font file has a ``get_ch()`` function accepting an ASCII character as its
|
Each font file has a ``get_ch()`` function accepting an ASCII character as its
|
||||||
argument. It returns a memoryview instance providing access to a bytearray
|
argument. It returns a memoryview instance providing access to a bytearray
|
||||||
corresponding to the individual glyph. The layout of this data is determined by
|
corresponding to the individual glyph. The layout of this data is determined by
|
||||||
the command line arguments presented to the ``font_to_py.py`` utility. The
|
the command line arguments presented to the ``font_to_py.py`` utility. It is
|
||||||
driver documentation should specify these to ensure the layout is optimal to
|
the responsibility of the driver to copy that data to the physical device.
|
||||||
simplify and speed transfer to the device. Mapping may be horizontal or
|
|
||||||
vertical, and the bit order of individual bytes may be defined. These are
|
|
||||||
detailed below.
|
|
||||||
|
|
||||||
The Python source file provides a fast means of accessing the byte data
|
The purpose of the ``font_to_py.py`` command line arguments specified to the
|
||||||
corresponding to an individual character. It is the responsibility of the
|
user is to ensure that the data layout is optimised for the device so that this
|
||||||
driver to copy that data to the physical device. The ``font_to_py.py``
|
copy operation is a fast bytewise copy or SPI/I2C transfer. The driver
|
||||||
utility has command line arguments specifying the organisation of data returned
|
documentation should therefore specify these arguments to ensure the layout is
|
||||||
by the font's ``get_ch()`` function.
|
optimal. Mapping may be horizontal or vertical, and the bit order of individual
|
||||||
|
bytes may be defined. These are detailed below.
|
||||||
|
|
||||||
The purpose of the command line arguments specified to the user is to
|
In the case of devices with their own frame buffer the ``Writer`` class will need
|
||||||
ensure that the data layout is optimised for the device so that the copy is a
|
|
||||||
simple bytewise copy or SPI/I2C transfer.
|
|
||||||
|
|
||||||
In the case of devices with their own frame buffer the Writer class will need
|
|
||||||
to be re-written or adapted to match the hardware's method of tracking such
|
to be re-written or adapted to match the hardware's method of tracking such
|
||||||
things as the text insertion point. Consider maintaining the class's interface
|
things as the text insertion point. Consideration should be given to employing
|
||||||
to simplify the writing of user code capable of being ported between displays.
|
the same interface as the ``Writer`` class to simplify the porting of user code
|
||||||
|
between displays with differing hardware.
|
||||||
|
|
||||||
## Font files
|
## Font files
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,10 @@ your code you will issue
|
||||||
import myfont
|
import myfont
|
||||||
```
|
```
|
||||||
|
|
||||||
The ``myfont`` module name will then be passed to the device driver to render
|
The ``myfont`` module name will then be used to instantiate a ``Writer`` object
|
||||||
strings on demand. The detailed layout of the Python file may be seen [here](./DRIVERS.md).
|
to render strings on demand. A practical example may be studied
|
||||||
|
[here](https://github.com/peterhinch/micropython-samples/blob/master/SSD1306/ssd1306_test.py).
|
||||||
|
The detailed layout of the Python file may be seen [here](./DRIVERS.md).
|
||||||
|
|
||||||
# Dependencies, links and licence
|
# Dependencies, links and licence
|
||||||
|
|
||||||
|
|
|
@ -35,14 +35,14 @@ This consists of three components:
|
||||||
2. The Writer class (writer.py) This facilitates writing text to a device
|
2. The Writer class (writer.py) This facilitates writing text to a device
|
||||||
given a suitably designed device driver. See [here](./DRIVERS.md).
|
given a suitably designed device driver. See [here](./DRIVERS.md).
|
||||||
3. A device driver specification. This includes an example for rendering text
|
3. A device driver specification. This includes an example for rendering text
|
||||||
to an SSD1306 device with arbitrary fonts. See [here](./DRIVERS.md).
|
to an SSD1306 device with arbitrary fonts. Also described in the above reference.
|
||||||
|
|
||||||
# font_to_py.py
|
# font_to_py.py
|
||||||
|
|
||||||
This is a command line utility written in Python 3 to be run on a PC. It takes
|
This is a command line utility written in Python 3 to be run on a PC. It takes
|
||||||
as input a font file in ttf or otf form and a height and outputs a Python
|
as input a font file in ``ttf`` or ``otf`` form together with a height in pixels
|
||||||
source file containing the font data. Fixed and variable pitch rendering are
|
and outputs a Python source file containing the font data. Fixed and variable
|
||||||
supported. The design has the following aims:
|
pitch rendering are supported. The design has the following aims:
|
||||||
|
|
||||||
* Independence of specific display hardware.
|
* Independence of specific display hardware.
|
||||||
* The path from font file to Python code to be fully open source.
|
* The path from font file to Python code to be fully open source.
|
||||||
|
|
Ładowanie…
Reference in New Issue