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

Skip to content

Commit e214945

Browse files
committed
TYP: Add overload for FT2Font.get_sfnt_table
1 parent 835220b commit e214945

File tree

3 files changed

+234
-225
lines changed

3 files changed

+234
-225
lines changed

lib/matplotlib/ft2font.pyi

Lines changed: 131 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import BinaryIO, Literal
1+
from typing import BinaryIO, Literal, TypedDict, overload
22

33
import numpy as np
44
from numpy.typing import NDArray
@@ -42,6 +42,122 @@ SCALABLE: int
4242
SFNT: int
4343
VERTICAL: int
4444

45+
class _SfntHeadDict(TypedDict):
46+
version: tuple[int, int]
47+
fontRevision: tuple[int, int]
48+
checkSumAdjustment: int
49+
magicNumber: int
50+
flags: int
51+
unitsPerEm: int
52+
created: tuple[int, int]
53+
modified: tuple[int, int]
54+
xMin: int
55+
yMin: int
56+
xMax: int
57+
yMax: int
58+
macStyle: int
59+
lowestRecPPEM: int
60+
fontDirectionHint: int
61+
indexToLocFormat: int
62+
glyphDataFormat: int
63+
64+
class _SfntMaxpDict(TypedDict):
65+
version: tuple[int, int]
66+
numGlyphs: int
67+
maxPoints: int
68+
maxContours: int
69+
maxComponentPoints: int
70+
maxComponentContours: int
71+
maxZones: int
72+
maxTwilightPoints: int
73+
maxStorage: int
74+
maxFunctionDefs: int
75+
maxInstructionDefs: int
76+
maxStackElements: int
77+
maxSizeOfInstructions: int
78+
maxComponentElements: int
79+
maxComponentDepth: int
80+
81+
class _SfntOs2Dict(TypedDict):
82+
version: int
83+
xAvgCharWidth: int
84+
usWeightClass: int
85+
usWidthClass: int
86+
fsType: int
87+
ySubscriptXSize: int
88+
ySubscriptYSize: int
89+
ySubscriptXOffset: int
90+
ySubscriptYOffset: int
91+
ySuperscriptXSize: int
92+
ySuperscriptYSize: int
93+
ySuperscriptXOffset: int
94+
ySuperscriptYOffset: int
95+
yStrikeoutSize: int
96+
yStrikeoutPosition: int
97+
sFamilyClass: int
98+
panose: bytes
99+
ulCharRange: tuple[int, int, int, int]
100+
achVendID: bytes
101+
fsSelection: int
102+
fsFirstCharIndex: int
103+
fsLastCharIndex: int
104+
105+
class _SfntHheaDict(TypedDict):
106+
version: tuple[int, int]
107+
ascent: int
108+
descent: int
109+
lineGap: int
110+
advanceWidthMax: int
111+
minLeftBearing: int
112+
minRightBearing: int
113+
xMaxExtent: int
114+
caretSlopeRise: int
115+
caretSlopeRun: int
116+
caretOffset: int
117+
metricDataFormat: int
118+
numOfLongHorMetrics: int
119+
120+
class _SfntVheaDict(TypedDict):
121+
version: tuple[int, int]
122+
vertTypoAscender: int
123+
vertTypoDescender: int
124+
vertTypoLineGap: int
125+
advanceHeightMax: int
126+
minTopSideBearing: int
127+
minBottomSizeBearing: int
128+
yMaxExtent: int
129+
caretSlopeRise: int
130+
caretSlopeRun: int
131+
caretOffset: int
132+
metricDataFormat: int
133+
numOfLongVerMetrics: int
134+
135+
class _SfntPostDict(TypedDict):
136+
format: tuple[int, int]
137+
italicAngle: tuple[int, int]
138+
underlinePosition: int
139+
underlineThickness: int
140+
isFixedPitch: int
141+
minMemType42: int
142+
maxMemType42: int
143+
minMemType1: int
144+
maxMemType1: int
145+
146+
class _SfntPcltDict(TypedDict):
147+
version: tuple[int, int]
148+
fontNumber: int
149+
pitch: int
150+
xHeight: int
151+
style: int
152+
typeFamily: int
153+
capHeight: int
154+
symbolSet: int
155+
typeFace: bytes
156+
characterComplement: bytes
157+
strokeWeight: int
158+
widthType: int
159+
serifStyle: int
160+
45161
class FT2Font:
46162
ascender: int
47163
bbox: tuple[int, int, int, int]
@@ -92,9 +208,20 @@ class FT2Font:
92208
self,
93209
) -> tuple[str, str, str, str, str, int, int, int, int]: ...
94210
def get_sfnt(self) -> dict[tuple[int, int, int, int], bytes]: ...
95-
def get_sfnt_table(
96-
self, name: Literal["head", "maxp", "OS/2", "hhea", "vhea", "post", "pclt"]
97-
) -> dict[str, tuple[int, int, int, int] | tuple[int, int] | int | bytes]: ...
211+
@overload
212+
def get_sfnt_table(self, name: Literal["head"]) -> _SfntHeadDict | None: ...
213+
@overload
214+
def get_sfnt_table(self, name: Literal["maxp"]) -> _SfntMaxpDict | None: ...
215+
@overload
216+
def get_sfnt_table(self, name: Literal["OS/2"]) -> _SfntOs2Dict | None: ...
217+
@overload
218+
def get_sfnt_table(self, name: Literal["hhea"]) -> _SfntHheaDict | None: ...
219+
@overload
220+
def get_sfnt_table(self, name: Literal["vhea"]) -> _SfntVheaDict | None: ...
221+
@overload
222+
def get_sfnt_table(self, name: Literal["post"]) -> _SfntPostDict | None: ...
223+
@overload
224+
def get_sfnt_table(self, name: Literal["pclt"]) -> _SfntPcltDict | None: ...
98225
def get_width_height(self) -> tuple[int, int]: ...
99226
def get_xys(self, antialiased: bool = ...) -> NDArray[np.float64]: ...
100227
def load_char(self, charcode: int, flags: int = ...) -> Glyph: ...

lib/matplotlib/tests/test_mathtext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def test_fontinfo():
281281
fontpath = mpl.font_manager.findfont("DejaVu Sans")
282282
font = mpl.ft2font.FT2Font(fontpath)
283283
table = font.get_sfnt_table("head")
284+
assert table is not None
284285
assert table['version'] == (1, 0)
285286

286287

0 commit comments

Comments
 (0)