Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove *math* parameter of various mathtext internal APIs.#22507

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 1 commit intomatplotlib:mainfromanntzer:mathtextunmath
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes fromall 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
5 changes: 5 additions & 0 deletionsdoc/api/next_api_changes/deprecations/22507-AL.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
The *math* parameter of ``mathtext.get_unicode_index``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In math mode, ASCII hyphens (U+002D) are now replaced by unicode minus signs
(U+2212) at the parsing stage.
60 changes: 30 additions & 30 deletionslib/matplotlib/_mathtext.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
QuotedString, Regex, StringEnd, ZeroOrMore, pyparsing_common)

import matplotlib as mpl
from . import cbook
from . import_api,cbook
from ._mathtext_data import (
latex_to_bakoma, stix_glyph_fixes, stix_virtual_fonts, tex2uni)
from .font_manager import FontProperties, findfont, get_font
Expand All@@ -33,7 +33,8 @@
# FONTS


def get_unicode_index(symbol, math=True):
@_api.delete_parameter("3.6", "math")
def get_unicode_index(symbol, math=True): # Publicly exported.
r"""
Return the integer index (from the Unicode table) of *symbol*.

Expand All@@ -45,15 +46,13 @@ def get_unicode_index(symbol, math=True):
math : bool, default: True
If False, always treat as a single Unicode character.
"""
# for a non-math symbol, simply return its Unicode index
if not math:
return ord(symbol)
# From UTF #25: U+2212 minus sign is the preferred
# representation of the unary and binary minus sign rather than
# the ASCII-derived U+002D hyphen-minus, because minus sign is
# unambiguous and because it is rendered with a more desirable
# length, usually longer than a hyphen.
if symbol == '-':
# Remove this block when the 'math' parameter is deleted.
if math and symbol == '-':
return 0x2212
try: # This will succeed if symbol is a single Unicode char
return ord(symbol)
Expand DownExpand Up@@ -98,7 +97,7 @@ def get_kern(self, font1, fontclass1, sym1, fontsize1,
"""
return 0.

def get_metrics(self, font, font_class, sym, fontsize, dpi, math=True):
def get_metrics(self, font, font_class, sym, fontsize, dpi):
r"""
Parameters
----------
Expand All@@ -117,8 +116,6 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi, math=True):
Font size in points.
dpi : float
Rendering dots-per-inch.
math : bool
Whether we are currently in math mode or not.

Returns
-------
Expand All@@ -136,7 +133,7 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi, math=True):
- *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)
info = self._get_info(font, font_class, sym, fontsize, dpi)
return info.metrics

def render_glyph(self, ox, oy, font, font_class, sym, fontsize, dpi):
Expand DownExpand Up@@ -217,14 +214,14 @@ def _get_offset(self, font, glyph, fontsize, dpi):
return (glyph.height / 64 / 2) + (fontsize/3 * dpi/72)
return 0.

def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
def _get_info(self, fontname, font_class, sym, fontsize, dpi):
key = fontname, font_class, sym, fontsize, dpi
bunch = self.glyphd.get(key)
if bunch is not None:
return bunch

font, num, slanted = self._get_glyph(
fontname, font_class, sym, fontsize, math)
fontname, font_class, sym, fontsize)

font.set_size(fontsize, dpi)
glyph = font.load_char(
Expand DownExpand Up@@ -314,7 +311,7 @@ def __init__(self, *args, **kwargs):

_slanted_symbols = set(r"\int \oint".split())

def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
def _get_glyph(self, fontname, font_class, sym, fontsize):
font = None
if fontname in self.fontmap and sym in latex_to_bakoma:
basename, num = latex_to_bakoma[sym]
Expand All@@ -329,7 +326,7 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
return font, num, slanted
else:
return self._stix_fallback._get_glyph(
fontname, font_class, sym, fontsize, math)
fontname, font_class, sym, fontsize)

# The Bakoma fonts contain many pre-sized alternatives for the
# delimiters. The AutoSizedChar class will use these alternatives
Expand DownExpand Up@@ -442,9 +439,9 @@ def __init__(self, *args, **kwargs):
def _map_virtual_font(self, fontname, font_class, uniindex):
return fontname, uniindex

def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
def _get_glyph(self, fontname, font_class, sym, fontsize):
try:
uniindex = get_unicode_index(sym, math)
uniindex = get_unicode_index(sym)
found_symbol = True
except ValueError:
uniindex = ord('?')
Expand DownExpand Up@@ -536,23 +533,20 @@ def __init__(self, *args, **kwargs):
self.fontmap[key] = fullpath
self.fontmap[name] = fullpath

def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
def _get_glyph(self, fontname, font_class, sym, fontsize):
# Override prime symbol to use Bakoma.
if sym == r'\prime':
return self.bakoma._get_glyph(
fontname, font_class, sym, fontsize, math)
return self.bakoma._get_glyph(fontname, font_class, sym, fontsize)
else:
# check whether the glyph is available in the display font
uniindex = get_unicode_index(sym)
font = self._get_font('ex')
if font is not None:
glyphindex = font.get_char_index(uniindex)
if glyphindex != 0:
return super()._get_glyph(
'ex', font_class, sym, fontsize, math)
return super()._get_glyph('ex', font_class, sym, fontsize)
# otherwise return regular glyph
return super()._get_glyph(
fontname, font_class, sym, fontsize, math)
return super()._get_glyph(fontname, font_class, sym, fontsize)


class DejaVuSerifFonts(DejaVuFonts):
Expand DownExpand Up@@ -913,15 +907,14 @@ class Char(Node):
`Hlist`.
"""

def __init__(self, c, state, math=True):
def __init__(self, c, state):
super().__init__()
self.c = c
self.font_output = state.font_output
self.font = state.font
self.font_class = state.font_class
self.fontsize = state.fontsize
self.dpi = state.dpi
self.math = math
# The real width, height and depth will be set during the
# pack phase, after we know the real fontsize
self._update_metrics()
Expand All@@ -931,8 +924,7 @@ def __repr__(self):

def _update_metrics(self):
metrics = self._metrics = self.font_output.get_metrics(
self.font, self.font_class, self.c, self.fontsize, self.dpi,
self.math)
self.font, self.font_class, self.c, self.fontsize, self.dpi)
if self.c == ' ':
self.width = metrics.advance
else:
Expand DownExpand Up@@ -1624,8 +1616,9 @@ class _MathStyle(enum.Enum):
SCRIPTSTYLE = enum.auto()
SCRIPTSCRIPTSTYLE = enum.auto()

_binary_operators = set(r'''
+ * -
_binary_operators = set(
'+ * - \N{MINUS SIGN}'
r'''
\pm \sqcap \rhd
\mp \sqcup \unlhd
\times \vee \unrhd
Expand DownExpand Up@@ -1922,7 +1915,7 @@ def math(self, s, loc, toks):

def non_math(self, s, loc, toks):
s = toks[0].replace(r'\$', '$')
symbols = [Char(c, self.get_state(), math=False) for c in s]
symbols = [Char(c, self.get_state()) for c in s]
hlist = Hlist(symbols)
# We're going into math now, so set font to 'it'
self.push_state()
Expand DownExpand Up@@ -1969,6 +1962,13 @@ def customspace(self, s, loc, toks):

def symbol(self, s, loc, toks):
c = toks["sym"]
if c == "-":
# "U+2212 minus sign is the preferred representation of the unary
# and binary minus sign rather than the ASCII-derived U+002D
# hyphen-minus, because minus sign is unambiguous and because it
# is rendered with a more desirable length, usually longer than a
# hyphen." (https://www.unicode.org/reports/tr25/)
c = "\N{MINUS SIGN}"
try:
char = Char(c, self.get_state())
except ValueError as err:
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/_mathtext_data.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,7 +132,7 @@
']' : ('cmr10', 0x5d),

'*' : ('cmsy10', 0xa4),
'-' : ('cmsy10', 0xa1),
'\N{MINUS SIGN}' : ('cmsy10', 0xa1),
'\\Downarrow' : ('cmsy10', 0x2b),
'\\Im' : ('cmsy10', 0x3d),
'\\Leftarrow' : ('cmsy10', 0x28),
Expand Down
View file
Open in desktop
Binary file not shown.
View file
Open in desktop
Binary file not shown.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp