|
32 | 32 | RendererBase)
|
33 | 33 | from matplotlib.backends.backend_mixed import MixedModeRenderer
|
34 | 34 | from matplotlib.figure import Figure
|
35 |
| -from matplotlib.font_manager import get_font, fontManager as _fontManager |
| 35 | +from matplotlib.font_manager import FontPath, get_font, fontManager as _fontManager |
36 | 36 | from matplotlib._afm import AFM
|
37 | 37 | from matplotlib.ft2font import FT2Font, FaceFlags, Kerning, LoadFlags, StyleFlags
|
38 | 38 | from matplotlib.transforms import Affine2D, BboxBase
|
@@ -899,8 +899,10 @@ def fontName(self, fontprop, subset=0):
|
899 | 899 | as the filename of the font.
|
900 | 900 | """
|
901 | 901 |
|
902 |
| - if isinstance(fontprop, str): |
| 902 | + if isinstance(fontprop, FontPath): |
903 | 903 | filenames = [fontprop]
|
| 904 | + elif isinstance(fontprop, str): |
| 905 | + filenames = [FontPath(fontprop, 0)] |
904 | 906 | elif mpl.rcParams['pdf.use14corefonts']:
|
905 | 907 | filenames = _fontManager._find_fonts_by_props(
|
906 | 908 | fontprop, fontext='afm', directory=RendererPdf._afm_font_dir
|
@@ -940,7 +942,7 @@ def writeFonts(self):
|
940 | 942 | _log.debug('Embedding Type-1 font %s from dvi.', dvifont.texname)
|
941 | 943 | fonts[pdfname] = self._embedTeXFont(dvifont)
|
942 | 944 | for (filename, subset), Fx in sorted(self._fontNames.items()):
|
943 |
| - _log.debug('Embedding font %s:%d.', filename, subset) |
| 945 | + _log.debug('Embedding font %r:%d.', filename, subset) |
944 | 946 | if filename.endswith('.afm'):
|
945 | 947 | # from pdf.use14corefonts
|
946 | 948 | _log.debug('Writing AFM font.')
|
@@ -992,7 +994,8 @@ def _embedTeXFont(self, dvifont):
|
992 | 994 |
|
993 | 995 | # Reduce the font to only the glyphs used in the document, get the encoding
|
994 | 996 | # for that subset, and compute various properties based on the encoding.
|
995 |
| - charmap = self._character_tracker.used[(dvifont.fname, 0)] |
| 997 | + font_path = FontPath(dvifont.fname, dvifont.face_index) |
| 998 | + charmap = self._character_tracker.used[(font_path, 0)] |
996 | 999 | chars = frozenset(charmap.keys())
|
997 | 1000 | t1font = t1font.subset(chars, self._get_subset_prefix(charmap.values()))
|
998 | 1001 | fontdict['BaseFont'] = Name(t1font.prop['FontName'])
|
@@ -1241,12 +1244,12 @@ def embedTTFType42(font, subset_index, charmap, descriptor):
|
1241 | 1244 | wObject = self.reserveObject('Type 0 widths')
|
1242 | 1245 | toUnicodeMapObject = self.reserveObject('ToUnicode map')
|
1243 | 1246 |
|
1244 |
| - _log.debug("SUBSET %s:%d characters: %s", filename, subset_index, charmap) |
| 1247 | + _log.debug("SUBSET %r:%d characters: %s", filename, subset_index, charmap) |
1245 | 1248 | with _backend_pdf_ps.get_glyphs_subset(filename,
|
1246 | 1249 | charmap.values()) as subset:
|
1247 | 1250 | fontdata = _backend_pdf_ps.font_as_file(subset)
|
1248 | 1251 | _log.debug(
|
1249 |
| - "SUBSET %s:%d %d -> %d", filename, subset_index, |
| 1252 | + "SUBSET %r:%d %d -> %d", filename, subset_index, |
1250 | 1253 | os.stat(filename).st_size, fontdata.getbuffer().nbytes
|
1251 | 1254 | )
|
1252 | 1255 |
|
@@ -2137,13 +2140,13 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
|
2137 | 2140 | for font, fontsize, ccode, glyph_index, ox, oy in glyphs:
|
2138 | 2141 | subset_index, subset_charcode = self.file._character_tracker.track_glyph(
|
2139 | 2142 | font, ccode, glyph_index)
|
2140 |
| - fontname = font.fname |
| 2143 | + font_path = FontPath(font.fname, font.face_index) |
2141 | 2144 | self._setup_textpos(ox, oy, 0, oldx, oldy)
|
2142 | 2145 | oldx, oldy = ox, oy
|
2143 |
| - if (fontname, subset_index, fontsize) != prev_font: |
2144 |
| - self.file.output(self.file.fontName(fontname, subset_index), fontsize, |
| 2146 | + if (font_path, subset_index, fontsize) != prev_font: |
| 2147 | + self.file.output(self.file.fontName(font_path, subset_index), fontsize, |
2145 | 2148 | Op.selectfont)
|
2146 |
| - prev_font = fontname, subset_index, fontsize |
| 2149 | + prev_font = font_path, subset_index, fontsize |
2147 | 2150 | self.file.output(self._encode_glyphs([subset_charcode], fonttype),
|
2148 | 2151 | Op.show)
|
2149 | 2152 | self.file.output(Op.end_text)
|
@@ -2329,7 +2332,9 @@ def output_singlebyte_chunk(kerns_or_chars):
|
2329 | 2332 | if (item.ft_object, subset) != prev_font:
|
2330 | 2333 | if singlebyte_chunk:
|
2331 | 2334 | output_singlebyte_chunk(singlebyte_chunk)
|
2332 |
| - ft_name = self.file.fontName(item.ft_object.fname, subset) |
| 2335 | + font_path = FontPath(item.ft_object.fname, |
| 2336 | + item.ft_object.face_index) |
| 2337 | + ft_name = self.file.fontName(font_path, subset) |
2333 | 2338 | self.file.output(ft_name, fontsize, Op.selectfont)
|
2334 | 2339 | self._setup_textpos(item.x, 0, 0, prev_start_x, 0, 0)
|
2335 | 2340 | singlebyte_chunk = []
|
|
0 commit comments