A character as close to the given width as possible. When using a font with multiple width versions of some characters (such as the BaKoMa fonts), the correct glyph will be selected, otherwise this will always just return a scaled version of the glyph.
| 1678 | |
| 1679 | |
| 1680 | class AutoWidthChar(Hlist): |
| 1681 | """ |
| 1682 | A character as close to the given width as possible. |
| 1683 | |
| 1684 | When using a font with multiple width versions of some characters (such as |
| 1685 | the BaKoMa fonts), the correct glyph will be selected, otherwise this will |
| 1686 | always just return a scaled version of the glyph. |
| 1687 | """ |
| 1688 | |
| 1689 | def __init__(self, c: str, width: float, state: ParserState, |
| 1690 | char_class: type[Char] = Char): |
| 1691 | alternatives = state.fontset.get_sized_alternatives_for_symbol(state.font, c) |
| 1692 | |
| 1693 | state = state.copy() |
| 1694 | for fontname, sym in alternatives: |
| 1695 | state.font = fontname |
| 1696 | char = char_class(sym, state) |
| 1697 | if char.width >= width: |
| 1698 | break |
| 1699 | |
| 1700 | factor = width / char.width |
| 1701 | state.fontsize *= factor |
| 1702 | char = char_class(sym, state) |
| 1703 | |
| 1704 | super().__init__([char]) |
| 1705 | self.width = char.width |
| 1706 | |
| 1707 | |
| 1708 | def ship(box: Box, xy: tuple[float, float] = (0, 0)) -> Output: |
no outgoing calls
no test coverage detected
searching dependent graphs…