From 45c247c4dff7a976fbc3dfbfb3ba9520f21d7176 Mon Sep 17 00:00:00 2001 From: Brian Cappello Date: Fri, 7 Jul 2017 10:18:58 -0400 Subject: [PATCH] revert get_char to get_ch rename for BC --- DRIVERS.md | 12 ++++++------ FONT_TO_PY.md | 2 +- README.md | 2 +- font_test.py | 6 ++++-- font_to_py.py | 4 ++-- writer.py | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/DRIVERS.md b/DRIVERS.md index 78fa947..1ca8706 100644 --- a/DRIVERS.md +++ b/DRIVERS.md @@ -110,7 +110,7 @@ buffer/device. ### 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 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 @@ -174,7 +174,7 @@ b'\x1b\x01\x35\x01\x4f\x01\x75\x01\x9e\x01\xb2\x01\xcc\x01\xe0\x01'\ _mvfont = memoryview(_font) # Boilerplate code omitted -def get_char(ch): +def get_ch(ch): # validate ch, if out of range use '?' # get offsets into _font and retrieve char 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 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 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) ## Binary font files @@ -255,7 +255,7 @@ of the character in pixels, with all subsequent bytes storing the line data. #### 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 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 @@ -274,7 +274,7 @@ A sample drawing implementation can be found [here](https://github.com/peterhinc #### 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 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 diff --git a/FONT_TO_PY.md b/FONT_TO_PY.md index 8d7689a..6fdecd8 100644 --- a/FONT_TO_PY.md +++ b/FONT_TO_PY.md @@ -114,7 +114,7 @@ gc.collect() micropython.mem_info() def foo(): - addr, height, width = freeserif.get_char('a') + addr, height, width = freeserif.get_ch('a') foo() diff --git a/README.md b/README.md index 1ab17ec..8a6b420 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ provided to font-to-py: ``reverse`` Returns ``True`` if bit reversal was specified. Should return ``False`` ``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: * A ``memoryview`` object containing the glyph bytes. diff --git a/font_test.py b/font_test.py index ef0faba..3158cec 100644 --- a/font_test.py +++ b/font_test.py @@ -51,7 +51,7 @@ def render_bitmapped_string(myfont, string): height = myfont.height() for row in range(height): for char in string: - data, _, width = myfont.get_char(char) + data, _, width = myfont.get_ch(char) if myfont.hmap(): render_row_hmap(data, row, height, width, myfont.reverse()) else: @@ -89,7 +89,7 @@ def render_linemapped_string(myfont, string): height = myfont.height() for row in range(height): for char in string: - is_lhmap, data, _, width = myfont.get_char(char) + is_lhmap, data, _, width = myfont.get_ch(char) if is_lhmap: render_row_lhmap(data, row, height, width) else: @@ -117,6 +117,8 @@ def render_row_lhmap(data, row, height, width): lines.append(lines[-1]) y += 1 data_i += 1 + if y == row: + break while len(lines) < height: lines.append([]) diff --git a/font_to_py.py b/font_to_py.py index 68c91ef..9b2449b 100755 --- a/font_to_py.py +++ b/font_to_py.py @@ -539,7 +539,7 @@ def _char_bounds(ch): GET_CHAR = """ _mvfont = memoryview(_font) -def get_char(ch): +def get_ch(ch): start, end = _char_bounds(ch) width = _from_bytes(_mvfont[start:start + 2]) return _mvfont[start + 2:end], %(height)s, width @@ -548,7 +548,7 @@ def get_char(ch): GET_CHAR_LMAP = """ _mvfont = memoryview(_font) -def get_char(ch): +def get_ch(ch): start, end = _char_bounds(ch) is_lhmap = _mvfont[start] width = _mvfont[start+1] diff --git a/writer.py b/writer.py index 41e3d73..73fbdf5 100644 --- a/writer.py +++ b/writer.py @@ -86,7 +86,7 @@ class Writer(object): self._newline() 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: self._newline() @@ -144,7 +144,7 @@ class Writer(object): self._newline() 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: self._newline()