pcface module¶
Font preview and bitmap arrays generator.
- pcface.cp437()¶
Return all CP437 characters in ascending order.
- Returns:
All CP437 characters as a string.
- Return type:
str
- pcface.main()¶
Generate previews, graphs, and bitmap arrays.
- pcface.make_bitmap(char, path, size, width, height)¶
Create bitmap for a given character.
The given font file is used to internally render the given character in memory. Then the rendered character in memory is read pixel by pixel to generate its bitmap. The returned value is a list of integers where each integer represents the bitmap of a row of pixels of the rendered character. The entire list of bitmaps returned represents all rows of pixels of the rendered character.
- Parameters:
char (str) – Character to create bitmap for.
path (str) – Path to font file.
size (int) – Font size that creates rendered glyph of given height.
width (int) – Width of each glyph in the given font.
height (int) – Height of each glyph in the given font.
- Returns:
Bitmap for the given character rendered with the given font.
- Return type:
list[int]
- pcface.make_bitmaps(chars, path, size, width, height)¶
Create bitmaps for all given characters.
For each character in
chars
, the bitmap of the character is computed as specified in docstring ofmake_bitmap()
. A list of bitmaps, one bitmap for each character, is returned.- Parameters:
chars (str) – One or more characters.
path (str) – Path to font file.
size (int) – Font size that creates rendered glyph of given height.
width (int) – Width of each glyph in the given font.
height (int) – Height of each glyph in the given font.
- Returns:
A list of bitmaps.
- Return type:
list[list[int]]
- pcface.make_font_list(chars, bitmaps, const_name)¶
Create JavaScript code to represent bitmaps as an array of arrays.
- Parameters:
chars (str) – One or more characters.
bitmaps (list[list[int]]) – A list of corresponding bitmaps.
const_name (str) – JavaScript constant name to assign the array to.
- Returns:
JavaScript code that represents bitmaps as an array of arrays.
- Return type:
str
- pcface.make_font_map(chars, bitmaps, const_name)¶
Create JavaScript code to represent bitmaps as an object.
- Parameters:
chars (str) – One or more characters.
bitmaps (list[list[int]]) – A list of corresponding bitmaps.
const_name (str) – Constant name to assign the object to.
- Returns:
JavaScript code that represents bitmaps as an object that maps each CP437 character (represented as Unicode) to its bitmap (an array of integers).
- Return type:
str
- pcface.make_graph(bitmap, width, symbols, prefix)¶
Create ASCII graph of the given bitmap.
The text representation of bitmap is a multiline string where each line represents one integer of the bitmap list. Each 0-bit of the bitmap is represented with the character symbols[0]. Similarly, each 1-bit of the bitmap is represented with the character symbols[1].
- Parameters:
bitmap (list[int]) – Bitmap of a single glyph.
width (int) – Width of each glyph.
symbols (str) – Symbols to use 0 and 1 in the graph.
prefix (bool) – Whether to prefix each line of output with an integer that represents the bitmap value for the corresponding row of the glyph.
- Returns:
ASCII graph of the bitmap of the given character.
- Return type:
str
- pcface.make_graphs(chars, bitmaps, width, symbols, prefix)¶
Create ASCII graphs of given bitmaps.
The returned value is a multiline string that represents text representations of one or more characters specified in chars. The bitmap representation of each character consists of the string returned by func:make_graph. In the returned value, each bitmap representation is preceded by one line of header that shows the character representation and the ASCII code of the character.
- Parameters:
chars (str) – One or more characters.
bitmaps (list[list[int]]) – A list of corresponding bitmaps.
width (int) – Width of each glyph.
symbols (str) – Symbols to use 0 and 1 in the graph.
prefix (bool) – Whether to prefix each line of output with an integer that represents the bitmap value for the corresponding row of the glyph.
- Returns:
A string containing the ASCII graphs of the bitmaps.
- Return type:
str
- pcface.make_preview(text, path, size, cols, width, height, scale)¶
Create a preview of the given text rendered with given font.
- Parameters:
text (char) – Text to create a preview image for.
path (str) – Path to font file.
size (int) – Font size that creates rendered glyph of given height.
cols (int) – Width of preview in terms of number of character columns.
width (int) – Width of each glyph in the given font.
height (int) – Height of each glyph in the given font.
- Returns:
Preview image.
- Return type:
Image