API

Font library API

class fontlib.api.FontStack[source]

Bases: object

A collection of font.Font objects

add_font(font)[source]

Add font.Font object to this stack.

Parameters:

font (.font.Font) – font instance.

event.emit():

  • FontStack.add_font (font) is released if the added font is new to this stack.

  • FontStack.add_alias (alias, font) is released if the added font is detected as an alias.

classmethod get_fontstack(config)[source]

Get fonstack instance by configuration <config>.

classmethod init_fontstack(config)[source]

Init fonstack by configuration <config>.

Register fonts from various resources into the fontlib database.

google fonts:

  • fonts from fonts.googleapis.com

Configuration [google fonts]fonts controls which font families will be registered. Select font families from https://fonts.google.com/

available builtin fonts:

available entry points:

  • fonts_ttf

  • fonts_otf

  • fonts_woff

  • fonts_woff2

E.g. to include all fonts from the fonts-python project install:

$ pip install font-amatic-sc font-caladea font-font-awesome \
              font-fredoka-one font-hanken-grotesk font-intuitive \
              font-source-sans-pro  font-source-serif-pro
list_fonts(name=None)[source]

Return generator of font.Font objects selected by name.

Parameters:

name – Name of the font

load_css(css_url)[source]

Add font.Font objects from @font-face rules.

Parameters:

css_url (str) – URL of a CSS (stylesheet) file defining @font-face rules

event.emit():

  • FontStack.load_css (css_url) is released each time function is called.

load_entry_point(ep_name)[source]

Add font.Font objects from ep_name.

Parameters:

ep_name – String with the name of the entry point (one of: fonts_ttf, fonts_otf fonts_woff, fonts_woff2)

event.emit():

  • FontStack.load_entry_point (ep_name) is released each time funcion is called.

save_font(font, dest_file)[source]

Save BLOB of font.Font into file <dest_file>

Parameters:
set_cache(cache)[source]

set cache

class fontlib.api.URLBlob(origin, **kwargs)[source]

Bases: Base, TableUtilsMixIn

A simple BLOB object

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

STATE_CACHED = 'cached'
STATE_LIST = ['remote', 'local', 'cached']
STATE_LOCAL = 'local'
STATE_REMOTE = 'remote'
font
id

A url-safe hash of URLBlob resource, used as unique resource ID

origin

The origin URL

state

State of the BLOB in the cache: [w]

  • remote : BLOB needs replication

  • local : BLOB is not cached but available from common filesystem

  • cached : a copy of the BLOB is localy available