Encapsulation of a font that a DVI file can refer to. This class holds a font's texname and size, supports comparison, and knows the widths of glyphs in the same units as the AFM file. There are also internal attributes (for use by dviread.py) that are *not* used for comparison
| 629 | |
| 630 | |
| 631 | class DviFont: |
| 632 | """ |
| 633 | Encapsulation of a font that a DVI file can refer to. |
| 634 | |
| 635 | This class holds a font's texname and size, supports comparison, |
| 636 | and knows the widths of glyphs in the same units as the AFM file. |
| 637 | There are also internal attributes (for use by dviread.py) that |
| 638 | are *not* used for comparison. |
| 639 | |
| 640 | The size is in Adobe points (converted from TeX points). |
| 641 | |
| 642 | Parameters |
| 643 | ---------- |
| 644 | scale : float |
| 645 | Factor by which the font is scaled from its natural size. |
| 646 | metrics : Tfm | TtfMetrics |
| 647 | TeX font metrics for this font |
| 648 | texname : bytes |
| 649 | Name of the font as used internally in the DVI file, as an ASCII |
| 650 | bytestring. This is usually very different from any external font |
| 651 | names; `PsfontsMap` can be used to find the external name of the font. |
| 652 | vf : Vf |
| 653 | A TeX "virtual font" file, or None if this font is not virtual. |
| 654 | |
| 655 | Attributes |
| 656 | ---------- |
| 657 | texname : bytes |
| 658 | fname : str |
| 659 | Compatibility shim so that DviFont can be used with |
| 660 | ``_backend_pdf_ps.CharacterTracker``; not a real filename. |
| 661 | size : float |
| 662 | Size of the font in Adobe points, converted from the slightly |
| 663 | smaller TeX points. |
| 664 | """ |
| 665 | |
| 666 | def __init__(self, scale, metrics, texname, vf): |
| 667 | _api.check_isinstance(bytes, texname=texname) |
| 668 | self._scale = scale |
| 669 | self._metrics = metrics |
| 670 | self.texname = texname |
| 671 | self._vf = vf |
| 672 | self._path = None |
| 673 | self._encoding = None |
| 674 | |
| 675 | @classmethod |
| 676 | def from_luatex(cls, scale, texname): |
| 677 | path_b, sep, rest = texname[1:].rpartition(b"]") |
| 678 | if not (texname.startswith(b"[") and sep and rest[:1] in [b"", b":"]): |
| 679 | raise ValueError(f"Invalid modern font name: {texname}") |
| 680 | # utf8 on Windows, not utf16! |
| 681 | path = path_b.decode("utf8") if os.name == "nt" else os.fsdecode(path_b) |
| 682 | subfont = 0 |
| 683 | effects = {} |
| 684 | if rest[1:]: |
| 685 | for kv in rest[1:].decode("ascii").split(";"): |
| 686 | key, val = kv.split("=", 1) |
| 687 | if key == "index": |
| 688 | subfont = val |
no test coverage detected
searching dependent graphs…