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

Skip to content

Typos and docs for mathtext fonts. #18004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/deprecations/18004-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*facename* parameter of `.mathtext.Fonts.render_glyph`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This parameter was renamed to *font* for consistency with the rest of the
`.Fonts` API.
17 changes: 2 additions & 15 deletions lib/matplotlib/_mathtext_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
r'\gamma' : ('psyr', 103),
r'\eta' : ('psyr', 104),
r'\iota' : ('psyr', 105),
r'\varpsi' : ('psyr', 106),
r'\varphi' : ('psyr', 106),
r'\kappa' : ('psyr', 108),
r'\nu' : ('psyr', 110),
r'\pi' : ('psyr', 112),
Expand Down Expand Up @@ -360,7 +360,7 @@
r'\prime' : ('psyr', 0o242),
r'\sharp' : ('psyr', 0o43),
r'\slash' : ('psyr', 0o57),
r'\Lamda' : ('psyr', 0o114),
r'\Lambda' : ('psyr', 0o114),
r'\neg' : ('psyr', 0o330),
r'\Upsilon' : ('psyr', 0o241),
r'\rightbrace' : ('psyr', 0o175),
Expand Down Expand Up @@ -1298,19 +1298,6 @@
(0x005a, 0x005a, 'rm', 0x2128), # Z
(0x0061, 0x007a, 'rm', 0x1d51e), # a-z
],
'it':
[
(0x0041, 0x0042, 'rm', 0x1d504), # A-B
(0x0043, 0x0043, 'rm', 0x212d), # C
(0x0044, 0x0047, 'rm', 0x1d507), # D-G
(0x0048, 0x0048, 'rm', 0x210c), # H
(0x0049, 0x0049, 'rm', 0x2111), # I
(0x004a, 0x0051, 'rm', 0x1d50d), # J-Q
(0x0052, 0x0052, 'rm', 0x211c), # R
(0x0053, 0x0059, 'rm', 0x1d516), # S-Y
(0x005a, 0x005a, 'rm', 0x2128), # Z
(0x0061, 0x007a, 'rm', 0x1d51e), # a-z
],
'bf':
[
(0x0041, 0x005a, 'bf', 0x1d56c), # A-Z
Expand Down
104 changes: 46 additions & 58 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,51 +407,50 @@ def destroy(self):

def get_kern(self, font1, fontclass1, sym1, fontsize1,
font2, fontclass2, sym2, fontsize2, dpi):
r"""
"""
Get the kerning distance for font between *sym1* and *sym2*.

*fontX*: one of the TeX font names::

tt, it, rm, cal, sf, bf or default/regular (non-math)

*fontclassX*: TODO

*symX*: a symbol in raw TeX form. e.g., '1', 'x' or '\sigma'

*fontsizeX*: the fontsize in points

*dpi*: the current dots-per-inch
See `~.Fonts.get_metrics` for a detailed description of the parameters.
"""
return 0.

def get_metrics(self, font, font_class, sym, fontsize, dpi, math=True):
r"""
*font*: one of the TeX font names::

tt, it, rm, cal, sf, bf or default/regular (non-math)

*font_class*: TODO

*sym*: a symbol in raw TeX form. e.g., '1', 'x' or '\sigma'

*fontsize*: font size in points

*dpi*: current dots-per-inch

*math*: whether sym is a math character

Returns an object with the following attributes:

- *advance*: The advance distance (in points) of the glyph.

- *height*: The height of the glyph in points.

- *width*: The width of the glyph in points.

- *xmin*, *xmax*, *ymin*, *ymax* - the ink rectangle of the glyph
Parameters
----------
font : str
One of the TeX font names: "tt", "it", "rm", "cal", "sf", "bf",
"default", "regular", "bb", "frak", "scr". "default" and "regular"
are synonyms and use the non-math font.
font_class : str
One of the TeX font names (as for *font*), but **not** "bb",
"frak", or "scr". This is used to combine two font classes. The
only supported combination currently is ``get_metrics("frak", "bf",
...)``.
sym : str
A symbol in raw TeX form, e.g., "1", "x", or "\sigma".
fontsize : float
Font size in points.
dpi : float
Rendering dots-per-inch.
math : bool
Whether we are currently in math mode or not.

- *iceberg* - the distance from the baseline to the top of
the glyph. This corresponds to TeX's definition of "height".
Returns
-------
object

The returned object has the following attributes (all floats,
except *slanted*):

- *advance*: The advance distance (in points) of the glyph.
- *height*: The height of the glyph in points.
- *width*: The width of the glyph in points.
- *xmin*, *xmax*, *ymin*, *ymax*: The ink rectangle of the glyph
- *iceberg*: The distance from the baseline to the top of the
glyph. (This corresponds to TeX's definition of "height".)
- *slanted*: Whether the glyph should be considered as "slanted"
(currently used for kerning sub/superscripts).
"""
info = self._get_info(font, font_class, sym, fontsize, dpi, math)
return info.metrics
Expand All @@ -465,23 +464,13 @@ def set_canvas_size(self, w, h, d):
self.mathtext_backend.set_canvas_size(
self.width, self.height, self.depth)

def render_glyph(self, ox, oy, facename, font_class, sym, fontsize, dpi):
@cbook._rename_parameter("3.4", "facename", "font")
def render_glyph(self, ox, oy, font, font_class, sym, fontsize, dpi):
"""
Draw a glyph at

- *ox*, *oy*: position

- *facename*: One of the TeX face names

- *font_class*:

- *sym*: TeX symbol name or single character

- *fontsize*: fontsize in points

- *dpi*: The dpi to draw at.
At position (*ox*, *oy*), draw the glyph specified by the remaining
parameters (see `get_metrics` for their detailed description).
"""
info = self._get_info(facename, font_class, sym, fontsize, dpi)
info = self._get_info(font, font_class, sym, fontsize, dpi)
self.used_characters.setdefault(info.font.fname, set()).add(info.num)
self.mathtext_backend.render_glyph(ox, oy, info)

Expand Down Expand Up @@ -771,12 +760,11 @@ def __init__(self, *args, **kwargs):
if rcParams['mathtext.fallback_to_cm'] is not None:
fallback_rc = ('cm' if rcParams['mathtext.fallback_to_cm']
else None)

font_class = {'stix': StixFonts,
'stixsans': StixSansFonts,
'cm': BakomaFonts
}.get(fallback_rc)
self.cm_fallback = font_class(*args, **kwargs) if font_class else None
font_cls = {'stix': StixFonts,
'stixsans': StixSansFonts,
'cm': BakomaFonts
}.get(fallback_rc)
self.cm_fallback = font_cls(*args, **kwargs) if font_cls else None

TruetypeFonts.__init__(self, *args, **kwargs)
self.fontmap = {}
Expand Down