FL.objects.FontLab.FakeLab

class FL.objects.FontLab.FakeLab

Bases: object

The FontLab program interface

The main class. It is used via the pre-instantiated object fl.

There is no explicit constructor for this class, use pre-initialized object ‘fl’

Always use “from FL import all” at the beginning of your macro.

__init__() None

Methods

Add(font)

Add 'font' to list of opened fonts and open the Font Window for it.

BeginProgress(title, counts)

Open a Progress dialog box with 'counts' number of 'ticks'.

CallCommand(commandcode)

Simulate a menu or toolbar command.

Close([fontindex])

Close the current or fontindex font

EditGlyph([glyphindex])

Open the Glyph window for the 'glyphindex' glyph in the current font

EndProgress()

Close the Progress dialog box.

ForSelected(function)

Call function for each selected glyph in the current font.

GenerateFont(*args)

Generate a Font.

GetCanvas()

Return a Canvas for the current Glyph Window.

GetConvert(c)

Copy conversion parameters from the current Glyph Window to the Canvas.

GetFileName(open_save[, suffix, filename, ...])

Open a file picker dialog.

GetPathName(title, message)

Show a folder picker.

GlyphToScreen(position)

Converts the glyph coordinates of the point to screen coordinates in the current Glyph Window.

HitContour(p)

Contour hit detection in the current Glyph Window.

LoadNamFile(namfilename)

Lock(lock)

Message(message[, question, okstring, ...])

Show an alert message dialog box.

Open(filename[, addtolist])

Open the font from file using current opening options.

OpenFont(filename)

Open a VFB file, or import a font from path filename.

Random(lovalue[, hivalue])

(hivalue) | (lovalue, hivalue)

Save(filename_or_fontindex[, filename])

(string filename) | (int fontindex, string filename)

ScreenToGlyph(position)

Converts the screen coordinates of the point to glyph coordinates in the current Glyph Window.

Select(glyphid[, value])

Change a glyph's selection state.

Selected([glyphindex])

Return 1 if current glyph or 'glyphindex' glyph is selected.

SetFontWindow(fontindex, position[, state])

Set the window size and style for the Font Window where font 'fontindex' is shown.

SetUndo()

Save the current state to the undo buffer.

TickProgress(tick)

Update the Progress bar, return False if the Cancel button was pressed.

TransformGlyph(glyph, code, text)

Transforms the glyph using one of the Transform actions.

Unselect()

Deselect all glyphs in the current font (fast operation).

UpdateFont([fontindex])

Updates current font or 'fontindex' (slow operation)

UpdateGlyph([glyphindex])

Update the current glyph or 'glyphindex' glyph of the current font

UpdateRect(r)

Updates the rectangle r in the current Glyph Window.

__init__()

Attributes

ifontslist

iglyph

delta

scale

preview

count

number of opened fonts (fast operation)

count_selected

number of the selected glyphs in the Font Window (fast operation)

filename

application filename

font

Return the currently active font or None.

glyph

Return the currently active glyph in Font, Glyph or Metrics windows.

ifont

Return the index of the currently active font, or -1 if there is no font

iobject

Return the index of currently selected object in the Glyph Window.

layer

Return the index of the currently active layer (master) in Glyph or Metrics windows.

mainwindow

Return a reference to FontLab's main window

path

full path to directory where running application is located

productnumber

product number

serialnumber

serial number as appears in the About window

tobject

Return the type of the currently selected object in the Glyph Window as int.

username

user name as appears in the About window

version

application version

window

reference to the currently active Glyph, Font or Metrics window

Add(font: Font) None

Add ‘font’ to list of opened fonts and open the Font Window for it.

BeginProgress(title: str, counts: int) None

Open a Progress dialog box with ‘counts’ number of ‘ticks’.

CallCommand(commandcode: int) None

Simulate a menu or toolbar command. Check WS_* constants for list of available commands.

Close(fontindex: int | None = None) None

Close the current or fontindex font

EditGlyph(glyphindex: int | None = None) None

Open the Glyph window for the ‘glyphindex’ glyph in the current font

EndProgress() None

Close the Progress dialog box.

ForSelected(function: Callable[[Font, Glyph, int], None]) None

Call function for each selected glyph in the current font. The function has the following format:

function(font: Font, glyph: Glyph, glyphindex: int)

GenerateFont(*args: Any) int

Generate a Font.

Parameters:
  • fontindex_or_fonttype (int) – The index of the font to be generated, or the font type, see below.

  • fonttype (int) – The font type, see below.

  • filename (str) – The path for the font to be generated.

Returns:

0 on success, -1 if the font was not generated.

Return type:

int

Available font types:

ftFONTLAB

FontLab VFB font

ftTYPE1

PC Type 1 font (binary/PFB)

ftTYPE1_MM

PC MultipleMaster font (PFB)

ftTYPE1ASCII

PC Type 1 font (ASCII/PFA)

ftTYPE1ASCII_MM

PC MultipleMaster font (ASCII/PFA)

ftTRUETYPE

PC TrueType/TT OpenType font (TTF)

ftOPENTYPE

PS OpenType (CFF-based) font (OTF)

ftMACTYPE1

Mac Type 1 font (generates suitcase and LWFN file, optionally AFM)

ftMACTRUETYPE

Mac TrueType font (generates suitcase)

ftMACTRUETYPE_DFONT

Mac TrueType font (generates suitcase with resources in data fork)

GetCanvas() Canvas

Return a Canvas for the current Glyph Window.

GetConvert(c: Canvas) None

Copy conversion parameters from the current Glyph Window to the Canvas.

GetFileName(open_save: int, suffix: str | None = None, filename: str | None = None, filetype: str | None = None) str

Open a file picker dialog.

Parameters:
  • open_save (int) – 0 for a Save dialog, 1 for an Open dialog.

  • suffix (str | None, optional) – The suggested file suffix. Ignored in Open dialogs. Defaults to None.

  • filename (str | None, optional) – The suggested file name. Defaults to None.

  • filetype (str | None, optional) – The suggested file type. Defaults to None.

Returns:

The path of the selected file.

Return type:

str

GetPathName(title: str, message: str) str

Show a folder picker.

Parameters:
  • title (str) – The title of the dialog.

  • message (str) – The message of the dialog

Returns:

The path of the selected folder.

Return type:

str

GlyphToScreen(position: Point) Point

Converts the glyph coordinates of the point to screen coordinates in the current Glyph Window.

HitContour(p: Point) tuple[int, int, float] | None

Contour hit detection in the current Glyph Window.

Parameters:

p (Point) – The point to use for hit detection.

Returns:

(nodeindex, nodesubindex, hit_time), or None

if the point doesn’t hit any contour.

Return type:

tuple[int, int, float] | None

Raises:
Message(message: str, question: str | None = None, okstring: str | None = None, cancelstring: str | None = None) int

Show an alert message dialog box. All parameters but the first can be omitted.

Parameters:
  • message (str) – The message.

  • question (str | None, optional) – The question text. Defaults to None.

  • okstring (str | None, optional) – The label of the OK button. Defaults to None.

  • cancelstring (str | None, optional) – The label of the Cancel button. Defaults to None.

Returns:

1 if the OK button was clicked, 2 if the Cancel button was clicked or

the window has been closed.

Return type:

int

Open(filename: str, addtolist: bool = True) None

Open the font from file using current opening options. If addtolist is True, the font is added to FontLab’s font list. The font is shown in a window.

Parameters:
  • filename (str) – _description_

  • addtolist (bool, optional) – _description_. Defaults to True.

addtolist seems to be ignored; the font window is always opened. If the file at the path is already opened, it will not be opened again.

OpenFont(filename: str) Font | None

Open a VFB file, or import a font from path filename. If successful, the Font is returned. The font is not added as a visible Window.

Parameters:

filename (str) – The path to the VFB or font.

Returns:

The font, or None if the file could not be opened.

Return type:

Font | None

Random(lovalue: float, hivalue: float | None = None) int

(hivalue) | (lovalue, hivalue)

  • returns random value (fast operation)

Save(filename_or_fontindex: str | int, filename: str | None = None) None

(string filename) | (int fontindex, string filename)

Save the current or selected font using standard FontLab’s Save routine.

ScreenToGlyph(position: Point) Point

Converts the screen coordinates of the point to glyph coordinates in the current Glyph Window.

Select(glyphid: str | Uni | int, value: bool | None = None) None

Change a glyph’s selection state. ‘glyphid’ may be string (glyph name), Uni (Unicode index) or integer (glyph index)

Parameters:
  • glyphid (str | Uni | int) – The glyph identifier.

  • value (bool | None, optional) – The selection state. Defaults to None. None is interpreted as True.

Raises:

RuntimeError – If no font is opened.

Selected(glyphindex: int | None = None) int

Return 1 if current glyph or ‘glyphindex’ glyph is selected.

SetFontWindow(fontindex: int, position: Rect, state: int | None = None) None

Set the window size and style for the Font Window where font ‘fontindex’ is shown.

Parameters:
  • fontindex (int) – The font index.

  • position (Rect) – The position and size of the window.

  • state (int | None, optional) – The window state. 0 = normal, 1 = minimized, 2 = maximized. Defaults to None.

SetUndo() None

Save the current state to the undo buffer.

TickProgress(tick: int) bool

Update the Progress bar, return False if the Cancel button was pressed. This is a relatively ‘expensive’ operation.

TransformGlyph(glyph: Glyph, code: int, text: str) None

Transforms the glyph using one of the Transform actions.

Save one of Transform Range programs for reference to format of the command string.

Unselect() None

Deselect all glyphs in the current font (fast operation).

UpdateFont(fontindex: int | None = None) None

Updates current font or ‘fontindex’ (slow operation)

UpdateGlyph(glyphindex: int | None = None) None

Update the current glyph or ‘glyphindex’ glyph of the current font

UpdateRect(r: Rect) None

Updates the rectangle r in the current Glyph Window.

property count: int

number of opened fonts (fast operation)

property count_selected: int

number of the selected glyphs in the Font Window (fast operation)

property filename: str

application filename

property font: Font | None

Return the currently active font or None.

property glyph: Glyph | None

Return the currently active glyph in Font, Glyph or Metrics windows.

property ifont: int

Return the index of the currently active font, or -1 if there is no font

property iobject: int

Return the index of currently selected object in the Glyph Window.

property layer: int | None

Return the index of the currently active layer (master) in Glyph or Metrics windows.

property mainwindow: int

Return a reference to FontLab’s main window

property path: str

full path to directory where running application is located

property productnumber: int

product number

property serialnumber: str

serial number as appears in the About window

property tobject: int

Return the type of the currently selected object in the Glyph Window as int.

property username: str

user name as appears in the About window

property version: str

application version

property window: int

reference to the currently active Glyph, Font or Metrics window