Created
April 20, 2024 11:58
-
-
Save cwalther/fb2b2ca00c59b0577089fbdc4d7e0a88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from framebuf import FrameBuffer, MONO_HMSB, MONO_HLSB | |
# currently only works for monochrome (fg, bg in {-1, 0, 1}) | |
class KeyedPalette(FrameBuffer): | |
def __init__(self, fg=0, bg=-1): | |
buf = bytearray(1) | |
if fg == -1: | |
self.key = fg = bg^1 | |
elif bg == -1: | |
self.key = bg = fg^1 | |
else: | |
self.key = -1 | |
buf[0] = (fg << 1) | bg | |
super().__init__(buf, 2, 1, MONO_HMSB) | |
def write(fb, s, x, y, font, palette=None): | |
for char in s: | |
glyph, char_height, char_width = font.get_ch(char) | |
if glyph: | |
fbc = FrameBuffer(bytearray(glyph), char_width, char_height, MONO_HMSB if font.reverse() else MONO_HLSB) | |
fb.blit(fbc, x, y, getattr(palette, 'key', -1), palette) | |
x += char_width | |
def measure(s, font): | |
w = 0 | |
for char in s: | |
glyph, h, cw = font.get_ch(char) | |
w += cw | |
return w, h |
bruno1950
commented
Apr 21, 2024
via email
You're perfectly right: there was a typo and now it works quite fine. Thanks for your patience and apologies for my bizarre code formatting. Have a nice evening
… Il 21/04/2024 18:43 CEST Christian Walther ***@***.***> ha scritto:
@cwalther commented on this gist.
---------------------------------------------
There is a period . where there should be a comma , in this line:
simplewriter.write(oled,'Hello World!', 0.20, freesans20)
If the fonts that come with nano-gui don’t include the ° glyph, you’ll have to make your own that does using font-to-py.py. This utility is not meant for running on the microcontroller, but on your PC. See the instructions https://github.com/peterhinch/micropython-font-to-py#readme.
By the way, see micropython/micropython#9111 for how to post code in a more readable way.
—
Reply to this email directly, view it on GitHub https://gist.github.com/cwalther/fb2b2ca00c59b0577089fbdc4d7e0a88#gistcomment-5031336 or unsubscribe https://github.com/notifications/unsubscribe-auth/A5BIYK22DA27QHFDKZXMSK3Y6PUCDBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTEOJXGY2TAOJTU52HE2LHM5SXFJTDOJSWC5DF.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Glad to help!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment