Skip to content

Commit b736a90

Browse files
authored
Merge pull request #31050 from QuLogic/extend-os2-table
ft2font: Extend OS/2 table with new fields
2 parents 695e9a1 + 2aa38ab commit b736a90

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

lib/matplotlib/ft2font.pyi

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from enum import Enum, Flag
22
from os import PathLike
33
import sys
4-
from typing import BinaryIO, Literal, NewType, TypeAlias, TypedDict, cast, final, overload
4+
from typing import BinaryIO, Literal, NewType, NotRequired, TypeAlias, TypedDict, cast, final, overload
55
from typing_extensions import Buffer # < Py 3.12
66

77
import numpy as np
@@ -142,6 +142,17 @@ class _SfntOs2Dict(TypedDict):
142142
fsSelection: int
143143
fsFirstCharIndex: int
144144
fsLastCharIndex: int
145+
# version >= 1
146+
ulCodePageRange: NotRequired[tuple[int, int]]
147+
# version >= 2
148+
sxHeight: NotRequired[int]
149+
sCapHeight: NotRequired[int]
150+
usDefaultChar: NotRequired[int]
151+
usBreakChar: NotRequired[int]
152+
usMaxContext: NotRequired[int]
153+
# version >= 5
154+
usLowerOpticalPointSize: NotRequired[int]
155+
usUpperOpticalPointSize: NotRequired[int]
145156

146157
class _SfntHheaDict(TypedDict):
147158
version: tuple[int, int]

lib/matplotlib/tests/test_ft2font.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ def test_ft2font_get_sfnt(font_name, expected):
590590
'ulCharRange': (3875565311, 3523280383, 170156073, 67117068),
591591
'achVendID': b'PfEd',
592592
'fsSelection': 64, 'fsFirstCharIndex': 32, 'fsLastCharIndex': 65535,
593+
'ulCodePageRange': (1610613247, 3758030848),
593594
},
594595
'hhea': {
595596
'version': (1, 0),
@@ -736,6 +737,12 @@ def test_ft2font_get_sfnt(font_name, expected):
736737
'ulCharRange': (3, 192, 0, 0),
737738
'achVendID': b'STIX',
738739
'fsSelection': 32, 'fsFirstCharIndex': 32, 'fsLastCharIndex': 10217,
740+
'ulCodePageRange': (2688417793, 2432565248),
741+
'sxHeight': 0,
742+
'sCapHeight': 0,
743+
'usDefaultChar': 0,
744+
'usBreakChar': 32,
745+
'usMaxContext': 1,
739746
},
740747
'hhea': {
741748
'version': (1, 0),

src/ft2font_wrapper.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,9 @@ PyFT2Font_get_sfnt_table(PyFT2Font *self, std::string tagname)
12631263
}
12641264
case FT_SFNT_OS2: {
12651265
auto t = static_cast<TT_OS2 *>(table);
1266-
return py::dict(
1267-
"version"_a=t->version,
1266+
auto version = t->version;
1267+
auto result = py::dict(
1268+
"version"_a=version,
12681269
"xAvgCharWidth"_a=t->xAvgCharWidth,
12691270
"usWeightClass"_a=t->usWeightClass,
12701271
"usWidthClass"_a=t->usWidthClass,
@@ -1287,6 +1288,22 @@ PyFT2Font_get_sfnt_table(PyFT2Font *self, std::string tagname)
12871288
"fsSelection"_a=t->fsSelection,
12881289
"fsFirstCharIndex"_a=t->usFirstCharIndex,
12891290
"fsLastCharIndex"_a=t->usLastCharIndex);
1291+
if (version >= 1) {
1292+
result["ulCodePageRange"] = py::make_tuple(t->ulCodePageRange1,
1293+
t->ulCodePageRange2);
1294+
}
1295+
if (version >= 2) {
1296+
result["sxHeight"] = t->sxHeight;
1297+
result["sCapHeight"] = t->sCapHeight;
1298+
result["usDefaultChar"] = t->usDefaultChar;
1299+
result["usBreakChar"] = t->usBreakChar;
1300+
result["usMaxContext"] = t->usMaxContext;
1301+
}
1302+
if (version >= 5) {
1303+
result["usLowerOpticalPointSize"] = t->usLowerOpticalPointSize;
1304+
result["usUpperOpticalPointSize"] = t->usUpperOpticalPointSize;
1305+
}
1306+
return result;
12901307
}
12911308
case FT_SFNT_HHEA: {
12921309
auto t = static_cast<TT_HoriHeader *>(table);

0 commit comments

Comments
 (0)