def getfont(self): if self._font is None: if self.fontfilename is not None: with config.open(self.fontfilename, [config.format.type1]) as fontfile: t1font = t1file.from_PF_bytes(fontfile.read()) assert self.basepsname == t1font.name, "corrupt MAP file" try: with config.open(os.path.splitext(self.fontfilename)[0], [config.format.afm], ascii=True) as metricfile: self._font = font.T1font(t1font, afmfile.AFMfile(metricfile)) except EnvironmentError: try: # fallback by using the pfm instead of the afm font metric # (in all major TeX distributions there is no pfm file format defined by kpsewhich, but # we can use the type1 format and search for the file including the expected suffix) with config.open( "%s.pfm" % os.path.splitext(self.fontfilename)[0], [config.format.type1]) as metricfile: self._font = font.T1font( t1font, pfmfile.PFMfile(metricfile, t1font)) except EnvironmentError: # we need to continue without any metric file self._font = font.T1font(t1font) else: # builtin font with config.open(self.basepsname, [config.format.afm], ascii=True) as metricfile: self._font = font.T1builtinfont( self.basepsname, afmfile.AFMfile(metricfile)) return self._font
def getfont(self): if self._font is None: if self.fontfilename is not None: fontfile = filelocator.open(self.fontfilename, [filelocator.format.type1], "rb") t1font = t1file.from_PF_bytes(fontfile.read()) fontfile.close() assert self.basepsname == t1font.name, "corrupt MAP file" try: metricfile = filelocator.open( os.path.splitext(self.fontfilename)[0], [filelocator.format.afm]) except IOError: self._font = font.T1font(t1font, None) else: self._font = font.T1font(t1font, afmfile.AFMfile(metricfile)) metricfile.close() else: metricfile = filelocator.open(self.basepsname, [filelocator.format.afm]) self._font = font.T1builtinfont(self.basepsname, afmfile.AFMfile(metricfile)) metricfile.close() return self._font
def getfont(self): if self._font is None: if self.fontfilename is not None: fontfile = filelocator.open(self.fontfilename, [filelocator.format.type1], "rb") t1font = t1file.from_PF_bytes(fontfile.read()) fontfile.close() assert self.basepsname == t1font.name, "corrupt MAP file" try: metricfile = filelocator.open( os.path.splitext(self.fontfilename)[0], [filelocator.format.afm]) except IOError: try: # fallback by using the pfm instead of the afm font metric # (in all major TeX distributions there is no pfm file format defined by kpsewhich, but # we can use the type1 format and search for the file including the expected suffix) metricfile = filelocator.open( "%s.pfm" % os.path.splitext(self.fontfilename)[0], [filelocator.format.type1]) except IOError: self._font = font.T1font(t1font) else: self._font = font.T1font( t1font, pfmfile.PFMfile(metricfile, t1font)) metricfile.close() else: self._font = font.T1font(t1font, afmfile.AFMfile(metricfile)) metricfile.close() else: metricfile = filelocator.open(self.basepsname, [filelocator.format.afm]) self._font = font.T1builtinfont(self.basepsname, afmfile.AFMfile(metricfile)) metricfile.close() return self._font