A psfonts.map formatted file, mapping TeX fonts to PS fonts. Parameters ---------- filename : str or path-like Notes ----- For historical reasons, TeX knows many Type-1 fonts by different names than the outside world. (For one thing, the names have to fit in ei
| 1049 | |
| 1050 | |
| 1051 | class PsfontsMap: |
| 1052 | """ |
| 1053 | A psfonts.map formatted file, mapping TeX fonts to PS fonts. |
| 1054 | |
| 1055 | Parameters |
| 1056 | ---------- |
| 1057 | filename : str or path-like |
| 1058 | |
| 1059 | Notes |
| 1060 | ----- |
| 1061 | For historical reasons, TeX knows many Type-1 fonts by different |
| 1062 | names than the outside world. (For one thing, the names have to |
| 1063 | fit in eight characters.) Also, TeX's native fonts are not Type-1 |
| 1064 | but Metafont, which is nontrivial to convert to PostScript except |
| 1065 | as a bitmap. While high-quality conversions to Type-1 format exist |
| 1066 | and are shipped with modern TeX distributions, we need to know |
| 1067 | which Type-1 fonts are the counterparts of which native fonts. For |
| 1068 | these reasons a mapping is needed from internal font names to font |
| 1069 | file names. |
| 1070 | |
| 1071 | A texmf tree typically includes mapping files called e.g. |
| 1072 | :file:`psfonts.map`, :file:`pdftex.map`, or :file:`dvipdfm.map`. |
| 1073 | The file :file:`psfonts.map` is used by :program:`dvips`, |
| 1074 | :file:`pdftex.map` by :program:`pdfTeX`, and :file:`dvipdfm.map` |
| 1075 | by :program:`dvipdfm`. :file:`psfonts.map` might avoid embedding |
| 1076 | the 35 PostScript fonts (i.e., have no filename for them, as in |
| 1077 | the Times-Bold example above), while the pdf-related files perhaps |
| 1078 | only avoid the "Base 14" pdf fonts. But the user may have |
| 1079 | configured these files differently. |
| 1080 | |
| 1081 | Examples |
| 1082 | -------- |
| 1083 | >>> map = PsfontsMap(find_tex_file('pdftex.map')) |
| 1084 | >>> entry = map[b'ptmbo8r'] |
| 1085 | >>> entry.texname |
| 1086 | b'ptmbo8r' |
| 1087 | >>> entry.psname |
| 1088 | b'Times-Bold' |
| 1089 | >>> entry.encoding |
| 1090 | '/usr/local/texlive/2008/texmf-dist/fonts/enc/dvips/base/8r.enc' |
| 1091 | >>> entry.effects |
| 1092 | {'slant': 0.16700000000000001} |
| 1093 | >>> entry.filename |
| 1094 | """ |
| 1095 | __slots__ = ('_filename', '_unparsed', '_parsed') |
| 1096 | |
| 1097 | # Create a filename -> PsfontsMap cache, so that calling |
| 1098 | # `PsfontsMap(filename)` with the same filename a second time immediately |
| 1099 | # returns the same object. |
| 1100 | @lru_cache |
| 1101 | def __new__(cls, filename): |
| 1102 | self = object.__new__(cls) |
| 1103 | self._filename = os.fsdecode(filename) |
| 1104 | # Some TeX distributions have enormous pdftex.map files which would |
| 1105 | # take hundreds of milliseconds to parse, but it is easy enough to just |
| 1106 | # store the unparsed lines (keyed by the first word, which is the |
| 1107 | # texname) and parse them on-demand. |
| 1108 | with open(filename, 'rb') as file: |
no outgoing calls
no test coverage detected
searching dependent graphs…