From cd8abb05432db34c92be271d7e38f1618d90565b Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 8 Jan 2022 12:11:44 +0100 Subject: [PATCH 1/2] Started deprecating afm, fontconfig_pattern, and type1font --- lib/matplotlib/{afm.py => _afm.py} | 0 lib/matplotlib/{fontconfig_pattern.py => _fontconfig_pattern.py} | 0 lib/matplotlib/{type1font.py => _type1font.py} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename lib/matplotlib/{afm.py => _afm.py} (100%) rename lib/matplotlib/{fontconfig_pattern.py => _fontconfig_pattern.py} (100%) rename lib/matplotlib/{type1font.py => _type1font.py} (100%) diff --git a/lib/matplotlib/afm.py b/lib/matplotlib/_afm.py similarity index 100% rename from lib/matplotlib/afm.py rename to lib/matplotlib/_afm.py diff --git a/lib/matplotlib/fontconfig_pattern.py b/lib/matplotlib/_fontconfig_pattern.py similarity index 100% rename from lib/matplotlib/fontconfig_pattern.py rename to lib/matplotlib/_fontconfig_pattern.py diff --git a/lib/matplotlib/type1font.py b/lib/matplotlib/_type1font.py similarity index 100% rename from lib/matplotlib/type1font.py rename to lib/matplotlib/_type1font.py From 1885e460ff39b73377f5a94197c9f8d301ac5288 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 8 Jan 2022 12:12:23 +0100 Subject: [PATCH 2/2] Recreated deprecated files and changed references --- .../next_api_changes/behavior/20715-JKS.rst | 6 +++--- .../next_api_changes/deprecations/22133-OG.rst | 6 ++++++ .../prev_api_changes/api_changes_0.91.0.rst | 2 +- .../prev_api_changes/api_changes_0.98.x.rst | 4 ++-- .../api_changes_3.5.0/behaviour.rst | 4 ++-- lib/matplotlib/_mathtext.py | 2 +- lib/matplotlib/afm.py | 5 +++++ lib/matplotlib/backends/_backend_pdf_ps.py | 2 +- lib/matplotlib/backends/backend_pdf.py | 8 +++----- lib/matplotlib/backends/backend_ps.py | 2 +- lib/matplotlib/font_manager.py | 8 ++++---- lib/matplotlib/fontconfig_pattern.py | 5 +++++ lib/matplotlib/rcsetup.py | 2 +- lib/matplotlib/tests/test_afm.py | 18 +++++++++--------- lib/matplotlib/tests/test_text.py | 2 +- lib/matplotlib/tests/test_type1font.py | 2 +- lib/matplotlib/type1font.py | 5 +++++ 17 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/22133-OG.rst create mode 100644 lib/matplotlib/afm.py create mode 100644 lib/matplotlib/fontconfig_pattern.py create mode 100644 lib/matplotlib/type1font.py diff --git a/doc/api/next_api_changes/behavior/20715-JKS.rst b/doc/api/next_api_changes/behavior/20715-JKS.rst index f0ca1d707d3d..a91aa40ed68c 100644 --- a/doc/api/next_api_changes/behavior/20715-JKS.rst +++ b/doc/api/next_api_changes/behavior/20715-JKS.rst @@ -1,8 +1,8 @@ ``Type1Font`` objects include more properties --------------------------------------------- -The `.type1font.Type1Font.prop` dictionary now includes more keys, such -as ``CharStrings`` and ``Subrs``. The value of the ``Encoding`` key is +The ``matplotlib._type1font.Type1Font.prop`` dictionary now includes more keys, +such as ``CharStrings`` and ``Subrs``. The value of the ``Encoding`` key is now a dictionary mapping codes to glyph names. The -`.type1font.Type1Font.transform` method now correctly removes +``matplotlib._type1font.Type1Font.transform`` method now correctly removes ``UniqueID`` properties from the font. diff --git a/doc/api/next_api_changes/deprecations/22133-OG.rst b/doc/api/next_api_changes/deprecations/22133-OG.rst new file mode 100644 index 000000000000..71d86906a9d8 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/22133-OG.rst @@ -0,0 +1,6 @@ +``AFM``, ``configfont_pattern`` and ``Type1Font`` deprecated +------------------------------------------------------------ + +The modules ``matplotlib.AFM``, ``matplotlib.configfont_pattern``, and +``matplotlib.Type1Font`` are considered internal and public access is +deprecated. \ No newline at end of file diff --git a/doc/api/prev_api_changes/api_changes_0.91.0.rst b/doc/api/prev_api_changes/api_changes_0.91.0.rst index b33fcb50f0ad..7ad3776be0ce 100644 --- a/doc/api/prev_api_changes/api_changes_0.91.0.rst +++ b/doc/api/prev_api_changes/api_changes_0.91.0.rst @@ -36,7 +36,7 @@ Changes for 0.91.0 pfa/pfb file, to get metrics and kerning information for a Type 1 font. -* The :class:`.AFM` class now supports querying CapHeight and stem +* The ``AFM`` class now supports querying CapHeight and stem widths. The get_name_char method now has an isord kwarg like get_width_char. diff --git a/doc/api/prev_api_changes/api_changes_0.98.x.rst b/doc/api/prev_api_changes/api_changes_0.98.x.rst index 41ee63502254..b6e52fdd0b9a 100644 --- a/doc/api/prev_api_changes/api_changes_0.98.x.rst +++ b/doc/api/prev_api_changes/api_changes_0.98.x.rst @@ -63,8 +63,8 @@ Changes for 0.98.x :meth:`matplotlib.axes.Axes.set_ylim` now return a copy of the ``viewlim`` array to avoid modify-in-place surprises. -* :meth:`matplotlib.afm.AFM.get_fullname` and - :meth:`matplotlib.afm.AFM.get_familyname` no longer raise an +* ``matplotlib.afm.AFM.get_fullname`` and + ``matplotlib.afm.AFM.get_familyname`` no longer raise an exception if the AFM file does not specify these optional attributes, but returns a guess based on the required FontName attribute. diff --git a/doc/api/prev_api_changes/api_changes_3.5.0/behaviour.rst b/doc/api/prev_api_changes/api_changes_3.5.0/behaviour.rst index fefc398c2e66..9168bd3a3a6a 100644 --- a/doc/api/prev_api_changes/api_changes_3.5.0/behaviour.rst +++ b/doc/api/prev_api_changes/api_changes_3.5.0/behaviour.rst @@ -229,8 +229,8 @@ defaults to *False*. Type 1 fonts have a large part of their code encrypted as an obsolete copy-protection measure. This part is now available decrypted as the -``decrypted`` attribute of `~.type1font.Type1Font`. This decrypted data is not -yet parsed, but this is a prerequisite for implementing subsetting. +``decrypted`` attribute of ``matplotlib.type1font.Type1Font``. This decrypted +data is not yet parsed, but this is a prerequisite for implementing subsetting. 3D contourf polygons placed between levels ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 58033fbfd7fe..5d28c59eba51 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -22,7 +22,7 @@ from ._mathtext_data import ( latex_to_bakoma, latex_to_standard, stix_glyph_fixes, stix_virtual_fonts, tex2uni) -from .afm import AFM +from ._afm import AFM from .font_manager import FontProperties, findfont, get_font from .ft2font import KERNING_DEFAULT diff --git a/lib/matplotlib/afm.py b/lib/matplotlib/afm.py new file mode 100644 index 000000000000..c0b28604bd8c --- /dev/null +++ b/lib/matplotlib/afm.py @@ -0,0 +1,5 @@ +from matplotlib._afm import * # noqa: F401, F403 +from matplotlib import _api +_api.warn_deprecated( + "3.6", message="The module %(name)s is deprecated since %(since)s.", + name=f"{__name__}") diff --git a/lib/matplotlib/backends/_backend_pdf_ps.py b/lib/matplotlib/backends/_backend_pdf_ps.py index 3224fb90e3a9..85e6c267923a 100644 --- a/lib/matplotlib/backends/_backend_pdf_ps.py +++ b/lib/matplotlib/backends/_backend_pdf_ps.py @@ -9,7 +9,7 @@ import matplotlib as mpl from .. import font_manager, ft2font -from ..afm import AFM +from .._afm import AFM from ..backend_bases import RendererBase diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index e0d04a56eb33..e4636e3adcae 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -26,7 +26,7 @@ from PIL import Image import matplotlib as mpl -from matplotlib import _api, _text_helpers, cbook +from matplotlib import _api, _text_helpers, _type1font, cbook, dviread from matplotlib._pylab_helpers import Gcf from matplotlib.backend_bases import ( _Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase, @@ -34,9 +34,7 @@ from matplotlib.backends.backend_mixed import MixedModeRenderer from matplotlib.figure import Figure from matplotlib.font_manager import findfont, get_font -from matplotlib.afm import AFM -import matplotlib.type1font as type1font -import matplotlib.dviread as dviread +from matplotlib._afm import AFM from matplotlib.ft2font import (FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, LOAD_NO_HINTING, KERNING_UNFITTED, FT2Font) from matplotlib.mathtext import MathTextParser @@ -982,7 +980,7 @@ def _embedTeXFont(self, fontinfo): return fontdictObject # We have a font file to embed - read it in and apply any effects - t1font = type1font.Type1Font(fontinfo.fontfile) + t1font = _type1font.Type1Font(fontinfo.fontfile) if fontinfo.effects: t1font = t1font.transform(fontinfo.effects) fontdict['BaseFont'] = Name(t1font.prop['FontName']) diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 33c41202dbb4..6631811eafae 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -22,7 +22,7 @@ import matplotlib as mpl from matplotlib import _api, cbook, _path, _text_helpers -from matplotlib.afm import AFM +from matplotlib._afm import AFM from matplotlib.backend_bases import ( _Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase, RendererBase) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 9b58008a7ff8..b7f4aa28bc41 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -43,8 +43,8 @@ from dummy_threading import Timer import matplotlib as mpl -from matplotlib import _api, afm, cbook, ft2font, rcParams -from matplotlib.fontconfig_pattern import ( +from matplotlib import _api, _afm, cbook, ft2font, rcParams +from matplotlib._fontconfig_pattern import ( parse_fontconfig_pattern, generate_fontconfig_pattern) from matplotlib.rcsetup import _validators @@ -553,7 +553,7 @@ def afmFontProperty(fontpath, font): Parameters ---------- - font : `.AFM` + font : AFM The AFM font file from which information will be extracted. Returns @@ -1107,7 +1107,7 @@ def addfont(self, path): """ if Path(path).suffix.lower() == ".afm": with open(path, "rb") as fh: - font = afm.AFM(fh) + font = _afm.AFM(fh) prop = afmFontProperty(path, font) self.afmlist.append(prop) else: diff --git a/lib/matplotlib/fontconfig_pattern.py b/lib/matplotlib/fontconfig_pattern.py new file mode 100644 index 000000000000..353cdc8f5c43 --- /dev/null +++ b/lib/matplotlib/fontconfig_pattern.py @@ -0,0 +1,5 @@ +from matplotlib._fontconfig_pattern import * # noqa: F401, F403 +from matplotlib import _api +_api.warn_deprecated( + "3.6", message="The module %(name)s is deprecated since %(since)s.", + name=f"{__name__}") diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 35531a8cc247..0eafec792b04 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -25,7 +25,7 @@ from matplotlib import _api, cbook from matplotlib.cbook import ls_mapper from matplotlib.colors import Colormap, is_color_like -from matplotlib.fontconfig_pattern import parse_fontconfig_pattern +from matplotlib._fontconfig_pattern import parse_fontconfig_pattern from matplotlib._enums import JoinStyle, CapStyle # Don't let the original cycler collide with our validating cycler diff --git a/lib/matplotlib/tests/test_afm.py b/lib/matplotlib/tests/test_afm.py index 2d54c16cb402..e5c6a83937cd 100644 --- a/lib/matplotlib/tests/test_afm.py +++ b/lib/matplotlib/tests/test_afm.py @@ -2,7 +2,7 @@ import pytest import logging -from matplotlib import afm +from matplotlib import _afm from matplotlib import font_manager as fm @@ -39,13 +39,13 @@ def test_nonascii_str(): inp_str = "привет" byte_str = inp_str.encode("utf8") - ret = afm._to_str(byte_str) + ret = _afm._to_str(byte_str) assert ret == inp_str def test_parse_header(): fh = BytesIO(AFM_TEST_DATA) - header = afm._parse_header(fh) + header = _afm._parse_header(fh) assert header == { b'StartFontMetrics': 2.0, b'FontName': 'MyFont-Bold', @@ -66,8 +66,8 @@ def test_parse_header(): def test_parse_char_metrics(): fh = BytesIO(AFM_TEST_DATA) - afm._parse_header(fh) # position - metrics = afm._parse_char_metrics(fh) + _afm._parse_header(fh) # position + metrics = _afm._parse_char_metrics(fh) assert metrics == ( {0: (250.0, 'space', [0, 0, 0, 0]), 42: (1141.0, 'foo', [40, 60, 800, 360]), @@ -81,13 +81,13 @@ def test_parse_char_metrics(): def test_get_familyname_guessed(): fh = BytesIO(AFM_TEST_DATA) - font = afm.AFM(fh) + font = _afm.AFM(fh) del font._header[b'FamilyName'] # remove FamilyName, so we have to guess assert font.get_familyname() == 'My Font' def test_font_manager_weight_normalization(): - font = afm.AFM(BytesIO( + font = _afm.AFM(BytesIO( AFM_TEST_DATA.replace(b"Weight Bold\n", b"Weight Custom\n"))) assert fm.afmFontProperty("", font).weight == "normal" @@ -107,7 +107,7 @@ def test_font_manager_weight_normalization(): def test_bad_afm(afm_data): fh = BytesIO(afm_data) with pytest.raises(RuntimeError): - afm._parse_header(fh) + _afm._parse_header(fh) @pytest.mark.parametrize( @@ -132,6 +132,6 @@ def test_bad_afm(afm_data): def test_malformed_header(afm_data, caplog): fh = BytesIO(afm_data) with caplog.at_level(logging.ERROR): - afm._parse_header(fh) + _afm._parse_header(fh) assert len(caplog.records) == 1 diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index 926e1cee35d4..aced39bc1afe 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -199,7 +199,7 @@ def test_antialiasing(): def test_afm_kerning(): fn = mpl.font_manager.findfont("Helvetica", fontext="afm") with open(fn, 'rb') as fh: - afm = mpl.afm.AFM(fh) + afm = mpl._afm.AFM(fh) assert afm.string_width_height('VAVAVAVAVAVA') == (7174.0, 718) diff --git a/lib/matplotlib/tests/test_type1font.py b/lib/matplotlib/tests/test_type1font.py index 6a16da10def1..1e173d5ea84d 100644 --- a/lib/matplotlib/tests/test_type1font.py +++ b/lib/matplotlib/tests/test_type1font.py @@ -1,4 +1,4 @@ -import matplotlib.type1font as t1f +import matplotlib._type1font as t1f import os.path import difflib import pytest diff --git a/lib/matplotlib/type1font.py b/lib/matplotlib/type1font.py new file mode 100644 index 000000000000..5a9faa1c66d4 --- /dev/null +++ b/lib/matplotlib/type1font.py @@ -0,0 +1,5 @@ +from matplotlib._type1font import * # noqa: F401, F403 +from matplotlib import _api +_api.warn_deprecated( + "3.6", message="The module %(name)s is deprecated since %(since)s.", + name=f"{__name__}")