Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit224bdb1

Browse files
committed
Support (first font of) TTC files.
TTC is a TrueType Collection file (a collection of TTFs). Currently,ft2font only supports getting the first font from the collection, andneither the pdf nor ps backends are able to use them (due to limitationsof ttconv). Still, it seems better than nothing to support them for Aggand SVG.
1 parentc508c35 commit224bdb1

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

‎.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ addons:
3535
-graphviz
3636
-libgeos-dev
3737
-otf-freefont
38+
-ttf-wqy-zenhei
3839

3940
env:
4041
global:

‎lib/matplotlib/backends/backend_pdf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,13 @@ def get_char_width(charcode):
984984

985985
# Make the charprocs array (using ttconv to generate the
986986
# actual outlines)
987-
rawcharprocs=ttconv.get_pdf_charprocs(
988-
filename.encode(sys.getfilesystemencoding()),glyph_ids)
987+
try:
988+
rawcharprocs=ttconv.get_pdf_charprocs(
989+
filename.encode(sys.getfilesystemencoding()),glyph_ids)
990+
exceptRuntimeError:
991+
_log.warning("The PDF backend does not currently support the "
992+
"selected font.")
993+
raise
989994
charprocs= {}
990995
forcharnameinsorted(rawcharprocs):
991996
stream=rawcharprocs[charname]

‎lib/matplotlib/backends/backend_ps.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,10 +1111,16 @@ def print_figure_impl(fh):
11111111
raiseRuntimeError(msg)
11121112
else:
11131113
fh.flush()
1114-
convert_ttf_to_ps(
1115-
font_filename.encode(
1116-
sys.getfilesystemencoding()),
1117-
fh,fonttype,glyph_ids)
1114+
try:
1115+
convert_ttf_to_ps(
1116+
font_filename.encode(
1117+
sys.getfilesystemencoding()),
1118+
fh,fonttype,glyph_ids)
1119+
exceptRuntimeError:
1120+
_log.warning("The PostScript backend does not "
1121+
"currently support the selected "
1122+
"font.")
1123+
raise
11181124
print("end",file=fh)
11191125
print("%%EndProlog",file=fh)
11201126

‎lib/matplotlib/font_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ def get_fontext_synonyms(fontext):
164164
Return a list of file extensions extensions that are synonyms for
165165
the given file extension *fileext*.
166166
"""
167-
return {'ttf':('ttf','otf'),
168-
'otf':('ttf','otf'),
169-
'afm':('afm',)}[fontext]
167+
return {'ttf':['ttf','ttc','otf'],
168+
'otf':['ttf','otf'],
169+
'afm':['afm']}[fontext]
170170

171171

172172
deflist_fonts(directory,extensions):

‎lib/matplotlib/tests/test_font_manager.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
frommatplotlib.font_managerimport (
1414
findfont,FontProperties,fontManager,json_dump,json_load,get_font,
1515
get_fontconfig_fonts,is_opentype_cff_font,fontManagerasfm)
16-
frommatplotlibimportrc_context
16+
frommatplotlibimportpyplotasplt,rc_context
1717

1818
ifsix.PY2:
1919
fromdistutils.spawnimportfind_executable
@@ -106,3 +106,19 @@ def test_hinting_factor(factor):
106106
# Check that hinting only changes text layout by a small (10%) amount.
107107
np.testing.assert_allclose(hinted_font.get_width_height(),expected,
108108
rtol=0.1)
109+
110+
111+
@pytest.mark.xfail(notos.environ.get("TRAVIS"),reason="Font may be missing.")
112+
deftest_find_ttc():
113+
fp=FontProperties(family=["WenQuanYi Zen Hei"])
114+
font=findfont(fp)
115+
assertos.path.basename(font)=="wqy-zenhei.ttc"
116+
117+
fig,ax=plt.subplots()
118+
ax.text(.5,.5,"\N{KANGXI RADICAL DRAGON}",fontproperties=fp)
119+
fig.savefig(six.BytesIO(),format="raw")
120+
fig.savefig(six.BytesIO(),format="svg")
121+
withpytest.raises(RuntimeError):
122+
fig.savefig(six.BytesIO(),format="pdf")
123+
withpytest.raises(RuntimeError):
124+
fig.savefig(six.BytesIO(),format="ps")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp