diff --git a/doc/api/next_api_changes/deprecations/30088-AL.rst b/doc/api/next_api_changes/deprecations/30088-AL.rst new file mode 100644 index 000000000000..ae1338da7f85 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/30088-AL.rst @@ -0,0 +1,4 @@ +*fontfile* parameter of ``PdfFile.createType1Descriptor`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This parameter is deprecated; all relevant pieces of information are now +directly extracted from the *t1font* argument. diff --git a/lib/matplotlib/_type1font.py b/lib/matplotlib/_type1font.py index b3e08f52c035..032b6a42ea63 100644 --- a/lib/matplotlib/_type1font.py +++ b/lib/matplotlib/_type1font.py @@ -579,6 +579,16 @@ def _parse(self): extras = ('(?i)([ -](regular|plain|italic|oblique|(semi)?bold|' '(ultra)?light|extra|condensed))+$') prop['FamilyName'] = re.sub(extras, '', prop['FullName']) + + # Parse FontBBox + toks = [*_tokenize(prop['FontBBox'].encode('ascii'), True)] + if ([tok.kind for tok in toks] + != ['delimiter', 'number', 'number', 'number', 'number', 'delimiter'] + or toks[-1].raw != toks[0].opposite()): + raise RuntimeError( + f"FontBBox should be a size-4 array, was {prop['FontBBox']}") + prop['FontBBox'] = [tok.value() for tok in toks[1:-1]] + # Decrypt the encrypted parts ndiscard = prop.get('lenIV', 4) cs = prop['CharStrings'] diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 73cf8bc19be2..073ca05bc172 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1034,14 +1034,15 @@ def _embedTeXFont(self, fontinfo): fontinfo.effects.get('extend', 1.0)) fontdesc = self._type1Descriptors.get((fontinfo.fontfile, effects)) if fontdesc is None: - fontdesc = self.createType1Descriptor(t1font, fontinfo.fontfile) + fontdesc = self.createType1Descriptor(t1font) self._type1Descriptors[(fontinfo.fontfile, effects)] = fontdesc fontdict['FontDescriptor'] = fontdesc self.writeObject(fontdictObject, fontdict) return fontdictObject - def createType1Descriptor(self, t1font, fontfile): + @_api.delete_parameter("3.11", "fontfile") + def createType1Descriptor(self, t1font, fontfile=None): # Create and write the font descriptor and the font file # of a Type-1 font fontdescObject = self.reserveObject('font descriptor') @@ -1076,16 +1077,14 @@ def createType1Descriptor(self, t1font, fontfile): if 0: flags |= 1 << 18 - ft2font = get_font(fontfile) - descriptor = { 'Type': Name('FontDescriptor'), 'FontName': Name(t1font.prop['FontName']), 'Flags': flags, - 'FontBBox': ft2font.bbox, + 'FontBBox': t1font.prop['FontBBox'], 'ItalicAngle': italic_angle, - 'Ascent': ft2font.ascender, - 'Descent': ft2font.descender, + 'Ascent': t1font.prop['FontBBox'][3], + 'Descent': t1font.prop['FontBBox'][1], 'CapHeight': 1000, # TODO: find this out 'XHeight': 500, # TODO: this one too 'FontFile': fontfileObject, @@ -1093,7 +1092,7 @@ def createType1Descriptor(self, t1font, fontfile): 'StemV': 50, # TODO # (see also revision 3874; but not all TeX distros have AFM files!) # 'FontWeight': a number where 400 = Regular, 700 = Bold - } + } self.writeObject(fontdescObject, descriptor)