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

Commit77c0e34

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 (that comes for free via FreeType).
1 parent2ac048b commit77c0e34

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

‎.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ addons:
4040
-texlive-latex-recommended
4141
-texlive-xetex
4242
-texlive-luatex
43+
-graphviz
44+
-libgeos-dev
45+
-otf-freefont
46+
-ttf-wqy-zenhei
4347

4448
env:
4549
global:

‎lib/matplotlib/backends/backend_pdf.py

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

969969
# Make the charprocs array (using ttconv to generate the
970970
# actual outlines)
971-
rawcharprocs=ttconv.get_pdf_charprocs(
972-
os.fsencode(filename),glyph_ids)
971+
try:
972+
rawcharprocs=ttconv.get_pdf_charprocs(
973+
os.fsencode(filename),glyph_ids)
974+
exceptRuntimeError:
975+
_log.warning("The PDF backend does not currently support the "
976+
"selected font.")
977+
raise
973978
charprocs= {}
974979
forcharnameinsorted(rawcharprocs):
975980
stream=rawcharprocs[charname]

‎lib/matplotlib/backends/backend_ps.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,14 @@ def print_figure_impl(fh):
11411141
"time; consider using the Cairo backend")
11421142
else:
11431143
fh.flush()
1144-
convert_ttf_to_ps(os.fsencode(font_filename),
1145-
fh,fonttype,glyph_ids)
1144+
try:
1145+
convert_ttf_to_ps(os.fsencode(font_filename),
1146+
fh,fonttype,glyph_ids)
1147+
exceptRuntimeError:
1148+
_log.warning("The PostScript backend does not "
1149+
"currently support the selected "
1150+
"font.")
1151+
raise
11461152
print("end",file=fh)
11471153
print("%%EndProlog",file=fh)
11481154

‎lib/matplotlib/font_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def get_fontext_synonyms(fontext):
142142
Return a list of file extensions extensions that are synonyms for
143143
the given file extension *fileext*.
144144
"""
145-
return {'ttf':('ttf','otf'),
146-
'otf':('ttf','otf'),
147-
'afm':('afm',)}[fontext]
145+
return {'ttf':['ttf','ttc','otf'],
146+
'otf':['ttf','otf'],
147+
'afm':['afm']}[fontext]
148148

149149

150150
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
@@ -9,7 +9,7 @@
99
frommatplotlib.font_managerimport (
1010
findfont,FontProperties,fontManager,json_dump,json_load,get_font,
1111
get_fontconfig_fonts,is_opentype_cff_font)
12-
frommatplotlibimportrc_context
12+
frommatplotlibimportpyplotasplt,rc_context
1313

1414
has_fclist=shutil.which('fc-list')isnotNone
1515

@@ -96,3 +96,19 @@ def test_hinting_factor(factor):
9696
# Check that hinting only changes text layout by a small (10%) amount.
9797
np.testing.assert_allclose(hinted_font.get_width_height(),expected,
9898
rtol=0.1)
99+
100+
101+
@pytest.mark.xfail(notos.environ.get("TRAVIS"),reason="Font may be missing.")
102+
deftest_find_ttc():
103+
fp=FontProperties(family=["WenQuanYi Zen Hei"])
104+
font=findfont(fp)
105+
assertos.path.basename(font)=="wqy-zenhei.ttc"
106+
107+
fig,ax=plt.subplots()
108+
ax.text(.5,.5,"\N{KANGXI RADICAL DRAGON}",fontproperties=fp)
109+
fig.savefig(six.BytesIO(),format="raw")
110+
fig.savefig(six.BytesIO(),format="svg")
111+
withpytest.raises(RuntimeError):
112+
fig.savefig(six.BytesIO(),format="pdf")
113+
withpytest.raises(RuntimeError):
114+
fig.savefig(six.BytesIO(),format="ps")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp