### Navigation

- index
- next |
- previous |
- Pygame SGE 0.7.0 documentation »
- Classes »

# sge.Font

class `sge.``Font`(name=None, ID=None, size=12, underline=False, bold=False, italic=False)

  Font handling class.

  This class stores a font for use by `sge.Sprite.draw_text()` and `sge.Room.project_text()`.

  Note that bold and italic rendering could be ugly. It is better to choose a bold or italic font rather than enabling bold or italic rendering, if possible.

  `size`

    The height of the font in pixels.

  `underline`

    Whether or not underlined rendering is enabled.

  `bold`

    Whether or not bold rendering is enabled.

    Note

    Using this option can be ugly. It is better to choose a bold font rather than enabling bold rendering, if possible.

  `italic`

    Whether or not italic rendering is enabled.

    Note

    Using this option can be ugly. It is better to choose an italic font rather than enabling italic rendering, if possible.

  `name`

    The name of the font as specified when it was created. (Read-only)

  `id`

    The unique identifier of the font. (Read-only)

## sge.Font Methods

`Font.``__init__`(name=None, ID=None, size=12, underline=False, bold=False, italic=False)

  Constructor method.

  Arguments:

  - `name` – The name of the font. Can be one of the following:

    - A string indicating the name of a font file located in one of the paths specified in `sge.font_directories`, e.g. `"MyFont.ttf"`.
    - A string indicating the case-insensitive name of a system font, e.g. `"Liberation Serif"`.
    - A list or tuple of strings indicating either a font file or a system font to choose from in order of preference.

    If none of the above methods return a valid font, the SGE will choose the font.

  - `ID` – The value to set `id` to. If set to `None`, `name` will be used, modified by the SGE if it is already the unique identifier of another font.

  All other arguments set the respective initial attributes of the font. See the documentation for `sge.Font` for more information.

  Note

  It is generally not a good practice to rely on system fonts. A font which you have on your system is probably not on everyone’s system. For example, most Windows systems have a font called Times New Roman, but this font is not normally found on Debian systems. On the other hand, Debian has the Liberation fonts installed by default, but these fonts are uncommon on Windows systems. Rather than relying on system fonts, choose a font which is under a free license (such as the GNU General Public License or the SIL Open Font License) and distribute it with your game; this will ensure that everyone sees text rendered the same way you do.

`Font.``get_size`(text, width=None, height=None)

  Return the size of a certain string of text when rendered.

  See the documentation for `sge.Sprite.draw_text()` for information about the arguments.

classmethod `Font.``from_sprite`(sprite, chars, ID=None, hsep=0, vsep=0, size=12, underline=False, bold=False, italic=False)

  Return a font derived from a sprite.

  Arguments:

  - `sprite` – The `sge.Sprite` object to derive the font from.
  - `chars` – A list of characters to set the sprite’s frames to. For example, `['A', 'B', 'C']` would assign the first frame to the letter “A”, the second frame to the letter “B”, and the third frame to the letter “C”. Any character not listed here will be rendered as its differently-cased counterpart if possible (e.g. “A” as “a”) or as a blank space otherwise.
  - `ID` – The value to set `id` to. If set to `None`, the name of the sprite will be used, modified by the SGE if it is already the unique identifier of another font.
  - `hsep` – The amount of horizontal space to place between characters when text is rendered.
  - `vsep` – The amount of vertical space to place between lines when text is rendered.

  All other arguments set the respective initial attributes of the font. See the documentation for `sge.Font` for more information.

  The font’s `name` attribute will be set to the name of the sprite the font is derived from.

  The font’s `size` attribute will indicate the height of the characters in pixels. The width of the characters will be adjusted proportionally.

### Navigation

- index
- next |
- previous |
- Pygame SGE 0.7.0 documentation »
- Classes »