diff --git a/lib/matplotlib/_api/__init__.pyi b/lib/matplotlib/_api/__init__.pyi index 0bcce210634f..aeefaa35ffaf 100644 --- a/lib/matplotlib/_api/__init__.pyi +++ b/lib/matplotlib/_api/__init__.pyi @@ -41,9 +41,7 @@ def check_isinstance( def list_suggestion_error_msg(name: str, potential: Any, values: Sequence[Any]) -> str: ... def check_in_list(values: Sequence[Any], /, **kwargs: Any) -> None: ... def check_shape(shape: tuple[int | None, ...], /, **kwargs: NDArray) -> None: ... -def getitem_checked( - mapping: Mapping[Any, _T], /, _error_cls: type[Exception], **kwargs: Any -) -> _T: ... +def getitem_checked(mapping: Mapping[Any, _T], /, _error_cls: type[Exception] = ..., **kwargs: Any) -> _T: ... def caching_module_getattr(cls: type) -> Callable[[str], Any]: ... @overload def define_aliases( diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index b04386e7666a..17dc1b8fb462 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -1721,8 +1721,8 @@ def ship(box: Box, xy: tuple[float, float] = (0, 0)) -> Output: off_h = ox off_v = oy + box.height output = Output(box) - phantom: list[bool] = [] + def render(node, *args): if not any(phantom): node.render(*args) diff --git a/lib/matplotlib/backend_bases.pyi b/lib/matplotlib/backend_bases.pyi index a69b36093839..94a8522717cd 100644 --- a/lib/matplotlib/backend_bases.pyi +++ b/lib/matplotlib/backend_bases.pyi @@ -15,7 +15,7 @@ from matplotlib.figure import Figure from matplotlib.font_manager import FontProperties from matplotlib.path import Path from matplotlib.texmanager import TexManager -from matplotlib.text import Text +from matplotlib.text import Text, TextToPath from matplotlib.transforms import Bbox, BboxBase, Transform, TransformedPath from collections.abc import Callable, Iterable, Sequence @@ -40,6 +40,7 @@ def register_backend( def get_registered_canvas_class(format: str) -> type[FigureCanvasBase]: ... class RendererBase: + _text2path: TextToPath def __init__(self) -> None: ... def open_group(self, s: str, gid: str | None = ...) -> None: ... def close_group(self, s: str) -> None: ... diff --git a/lib/matplotlib/backends/_backend_pdf_ps.py b/lib/matplotlib/backends/_backend_pdf_ps.py index a06779b8efee..87fbae4d749b 100644 --- a/lib/matplotlib/backends/_backend_pdf_ps.py +++ b/lib/matplotlib/backends/_backend_pdf_ps.py @@ -18,6 +18,7 @@ if typing.TYPE_CHECKING: + from .font_manager import FontPath from .ft2font import CharacterCodeType, FT2Font, GlyphIndexType from fontTools.ttLib import TTFont @@ -34,7 +35,7 @@ def _cached_get_afm_from_fname(fname): return AFM(fh) -def get_glyphs_subset(fontfile: str, glyphs: set[GlyphIndexType]) -> TTFont: +def get_glyphs_subset(fontfile: FontPath, glyphs: set[GlyphIndexType]) -> TTFont: """ Subset a TTF font. @@ -199,7 +200,7 @@ def __init__(self, subset_size: int = 0): self.subset_size = subset_size def track(self, font: FT2Font, s: str, - features: tuple[str, ...] | None = ..., + features: tuple[str, ...] | None = None, language: str | tuple[tuple[str, int, int], ...] | None = None ) -> list[tuple[int, CharacterCodeType]]: """ diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index a62890d7c3b1..a16c7a25aec2 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -254,7 +254,10 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle): ctx.new_path() ctx.select_font_face(*_cairo_font_args_from_font_prop(ttfFontProperty(font))) ctx.set_font_size(self.points_to_pixels(fontsize)) - ctx.show_glyphs([(idx, ox, -oy) for _, _, idx, ox, oy in font_glyphs]) + ctx.show_glyphs([ + (glyph_index, ox, -oy) + for _font, _size, _ccode, glyph_index, ox, oy in font_glyphs + ]) for ox, oy, w, h in rects: ctx.new_path() diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index e41618d67579..979744d1ef5c 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -121,7 +121,7 @@ def glyph_name_or_index(self): # control all involved versions and are deeply familiar with the # implementation", but a further mapping bug was fixed in luaotfload # commit 8f2dca4, first included in v3.23). - entry = self._get_pdftexmap_entry() + entry = PsfontsMap(find_tex_file("pdftex.map"))[self.font.texname] return (_parse_enc(entry.encoding)[self.glyph] if entry.encoding is not None else self.glyph) diff --git a/lib/matplotlib/font_manager.pyi b/lib/matplotlib/font_manager.pyi index b5c131d33702..4bb1a8bae2a9 100644 --- a/lib/matplotlib/font_manager.pyi +++ b/lib/matplotlib/font_manager.pyi @@ -133,11 +133,19 @@ class FontManager: self, prop: str | FontProperties, fontext: Literal["ttf", "afm"] = ..., - directory: str | None = ..., + directory: str | os.PathLike | None = ..., fallback_to_default: bool = ..., rebuild_if_missing: bool = ..., ) -> FontPath: ... def get_font_names(self) -> list[str]: ... + def _find_fonts_by_props( + self, + prop: str | FontProperties, + fontext: Literal["ttf", "afm"] = ..., + directory: str | os.PathLike | None = ..., + fallback_to_default: bool = ..., + rebuild_if_missing: bool = ..., + ) -> list[FontPath]: ... def is_opentype_cff_font(filename: str) -> bool: ... def get_font( @@ -149,8 +157,8 @@ fontManager: FontManager def findfont( prop: str | FontProperties, fontext: Literal["ttf", "afm"] = ..., - directory: str | None = ..., + directory: str | os.PathLike | None = ..., fallback_to_default: bool = ..., rebuild_if_missing: bool = ..., -) -> str: ... +) -> FontPath: ... def get_font_names() -> list[str]: ... diff --git a/lib/matplotlib/ft2font.pyi b/lib/matplotlib/ft2font.pyi index 05f987292ffc..f8057742b376 100644 --- a/lib/matplotlib/ft2font.pyi +++ b/lib/matplotlib/ft2font.pyi @@ -239,7 +239,8 @@ class FT2Font(Buffer): *, face_index: int = ..., _fallback_list: list[FT2Font] | None = ..., - _kerning_factor: int | None = ... + _kerning_factor: int | None = ..., + _warn_if_used: bool = ..., ) -> None: ... if sys.version_info[:2] >= (3, 12): def __buffer__(self, /, flags: int) -> memoryview: ...