-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcyzhban.pyx
40 lines (32 loc) · 1.29 KB
/
cyzhban.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
cimport cyzhban
from cpython.buffer cimport Py_buffer, PyObject_GetBuffer, PyBuffer_Release, PyBUF_CONTIG_RO
class SomeError(Exception):
pass
cdef class simprinter:
cdef cyzhban.zhban_t *_zhban
cdef cyzhban.zhban_rect_t sizer_rv
cdef cyzhban.zhban_rect_t render_rv
def __cinit__(self, facebuf, pixheight): # facebuf is bytes, memoryview or something like that..
cdef Py_buffer buf
PyObject_GetBuffer(facebuf, &buf, PyBUF_CONTIG_RO)
self._zhban = cyzhban.zhban_open(buf.buf, buf.len, pixheight, 100500<<10, 100500<<10)
PyBuffer_Release(&buf)
if self._zhban is NULL:
raise MemoryError()
def __dealloc__(self):
if self._zhban is not NULL:
cyzhban.zhban_drop(self._zhban)
cdef size(self, text):
cdef Py_buffer buf
PyObject_GetBuffer(text, &buf, PyBUF_CONTIG_RO)
fail = zhban_size(self._zhban, <uint16_t *>buf.buf, buf.len, &self.sizer_rv)
PyBuffer_Release(&buf)
if fail:
raise SomeError
cdef texture(self, text):
cdef Py_buffer buf
PyObject_GetBuffer(text, &buf, PyBUF_CONTIG_RO)
fail = zhban_render(self._zhban, <uint16_t *>buf.buf, buf.len, &self.render_rv)
PyBuffer_Release(&buf)
if fail:
raise SomeError