|
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
|
@@ -893,8 +893,10 @@ def fontName(self, fontprop, subset=0):
|
893 | 893 | as the filename of the font.
|
894 | 894 | """
|
895 | 895 |
|
896 |
| - if isinstance(fontprop, str): |
| 896 | + if isinstance(fontprop, FontPath): |
897 | 897 | filenames = [fontprop]
|
| 898 | + elif isinstance(fontprop, str): |
| 899 | + filenames = [FontPath(fontprop, 0)] |
898 | 900 | elif mpl.rcParams['pdf.use14corefonts']:
|
899 | 901 | filenames = _fontManager._find_fonts_by_props(
|
900 | 902 | fontprop, fontext='afm', directory=RendererPdf._afm_font_dir
|
@@ -934,7 +936,7 @@ def writeFonts(self):
|
934 | 936 | _log.debug('Embedding Type-1 font %s from dvi.', dvifont.texname)
|
935 | 937 | fonts[pdfname] = self._embedTeXFont(dvifont)
|
936 | 938 | for (filename, subset), Fx in sorted(self._fontNames.items()):
|
937 |
| - _log.debug('Embedding font %s:%d.', filename, subset) |
| 939 | + _log.debug('Embedding font %r:%d.', filename, subset) |
938 | 940 | if filename.endswith('.afm'):
|
939 | 941 | # from pdf.use14corefonts
|
940 | 942 | _log.debug('Writing AFM font.')
|
@@ -985,7 +987,8 @@ def _embedTeXFont(self, dvifont):
|
985 | 987 |
|
986 | 988 | # Reduce the font to only the glyphs used in the document, get the encoding
|
987 | 989 | # for that subset, and compute various properties based on the encoding.
|
988 |
| - charmap = self._character_tracker.used[dvifont.fname][0] |
| 990 | + font_path = FontPath(dvifont.fname, dvifont.face_index) |
| 991 | + charmap = self._character_tracker.used[font_path][0] |
989 | 992 | chars = {
|
990 | 993 | # DVI type 1 fonts always map single glyph to single character.
|
991 | 994 | ord(self._character_tracker.subset_to_unicode(dvifont.fname, 0, ccode))
|
@@ -1240,12 +1243,12 @@ def embedTTFType42(font, subset_index, charmap, descriptor):
|
1240 | 1243 | wObject = self.reserveObject('Type 0 widths')
|
1241 | 1244 | toUnicodeMapObject = self.reserveObject('ToUnicode map')
|
1242 | 1245 |
|
1243 |
| - _log.debug("SUBSET %s:%d characters: %s", filename, subset_index, charmap) |
| 1246 | + _log.debug("SUBSET %r:%d characters: %s", filename, subset_index, charmap) |
1244 | 1247 | with _backend_pdf_ps.get_glyphs_subset(filename,
|
1245 | 1248 | charmap.values()) as subset:
|
1246 | 1249 | fontdata = _backend_pdf_ps.font_as_file(subset)
|
1247 | 1250 | _log.debug(
|
1248 |
| - "SUBSET %s:%d %d -> %d", filename, subset_index, |
| 1251 | + "SUBSET %r:%d %d -> %d", filename, subset_index, |
1249 | 1252 | os.stat(filename).st_size, fontdata.getbuffer().nbytes
|
1250 | 1253 | )
|
1251 | 1254 |
|
@@ -2136,13 +2139,13 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
|
2136 | 2139 | for font, fontsize, ccode, glyph_index, ox, oy in glyphs:
|
2137 | 2140 | subset_index, subset_charcode = self.file._character_tracker.track_glyph(
|
2138 | 2141 | font, ccode, glyph_index)
|
2139 |
| - fontname = font.fname |
| 2142 | + font_path = FontPath(font.fname, font.face_index) |
2140 | 2143 | self._setup_textpos(ox, oy, 0, oldx, oldy)
|
2141 | 2144 | oldx, oldy = ox, oy
|
2142 |
| - if (fontname, subset_index, fontsize) != prev_font: |
2143 |
| - self.file.output(self.file.fontName(fontname, subset_index), fontsize, |
| 2145 | + if (font_path, subset_index, fontsize) != prev_font: |
| 2146 | + self.file.output(self.file.fontName(font_path, subset_index), fontsize, |
2144 | 2147 | Op.selectfont)
|
2145 |
| - prev_font = fontname, subset_index, fontsize |
| 2148 | + prev_font = font_path, subset_index, fontsize |
2146 | 2149 | self.file.output(self._encode_glyphs([subset_charcode], fonttype),
|
2147 | 2150 | Op.show)
|
2148 | 2151 | self.file.output(Op.end_text)
|
@@ -2333,7 +2336,9 @@ def output_singlebyte_chunk(kerns_or_chars):
|
2333 | 2336 | if (item.ft_object, subset) != prev_font:
|
2334 | 2337 | if singlebyte_chunk:
|
2335 | 2338 | output_singlebyte_chunk(singlebyte_chunk)
|
2336 |
| - ft_name = self.file.fontName(item.ft_object.fname, subset) |
| 2339 | + font_path = FontPath(item.ft_object.fname, |
| 2340 | + item.ft_object.face_index) |
| 2341 | + ft_name = self.file.fontName(font_path, subset) |
2337 | 2342 | self.file.output(ft_name, fontsize, Op.selectfont)
|
2338 | 2343 | self._setup_textpos(item.x, 0, 0, prev_start_x, 0, 0)
|
2339 | 2344 | singlebyte_chunk = []
|
|
0 commit comments