kopia lustrzana https://github.com/peterhinch/micropython-font-to-py
Writer/CWriter clip partial characters.
rodzic
8780c22105
commit
3c9eec9476
|
@ -97,6 +97,7 @@ class Writer():
|
||||||
self.glyph = None # Current char
|
self.glyph = None # Current char
|
||||||
self.char_height = 0
|
self.char_height = 0
|
||||||
self.char_width = 0
|
self.char_width = 0
|
||||||
|
self.clip_width = 0
|
||||||
|
|
||||||
def _getstate(self):
|
def _getstate(self):
|
||||||
return Writer.state[self.devid]
|
return Writer.state[self.devid]
|
||||||
|
@ -199,13 +200,17 @@ class Writer():
|
||||||
return
|
return
|
||||||
glyph, char_height, char_width = self.font.get_ch(char)
|
glyph, char_height, char_width = self.font.get_ch(char)
|
||||||
s = self._getstate()
|
s = self._getstate()
|
||||||
|
np = None # Allow restriction on printable columns
|
||||||
if self.usd:
|
if self.usd:
|
||||||
if s.text_row - char_height < 0:
|
if s.text_row - char_height < 0:
|
||||||
if self.row_clip:
|
if self.row_clip:
|
||||||
return
|
return
|
||||||
self._newline()
|
self._newline()
|
||||||
if s.text_col - char_width < 0:
|
oh = s.text_col - char_width # Amount glyph would overhang edge (-ve)
|
||||||
|
if oh < 0:
|
||||||
if self.col_clip:
|
if self.col_clip:
|
||||||
|
np = char_width + oh # No of printable columns
|
||||||
|
if np <= 0:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self._newline()
|
self._newline()
|
||||||
|
@ -214,14 +219,18 @@ class Writer():
|
||||||
if self.row_clip:
|
if self.row_clip:
|
||||||
return
|
return
|
||||||
self._newline()
|
self._newline()
|
||||||
if s.text_col + char_width > self.screenwidth:
|
oh = s.text_col + char_width - self.screenwidth # Overhang (+ve)
|
||||||
|
if oh > 0:
|
||||||
if self.col_clip:
|
if self.col_clip:
|
||||||
|
np = char_width - oh # No. of printable columns
|
||||||
|
if np <= 0:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self._newline()
|
self._newline()
|
||||||
self.glyph = glyph
|
self.glyph = glyph
|
||||||
self.char_height = char_height
|
self.char_height = char_height
|
||||||
self.char_width = char_width
|
self.char_width = char_width
|
||||||
|
self.clip_width = char_width if np is None else np
|
||||||
|
|
||||||
# Method using blitting. Efficient rendering for monochrome displays.
|
# Method using blitting. Efficient rendering for monochrome displays.
|
||||||
# Tested on SSD1306. Invert is for black-on-white rendering.
|
# Tested on SSD1306. Invert is for black-on-white rendering.
|
||||||
|
@ -234,7 +243,7 @@ class Writer():
|
||||||
if invert:
|
if invert:
|
||||||
for i, v in enumerate(buf):
|
for i, v in enumerate(buf):
|
||||||
buf[i] = 0xFF & ~ v
|
buf[i] = 0xFF & ~ v
|
||||||
fbc = framebuf.FrameBuffer(buf, self.char_width, self.char_height, self.map)
|
fbc = framebuf.FrameBuffer(buf, self.clip_width, self.char_height, self.map)
|
||||||
self.device.blit(fbc, s.text_col, s.text_row)
|
self.device.blit(fbc, s.text_col, s.text_row)
|
||||||
s.text_col += self.char_width
|
s.text_col += self.char_width
|
||||||
self.cpos += 1
|
self.cpos += 1
|
||||||
|
@ -278,6 +287,7 @@ class CWriter(Writer):
|
||||||
fbc = framebuf.FrameBuffer(buf, self.char_width, self.char_height, self.map)
|
fbc = framebuf.FrameBuffer(buf, self.char_width, self.char_height, self.map)
|
||||||
fgcolor = self.bgcolor if invert else self.fgcolor
|
fgcolor = self.bgcolor if invert else self.fgcolor
|
||||||
bgcolor = self.fgcolor if invert else self.bgcolor
|
bgcolor = self.fgcolor if invert else self.bgcolor
|
||||||
|
# render clips a glyph if outside bounds of destination
|
||||||
render(self.device, fbc, s.text_col, s.text_row, fgcolor, bgcolor)
|
render(self.device, fbc, s.text_col, s.text_row, fgcolor, bgcolor)
|
||||||
s.text_col += self.char_width
|
s.text_col += self.char_width
|
||||||
self.cpos += 1
|
self.cpos += 1
|
||||||
|
@ -289,6 +299,7 @@ class CWriter(Writer):
|
||||||
return # All done
|
return # All done
|
||||||
char_height = self.char_height
|
char_height = self.char_height
|
||||||
char_width = self.char_width
|
char_width = self.char_width
|
||||||
|
clip_width = self.clip_width
|
||||||
|
|
||||||
div, mod = divmod(char_width, 8)
|
div, mod = divmod(char_width, 8)
|
||||||
gbytes = div + 1 if mod else div # No. of bytes per row of glyph
|
gbytes = div + 1 if mod else div # No. of bytes per row of glyph
|
||||||
|
@ -299,7 +310,7 @@ class CWriter(Writer):
|
||||||
drow = s.text_row # Destination row
|
drow = s.text_row # Destination row
|
||||||
wcol = s.text_col # Destination column of character start
|
wcol = s.text_col # Destination column of character start
|
||||||
for srow in range(char_height): # Source row
|
for srow in range(char_height): # Source row
|
||||||
for scol in range(char_width): # Source column
|
for scol in range(clip_width): # Source column
|
||||||
# Destination column: add/subtract writer column
|
# Destination column: add/subtract writer column
|
||||||
if usd:
|
if usd:
|
||||||
dcol = wcol - scol
|
dcol = wcol - scol
|
||||||
|
|
Ładowanie…
Reference in New Issue