font load
Reads a font file of the app and gives its family.
font load FILENAME ?-family NAME?
Description
Reads a TrueType or OpenType font file (.ttf or .otf with TrueType outlines), or a collection of them (.ttc, up to 16 faces), from the folder of the app: the folder of the main script, where ztk::style load reads too. In a bundle or an app in one file, the folder is in the payload; on the web, the page gives the bytes by the name of the file. A name with .. or a path out of the folder is an error, and so is a file larger than 32 MiB.
Each face of the file gets the family of its name table, or NAME with -family. A description with that family, such as {Brand 12 bold}, then draws with the face of the same slant and the nearest weight, on each platform, before an installed font or a font of the system with the same name. A family of several files, such as a regular and a bold file, is one family.
A font file is data of the app: a bad or a cut file gives an error and adds no face. A @font-face rule of a sheet of ztk::style reads a font file too (docs/styling.md).
An app with the files fonts/brand-regular.ttf and fonts/brand-bold.ttf beside its script makes one family of them with font load fonts/brand-regular.ttf -family Brand and font load fonts/brand-bold.ttf -family Brand, and then font create Heading -family Brand -size 16 -weight bold draws with the bold file.
Returns
The family of the first face of the file.
Examples
# The folder of the example has no font file.
% list [catch {font load fonts/none.ttf} message] [string match {cannot read*} $message]
1 1
Errors
% font load ../shared/a.ttf
file "../shared/a.ttf" is outside the app folder
-errorcode NONE
% font load a.ttf -size 3
bad option "-size": must be -family
-errorcode NONE
% font load
wrong # args: should be "font load fileName ?-family name?"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.10