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

Skip to content

Expire mathttext-related deprecations #22107

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
Jan 7, 2022
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
1 change: 0 additions & 1 deletion doc/api/mathtext_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
:members:
:undoc-members:
:show-inheritance:
:exclude-members: Box, Char, ComputerModernFontConstants, DejaVuSansFontConstants, DejaVuSerifFontConstants, FontConstantsBase, Fonts, Glue, Kern, Node, Parser, STIXFontConstants, STIXSansFontConstants, Ship, StandardPsFonts, TruetypeFonts
40 changes: 40 additions & 0 deletions doc/api/next_api_changes/removals/22107-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Removal of deprecated ``mathtext`` APIs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following `matplotlib.mathtext` APIs have been removed:
- ``Fonts`` and all its subclasses,
- ``FontConstantsBase`` and all its subclasses,
- ``Node`` and all its subclasses,
- ``Ship``, ``ship``,
- ``Error``,
- ``Parser``,
- ``SHRINK_FACTOR``, ``GROW_FACTOR``,
- ``NUM_SIZE_LEVELS``,
- ``latex_to_bakoma``, ``latex_to_cmex``, ``latex_to_standard``,
- ``stix_virtual_fonts``,
- ``tex2uni``

Removal of various ``mathtext`` helpers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following `matplotlib.mathtext` classes:
- ``MathtextBackendPdf``,
- ``MathtextBackendPs``,
- ``MathtextBackendSvg``,
- ``MathtextBackendCairo``,
and the ``.mathtext_parser`` attributes on
- `.RendererPdf`,
- `.RendererPS`,
- `.RendererSVG`,
- `.RendererCairo`
have been removed. The `.MathtextBackendPath` class can be used instead.

The methods ``get_depth``, ``parse``, ``to_mask``, ``to_rgba``, and ``to_png``
of `.MathTextParser` have been removed. Use `.mathtext.math_to_image` instead.

The unused ``StandardPsFonts.pswriter`` has been removed.

``ps.useafm`` removed for ``mathtext``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The setting :rc:`ps.useafm` no longer has any effect on `matplotlib.mathtext`.
9 changes: 4 additions & 5 deletions doc/sphinxext/math_symbol_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from docutils.parsers.rst import Directive

from matplotlib import mathtext
from matplotlib import _mathtext, _mathtext_data


symbols = [
Expand Down Expand Up @@ -103,9 +103,9 @@ def run(state_machine):
def render_symbol(sym):
if sym.startswith("\\"):
sym = sym[1:]
if sym not in {*mathtext.Parser._overunder_functions,
*mathtext.Parser._function_names}:
sym = chr(mathtext.tex2uni[sym])
if sym not in (_mathtext.Parser._overunder_functions |
_mathtext.Parser._function_names):
sym = chr(_mathtext_data.tex2uni[sym])
return f'\\{sym}' if sym in ('\\', '|') else sym

lines = []
Expand Down Expand Up @@ -149,7 +149,6 @@ def setup(app):

if __name__ == "__main__":
# Do some verification of the tables
from matplotlib import _mathtext_data

print("SYMBOLS NOT IN STIX:")
all_symbols = {}
Expand Down
21 changes: 0 additions & 21 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from collections import namedtuple
import enum
import functools
from io import StringIO
import logging
import os
import types
Expand Down Expand Up @@ -92,14 +91,6 @@ def __init__(self, default_font_prop, mathtext_backend):
self.mathtext_backend = mathtext_backend
self.used_characters = {}

@_api.deprecated("3.4")
def destroy(self):
"""
Fix any cyclical references before the object is about
to be destroyed.
"""
self.used_characters = None

def get_kern(self, font1, fontclass1, sym1, fontsize1,
font2, fontclass2, sym2, fontsize2, dpi):
"""
Expand Down Expand Up @@ -203,11 +194,6 @@ def get_results(self, box):
"""
result = self.mathtext_backend.get_results(
box, self.get_used_characters())
if self.destroy != TruetypeFonts.destroy.__get__(self):
destroy = _api.deprecate_method_override(
__class__.destroy, self, since="3.4")
if destroy:
destroy()
return result

def get_sized_alternatives_for_symbol(self, fontname, sym):
Expand Down Expand Up @@ -235,11 +221,6 @@ def __init__(self, default_font_prop, mathtext_backend):
self._fonts['default'] = default_font
self._fonts['regular'] = default_font

@_api.deprecated("3.4")
def destroy(self):
self.glyphd = None
super().destroy()

def _get_font(self, font):
if font in self.fontmap:
basename = self.fontmap[font]
Expand Down Expand Up @@ -803,8 +784,6 @@ def __init__(self, default_font_prop, mathtext_backend=None):
self.fonts['default'] = default_font
self.fonts['regular'] = default_font

pswriter = _api.deprecated("3.4")(property(lambda self: StringIO()))

def _get_font(self, font):
if font in self.fontmap:
basename = self.fontmap[font]
Expand Down
7 changes: 1 addition & 6 deletions lib/matplotlib/backends/_backend_pdf_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
s, fontsize, renderer=self)
return w, h, d
elif ismath:
# Circular import.
from matplotlib.backends.backend_ps import RendererPS
parse = self._text2path.mathtext_parser.parse(
s, 72, prop,
_force_standard_ps_fonts=(isinstance(self, RendererPS)
and mpl.rcParams["ps.useafm"]))
parse = self._text2path.mathtext_parser.parse(s, 72, prop)
return parse.width, parse.height, parse.depth
elif mpl.rcParams[self._use_afm_rc_name]:
font = self._get_font_afm(prop)
Expand Down
4 changes: 0 additions & 4 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
_Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
RendererBase)
from matplotlib.font_manager import ttfFontProperty
from matplotlib.mathtext import MathTextParser
from matplotlib.path import Path
from matplotlib.transforms import Affine2D

Expand Down Expand Up @@ -123,9 +122,6 @@ def attr(field):


class RendererCairo(RendererBase):
mathtext_parser = _api.deprecated("3.4")(
property(lambda self: MathTextParser('Cairo')))

def __init__(self, dpi):
self.dpi = dpi
self.gc = GraphicsContextCairo(renderer=self)
Expand Down
6 changes: 0 additions & 6 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import matplotlib.dviread as dviread
from matplotlib.ft2font import (FIXED_WIDTH, ITALIC, LOAD_NO_SCALE,
LOAD_NO_HINTING, KERNING_UNFITTED, FT2Font)
from matplotlib.mathtext import MathTextParser
from matplotlib.transforms import Affine2D, BboxBase
from matplotlib.path import Path
from matplotlib.dates import UTC
Expand Down Expand Up @@ -1900,11 +1899,6 @@ def __init__(self, file, image_dpi, height, width):
self.gc = self.new_gc()
self.image_dpi = image_dpi

@_api.deprecated("3.4")
@property
def mathtext_parser(self):
return MathTextParser("Pdf")

def finalize(self):
self.file.output(*self.gc.finalize())

Expand Down
11 changes: 2 additions & 9 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
from enum import Enum
import functools
import glob
from io import StringIO, TextIOWrapper
from io import StringIO
import logging
import math
import os
import pathlib
import tempfile
import re
import shutil
from tempfile import TemporaryDirectory
Expand All @@ -30,7 +29,6 @@
from matplotlib.font_manager import get_font
from matplotlib.ft2font import LOAD_NO_HINTING, LOAD_NO_SCALE, FT2Font
from matplotlib._ttconv import convert_ttf_to_ps
from matplotlib.mathtext import MathTextParser
from matplotlib._mathtext_data import uni2type1
from matplotlib.path import Path
from matplotlib.texmanager import TexManager
Expand Down Expand Up @@ -263,9 +261,6 @@ class RendererPS(_backend_pdf_ps.RendererPDFPSBase):
_afm_font_dir = cbook._get_data_path("fonts/afm")
_use_afm_rc_name = "ps.useafm"

mathtext_parser = _api.deprecated("3.4")(property(
lambda self: MathTextParser("PS")))

def __init__(self, width, height, pswriter, imagedpi=72):
# Although postscript itself is dpi independent, we need to inform the
# image code about a requested dpi to generate high resolution images
Expand Down Expand Up @@ -689,9 +684,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
def draw_mathtext(self, gc, x, y, s, prop, angle):
"""Draw the math text using matplotlib.mathtext."""
width, height, descent, glyphs, rects = \
self._text2path.mathtext_parser.parse(
s, 72, prop,
_force_standard_ps_fonts=mpl.rcParams["ps.useafm"])
self._text2path.mathtext_parser.parse(s, 72, prop)
self.set_color(*gc.get_rgb())
self._pswriter.write(
f"gsave\n"
Expand Down
6 changes: 0 additions & 6 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from matplotlib.backends.backend_mixed import MixedModeRenderer
from matplotlib.colors import rgb2hex
from matplotlib.dates import UTC
from matplotlib.mathtext import MathTextParser
from matplotlib.path import Path
from matplotlib import _path
from matplotlib.transforms import Affine2D, Affine2DBase
Expand Down Expand Up @@ -318,11 +317,6 @@ def __init__(self, width, height, svgwriter, basename=None, image_dpi=72,
self._write_metadata(metadata)
self._write_default_style()

@_api.deprecated("3.4")
@property
def mathtext_parser(self):
return MathTextParser('SVG')

def finalize(self):
self._write_clips()
self._write_hatches()
Expand Down
Loading