Use the Bakoma TrueType fonts for rendering. Symbols are strewn about a number of font files, each of which has its own proprietary 8-bit encoding.
| 470 | |
| 471 | |
| 472 | class BakomaFonts(TruetypeFonts): |
| 473 | """ |
| 474 | Use the Bakoma TrueType fonts for rendering. |
| 475 | |
| 476 | Symbols are strewn about a number of font files, each of which has |
| 477 | its own proprietary 8-bit encoding. |
| 478 | """ |
| 479 | _fontmap = { |
| 480 | 'normal': 'cmmi10', |
| 481 | 'cal': 'cmsy10', |
| 482 | 'rm': 'cmr10', |
| 483 | 'tt': 'cmtt10', |
| 484 | 'it': 'cmti10', |
| 485 | 'bf': 'cmb10', |
| 486 | 'sf': 'cmss10', |
| 487 | 'ex': 'cmex10', |
| 488 | } |
| 489 | |
| 490 | def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlags): |
| 491 | self._stix_fallback = StixFonts(default_font_prop, load_glyph_flags) |
| 492 | |
| 493 | super().__init__(default_font_prop, load_glyph_flags) |
| 494 | for key, val in self._fontmap.items(): |
| 495 | fullpath = findfont(val) |
| 496 | self.fontmap[key] = fullpath |
| 497 | self.fontmap[val] = fullpath |
| 498 | |
| 499 | _slanted_symbols = set(r"\int \oint".split()) |
| 500 | |
| 501 | def _get_glyph(self, fontname: str, font_class: str, |
| 502 | sym: str) -> tuple[FT2Font, CharacterCodeType, bool]: |
| 503 | font = None |
| 504 | |
| 505 | if fontname in self.fontmap and sym in latex_to_bakoma: |
| 506 | basename, num = latex_to_bakoma[sym] |
| 507 | slanted = (basename in ("cmmi10", "cmti10")) or sym in self._slanted_symbols |
| 508 | font = self._get_font(basename) |
| 509 | elif len(sym) == 1: |
| 510 | slanted = (fontname in ("it", "normal")) |
| 511 | if fontname == "normal" and sym.isdigit(): |
| 512 | # use digits from cmr (roman alphabet) instead of cmm (math alphabet), |
| 513 | # same as LaTeX does. |
| 514 | fontname = "rm" |
| 515 | slanted = False |
| 516 | font = self._get_font(fontname) |
| 517 | if font is not None: |
| 518 | num = ord(sym) |
| 519 | if font is not None and font.get_char_index(num) != 0: |
| 520 | return font, num, slanted |
| 521 | else: |
| 522 | return self._stix_fallback._get_glyph(fontname, font_class, sym) |
| 523 | |
| 524 | # The Bakoma fonts contain many pre-sized alternatives for the delimiters. The |
| 525 | # Auto(Height|Width)Char classes will use these alternatives and select the best |
| 526 | # (closest sized) glyph. |
| 527 | _latex_sizes = ('big', 'Big', 'bigg', 'Bigg') |
| 528 | _size_alternatives = { |
| 529 | '(': [('rm', '('), *[('ex', fr'\__parenleft{s}__') for s in _latex_sizes]], |
no outgoing calls
no test coverage detected
searching dependent graphs…