batgrl.figfont#
Support for loading and rendering FIGfonts.
A FIGFont (class) represents a FIGfont (file) which describe how to render ascii art from normal text. FIGFont.render_array will render the ascii art into a numpy array that can be copied into a Text canvas. FIGFont.render_str will render the ascii art into a multiline string.
References#
See Also#
Classes
|
An object representation of a FIGfont. |
|
Character layout for a FIGFont. |
- class batgrl.figfont.FIGFont(hardblank: str = '$', reverse_text: bool = False, layout: ~batgrl.figfont.FullLayout = <FullLayout.Universal: 128>, reverse_universal_smush: bool = False, font: dict[str, ~numpy.ndarray[~typing.Any, ~numpy.dtype[dtype('<U1')]]] = <factory>, comments: str = '')#
Bases:
object
An object representation of a FIGfont.
- Parameters:
- hardblankstr, default: “$”
This character is used to represent whitespace that shouldn’t be smushed.
- reverse_textbool, default: False
If true, text will be rendered right-to-left.
- layoutFullLayout, default: FullLayout.Universal
Controls how characters are fitted in rendered text.
- reverse_universal_smushbool, default: False
Whether universal smushing will display earliest sub-character.
- fontdict[str, NDArray[np.dtype(“<U1”)]], default: {}
A dictionary of characters to their ascii art representations.
- commentsstr, default: “”
Additional comments about this font.
- Attributes:
- hardblankstr
This character is used to represent whitespace that shouldn’t be smushed.
- reverse_textbool
If true, text will be rendered right-to-left.
- layoutFullLayout.Universal
Controls how characters are fitted in rendered text.
- reverse_universal_smushbool
Whether universal smushing will display earliest sub-character.
- fontdict[str, NDArray[np.dtype(“<U1”)]]
A dictionary of characters to their ascii art representations.
- commentsstr
Additional comments about this font.
Methods
from_path(path)
Load a FIGFont from a path.
render_array(text)
Render text as ascii art into a 2D “<U1” numpy array.
render_str(text)
Render text as ascii art into a multiline string.
- comments: str = ''#
Additional comments about this font.
- font: dict[str, ndarray[Any, dtype[dtype('<U1')]]]#
A dictionary of characters to their ascii art representations.
- classmethod from_dict(attrs: dict) Self #
Return a FIGFont from a dictionary.
- classmethod from_path(path: Path) Self #
Load a FIGFont from a path.
- hardblank: str = '$'#
This character is used to represent whitespace that shouldn’t be smushed.
- property height: int#
Height of characters in this font.
- render_array(text: str) ndarray[Any, dtype[dtype('<U1')]] #
Render text as ascii art into a 2D “<U1” numpy array.
- Parameters:
- textstr
Text to render as ascii art into an array.
- Returns:
- NDArray[np.dtype(“<U1”)]
The rendered array.
- render_str(text: str) str #
Render text as ascii art into a multiline string.
- Parameters:
- textstr
Text to render as ascii art into a multiline string.
- Returns:
- str
The rendered string.
- reverse_text: bool = False#
If true, text will be rendered right-to-left.
- reverse_universal_smush: bool = False#
Whether universal smushing will display earliest sub-character.
- class batgrl.figfont.FullLayout(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
IntFlag
Character layout for a FIGFont.
The layout modes are:
FullWidth: Each character occupies the full width or height of its arrangement of sub-characters.
Kerning: Each character is moved together until they touch.
Smushing: Each character is moved one step closer after they touch, so that they overlap. Additional smushing rules determine which sub-character is used for each overlap.
There are two types of smushing:
Universal: The sub-character from the earlier character is replaced by the sub-character from the later character. (This behavior can be reversed with reverse_universal_smush)
Controlled: Uses a set of smushing rules.
The controlled smushing rules are:
Equal: Two sub-characters are smushed into a single sub-character if they are equal (except for hardblanks).
Underscore: An underscore (
"_"
) will be replaced by any of:"|"
,"/"
,"\"
,"["
,"]"
,"{"
,"}"
,"("
,")"
,"<"
,">"
.Hierarchy: A hierarchy of six classes is used:
"|"
,"/\"
,"[]"
,"{}"
,"()"
, and"<>"
. When two sub-characters are from different classes, the latter class will be used.Pair: Replaces opposite brackets (
"[]"
or"]["
), braces ("{}"
or"}{"
), and parentheses ("()"
or")("
) with a vertical bar ("|"
).BigX: Replaces
"/\"
with"|"
,"\/"
with"Y"
, and"><"
into"X"
.HardBlank: Two hardblanks will be replaced with a single hardblank.
- classmethod from_old_layout(old_layout: int) Self #
Return a full layout from an old layout.