Compare commits

..

4 commits

Author SHA1 Message Date
Scott Shawcroft
26e1493ad6
Merge pull request #5 from FoamyGuy/update_docs_badge_url
Some checks failed
Build CI / test (push) Has been cancelled
fix docs badge url
2025-04-21 11:04:54 -07:00
foamyguy
1c80329624 fix docs badge url 2025-04-16 13:00:54 -05:00
Scott Shawcroft
2ad6132cbb
Merge pull request #4 from dglaude/patch-1
ReadTheDoc URL with - or with _ ???
2025-04-16 10:52:12 -07:00
David Glaude
29773c25c1
ReadTheDoc URL with - or with _ ???
I don't know what is going on, but the documentation link is wrong in the Readme.

I have not compare to other library to know if they use "-" or "_" I just fix this link.
2025-04-16 13:21:42 +02:00
2 changed files with 25 additions and 53 deletions

View file

@ -3,7 +3,7 @@ Introduction
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-display-emoji-text/badge/?version=latest
:target: https://docs.circuitpython.org/projects/display_emoji_text/en/latest/
:target: https://docs.circuitpython.org/projects/display-emoji-text/en/latest/
:alt: Documentation Status
@ -111,7 +111,7 @@ Usage Example
Documentation
=============
API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/display_emoji_text/en/latest/>`_.
API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/display-emoji-text/en/latest/>`_.
For information on building library documentation, please check out
`this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.

View file

@ -76,13 +76,12 @@ class EmojiLabel(Widget):
FIVE_WIDES = [127947, 9977, 128105, 127948, 128104, 128065, 127987]
def __init__(
self,
text,
scale=1,
ascii_font=terminalio.FONT,
fg_color=0xFFFFFF,
# ruff: noqa: PLR0912, PLR0915, PLR1702
# Too many branches, Too many statements, Too many nested blocks
self,
text,
scale=1,
ascii_font=terminalio.FONT,
# ruff: noqa: PLR0912, PLR0915, PLR1702
# Too many branches, Too many statements, Too many nested blocks
):
try:
os.stat("emoji")
@ -95,40 +94,26 @@ class EmojiLabel(Widget):
self.font = ascii_font
self.ascii_palette = displayio.Palette(2)
self.ascii_palette[0] = 0x000000
self.ascii_palette.make_transparent(0)
self.ascii_palette[1] = fg_color
self._text = text
self._width = 0
self._height = 12
self._bounding_box = [0, 0, 0, 12]
self._row_width = 0
self._next_x = 0
self._next_y = 0
self._update_text(self._text)
def _update_text(self, new_text):
while len(self) > 0:
del self[0]
self.ascii_palette[1] = 0xFFFFFF
self._width = 0
self._height = 12
self._bounding_box = [0, 0, 0, 12]
self._bounding_box = [0, 0, 0, 0]
self._row_width = 0
self._next_x = 0
self._next_y = 0
self._last_x = 0
self._last_y = 0
skip_count = 0
for i, char in enumerate(new_text):
for i, char in enumerate(text):
if skip_count > 0:
skip_count -= 1
continue
# print(char)
if char == "\n":
# print("newline")
self._next_y += 12
self._next_x = 0
self._last_y += 12
self._last_x = 0
self._height += 12
self._row_width = 0
self._bounding_box[3] = self._height
@ -150,16 +135,14 @@ class EmojiLabel(Widget):
skip_source_index=0,
)
tg = displayio.TileGrid(bitmap=bmp, pixel_shader=self.ascii_palette)
self.append(tg)
tg.x = self._next_x
tg.y = self._next_y
tg.x = self._last_x
tg.y = self._last_y
self._row_width += bmp.width
if self._width < self._row_width:
self._width = self._row_width
self._bounding_box[2] = self._width
self._next_x += found_glyph.width
self._last_x += found_glyph.width
self.append(tg)
else:
bmp = None
for cur_range in EmojiLabel.MULTI_CODE_RANGES:
@ -168,9 +151,8 @@ class EmojiLabel(Widget):
if ord(char) in EmojiLabel.FIVE_WIDES:
# try 5 wide file
try:
filename = f"emoji/U+{ord(char):X}_U+{ord(new_text[i + 1]):X}_U+{ord(new_text[i + 2]):X}_U+{ord(new_text[i + 3]):X}_U+{ord(new_text[i + 4]):X}.png" # noqa: E501, Line too long
filename = f"emoji/U+{ord(char):X}_U+{ord(text[i + 1]):X}_U+{ord(text[i + 2]):X}_U+{ord(text[i + 3]):X}_U+{ord(text[i + 4]):X}.png" # noqa: E501, Line too long
bmp, palette = adafruit_imageload.load(filename)
skip_count = 4
break
except (OSError, IndexError):
@ -178,14 +160,14 @@ class EmojiLabel(Widget):
# try 4 wide file
try:
filename = f"emoji/U+{ord(char):X}_U+{ord(new_text[i + 1]):X}_U+{ord(new_text[i + 2]):X}_U+{ord(new_text[i + 3]):X}.png" # noqa: E501, Line too long
filename = f"emoji/U+{ord(char):X}_U+{ord(text[i + 1]):X}_U+{ord(text[i + 2]):X}_U+{ord(text[i + 3]):X}.png" # noqa: E501, Line too long
bmp, palette = adafruit_imageload.load(filename)
skip_count = 3
break
except (OSError, IndexError):
# try double wide file
try:
filename = f"emoji/U+{ord(char):X}_U+{ord(new_text[i + 1]):X}.png"
filename = f"emoji/U+{ord(char):X}_U+{ord(text[i + 1]):X}.png"
bmp, palette = adafruit_imageload.load(filename)
skip_count = 1
break
@ -197,30 +179,20 @@ class EmojiLabel(Widget):
filename = f"emoji/U+{ord(char):X}.png"
try:
bmp, palette = adafruit_imageload.load(filename)
except OSError:
print(f"Unable to render: {hex(ord(char))}")
try:
tg = displayio.TileGrid(bitmap=bmp, pixel_shader=palette)
tg.x = self._next_x
tg.y = self._next_y
tg.x = self._last_x
tg.y = self._last_y
self._row_width += bmp.width
if self._width < self._row_width:
self._width = self._row_width
self._bounding_box[2] = self._width
self._next_x += bmp.width + 1
self._last_x += bmp.width + 1
self.append(tg)
except TypeError:
# Unsupported bitmap type
print(f"Unable to render {hex(ord(char))}. Unsupported bitmap")
@property
def text(self):
return self._text
@text.setter
def text(self, new_text):
if new_text != self._text:
self._update_text(new_text)