revert get_char to get_ch rename for BC

pull/3/head
Brian Cappello 2017-07-07 10:18:58 -04:00
rodzic 9da8817f68
commit 45c247c4df
6 zmienionych plików z 16 dodań i 14 usunięć

Wyświetl plik

@ -110,7 +110,7 @@ buffer/device.
### Specifying the font file ### Specifying the font file
Each font file has a ``get_char()`` 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. It is the command line arguments presented to the ``font_to_py.py`` utility. It is
@ -174,7 +174,7 @@ b'\x1b\x01\x35\x01\x4f\x01\x75\x01\x9e\x01\xb2\x01\xcc\x01\xe0\x01'\
_mvfont = memoryview(_font) _mvfont = memoryview(_font)
# Boilerplate code omitted # Boilerplate code omitted
def get_char(ch): def get_ch(ch):
# validate ch, if out of range use '?' # validate ch, if out of range use '?'
# get offsets into _font and retrieve char width # get offsets into _font and retrieve char width
# Return: memoryview of bitmap, height and width # Return: memoryview of bitmap, height and width
@ -190,11 +190,11 @@ will fit the available space. If it will fit on the assumption that all chars
are maximum width, it can be rendered rapidly without doing a character by are maximum width, it can be rendered rapidly without doing a character by
character check. character check.
``get_char()`` returns a memoryview of an individual glyph with its dimensions ``get_ch()`` returns a memoryview of an individual glyph with its dimensions
and contains all the bytes required to render the character including trailing and contains all the bytes required to render the character including trailing
space. space.
For line-mapped fonts, `get_char()` returns a 4-tuple: For line-mapped fonts, `get_ch()` returns a 4-tuple:
(is_horizontal_mapping, memoryview_of_char_line_data, height, width) (is_horizontal_mapping, memoryview_of_char_line_data, height, width)
## Binary font files ## Binary font files
@ -255,7 +255,7 @@ of the character in pixels, with all subsequent bytes storing the line data.
#### Horizontal Line Mapping #### Horizontal Line Mapping
For horizontally mapped line data, the format returned by `get_char` is as follows: For horizontally mapped line data, the format returned by `get_ch` is as follows:
For each row in the character with pixel data, the first byte specifies how many For each row in the character with pixel data, the first byte specifies how many
lines are in the row, and the second byte specifies the `y` coordinate of each of lines are in the row, and the second byte specifies the `y` coordinate of each of
the lines (with (0,0) being the top-left). Each line in the row then follows as the lines (with (0,0) being the top-left). Each line in the row then follows as
@ -274,7 +274,7 @@ A sample drawing implementation can be found [here](https://github.com/peterhinc
#### Vertical Line Mapping #### Vertical Line Mapping
For vertically mapped line data, the format returned by `get_char` is similar: For vertically mapped line data, the format returned by `get_ch` is similar:
For each column in the character with pixel data, the first byte specifies how For each column in the character with pixel data, the first byte specifies how
many lines are in the column, and the second byte specifies the `x` coordinate many lines are in the column, and the second byte specifies the `x` coordinate
of each of the lines (again with (0,0) being the top-left). Each line in the of each of the lines (again with (0,0) being the top-left). Each line in the

Wyświetl plik

@ -114,7 +114,7 @@ gc.collect()
micropython.mem_info() micropython.mem_info()
def foo(): def foo():
addr, height, width = freeserif.get_char('a') addr, height, width = freeserif.get_ch('a')
foo() foo()

Wyświetl plik

@ -80,7 +80,7 @@ provided to font-to-py:
``reverse`` Returns ``True`` if bit reversal was specified. Should return ``False`` ``reverse`` Returns ``True`` if bit reversal was specified. Should return ``False``
``monospaced`` Returns ``True`` if monospaced rendering was specified. ``monospaced`` Returns ``True`` if monospaced rendering was specified.
Glyphs are returned with the ``get_char`` method. Its argument is a character Glyphs are returned with the ``get_ch`` method. Its argument is a character
and it returns the following values: and it returns the following values:
* A ``memoryview`` object containing the glyph bytes. * A ``memoryview`` object containing the glyph bytes.

Wyświetl plik

@ -51,7 +51,7 @@ def render_bitmapped_string(myfont, string):
height = myfont.height() height = myfont.height()
for row in range(height): for row in range(height):
for char in string: for char in string:
data, _, width = myfont.get_char(char) data, _, width = myfont.get_ch(char)
if myfont.hmap(): if myfont.hmap():
render_row_hmap(data, row, height, width, myfont.reverse()) render_row_hmap(data, row, height, width, myfont.reverse())
else: else:
@ -89,7 +89,7 @@ def render_linemapped_string(myfont, string):
height = myfont.height() height = myfont.height()
for row in range(height): for row in range(height):
for char in string: for char in string:
is_lhmap, data, _, width = myfont.get_char(char) is_lhmap, data, _, width = myfont.get_ch(char)
if is_lhmap: if is_lhmap:
render_row_lhmap(data, row, height, width) render_row_lhmap(data, row, height, width)
else: else:
@ -117,6 +117,8 @@ def render_row_lhmap(data, row, height, width):
lines.append(lines[-1]) lines.append(lines[-1])
y += 1 y += 1
data_i += 1 data_i += 1
if y == row:
break
while len(lines) < height: while len(lines) < height:
lines.append([]) lines.append([])

Wyświetl plik

@ -539,7 +539,7 @@ def _char_bounds(ch):
GET_CHAR = """ GET_CHAR = """
_mvfont = memoryview(_font) _mvfont = memoryview(_font)
def get_char(ch): def get_ch(ch):
start, end = _char_bounds(ch) start, end = _char_bounds(ch)
width = _from_bytes(_mvfont[start:start + 2]) width = _from_bytes(_mvfont[start:start + 2])
return _mvfont[start + 2:end], %(height)s, width return _mvfont[start + 2:end], %(height)s, width
@ -548,7 +548,7 @@ def get_char(ch):
GET_CHAR_LMAP = """ GET_CHAR_LMAP = """
_mvfont = memoryview(_font) _mvfont = memoryview(_font)
def get_char(ch): def get_ch(ch):
start, end = _char_bounds(ch) start, end = _char_bounds(ch)
is_lhmap = _mvfont[start] is_lhmap = _mvfont[start]
width = _mvfont[start+1] width = _mvfont[start+1]

Wyświetl plik

@ -86,7 +86,7 @@ class Writer(object):
self._newline() self._newline()
return return
glyph, char_height, char_width = self.font.get_char(char) glyph, char_height, char_width = self.font.get_ch(char)
if Writer.x_pos + char_width > self.display.screen_width: if Writer.x_pos + char_width > self.display.screen_width:
self._newline() self._newline()
@ -144,7 +144,7 @@ class Writer(object):
self._newline() self._newline()
return return
is_lhmap, data, char_height, char_width = self.font.get_char(char) is_lhmap, data, char_height, char_width = self.font.get_ch(char)
if Writer.x_pos + char_width > self.display.screen_width: if Writer.x_pos + char_width > self.display.screen_width:
self._newline() self._newline()