Bit converter
Details
- File: FontGenerator/BitConverter.py
- Details: Python 3.9
- Date: 2022-10-08
- Version: v1.0.0
Description
Converts a TTF font to a bitmap which can be used by OTOS.
Author
Sebastian Oberschwendtner, sebastian.oberschwendtner@gmail.com
Code
create_canvas
def create_canvas(height_px: int, width_px: int) -> Image
Creates a canvas for the font.
Arguments:
height_pxint - 1x1 [px] The height of the canvas.width_pxint - 1x1 [px] The width of the canvas.
Returns:
PIL.Image- 1x1 [-] The canvas.
get_max_width
def get_max_width(font: ImageFont.FreeTypeFont) -> int
Get the maximum required width of the font in pixels.
Arguments:
fontImageFont.FreeTypeFont - 1x1 [-] The current font type with requested font size.
Returns:
int- 1x1 [px] The maximum width of the font in pixels.
get_max_offset
def get_max_offset(font: ImageFont.FreeTypeFont) -> int
Get the maximum offset in y direction to fit all characters.
Arguments:
fontImageFont.FreeTypeFont - 1x1 [-] The current font type with requested font size.
Returns:
int- 1x1 [px] The maximum Y offset of the font in pixels.
convert_pixel_sequence
def convert_pixel_sequence(sequence) -> int
Converts a pixel sequence to a byte.
Arguments:
sequencelist - 1x8 [px] The pixel sequence.
Returns:
int- 1x1 [-] The converted byte.
Class FontConverter
class FontConverter()
Converts a TTF font to a bitmap which can be used by OTOS.
fontname
@property
def fontname() -> str
Gets the name of the font.
Returns:
str- 1x1 [-] The name of the font.
height_px
@property
def height_px() -> int
The height of the font in pixels.
Returns:
int- [px] The height of the font in pixels.
width_px
@property
def width_px() -> int
The width of the font in pixels.
Returns:
int- [px] The width of the font in pixels.
__init__
def __init__(font_path: str, font_size: int)
Creates a new font converter.
Arguments:
font_pathstr - 1x1 [-] The path to the font file.font_sizeint - 1x1 [px] The font size in pixels.
convert_character
def convert_character(character: int) -> list
Converts a character to a bitmap.
Arguments:
characterint - 1x1 [-] The character to convert.
Returns:
list- 1x1 [-] The bitmap.