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

Skip to content

Commit 9756aca

Browse files
authored
Merge pull request #18004 from anntzer/mathtext
Typos and docs for mathtext fonts.
2 parents d8db93f + 8b04e35 commit 9756aca

File tree

3 files changed

+52
-73
lines changed

3 files changed

+52
-73
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*facename* parameter of `.mathtext.Fonts.render_glyph`
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
This parameter was renamed to *font* for consistency with the rest of the
4+
`.Fonts` API.

lib/matplotlib/_mathtext_data.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
r'\gamma' : ('psyr', 103),
274274
r'\eta' : ('psyr', 104),
275275
r'\iota' : ('psyr', 105),
276-
r'\varpsi' : ('psyr', 106),
276+
r'\varphi' : ('psyr', 106),
277277
r'\kappa' : ('psyr', 108),
278278
r'\nu' : ('psyr', 110),
279279
r'\pi' : ('psyr', 112),
@@ -360,7 +360,7 @@
360360
r'\prime' : ('psyr', 0o242),
361361
r'\sharp' : ('psyr', 0o43),
362362
r'\slash' : ('psyr', 0o57),
363-
r'\Lamda' : ('psyr', 0o114),
363+
r'\Lambda' : ('psyr', 0o114),
364364
r'\neg' : ('psyr', 0o330),
365365
r'\Upsilon' : ('psyr', 0o241),
366366
r'\rightbrace' : ('psyr', 0o175),
@@ -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: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -408,51 +408,50 @@ def destroy(self):
408408

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

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

469-
def render_glyph(self, ox, oy, facename, font_class, sym, fontsize, dpi):
468+
@cbook._rename_parameter("3.4", "facename", "font")
469+
def render_glyph(self, ox, oy, font, font_class, sym, fontsize, dpi):
470470
"""
471-
Draw a glyph at
472-
473-
- *ox*, *oy*: position
474-
475-
- *facename*: One of the TeX face names
476-
477-
- *font_class*:
478-
479-
- *sym*: TeX symbol name or single character
480-
481-
- *fontsize*: fontsize in points
482-
483-
- *dpi*: The dpi to draw at.
471+
At position (*ox*, *oy*), draw the glyph specified by the remaining
472+
parameters (see `get_metrics` for their detailed description).
484473
"""
485-
info = self._get_info(facename, font_class, sym, fontsize, dpi)
474+
info = self._get_info(font, font_class, sym, fontsize, dpi)
486475
self.used_characters.setdefault(info.font.fname, set()).add(info.num)
487476
self.mathtext_backend.render_glyph(ox, oy, info)
488477

@@ -777,12 +766,11 @@ def __init__(self, *args, **kwargs):
777766
if rcParams['mathtext.fallback_to_cm'] is not None:
778767
fallback_rc = ('cm' if rcParams['mathtext.fallback_to_cm']
779768
else None)
780-
781-
font_class = {'stix': StixFonts,
782-
'stixsans': StixSansFonts,
783-
'cm': BakomaFonts
784-
}.get(fallback_rc)
785-
self.cm_fallback = font_class(*args, **kwargs) if font_class else None
769+
font_cls = {'stix': StixFonts,
770+
'stixsans': StixSansFonts,
771+
'cm': BakomaFonts
772+
}.get(fallback_rc)
773+
self.cm_fallback = font_cls(*args, **kwargs) if font_cls else None
786774

787775
super().__init__(*args, **kwargs)
788776
self.fontmap = {}

0 commit comments

Comments
 (0)