Skip to content

Commit 539085d

Browse files
authored
Merge pull request matplotlib#31634 from QuLogic/fix-font-typehints
Fix some font-related issues
2 parents 0dd4d05 + 0260760 commit 539085d

8 files changed

Lines changed: 25 additions & 13 deletions

File tree

lib/matplotlib/_api/__init__.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ def check_isinstance(
4242
def list_suggestion_error_msg(name: str, potential: Any, values: Sequence[Any]) -> str: ...
4343
def check_in_list(values: Sequence[Any], /, **kwargs: Any) -> None: ...
4444
def check_shape(shape: tuple[int | None, ...], /, **kwargs: NDArray) -> None: ...
45-
def getitem_checked(
46-
mapping: Mapping[Any, _T], /, _error_cls: type[Exception], **kwargs: Any
47-
) -> _T: ...
45+
def getitem_checked(mapping: Mapping[Any, _T], /, _error_cls: type[Exception] = ..., **kwargs: Any) -> _T: ...
4846
def caching_module_getattr(cls: type) -> Callable[[str], Any]: ...
4947
@overload
5048
def define_aliases(

lib/matplotlib/_mathtext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,8 +1721,8 @@ def ship(box: Box, xy: tuple[float, float] = (0, 0)) -> Output:
17211721
off_h = ox
17221722
off_v = oy + box.height
17231723
output = Output(box)
1724-
17251724
phantom: list[bool] = []
1725+
17261726
def render(node, *args):
17271727
if not any(phantom):
17281728
node.render(*args)

lib/matplotlib/backend_bases.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from matplotlib.figure import Figure
1515
from matplotlib.font_manager import FontProperties
1616
from matplotlib.path import Path
1717
from matplotlib.texmanager import TexManager
18-
from matplotlib.text import Text
18+
from matplotlib.text import Text, TextToPath
1919
from matplotlib.transforms import Bbox, BboxBase, Transform, TransformedPath
2020

2121
from collections.abc import Callable, Iterable, Sequence
@@ -40,6 +40,7 @@ def register_backend(
4040
def get_registered_canvas_class(format: str) -> type[FigureCanvasBase]: ...
4141

4242
class RendererBase:
43+
_text2path: TextToPath
4344
def __init__(self) -> None: ...
4445
def open_group(self, s: str, gid: str | None = ...) -> None: ...
4546
def close_group(self, s: str) -> None: ...

lib/matplotlib/backends/_backend_pdf_ps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
if typing.TYPE_CHECKING:
21+
from .font_manager import FontPath
2122
from .ft2font import CharacterCodeType, FT2Font, GlyphIndexType
2223
from fontTools.ttLib import TTFont
2324

@@ -34,7 +35,7 @@ def _cached_get_afm_from_fname(fname):
3435
return AFM(fh)
3536

3637

37-
def get_glyphs_subset(fontfile: str, glyphs: set[GlyphIndexType]) -> TTFont:
38+
def get_glyphs_subset(fontfile: FontPath, glyphs: set[GlyphIndexType]) -> TTFont:
3839
"""
3940
Subset a TTF font.
4041
@@ -199,7 +200,7 @@ def __init__(self, subset_size: int = 0):
199200
self.subset_size = subset_size
200201

201202
def track(self, font: FT2Font, s: str,
202-
features: tuple[str, ...] | None = ...,
203+
features: tuple[str, ...] | None = None,
203204
language: str | tuple[tuple[str, int, int], ...] | None = None
204205
) -> list[tuple[int, CharacterCodeType]]:
205206
"""

lib/matplotlib/backends/backend_cairo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
254254
ctx.new_path()
255255
ctx.select_font_face(*_cairo_font_args_from_font_prop(ttfFontProperty(font)))
256256
ctx.set_font_size(self.points_to_pixels(fontsize))
257-
ctx.show_glyphs([(idx, ox, -oy) for _, _, idx, ox, oy in font_glyphs])
257+
ctx.show_glyphs([
258+
(glyph_index, ox, -oy)
259+
for _font, _size, _ccode, glyph_index, ox, oy in font_glyphs
260+
])
258261

259262
for ox, oy, w, h in rects:
260263
ctx.new_path()

lib/matplotlib/dviread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def glyph_name_or_index(self):
121121
# control all involved versions and are deeply familiar with the
122122
# implementation", but a further mapping bug was fixed in luaotfload
123123
# commit 8f2dca4, first included in v3.23).
124-
entry = self._get_pdftexmap_entry()
124+
entry = PsfontsMap(find_tex_file("pdftex.map"))[self.font.texname]
125125
return (_parse_enc(entry.encoding)[self.glyph]
126126
if entry.encoding is not None else self.glyph)
127127

lib/matplotlib/font_manager.pyi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,19 @@ class FontManager:
133133
self,
134134
prop: str | FontProperties,
135135
fontext: Literal["ttf", "afm"] = ...,
136-
directory: str | None = ...,
136+
directory: str | os.PathLike | None = ...,
137137
fallback_to_default: bool = ...,
138138
rebuild_if_missing: bool = ...,
139139
) -> FontPath: ...
140140
def get_font_names(self) -> list[str]: ...
141+
def _find_fonts_by_props(
142+
self,
143+
prop: str | FontProperties,
144+
fontext: Literal["ttf", "afm"] = ...,
145+
directory: str | os.PathLike | None = ...,
146+
fallback_to_default: bool = ...,
147+
rebuild_if_missing: bool = ...,
148+
) -> list[FontPath]: ...
141149

142150
def is_opentype_cff_font(filename: str) -> bool: ...
143151
def get_font(
@@ -149,8 +157,8 @@ fontManager: FontManager
149157
def findfont(
150158
prop: str | FontProperties,
151159
fontext: Literal["ttf", "afm"] = ...,
152-
directory: str | None = ...,
160+
directory: str | os.PathLike | None = ...,
153161
fallback_to_default: bool = ...,
154162
rebuild_if_missing: bool = ...,
155-
) -> str: ...
163+
) -> FontPath: ...
156164
def get_font_names() -> list[str]: ...

lib/matplotlib/ft2font.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ class FT2Font(Buffer):
239239
*,
240240
face_index: int = ...,
241241
_fallback_list: list[FT2Font] | None = ...,
242-
_kerning_factor: int | None = ...
242+
_kerning_factor: int | None = ...,
243+
_warn_if_used: bool = ...,
243244
) -> None: ...
244245
if sys.version_info[:2] >= (3, 12):
245246
def __buffer__(self, /, flags: int) -> memoryview: ...

0 commit comments

Comments
 (0)