BmfFonts.Font

From MiniScript Wiki
Jump to navigation Jump to search

The Font class is the one of two classes found in the bmfFonts module. It is able to load BMF font files into memory and print them to a PixelDisplay.

Methods

Method Description
setKern(c1, c2, kern) Takes two character values and records the kern spacing between them.
kern(c1, c2) Returns the appropriate spacing between two characters. Defaults to 0 if there is no value for those two characters in the kernMap property.
load(path) Main entry point for reading a font from disk. Call this on the Font class itself (i.e. not an instance). Pass in the path to the font file and get back a new Font object.
save(path) Saves this font to disk, in either version 1.1 or version 1.2 format (depending on self.version). Note that this method ignores self.data, and creates new data from the current font attributes and character data.
charData(c) Gets the character data for the given character. Returns null if not found. (But if it fails to find a lowercase letter, it automatically looks for the upper case version.
addChar(c, image, relX=0, relY=0, shift=null) Adds a new character to this font.
renderChar(c, g, destX=0, destY=0) Render the given character into any drawing context 'g' which has a setPixel method.
getCharImage(c) Make and return an Image of the given character.
makeCharImage(c) Get an Image that represents the given character. This method uses a cache, so is faster after the first call.
printChar(c, x=480, y=320, scale=1, tint="#FFFFFF") Render (draw) the given character to gfx, and return how far to shift the cursor. This uses the image cache, so it gets faster after the first drawing of each character.
print(s, x=20, y=320, scale=1, tint="#FFFFFF") Print the given string to gfx at the given location.
printCentered(s, x=20, y=320, scale=1, tint="#FFFFFF") Print the given string to gfx at the given location.
printRight(s, x=940, y=320, scale=1, tint="#FFFFFF") Print the given string to gfx, right-aligned on x.
width(s, scale=1) Return the width of the given string in this font.
lenToFit(s, width=100) Return the number of characters of the given string that fit a given width.