Skip to content

Commit 10a6700

Browse files
committed
ft2font: Read more entries from OS/2 font table
Apparently, when adding the additional fields in matplotlib#31050, I never noticed that some of the required fields were not exposed. Also, fix a few typos in the field names.
1 parent 948fbde commit 10a6700

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

lib/matplotlib/ft2font.pyi

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,16 @@ class _SfntOs2Dict(TypedDict):
137137
yStrikeoutPosition: int
138138
sFamilyClass: int
139139
panose: bytes
140-
ulCharRange: tuple[int, int, int, int]
140+
ulUnicodeRange: tuple[int, int, int, int]
141141
achVendID: bytes
142142
fsSelection: int
143-
fsFirstCharIndex: int
144-
fsLastCharIndex: int
143+
usFirstCharIndex: int
144+
usLastCharIndex: int
145+
sTypoAscender: int
146+
sTypoDescender: int
147+
sTypoLineGap: int
148+
usWinAscent: int
149+
usWinDescent: int
145150
# version >= 1
146151
ulCodePageRange: NotRequired[tuple[int, int]]
147152
# version >= 2
@@ -176,7 +181,7 @@ class _SfntVheaDict(TypedDict):
176181
vertTypoLineGap: int
177182
advanceHeightMax: int
178183
minTopSideBearing: int
179-
minBottomSizeBearing: int
184+
minBottomSideBearing: int
180185
yMaxExtent: int
181186
caretSlopeRise: int
182187
caretSlopeRun: int

lib/matplotlib/tests/test_ft2font.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,11 @@ def test_ft2font_get_sfnt(font_name, expected):
587587
'yStrikeoutSize': 102, 'yStrikeoutPosition': 530,
588588
'sFamilyClass': 0,
589589
'panose': b'\x02\x0b\x06\x03\x03\x08\x04\x02\x02\x04',
590-
'ulCharRange': (3875565311, 3523280383, 170156073, 67117068),
590+
'ulUnicodeRange': (3875565311, 3523280383, 170156073, 67117068),
591591
'achVendID': b'PfEd',
592-
'fsSelection': 64, 'fsFirstCharIndex': 32, 'fsLastCharIndex': 65535,
592+
'fsSelection': 64, 'usFirstCharIndex': 32, 'usLastCharIndex': 65535,
593+
'sTypoAscender': 1556, 'sTypoDescender': -492, 'sTypoLineGap': 410,
594+
'usWinAscent': 1901, 'usWinDescent': 483,
593595
'ulCodePageRange': (1610613247, 3758030848),
594596
},
595597
'hhea': {
@@ -654,9 +656,11 @@ def test_ft2font_get_sfnt(font_name, expected):
654656
'yStrikeoutSize': 102, 'yStrikeoutPosition': 530,
655657
'sFamilyClass': 0,
656658
'panose': b'\x02\x0b\x05\x00\x00\x00\x00\x00\x00\x00',
657-
'ulCharRange': (0, 0, 0, 0),
659+
'ulUnicodeRange': (0, 0, 0, 0),
658660
'achVendID': b'\x00\x00\x00\x00',
659-
'fsSelection': 64, 'fsFirstCharIndex': 32, 'fsLastCharIndex': 9835,
661+
'fsSelection': 64, 'usFirstCharIndex': 32, 'usLastCharIndex': 9835,
662+
'sTypoAscender': 1276, 'sTypoDescender': -469, 'sTypoLineGap': 0,
663+
'usWinAscent': 1430, 'usWinDescent': 477,
660664
},
661665
'hhea': {
662666
'version': (1, 0),
@@ -734,9 +738,11 @@ def test_ft2font_get_sfnt(font_name, expected):
734738
'yStrikeoutSize': 20, 'yStrikeoutPosition': 1037,
735739
'sFamilyClass': 0,
736740
'panose': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
737-
'ulCharRange': (3, 192, 0, 0),
741+
'ulUnicodeRange': (3, 192, 0, 0),
738742
'achVendID': b'STIX',
739-
'fsSelection': 32, 'fsFirstCharIndex': 32, 'fsLastCharIndex': 10217,
743+
'fsSelection': 32, 'usFirstCharIndex': 32, 'usLastCharIndex': 10217,
744+
'sTypoAscender': 750, 'sTypoDescender': -250, 'sTypoLineGap': 1499,
745+
'usWinAscent': 2095, 'usWinDescent': 404,
740746
'ulCodePageRange': (2688417793, 2432565248),
741747
'sxHeight': 0,
742748
'sCapHeight': 0,

src/ft2font_wrapper.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,12 +1282,17 @@ PyFT2Font_get_sfnt_table(PyFT2Font *self, std::string tagname)
12821282
"yStrikeoutPosition"_a=t->yStrikeoutPosition,
12831283
"sFamilyClass"_a=t->sFamilyClass,
12841284
"panose"_a=py::bytes(reinterpret_cast<const char *>(t->panose), 10),
1285-
"ulCharRange"_a=py::make_tuple(t->ulUnicodeRange1, t->ulUnicodeRange2,
1286-
t->ulUnicodeRange3, t->ulUnicodeRange4),
1285+
"ulUnicodeRange"_a=py::make_tuple(t->ulUnicodeRange1, t->ulUnicodeRange2,
1286+
t->ulUnicodeRange3, t->ulUnicodeRange4),
12871287
"achVendID"_a=py::bytes(reinterpret_cast<const char *>(t->achVendID), 4),
12881288
"fsSelection"_a=t->fsSelection,
1289-
"fsFirstCharIndex"_a=t->usFirstCharIndex,
1290-
"fsLastCharIndex"_a=t->usLastCharIndex);
1289+
"usFirstCharIndex"_a=t->usFirstCharIndex,
1290+
"usLastCharIndex"_a=t->usLastCharIndex,
1291+
"sTypoAscender"_a=t->sTypoAscender,
1292+
"sTypoDescender"_a=t->sTypoDescender,
1293+
"sTypoLineGap"_a=t->sTypoLineGap,
1294+
"usWinAscent"_a=t->usWinAscent,
1295+
"usWinDescent"_a=t->usWinDescent);
12911296
if (version >= 1) {
12921297
result["ulCodePageRange"] = py::make_tuple(t->ulCodePageRange1,
12931298
t->ulCodePageRange2);
@@ -1333,7 +1338,7 @@ PyFT2Font_get_sfnt_table(PyFT2Font *self, std::string tagname)
13331338
"vertTypoLineGap"_a=t->Line_Gap,
13341339
"advanceHeightMax"_a=t->advance_Height_Max,
13351340
"minTopSideBearing"_a=t->min_Top_Side_Bearing,
1336-
"minBottomSizeBearing"_a=t->min_Bottom_Side_Bearing,
1341+
"minBottomSideBearing"_a=t->min_Bottom_Side_Bearing,
13371342
"yMaxExtent"_a=t->yMax_Extent,
13381343
"caretSlopeRise"_a=t->caret_Slope_Rise,
13391344
"caretSlopeRun"_a=t->caret_Slope_Run,

0 commit comments

Comments
 (0)