X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/matplotlib/ft2font.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum, Flag
from os import PathLike
import sys
from typing import BinaryIO, Literal, NewType, TypeAlias, TypedDict, cast, final, overload
from typing import BinaryIO, Literal, NewType, NotRequired, TypeAlias, TypedDict, cast, final, overload
from typing_extensions import Buffer # < Py 3.12

import numpy as np
Expand Down Expand Up @@ -142,6 +142,17 @@ class _SfntOs2Dict(TypedDict):
fsSelection: int
fsFirstCharIndex: int
fsLastCharIndex: int
# version >= 1
ulCodePageRange: NotRequired[tuple[int, int]]
# version >= 2
sxHeight: NotRequired[int]
sCapHeight: NotRequired[int]
usDefaultChar: NotRequired[int]
usBreakChar: NotRequired[int]
usMaxContext: NotRequired[int]
# version >= 5
usLowerOpticalPointSize: NotRequired[int]
usUpperOpticalPointSize: NotRequired[int]

class _SfntHheaDict(TypedDict):
version: tuple[int, int]
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_ft2font.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ def test_ft2font_get_sfnt(font_name, expected):
'ulCharRange': (3875565311, 3523280383, 170156073, 67117068),
'achVendID': b'PfEd',
'fsSelection': 64, 'fsFirstCharIndex': 32, 'fsLastCharIndex': 65535,
'ulCodePageRange': (1610613247, 3758030848),
},
'hhea': {
'version': (1, 0),
Expand Down Expand Up @@ -736,6 +737,12 @@ def test_ft2font_get_sfnt(font_name, expected):
'ulCharRange': (3, 192, 0, 0),
'achVendID': b'STIX',
'fsSelection': 32, 'fsFirstCharIndex': 32, 'fsLastCharIndex': 10217,
'ulCodePageRange': (2688417793, 2432565248),
'sxHeight': 0,
'sCapHeight': 0,
'usDefaultChar': 0,
'usBreakChar': 32,
'usMaxContext': 1,
},
'hhea': {
'version': (1, 0),
Expand Down
21 changes: 19 additions & 2 deletions src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,8 +1263,9 @@ PyFT2Font_get_sfnt_table(PyFT2Font *self, std::string tagname)
}
case FT_SFNT_OS2: {
auto t = static_cast<TT_OS2 *>(table);
return py::dict(
"version"_a=t->version,
auto version = t->version;
auto result = py::dict(
"version"_a=version,
"xAvgCharWidth"_a=t->xAvgCharWidth,
"usWeightClass"_a=t->usWeightClass,
"usWidthClass"_a=t->usWidthClass,
Expand All @@ -1287,6 +1288,22 @@ PyFT2Font_get_sfnt_table(PyFT2Font *self, std::string tagname)
"fsSelection"_a=t->fsSelection,
"fsFirstCharIndex"_a=t->usFirstCharIndex,
"fsLastCharIndex"_a=t->usLastCharIndex);
if (version >= 1) {
result["ulCodePageRange"] = py::make_tuple(t->ulCodePageRange1,
t->ulCodePageRange2);
}
if (version >= 2) {
result["sxHeight"] = t->sxHeight;
result["sCapHeight"] = t->sCapHeight;
result["usDefaultChar"] = t->usDefaultChar;
result["usBreakChar"] = t->usBreakChar;
result["usMaxContext"] = t->usMaxContext;
}
if (version >= 5) {
result["usLowerOpticalPointSize"] = t->usLowerOpticalPointSize;
result["usUpperOpticalPointSize"] = t->usUpperOpticalPointSize;
}
return result;
}
case FT_SFNT_HHEA: {
auto t = static_cast<TT_HoriHeader *>(table);
Expand Down
Loading
X Tutup