Font

Info Class

class gensty.font.Info(fontfile, smufl=None)[source]

Bases: object

Info. Handles opentype fonts (otf, ttf) and creates codepoint/symbol (unicode) List of Tuples based either on sMuFL glyphnames.json file or the font itself as parsed by fontTools. Additionally the Class retrieves the font name.

fontfile

The font file (otf,ttf).

Type

str

name

The font name as retrieved from font file.

Type

str

codepoints

Codepoints and Symbol.

Type

List[Tuple[str,str]]

errors

List of error messages.

Type

List[str]

Codepoints()[source]

Codepoints.Retrieves the codepoints and symbols for the desired font, handles differently if its smufl font.

Returns

The final list of codepoints/description.

Return type

List[Tuple[int, str]]

Identifier(prefix=True)[source]

Identifier. Removes spaces and forces lowercase for font name, by default adds prefix ‘fnt’ so we can avoid issues with identical names.

Parameters

prefix (bool) – Font prefix.

Returns

Font name identifier.

Return type

str

__fontCharList(charcodes, private=False, excluded=[])

__fontCharList. Accepts list of tuples with charcodes and codepoints and returns names and charcodes.

Parameters
  • charcodes (list) – Codepoints/Symbols created by

  • func~gensty.font.LaTeXstyle.__fontCodepoints

  • private (bool) – Allow private symbols.

  • excluded (list) – List of excluded symbols.

Returns

List of codepoints and description.

Return type

List[Tuple[str, str]]

__fontCodepoints()

__fontCodepoints. Creates a list of codepoints and names for every character/symbol in the given font.

Returns

A list of Tuples with condpoints and UTF-8 description.

Return type

List[Tuple[int, str]]

__getName()

__getName. Get the name from the font’s names table. Customized function based on original retrieved from: https://bit.ly/3lS4nMO

Returns

Font name.

Return type

str

__glyphnameParse()

__glyphnameParse. Parses glyphname file according w3c/smufl reference.

Returns

A list of codepoint and their description.

Return type

List[Tuple[str, str]]

LatexStyle Class

class gensty.font.LaTeXstyle(version=None, author=None, **kwargs)[source]

Bases: gensty.font.Info

LaTeXstyle. Creates LaTeX Style package in three parts:

  • Header. Includes Package name and requirements.

  • DefCommands: The definitions of commands.

  • Commands: LaTeX commands based on provided codepoints.

  • File: The full LaTeX Style package including all above.

Commands()[source]

Commands. Generates LaTeX commands for each char code.

Returns

Commands based on symbols from font.

Return type

str

DefCommands()[source]

DefCommands. Fills Commands definition style partial.

Returns

LaTeX Package commands definition.

Return type

str

File()[source]

File. Creates a full LaTeX Style package.

Returns

LaTeX Style package.

Return type

str

Header()[source]

Header. Fills header style partial template

Returns

LaTeX Style package header partial.

Return type

str

__defcommands()

__defcommands. Creates command name, definition and command.

Returns

Definition of commands.

Return type

Tuple[str, str]

__description()

Creates default description text based on name and version.

Returns

Description text for header.

Return type

str

__makeTemplate(template, tokens)

__makeTemplate. Parses and replace tokens in template string.

Parameters
  • template (str) – Template file

  • tokens (dict) – Tokens dict.

Returns

String based on provided template.

Return type

str

__requirements(requirements=[])

__requirements. Creates LaTeX package requirements. By default fontspec is nessessary.

Parameters

requirements (list) – List of requirements.

Returns

LaTeX package requirements.

Return type

str

setCommand(commandName)[source]

setCommand. Forces a command name different from default (font name)

Parameters

commandName (str) – Command Name

Return type

str

setPackage(packageName)[source]

setPackage. Sets the package Name, overides default (font name).

Parameters

packageName (str) – The package name