Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c4a40a

Browse files
committed
Improve docs of mathtext internals.
... in particular regarding the undocumented *font_class* parameter. Also rename an unrelated variable also named `font_class` to avoid confusion. Also remove redundant entry for mathfrak+mathit in `stix_virtual_fonts` -- there's actually no frak+it font, the table just duplicates frak+rm, but we already fallback to rm by default anyways.
1 parent 80848d2 commit 2c4a40a

File tree

2 files changed

+41
-69
lines changed

2 files changed

+41
-69
lines changed

lib/matplotlib/_mathtext_data.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,19 +1298,6 @@
12981298
(0x005a, 0x005a, 'rm', 0x2128), # Z
12991299
(0x0061, 0x007a, 'rm', 0x1d51e), # a-z
13001300
],
1301-
'it':
1302-
[
1303-
(0x0041, 0x0042, 'rm', 0x1d504), # A-B
1304-
(0x0043, 0x0043, 'rm', 0x212d), # C
1305-
(0x0044, 0x0047, 'rm', 0x1d507), # D-G
1306-
(0x0048, 0x0048, 'rm', 0x210c), # H
1307-
(0x0049, 0x0049, 'rm', 0x2111), # I
1308-
(0x004a, 0x0051, 'rm', 0x1d50d), # J-Q
1309-
(0x0052, 0x0052, 'rm', 0x211c), # R
1310-
(0x0053, 0x0059, 'rm', 0x1d516), # S-Y
1311-
(0x005a, 0x005a, 'rm', 0x2128), # Z
1312-
(0x0061, 0x007a, 'rm', 0x1d51e), # a-z
1313-
],
13141301
'bf':
13151302
[
13161303
(0x0041, 0x005a, 'bf', 0x1d56c), # A-Z

lib/matplotlib/mathtext.py

Lines changed: 41 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -407,51 +407,48 @@ def destroy(self):
407407

408408
def get_kern(self, font1, fontclass1, sym1, fontsize1,
409409
font2, fontclass2, sym2, fontsize2, dpi):
410-
r"""
410+
"""
411411
Get the kerning distance for font between *sym1* and *sym2*.
412412
413-
*fontX*: one of the TeX font names::
414-
415-
tt, it, rm, cal, sf, bf or default/regular (non-math)
416-
417-
*fontclassX*: TODO
418-
419-
*symX*: a symbol in raw TeX form. e.g., '1', 'x' or '\sigma'
420-
421-
*fontsizeX*: the fontsize in points
422-
423-
*dpi*: the current dots-per-inch
413+
See `get_metrics` for a detailed description of the parameters.
424414
"""
425415
return 0.
426416

427417
def get_metrics(self, font, font_class, sym, fontsize, dpi, math=True):
428418
r"""
429-
*font*: one of the TeX font names::
430-
431-
tt, it, rm, cal, sf, bf or default/regular (non-math)
432-
433-
*font_class*: TODO
434-
435-
*sym*: a symbol in raw TeX form. e.g., '1', 'x' or '\sigma'
436-
437-
*fontsize*: font size in points
438-
439-
*dpi*: current dots-per-inch
440-
441-
*math*: whether sym is a math character
442-
443-
Returns an object with the following attributes:
444-
445-
- *advance*: The advance distance (in points) of the glyph.
446-
447-
- *height*: The height of the glyph in points.
448-
449-
- *width*: The width of the glyph in points.
450-
451-
- *xmin*, *xmax*, *ymin*, *ymax* - the ink rectangle of the glyph
419+
Parameters
420+
----------
421+
font : str
422+
One of the TeX font names: tt, it, rm, cal, sf, bf, default/regular
423+
(non-math), bb, frak, scr.
424+
font_class : str
425+
One of the TeX font names (as for *font*), but **not** bb, frak, or
426+
scr. This is used to combine e.g. "frak" with "bf" (the only
427+
combination that currently actually works).
428+
sym : str
429+
A symbol in raw TeX form, e.g., "1", "x", or "\sigma".
430+
fontsize : float
431+
Font size in points.
432+
dpi : float
433+
Rendering dots-per-inch.
434+
math : bool
435+
Whether we are currently in math mode or not.
452436
453-
- *iceberg* - the distance from the baseline to the top of
454-
the glyph. This corresponds to TeX's definition of "height".
437+
Returns
438+
-------
439+
object
440+
441+
The returned object has the following attributes (all floats,
442+
except *slanted*):
443+
444+
- *advance*: The advance distance (in points) of the glyph.
445+
- *height*: The height of the glyph in points.
446+
- *width*: The width of the glyph in points.
447+
- *xmin*, *xmax*, *ymin*, *ymax*: The ink rectangle of the glyph
448+
- *iceberg*: The distance from the baseline to the top of the
449+
glyph. (This corresponds to TeX's definition of "height".)
450+
- *slanted*: Whether the glyph should be considered as "slanted"
451+
(currently used for kerning sub/superscripts).
455452
"""
456453
info = self._get_info(font, font_class, sym, fontsize, dpi, math)
457454
return info.metrics
@@ -467,19 +464,8 @@ def set_canvas_size(self, w, h, d):
467464

468465
def render_glyph(self, ox, oy, facename, font_class, sym, fontsize, dpi):
469466
"""
470-
Draw a glyph at
471-
472-
- *ox*, *oy*: position
473-
474-
- *facename*: One of the TeX face names
475-
476-
- *font_class*:
477-
478-
- *sym*: TeX symbol name or single character
479-
480-
- *fontsize*: fontsize in points
481-
482-
- *dpi*: The dpi to draw at.
467+
At position (*ox*, *oy*), draw the glyph specified by the remaining
468+
parameters (see `get_metrics` for their detailed description).
483469
"""
484470
info = self._get_info(facename, font_class, sym, fontsize, dpi)
485471
self.used_characters.setdefault(info.font.fname, set()).add(info.num)
@@ -771,12 +757,11 @@ def __init__(self, *args, **kwargs):
771757
if rcParams['mathtext.fallback_to_cm'] is not None:
772758
fallback_rc = ('cm' if rcParams['mathtext.fallback_to_cm']
773759
else None)
774-
775-
font_class = {'stix': StixFonts,
776-
'stixsans': StixSansFonts,
777-
'cm': BakomaFonts
778-
}.get(fallback_rc)
779-
self.cm_fallback = font_class(*args, **kwargs) if font_class else None
760+
font_cls = {'stix': StixFonts,
761+
'stixsans': StixSansFonts,
762+
'cm': BakomaFonts
763+
}.get(fallback_rc)
764+
self.cm_fallback = font_cls(*args, **kwargs) if font_cls else None
780765

781766
TruetypeFonts.__init__(self, *args, **kwargs)
782767
self.fontmap = {}

0 commit comments

Comments
 (0)