Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0fec7f1

Browse filesBrowse files
Stephen-Chilcotetimhoffm
authored andcommitted
Correctly get weight & style hints from certain newer Microsoft fonts (#12945)
1 parent 51be868 commit 0fec7f1
Copy full SHA for 0fec7f1

File tree

Expand file treeCollapse file tree

2 files changed

+25
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-3
lines changed

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,13 @@ def ttfFontProperty(font):
321321
sfnt = font.get_sfnt()
322322
# These tables are actually mac_roman-encoded, but mac_roman support may be
323323
# missing in some alternative Python implementations and we are only going
324-
# to look for ASCII substrings, where any ASCII-compatible encoding works.
325-
sfnt2 = sfnt.get((1, 0, 0, 2), b'').decode('latin-1').lower()
326-
sfnt4 = sfnt.get((1, 0, 0, 4), b'').decode('latin-1').lower()
324+
# to look for ASCII substrings, where any ASCII-compatible encoding works
325+
# - or big-endian UTF-16, since important Microsoft fonts use that.
326+
sfnt2 = (sfnt.get((1, 0, 0, 2), b'').decode('latin-1').lower() or
327+
sfnt.get((3, 1, 0x0409, 2), b'').decode('utf_16_be').lower())
328+
sfnt4 = (sfnt.get((1, 0, 0, 4), b'').decode('latin-1').lower() or
329+
sfnt.get((3, 1, 0x0409, 4), b'').decode('utf_16_be').lower())
330+
327331
if sfnt4.find('oblique') >= 0:
328332
style = 'oblique'
329333
elif sfnt4.find('italic') >= 0:

‎lib/matplotlib/tests/test_font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_font_manager.py
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22
import shutil
3+
import sys
34
import warnings
45

56
import numpy as np
@@ -87,3 +88,20 @@ def test_hinting_factor(factor):
8788
# Check that hinting only changes text layout by a small (10%) amount.
8889
np.testing.assert_allclose(hinted_font.get_width_height(), expected,
8990
rtol=0.1)
91+
92+
93+
@pytest.mark.skipif(sys.platform != "win32",
94+
reason="Need Windows font to test against")
95+
def test_utf16m_sfnt():
96+
segoe_ui_semibold = None
97+
for f in fontManager.ttflist:
98+
# seguisbi = Microsoft Segoe UI Semibold
99+
if f.fname[-12:] == "seguisbi.ttf":
100+
segoe_ui_semibold = f
101+
break
102+
else:
103+
pytest.xfail(reason="Couldn't find font to test against.")
104+
105+
# Check that we successfully read the "semibold" from the font's
106+
# sfnt table and set its weight accordingly
107+
assert segoe_ui_semibold.weight == "semibold"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.