API¶
Font library API
- class fontlib.api.FontStack[source]¶
Bases:
objectA collection of
font.Fontobjects- add_font(font)[source]¶
Add
font.Fontobject to this stack.- Parameters:
font (.font.Font) – font instance.
- 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]fontscontrols which font families will be registered. Select font families from https://fonts.google.com/available builtin fonts:
available entry points:
fonts_ttffonts_otffonts_wofffonts_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.Fontobjects selected byname.- Parameters:
name – Name of the font
- load_css(css_url)[source]¶
Add
font.Fontobjects from @font-face rules.- Parameters:
css_url (str) – URL of a CSS (stylesheet) file defining
@font-facerules
FontStack.load_css(css_url) is released each time function is called.
- load_entry_point(ep_name)[source]¶
Add
font.Fontobjects fromep_name.- Parameters:
ep_name – String with the name of the entry point (one of:
fonts_ttf,fonts_otffonts_woff,fonts_woff2)
FontStack.load_entry_point(ep_name) is released each time funcion is called.
- save_font(font, dest_file)[source]¶
Save BLOB of
font.Fontinto file <dest_file>- Parameters:
font (font.Font) – font instance
dest_file (fspath.fspath.FSPath) – Filename of the destination
- class fontlib.api.URLBlob(origin, **kwargs)[source]¶
Bases:
Base,TableUtilsMixInA 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¶
- origin¶
The origin URL
- state¶
State of the BLOB in the cache:
[w]remote: BLOB needs replicationlocal: BLOB is not cached but available from common filesystemcached: a copy of the BLOB is localy available