12#define PY_SSIZE_T_CLEAN
45 ".. function:: position(fontid, x, y, z)\n"
47 " Set the position for drawing text.\n"
49 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
51 " :type fontid: int\n"
52 " :arg x: X axis position to draw the text.\n"
54 " :arg y: Y axis position to draw the text.\n"
56 " :arg z: Z axis position to draw the text.\n"
63 if (!PyArg_ParseTuple(args,
"ifff:blf.position", &fontid, &
x, &
y, &
z)) {
75 ".. function:: size(fontid, size)\n"
77 " Set the size for drawing text.\n"
79 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
81 " :type fontid: int\n"
82 " :arg size: Point size of the font.\n"
83 " :type size: float\n");
89 if (!PyArg_ParseTuple(args,
"if:blf.size", &fontid, &
size)) {
101 ".. function:: aspect(fontid, aspect)\n"
103 " Set the aspect for drawing text.\n"
105 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
107 " :type fontid: int\n"
108 " :arg aspect: The aspect ratio for text drawing to use.\n"
109 " :type aspect: float\n");
115 if (!PyArg_ParseTuple(args,
"if:blf.aspect", &fontid, &aspect)) {
127 ".. function:: color(fontid, r, g, b, a)\n"
129 " Set the color for drawing text.\n"
131 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
133 " :type fontid: int\n"
134 " :arg r: red channel 0.0 - 1.0.\n"
136 " :arg g: green channel 0.0 - 1.0.\n"
138 " :arg b: blue channel 0.0 - 1.0.\n"
140 " :arg a: alpha channel 0.0 - 1.0.\n"
141 " :type a: float\n");
147 if (!PyArg_ParseTuple(args,
"iffff:blf.color", &fontid, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
164 ".. function:: draw(fontid, text)\n"
166 " Draw text in the current context.\n"
168 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
170 " :type fontid: int\n"
171 " :arg text: the text to draw.\n"
172 " :type text: str\n");
176 Py_ssize_t text_length;
179 if (!PyArg_ParseTuple(args,
"is#:blf.draw", &fontid, &text, &text_length)) {
190 py_blf_draw_buffer_doc,
191 ".. function:: draw_buffer(fontid, text)\n"
193 " Draw text into the buffer bound to the fontid.\n"
195 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
197 " :type fontid: int\n"
198 " :arg text: the text to draw.\n"
199 " :type text: str\n");
203 Py_ssize_t text_length;
206 if (!PyArg_ParseTuple(args,
"is#:blf.draw_buffer", &fontid, &text, &text_length)) {
217 py_blf_dimensions_doc,
218 ".. function:: dimensions(fontid, text)\n"
220 " Return the width and height of the text.\n"
222 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
224 " :type fontid: int\n"
225 " :arg text: the text to draw.\n"
227 " :return: the width and height of the text.\n"
228 " :rtype: tuple[float, float]\n");
236 if (!PyArg_ParseTuple(args,
"is:blf.dimensions", &fontid, &text)) {
242 ret = PyTuple_New(2);
250 ".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n"
252 " Set the clipping, enable/disable using CLIPPING.\n"
254 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
256 " :type fontid: int\n"
257 " :arg xmin: Clip the drawing area by these bounds.\n"
258 " :type xmin: float\n"
259 " :arg ymin: Clip the drawing area by these bounds.\n"
260 " :type ymin: float\n"
261 " :arg xmax: Clip the drawing area by these bounds.\n"
262 " :type xmax: float\n"
263 " :arg ymax: Clip the drawing area by these bounds.\n"
264 " :type ymax: float\n");
267 float xmin, ymin, xmax, ymax;
270 if (!PyArg_ParseTuple(args,
"iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) {
281 py_blf_word_wrap_doc,
282 ".. function:: word_wrap(fontid, wrap_width)\n"
284 " Set the wrap width, enable/disable using WORD_WRAP.\n"
286 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
288 " :type fontid: int\n"
289 " :arg wrap_width: The width (in pixels) to wrap words at.\n"
290 " :type wrap_width: int\n");
296 if (!PyArg_ParseTuple(args,
"ii:blf.word_wrap", &fontid, &wrap_width)) {
308 ".. function:: disable(fontid, option)\n"
312 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
314 " :type fontid: int\n"
315 " :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
316 " :type option: int\n");
321 if (!PyArg_ParseTuple(args,
"ii:blf.disable", &fontid, &option)) {
333 ".. function:: enable(fontid, option)\n"
337 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
339 " :type fontid: int\n"
340 " :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
341 " :type option: int\n");
346 if (!PyArg_ParseTuple(args,
"ii:blf.enable", &fontid, &option)) {
358 ".. function:: rotation(fontid, angle)\n"
360 " Set the text rotation angle, enable/disable using ROTATION.\n"
362 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
364 " :type fontid: int\n"
365 " :arg angle: The angle for text drawing to use.\n"
366 " :type angle: float\n");
372 if (!PyArg_ParseTuple(args,
"if:blf.rotation", &fontid, &
angle)) {
384 ".. function:: shadow(fontid, level, r, g, b, a)\n"
386 " Shadow options, enable/disable using SHADOW .\n"
388 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
390 " :type fontid: int\n"
391 " :arg level: The blur level (0, 3, 5) or outline (6).\n"
392 " :type level: int\n"
393 " :arg r: Shadow color (red channel 0.0 - 1.0).\n"
395 " :arg g: Shadow color (green channel 0.0 - 1.0).\n"
397 " :arg b: Shadow color (blue channel 0.0 - 1.0).\n"
399 " :arg a: Shadow color (alpha channel 0.0 - 1.0).\n"
400 " :type a: float\n");
406 if (!PyArg_ParseTuple(
407 args,
"iiffff:blf.shadow", &fontid, &level, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
412 if (!
ELEM(level, 0, 3, 5, 6)) {
413 PyErr_SetString(PyExc_TypeError,
"blf.shadow expected arg to be in (0, 3, 5, 6)");
424 py_blf_shadow_offset_doc,
425 ".. function:: shadow_offset(fontid, x, y)\n"
427 " Set the offset for shadow text.\n"
429 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
431 " :type fontid: int\n"
432 " :arg x: Vertical shadow offset value in pixels.\n"
434 " :arg y: Horizontal shadow offset value in pixels.\n"
435 " :type y: float\n");
440 if (!PyArg_ParseTuple(args,
"iii:blf.shadow_offset", &fontid, &
x, &
y)) {
452 ".. function:: load(filepath)\n"
454 " Load a new font.\n"
456 " :arg filepath: the filepath of the font.\n"
457 " :type filepath: str | bytes\n"
458 " :return: the new font's fontid or -1 if there was an error.\n"
463 if (!PyArg_ParseTuple(args,
474 return PyLong_FromLong(font_id);
480 ".. function:: unload(filepath)\n"
482 " Unload an existing font.\n"
484 " :arg filepath: the filepath of the font.\n"
485 " :type filepath: str | bytes\n");
489 if (!PyArg_ParseTuple(args,
513 PyErr_SetString(PyExc_ValueError,
514 "BLFImBufContext.__enter__: unable to enter the same context more than once");
519 if (ibuf ==
nullptr) {
524 if (buffer_state ==
nullptr) {
525 PyErr_Format(PyExc_ValueError,
"bind_imbuf: unknown fontid %d",
self->fontid);
534 self->buffer_state = buffer_state;
542 self->buffer_state =
nullptr;
549 if (
self->buffer_state) {
557 PyObject_GC_UnTrack(
self);
558 Py_CLEAR(
self->py_imbuf);
559 PyObject_GC_Del(
self);
564 Py_VISIT(
self->py_imbuf);
570 Py_CLEAR(
self->py_imbuf);
576# pragma clang diagnostic push
577# pragma clang diagnostic ignored "-Wcast-function-type"
579# pragma GCC diagnostic push
580# pragma GCC diagnostic ignored "-Wcast-function-type"
592# pragma clang diagnostic pop
594# pragma GCC diagnostic pop
599 PyVarObject_HEAD_INIT(
nullptr, 0)
618 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
654 py_blf_bind_imbuf_doc,
655 ".. method:: bind_imbuf(fontid, image)\n"
657 " Context manager to draw text into an image buffer instead of the GPU's context.\n"
659 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
661 " :type fontid: int\n"
662 " :arg imbuf: The image to draw into.\n"
663 " :type imbuf: :class:`imbuf.types.ImBuf`\n"
665 " :return: The BLF ImBuf context manager.\n"
666 " :rtype: BLFImBufContext\n");
670 PyObject *py_imbuf =
nullptr;
671 const char *display_name =
nullptr;
673 static const char *_keywords[] = {
680 static _PyArg_Parser _parser = {
690 if (!_PyArg_ParseTupleAndKeywordsFast(
691 args, kwds, &_parser, &fontid, &
Py_ImBuf_Type, &py_imbuf, &display_name))
701 ret->py_imbuf = Py_NewRef(py_imbuf);
703 ret->fontid = fontid;
704 ret->buffer_state =
nullptr;
706 PyObject_GC_Track(
ret);
708 return (PyObject *)
ret;
715# pragma clang diagnostic push
716# pragma clang diagnostic ignored "-Wcast-function-type"
718# pragma GCC diagnostic push
719# pragma GCC diagnostic ignored "-Wcast-function-type"
725 {
"aspect", (PyCFunction)
py_blf_aspect, METH_VARARGS, py_blf_aspect_doc},
726 {
"clipping", (PyCFunction)
py_blf_clipping, METH_VARARGS, py_blf_clipping_doc},
727 {
"word_wrap", (PyCFunction)
py_blf_word_wrap, METH_VARARGS, py_blf_word_wrap_doc},
728 {
"disable", (PyCFunction)
py_blf_disable, METH_VARARGS, py_blf_disable_doc},
729 {
"dimensions", (PyCFunction)
py_blf_dimensions, METH_VARARGS, py_blf_dimensions_doc},
730 {
"draw", (PyCFunction)
py_blf_draw, METH_VARARGS, py_blf_draw_doc},
731 {
"draw_buffer", (PyCFunction)
py_blf_draw_buffer, METH_VARARGS, py_blf_draw_buffer_doc},
732 {
"enable", (PyCFunction)
py_blf_enable, METH_VARARGS, py_blf_enable_doc},
733 {
"position", (PyCFunction)
py_blf_position, METH_VARARGS, py_blf_position_doc},
734 {
"rotation", (PyCFunction)
py_blf_rotation, METH_VARARGS, py_blf_rotation_doc},
735 {
"shadow", (PyCFunction)
py_blf_shadow, METH_VARARGS, py_blf_shadow_doc},
737 {
"size", (PyCFunction)
py_blf_size, METH_VARARGS, py_blf_size_doc},
738 {
"color", (PyCFunction)
py_blf_color, METH_VARARGS, py_blf_color_doc},
739 {
"load", (PyCFunction)
py_blf_load, METH_VARARGS, py_blf_load_doc},
740 {
"unload", (PyCFunction)
py_blf_unload, METH_VARARGS, py_blf_unload_doc},
744 METH_VARARGS | METH_KEYWORDS,
745 py_blf_bind_imbuf_doc},
747 {
nullptr,
nullptr, 0,
nullptr},
752# pragma clang diagnostic pop
754# pragma GCC diagnostic pop
761 "This module provides access to Blender's text drawing functions.");
780 PyModule_AddIntConstant(submodule,
"ROTATION",
BLF_ROTATION);
781 PyModule_AddIntConstant(submodule,
"CLIPPING",
BLF_CLIPPING);
782 PyModule_AddIntConstant(submodule,
"SHADOW",
BLF_SHADOW);
783 PyModule_AddIntConstant(submodule,
"WORD_WRAP",
BLF_WORD_WRAP);
void BLF_size(int fontid, float size)
void BLF_buffer_state_free(BLFBufferState *buffer_state)
void BLF_enable(int fontid, FontFlags flag)
void BLF_buffer_state_pop(BLFBufferState *buffer_state)
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
void BLF_aspect(int fontid, float x, float y, float z)
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, const ColorSpace *colorspace)
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
void BLF_color4fv(int fontid, const float rgba[4])
void BLF_shadow_offset(int fontid, int x, int y)
BLFBufferState * BLF_buffer_state_push(int fontid)
void BLF_rotation(int fontid, float angle)
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode=BLFWrapMode::Minimal)
int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLF_buffer_col(int fontid, const float srgb_color[4]) ATTR_NONNULL(2)
void BLF_disable(int fontid, FontFlags flag)
int void BLF_unload(const char *filepath) ATTR_NONNULL(1)
void BLF_position(int fontid, float x, float y, float z)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
static PyObject * py_blf_word_wrap(PyObject *, PyObject *args)
static int py_blf_bind_imbuf_clear(BPyBLFImBufContext *self)
static int py_blf_bind_imbuf_traverse(BPyBLFImBufContext *self, visitproc visit, void *arg)
static PyObject * py_blf_enable(PyObject *, PyObject *args)
static PyObject * py_blf_aspect(PyObject *, PyObject *args)
static PyModuleDef BLF_module_def
static PyObject * py_blf_color(PyObject *, PyObject *args)
static PyObject * py_blf_shadow_offset(PyObject *, PyObject *args)
static PyMethodDef BLF_methods[]
static PyObject * py_blf_unload(PyObject *, PyObject *args)
static void py_blf_bind_imbuf_dealloc(BPyBLFImBufContext *self)
static PyObject * py_blf_bind_imbuf_exit(BPyBLFImBufContext *self, PyObject *)
static PyTypeObject BPyBLFImBufContext_Type
static PyObject * py_blf_load(PyObject *, PyObject *args)
static PyObject * py_blf_shadow(PyObject *, PyObject *args)
static PyObject * py_blf_dimensions(PyObject *, PyObject *args)
static PyObject * py_blf_clipping(PyObject *, PyObject *args)
static PyObject * py_blf_bind_imbuf_enter(BPyBLFImBufContext *self)
static PyObject * py_blf_rotation(PyObject *, PyObject *args)
static PyObject * py_blf_draw_buffer(PyObject *, PyObject *args)
static PyObject * py_blf_bind_imbuf(PyObject *, PyObject *args, PyObject *kwds)
static PyObject * py_blf_disable(PyObject *, PyObject *args)
static PyObject * py_blf_draw(PyObject *, PyObject *args)
static PyObject * py_blf_size(PyObject *, PyObject *args)
PyDoc_STRVAR(py_blf_position_doc, ".. function:: position(fontid, x, y, z)\n" "\n" " Set the position for drawing text.\n" "\n" " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " "font use 0.\n" " :type fontid: int\n" " :arg x: X axis position to draw the text.\n" " :type x: float\n" " :arg y: Y axis position to draw the text.\n" " :type y: float\n" " :arg z: Z axis position to draw the text.\n" " :type z: float\n")
static PyObject * py_blf_position(PyObject *, PyObject *args)
static PyMethodDef py_blf_bind_imbuf_methods[]
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
PyTypeObject Py_ImBuf_Type
ImBuf * BPy_ImBuf_FromPyObject(PyObject *py_imbuf)
int PyC_ParseUnicodeAsBytesAndSize(PyObject *o, void *p)
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()
#define PyTuple_SET_ITEMS(op_arg,...)
BLFBufferState * buffer_state
PyObject_HEAD PyObject * py_imbuf
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer