global font
The font library provides the interface into the internals of the font system,
and it also contains helper functions to load traditional TeX font metrics
formats. Other font loading functionality is provided by the fontloader
library that will be discussed in the next section.
😱 Types incomplete or incorrect? 🙏 Please contribute!
methods
font.read_tfm
function font.read_tfm(
name: string,
at_size: integer
) -> TfmFont {
name = string,
area = string,
used = boolean,
characters = table<integer,FontCharacter>,
checksum = integer,
designsize = integer,
direction = FontDirection,
parameters = FontParameters,
size = integer,
tounicode = integer,
}
at_size
- If at_size
is positive, it specifies an “at size” in scaled points. If at_size
is negative, its absolute value represents a “scaled” setting relative to the designsize of the font.
Parse a font metrics file, at the size indicated by the number.
Load a TFM (TeX
font metric) file.
Example:
Reference:
- Corresponding C source code: lfontlib.c#L38-L64
font.read_vf
function font.read_vf(
name,
at_size: integer
) -> VfFont {
name = string,
characters = table<integer,FontCharacter>,
checksum = integer,
fonts = table,
header = string,
type = string,
}
at_size
- If s
is positive, it specifies an “at size” in scaled points. If at_size
is negative, its absolute value represents a “scaled” setting relative to the designsize of the font.
Parse a virtual font metrics file, at the size indicated by the number.
Load a VF (virtual font) file.
Example:
The meaning of the number at_size
and the format of the returned table are
similar to the ones in the read_tfm
function.
Reference:
- Corresponding C source code: lfontlib.c#L67-L83
font.setfont
function font.setfont(
font_id: integer,
f: Font {
name = string,
area = string,
used = boolean,
characters = table<integer,FontCharacter>,
checksum = integer,
designsize = integer,
direction = FontDirection,
encodingbytes = integer,
encodingname = string,
fonts = table,
psname = string,
fullname = string,
...(+24)
}
)
Set an internal font id from a lua table.
Reference:
- Corresponding C source code: lfontlib.c#L156-L173
font.getfont
Fetch an internal font id as a Lua table.
Note that at the moment, each access to the font.fonts
or call to font.getfont
creates a Lua table for the whole font unless you cached it.
Reference:
- Corresponding C source code: lfontlib.c#L251-L258
font.getcopy
Copy the internal data of a font.
Reference:
- Corresponding C source code: lfontlib.c#L260-L267
font.getparameters
Return a table of the parameters as known to TeX. These can be different from the ones in the cached table.
Reference:
- Corresponding C source code: lfontlib.c#L269-L276
font.frozen
Test for the status of a font.
Return true if the font is frozen and can no longer be altered.
The return value is one of true
(unassignable), false
(can be
changed) or nil
(not a valid font at all).
Reference:
- Corresponding C source code: lfontlib.c#L135-L153
font.define
function font.define(f: Font {
name = string,
area = string,
used = boolean,
characters = table<integer,FontCharacter>,
checksum = integer,
designsize = integer,
direction = FontDirection,
encodingbytes = integer,
encodingname = string,
fonts = table,
psname = string,
fullname = string,
...(+24)
}) -> font_id integer
Define a font into font.fonts
.
Reference:
- Corresponding C source code: lfontlib.c#L209-L235
font.define
function font.define(
font_id: integer,
f: Font {
name = string,
area = string,
used = boolean,
characters = table<integer,FontCharacter>,
checksum = integer,
designsize = integer,
direction = FontDirection,
encodingbytes = integer,
encodingname = string,
fonts = table,
psname = string,
fullname = string,
...(+24)
}
) -> i integer
An alternative call is:
Where the first argument is a reserved font id (see below).
font.addcharacters
function font.addcharacters(
font_id: integer,
f: Font {
name = string,
area = string,
used = boolean,
characters = table<integer,FontCharacter>,
checksum = integer,
designsize = integer,
direction = FontDirection,
encodingbytes = integer,
encodingname = string,
fonts = table,
psname = string,
fullname = string,
...(+24)
}
)
Add characters to a font.
The table passed can have the fields characters
which is a (sub)table
like the one used in font.define()
, and for virtual fonts a fonts
table can be
added. The characters defined in the characters
table are added (when not
yet present) or replace an existing entry. Keep in mind that replacing can have
side effects because a character already can have been used. Instead of posing
restrictions we expect the user to be careful. (The setfont
helper is
a more drastic replacer.)
Example:
local newcharacters = {}
for gid = 0, #glyphs do
local glyph = glyphs[gid]
if glyph.used then
local character = characters[gid + gid_offset]
newcharacters[gid + gid_offset] = character
local unicode = nominals[gid]
if unicode then
newcharacters[unicode] = character
end
character.tounicode = glyph.tounicode or unicode or "FFFD"
character.used = true
end
end
font.addcharacters(font_id, { characters = newcharacters })
Reference:
- Corresponding C source code: lfontlib.c#L175-L188
font.nextid
Return the next free font id number.
Return the font id number that would be returned by a font.define
call if it was executed at this spot in the code flow.
This is useful for virtual
fonts that need to reference themselves. If you pass true
as argument,
the id gets reserved and you can pass to font.define
as first argument.
This can be handy when you create complex virtual fonts.
Reference:
- Corresponding C source code: lfontlib.c#L240-L249
font.id
Return the font id of the font accessed by the csname given.
Return the font id associated with csname
, or -1
if csname
is not defined.
Reference:
- Corresponding C source code: lfontlib.c#L278-L296
font.max
@return max_font_id
- The largest used index in font.fonts
.
😱 Types incomplete or incorrect? 🙏 Please contribute!
Return the highest used font id at this moment.
Get the largest used index in font.fonts
.
Reference:
- Corresponding C source code: lfontlib.c#L102-L106
font.current
Set the currently used / active font number.
Reference:
- Corresponding C source code: lfontlib.c#L85-L100
font.current
Get the currently used / active font number.
Reference:
- Corresponding C source code: lfontlib.c#L85-L100
font.each
Iterate over all the defined fonts.
This is an iterator over each of the defined TeX fonts. The first returned
value is the index in font.fonts
, the second the font itself, as a Lua
table. The indices are listed incrementally, but they do not always form an array
of consecutive numbers: in some cases there can be holes in the sequence.
Example:
local inspect = require('inspect')
for font_id, font in font.each() do
print(font_id, inspect(font))
end
Reference:
- Corresponding C source code: lfontlib.c#L127-L133
font.setexpansion
Because we store the actual state of expansion with each glyph and don't have special font instances, we can change some font related parameters before lines are constructed, like:
This is mostly meant for experiments (or an optimizing routing written in Lua) so there is no primitive.
Reference:
- Corresponding C source code: lfontlib.c#L190-L204
fields
font.fonts
The whole table of TeX fonts is accessible from Lua using a virtual array.
Because this is a virtual array, you cannot call pairs
on it
😱 Types incomplete or incorrect? 🙏 Please contribute!