|
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, LoadFlags, StyleFlags
|
38 | 38 | from matplotlib.transforms import Affine2D, BboxBase
|
@@ -894,8 +894,10 @@ def fontName(self, fontprop, subset=0):
|
894 | 894 | as the filename of the font.
|
895 | 895 | """
|
896 | 896 |
|
897 |
| - if isinstance(fontprop, str): |
| 897 | + if isinstance(fontprop, FontPath): |
898 | 898 | filenames = [fontprop]
|
| 899 | + elif isinstance(fontprop, str): |
| 900 | + filenames = [FontPath(fontprop, 0)] |
899 | 901 | elif mpl.rcParams['pdf.use14corefonts']:
|
900 | 902 | filenames = _fontManager._find_fonts_by_props(
|
901 | 903 | fontprop, fontext='afm', directory=RendererPdf._afm_font_dir
|
@@ -935,7 +937,7 @@ def writeFonts(self):
|
935 | 937 | _log.debug('Embedding Type-1 font %s from dvi.', dvifont.texname)
|
936 | 938 | fonts[pdfname] = self._embedTeXFont(dvifont)
|
937 | 939 | for (filename, subset), Fx in sorted(self._fontNames.items()):
|
938 |
| - _log.debug('Embedding font %s:%d.', filename, subset) |
| 940 | + _log.debug('Embedding font %r:%d.', filename, subset) |
939 | 941 | if filename.endswith('.afm'):
|
940 | 942 | # from pdf.use14corefonts
|
941 | 943 | _log.debug('Writing AFM font.')
|
@@ -986,7 +988,8 @@ def _embedTeXFont(self, dvifont):
|
986 | 988 |
|
987 | 989 | # Reduce the font to only the glyphs used in the document, get the encoding
|
988 | 990 | # for that subset, and compute various properties based on the encoding.
|
989 |
| - charmap = self._character_tracker.used[dvifont.fname][0] |
| 991 | + font_path = FontPath(dvifont.fname, dvifont.face_index) |
| 992 | + charmap = self._character_tracker.used[font_path][0] |
990 | 993 | chars = {
|
991 | 994 | # DVI fonts always map single glyph to single character.
|
992 | 995 | ord(self._character_tracker.subset_to_unicode(dvifont.fname, 0, ccode))
|
@@ -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)
|
@@ -2337,7 +2340,9 @@ def output_singlebyte_chunk(kerns_or_chars):
|
2337 | 2340 | item.ft_object, item.char, item.glyph_index)
|
2338 | 2341 | if (item.ft_object, subset) != prev_font:
|
2339 | 2342 | output_singlebyte_chunk(singlebyte_chunk)
|
2340 |
| - ft_name = self.file.fontName(item.ft_object.fname, subset) |
| 2343 | + font_path = FontPath(item.ft_object.fname, |
| 2344 | + item.ft_object.face_index) |
| 2345 | + ft_name = self.file.fontName(font_path, subset) |
2341 | 2346 | self.file.output(ft_name, fontsize, Op.selectfont)
|
2342 | 2347 | self._setup_textpos(item.x, 0, 0, prev_start_x, 0, 0)
|
2343 | 2348 | prev_font = (item.ft_object, subset)
|
|
0 commit comments