A character as close to the given height and depth as possible. When using a font with multiple height 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.
| 1640 | |
| 1641 | |
| 1642 | class AutoHeightChar(Hlist): |
| 1643 | """ |
| 1644 | A character as close to the given height and depth as possible. |
| 1645 | |
| 1646 | When using a font with multiple height versions of some characters (such as |
| 1647 | the BaKoMa fonts), the correct glyph will be selected, otherwise this will |
| 1648 | always just return a scaled version of the glyph. |
| 1649 | """ |
| 1650 | |
| 1651 | def __init__(self, c: str, height: float, depth: float, state: ParserState, |
| 1652 | factor: float | None = None): |
| 1653 | alternatives = state.fontset.get_sized_alternatives_for_symbol(state.font, c) |
| 1654 | |
| 1655 | x_height = state.fontset.get_xheight(state.font, state.fontsize, state.dpi) |
| 1656 | |
| 1657 | state = state.copy() |
| 1658 | target_total = height + depth |
| 1659 | for fontname, sym in alternatives: |
| 1660 | state.font = fontname |
| 1661 | char = Char(sym, state) |
| 1662 | # Ensure that size 0 is chosen when the text is regular sized but |
| 1663 | # with descender glyphs by subtracting 0.2 * x_height |
| 1664 | if char.height + char.depth >= target_total - 0.2 * x_height: |
| 1665 | break |
| 1666 | |
| 1667 | shift = 0.0 |
| 1668 | if state.font != '0' or len(alternatives) == 1: |
| 1669 | if factor is None: |
| 1670 | factor = target_total / (char.height + char.depth) |
| 1671 | state.fontsize *= factor |
| 1672 | char = Char(sym, state) |
| 1673 | |
| 1674 | shift = (depth - char.depth) |
| 1675 | |
| 1676 | super().__init__([char]) |
| 1677 | self.shift_amount = shift |
| 1678 | |
| 1679 | |
| 1680 | class AutoWidthChar(Hlist): |
no outgoing calls
no test coverage detected
searching dependent graphs…