Skip to content

change simpletest script to work with CPython and CircuitPython #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions examples/bitmap_font_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# Call this with the font file as the command line argument.
"""
This example loads a font and uses it to print an
ASCII art representation of the given string specimen
"""

import os
import sys

# Add paths so this runs in CPython in-place.
sys.path.append(os.path.join(sys.path[0], ".."))
from adafruit_bitmap_font import bitmap_font # pylint: disable=wrong-import-position

sys.path.append(os.path.join(sys.path[0], "../test"))
font = bitmap_font.load_font(sys.argv[1])
specimen = "Adafruit CircuitPython" if len(sys.argv) == 2 else sys.argv[2]
# you can change this to a different bdf or pcf font file
font_file = "fonts/LeagueSpartan-Bold-16.bdf"

# you can change the string that will get printed here
message = "<3 Blinka"

font = bitmap_font.load_font(font_file)

_, height, _, dy = font.get_bounding_box()
font.load_glyphs(specimen)
font.load_glyphs(message)

for y in range(height):
for c in specimen:
for c in message:
glyph = font.get_glyph(ord(c))
if not glyph:
continue
Expand Down