1 # SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
7 ================================================================================
11 **Software and Dependencies:**
14 https://github.com/adafruit/Adafruit_Blinka/releases
16 * Author(s): Melissa LeBlanc-Williams
21 from dataclasses import dataclass
22 from typing import Union, Tuple, Optional
23 from displayio import Bitmap
26 from typing import Protocol
28 from typing_extensions import Protocol
30 __version__ = "0.0.0+auto.0"
31 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
33 DEFAULT_FONT = "displayio/resources/ter-u12n.bdf"
36 class FontProtocol(Protocol):
37 """A protocol shared by `BuiltinFont` and classes in ``adafruit_bitmap_font``"""
39 def get_bounding_box(self) -> Union[Tuple[int, int], Tuple[int, int, int, int]]:
40 """Retrieve the maximum bounding box of any glyph in the font.
42 The four element version is ``(width, height, x_offset, y_offset)``.
43 The two element version is ``(width, height)``, in which
44 ``x_offset`` and ``y_offset`` are assumed to be zero.
47 def get_glyph(self, codepoint: int) -> Optional["Glyph"]:
48 """Retrieve the Glyph for a given code point
50 If the code point is not present in the font, `None` is returned.
55 """Simulate a font built into CircuitPython"""
61 # Place import here to avoid circular import
62 from adafruit_bitmap_font import ( # pylint: disable=import-outside-toplevel
66 self._font = bitmap_font.load_font(
67 os.path.dirname(__file__) + "/" + DEFAULT_FONT
70 self._font.load_glyphs(set(range(0x20, 0x7F)))
72 def get_bounding_box(self) -> Union[Tuple[int, int], Tuple[int, int, int, int]]:
73 """Returns the maximum bounds of all glyphs in the font in
74 a tuple of two values: width, height.
76 return self._font.get_bounding_box()[0:2]
78 def get_glyph(self, codepoint: int) -> Optional["Glyph"]:
79 """Returns a `fontio.Glyph` for the given codepoint or None if no glyph is available."""
80 return self._font.get_glyph(codepoint)
84 """Bitmap containing all font glyphs starting with ASCII and followed by unicode. Use
85 `get_glyph` in most cases. This is useful for use with `displayio.TileGrid` and
86 `terminalio.Terminal`.
88 return self._font.bitmap_class
93 # pylint: disable=invalid-name
94 """Storage of glyph info"""