gws.lib.font¶
Fonts for server-side rendering.
This package installs custom fonts on the server and loads fonts for drawing.
Fonts are configured in the fonts option of the application. On configuration,
all files from the given directory are copied to the system font directory
/usr/local/share/fonts and the font cache is rebuilt with fc-cache.
Installed fonts can then be loaded by name with from_name, for example, to draw SVG labels.
Example:
fonts {
dir "/data/fonts"
}
Source code: gws.lib.font
Package Contents¶
- class gws.lib.font.Config(*args, **kwargs)¶
Bases:
gws.ConfigCustom fonts, installed on the server for rendering.
- dir: gws.DirPath¶
Directory with font files to install.
- gws.lib.font.configure(cfg: Config)¶
Install fonts according to the configuration.
- Parameters:
cfg – Font configuration. If
diris not set, nothing is done.
- gws.lib.font.from_name(name: str, size: int)¶
Load a TrueType or OpenType font.
- Parameters:
name – Font file name or path, as understood by
PIL.ImageFont.truetype.size – Font size in points.
- Returns:
A
PIL.ImageFont.FreeTypeFontobject.
- gws.lib.font.install_fonts(source_dir)¶
Copy font files to the system font directory and rebuild the font cache.
- Parameters:
source_dir – Directory with font files. Files in subdirectories are also copied.