font.py (libcaca-0.99.beta19) | : | font.py (libcaca-0.99.beta20.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
# http://www.wtfpl.net/ for more details. | # http://www.wtfpl.net/ for more details. | |||
# | # | |||
""" Libcaca Python bindings """ | """ Libcaca Python bindings """ | |||
import ctypes | import ctypes | |||
import errno | import errno | |||
from caca import _lib, _PYTHON3, _str_to_bytes | from caca import _lib, _PYTHON3, _str_to_bytes | |||
class _FontStruct(ctypes.Structure): | ||||
pass | ||||
class _Font(object): | class _Font(object): | |||
""" Model for Font object. | """ Model for Font object. | |||
""" | """ | |||
def __init__(self): | def __init__(self): | |||
self._font = 0 | self._font = None | |||
def from_param(self): | def from_param(self): | |||
""" Required by ctypes module to call object as parameter of | """ Required by ctypes module to call object as parameter of | |||
a C function. | a C function. | |||
""" | """ | |||
return self._font | return self._font | |||
def __del__(self): | def __del__(self): | |||
if hasattr(self, "_font"): | if hasattr(self, "_font"): | |||
if self._font > 0: | if self._font: | |||
self._free() | self._free() | |||
def __str__(self): | def __str__(self): | |||
return "<CacaFont>" | return "<CacaFont>" | |||
def _free(self): | def _free(self): | |||
""" Free a libcaca font. | """ Free a libcaca font. | |||
""" | """ | |||
_lib.caca_free_font.argtypes = [_Font] | _lib.caca_free_font.argtypes = [_Font] | |||
_lib.caca_free_font.restype = ctypes.c_int | _lib.caca_free_font.restype = ctypes.c_int | |||
skipping to change at line 65 | skipping to change at line 68 | |||
""" Font constructor | """ Font constructor | |||
font -- the memory area containing the font or its name | font -- the memory area containing the font or its name | |||
size -- the size of the memory area, or 0 if the font name is giv en | size -- the size of the memory area, or 0 if the font name is giv en | |||
""" | """ | |||
if size == 0: | if size == 0: | |||
_lib.caca_load_font.argtypes = [ctypes.c_char_p, ctypes.c_int] | _lib.caca_load_font.argtypes = [ctypes.c_char_p, ctypes.c_int] | |||
else: | else: | |||
raise FontError("Unsupported method") | raise FontError("Unsupported method") | |||
_lib.caca_load_font.restype = ctypes.c_int | _lib.caca_load_font.restype = ctypes.POINTER(_FontStruct) | |||
if _PYTHON3: | if _PYTHON3: | |||
font = _str_to_bytes(font) | font = _str_to_bytes(font) | |||
self._font = _lib.caca_load_font(font, size) | self._font = _lib.caca_load_font(font, size) | |||
if self._font == 0: | if self._font == 0: | |||
err = ctypes.c_int.in_dll(_lib, "errno") | err = ctypes.c_int.in_dll(_lib, "errno") | |||
if err.value == errno.ENOENT: | if err.value == errno.ENOENT: | |||
raise FontError("Requested built-in font does not exist") | raise FontError("Requested built-in font does not exist") | |||
elif err.value == errno.EINVAL: | elif err.value == errno.EINVAL: | |||
End of changes. 4 change blocks. | ||||
3 lines changed or deleted | 6 lines changed or added |