ConsoleUser

Copyright (c) 2010-2023 Skaion Corporarion, www.skaion.com

This project was developed in part by numerous sponsorships from the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints of Governmental purposes notwithstanding any copyright notation thereon.

All content reflects those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of the U.S. Government or Skaion Corporation.

class Font.Font(config, fontname, trim_font_bottom=0)

A class wrapping a font type, so that images (as arrays) can be retrieved for how any letter looks in that font.

Parameters:

  • config: a <no title> object

  • fontname: a string which maps to a file in the fonts directory

  • trimFontBottom: a number of rows to trim from the bottom of each char

find_in_region(text, region, fgcolor=0, bgcolor=63, maxrows=- 1)

Attempt to find all areas of the given region that math the text rendered in this font. Return a list of all matches.

Parameters:

  • text: the string to search for

  • region: the region being searched

  • fgcolor: the color of the text

  • bgcolor: the background color on which the text is found

  • maxrows: the maximum number of rows of each character to include

get_fmap(char)

Get the array of that represents the given character in this font

Parameters:

  • char: the character to lookup

Return: the character as rendered in the given font

get_trim()

Get the current number of rows that will be trimmed from the bottom of each char

set_trim(new_trim)

Update the number of rows trimmed from the bottom of each char

text_to_region(text, fgcolor=0, bgcolor=63, maxrows=- 1, strict=False)

Convert the given text to an screen as rendered in this font and with the given colors/pixel values. By default the region will be a mask of bgcolor and not bgcolor with a ring of transparent pixels around the not bgcolor section. This will handle matching antialiased text, but will not help if the only differentiator of interest is the foreground color. If that is what’s needed specify strict=True and the region will then be only bgcolor and fgcolor.

The numpy array will be created in row-major order

Parameters:

  • text: the string to convert to an image

  • fgcolor: the color (pixel value) the text

  • bgcolor: the color (pixel value) of the background

  • maxrows: the maximum number of rows to included. a value <= 0 means all rows

  • strict: This will construct a strict region without using the masks or transparent pixels

Return: a <no title> object containing this text

text_to_region_column_major(text, fgcolor=0, bgcolor=63, maxrows=- 1, mask=False)

Convert the given text to an screen as rendered in this font and with the given colors/pixel values.

The numpy array will be created in column-major order

Parameters:

  • text: the string to convert to an image

  • fgcolor: the color (pixel value) the text

  • bgcolor: the color (pixel value) of the background

  • maxrows: the maximum number of rows to included. a value <= 0 means all rows

  • mask: Use the constructed region as a mask, using values specific to PatternMatcher interpretation

Return: a <no title> object containing this text

exception Font.UnusedException
Font.clean_up()

Make sure the FONTS_DAT shelve is closed properly at exit

Font.load_dat_from_files()

This assumes the filesystem itself is the organizing structure and loads from a series of directories, each of which has files representing the character in the font.