You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve usability of dviread.Text by third parties.
dviread.Text specifies individual glyphs in parsed dvi files; this is
used by the pdf and svg backends (via textpath, for svg) to parse the
result of usetex-compiled strings and embed the right glyphs at the
right places in the output file (as a reminder, agg currenly uses dvipng
to rasterize the dvi file, and the ps backend relies on pstricks).
Unfortunately, if third-party backends (e.g. mplcairo) want to do use
the same strategy as pdf/svg, then they need to jump through a few hoops
(e.g. understand PsfontsMap and find_tex_font) and use some private APIs
(_parse_enc), as explained below. Try to improve the situation, by
adding some methods on the Text class (which may later allow deprecating
PsfontsMap and find_tex_font as public API).
First, the actual font to be used is speficied via the `.font`
attribute, which itself has a `.texname` which itself must be used as
a key into `PsfontsMap(find_tex_font("pdftex.map"))` to get the actual
font path (and some other info). Instead, just provide a `.font_path`
property. pdftex.map can also require that the font be "slanted" or
"extended" (that's some of the "other info), lift that as well to
`.font_effects`. The `.font` attribute has a `.size`; also we can lift
up to `.font_size`. Altogether, this will allow making `.font` private
(later) -- except for the fact that Text is a namedtuple so deprecating
fields is rather annoying.
The trickiest part is actually specifying what glyph to select from the
font. dvi just gives us an integer, whose interpretation depends again
on pdftex.map. If pdftex.map specifies "no encoding" for the font, then
the integer is the "native glyph index" of the font, and should be
passed as-is to FreeType's FT_Load_Char (after selecting the native
charmap). If pdftex.map does specify an encoding, then that's a file
that needs to be separately loaded, parsed (with _parse_enc), and
ultimately converts the index into a glyph name (which can be passed to
FreeType's FT_Load_Glyph). Altogether, from the PoV of the end user,
the "glyph specification" is thus either an int (a native charmap index)
or a str (a glyph name); thus, provide `.glyph_name_or_index` which is
that API.
As an example of using that API, see the changes to textpath.py.
0 commit comments