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.
- 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 byname
.- 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
FontStack.load_css
(css_url
) is released each time function is called.
- load_entry_point(ep_name)[source]¶
Add
font.Font
objects fromep_name
.- Parameters:
ep_name – String with the name of the entry point (one of:
fonts_ttf
,fonts_otf
fonts_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.Font
into 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
,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¶
- 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