Пример #1
0
def load_truetype_font(path: str, tile_width: int,
                       tile_height: int) -> Tileset:
    """Return a new Tileset from a `.ttf` or `.otf` file.

    Same as :any:`set_truetype_font`, but returns a :any:`Tileset` instead.
    You can send this Tileset to :any:`set_default`.

    This function is provisional.  The API may change.
    """
    if not os.path.exists(path):
        raise RuntimeError("File not found:\n\t%s" %
                           (os.path.realpath(path), ))
    cdata = lib.TCOD_load_truetype_font_(path.encode(), tile_width,
                                         tile_height)
    if not cdata:
        raise RuntimeError(ffi.string(lib.TCOD_get_error()))
    return Tileset._claim(cdata)
Пример #2
0
def set_truetype_font(path: str, tile_width: int, tile_height: int) -> None:
    """Set the default tileset from a `.ttf` or `.otf` file.

    `path` is the file path for the font file.

    `tile_width` and `tile_height` are the desired size of the tiles in the new
    tileset.  The font will be scaled to fit the given `tile_height` and
    `tile_width`.

    This function will only affect the `SDL2` and `OPENGL2` renderers.

    This function must be called before :any:`tcod.console_init_root`.  Once
    the root console is setup you may call this funtion again to change the
    font.  The tileset can be changed but the window will not be resized
    automatically.

    .. versionadded:: 9.2
    """
    if not os.path.exists(path):
        raise RuntimeError("File not found:\n\t%s" %
                           (os.path.realpath(path), ))
    if lib.TCOD_tileset_load_truetype_(path.encode(), tile_width, tile_height):
        raise RuntimeError(ffi.string(lib.TCOD_get_error()))
Пример #3
0
def _unpack_char_p(char_p):
    if char_p == ffi.NULL:
        return ""
    return ffi.string(char_p).decode()
Пример #4
0
def _unpack_char_p(char_p: Any) -> str:
    if char_p == ffi.NULL:
        return ""
    return ffi.string(char_p).decode()  # type: ignore
Пример #5
0
def _check(error: int) -> None:
    """Detect and convert a libtcod error code it into an exception."""
    if error < 0:
        raise RuntimeError(ffi.string(lib.TCOD_get_error()).decode())