:class:`AutoWidthChar` will create 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 t
| 2008 | self.shift_amount = shift |
| 2009 | |
| 2010 | class AutoWidthChar(Hlist): |
| 2011 | """ |
| 2012 | :class:`AutoWidthChar` will create a character as close to the |
| 2013 | given width as possible. When using a font with multiple width |
| 2014 | versions of some characters (such as the BaKoMa fonts), the |
| 2015 | correct glyph will be selected, otherwise this will always just |
| 2016 | return a scaled version of the glyph. |
| 2017 | """ |
| 2018 | def __init__(self, c, width, state, always=False, char_class=Char): |
| 2019 | alternatives = state.font_output.get_sized_alternatives_for_symbol( |
| 2020 | state.font, c) |
| 2021 | |
| 2022 | state = state.copy() |
| 2023 | for fontname, sym in alternatives: |
| 2024 | state.font = fontname |
| 2025 | char = char_class(sym, state) |
| 2026 | if char.width >= width: |
| 2027 | break |
| 2028 | |
| 2029 | factor = width / char.width |
| 2030 | state.fontsize *= factor |
| 2031 | char = char_class(sym, state) |
| 2032 | |
| 2033 | Hlist.__init__(self, [char]) |
| 2034 | self.width = char.width |
| 2035 | |
| 2036 | |
| 2037 | class Ship(object): |