12#define PY_SSIZE_T_CLEAN
46 ".. function:: position(fontid, x, y, z)\n"
48 " Set the position for drawing text.\n"
50 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
52 " :type fontid: int\n"
53 " :arg x: X axis position to draw the text.\n"
55 " :arg y: Y axis position to draw the text.\n"
57 " :arg z: Z axis position to draw the text.\n"
65 if (!PyArg_ParseTuple(args,
"ifff:blf.position", &fontid, &
x, &
y, &
z)) {
77 ".. function:: size(fontid, size)\n"
79 " Set the size for drawing text.\n"
81 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
83 " :type fontid: int\n"
84 " :arg size: Point size of the font.\n"
85 " :type size: float\n");
91 if (!PyArg_ParseTuple(args,
"if:blf.size", &fontid, &
size)) {
103 ".. function:: aspect(fontid, aspect)\n"
105 " Set the aspect for drawing text.\n"
107 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
109 " :type fontid: int\n"
110 " :arg aspect: The aspect ratio for text drawing to use.\n"
111 " :type aspect: float\n");
117 if (!PyArg_ParseTuple(args,
"if:blf.aspect", &fontid, &aspect)) {
129 ".. function:: color(fontid, r, g, b, a)\n"
131 " Set the color for drawing text.\n"
133 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
135 " :type fontid: int\n"
136 " :arg r: red channel 0.0 - 1.0.\n"
138 " :arg g: green channel 0.0 - 1.0.\n"
140 " :arg b: blue channel 0.0 - 1.0.\n"
142 " :arg a: alpha channel 0.0 - 1.0.\n"
143 " :type a: float\n");
149 if (!PyArg_ParseTuple(args,
"iffff:blf.color", &fontid, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
166 ".. function:: draw(fontid, text)\n"
168 " Draw text in the current context.\n"
170 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
172 " :type fontid: int\n"
173 " :arg text: the text to draw.\n"
174 " :type text: str\n");
178 Py_ssize_t text_length;
181 if (!PyArg_ParseTuple(args,
"is#:blf.draw", &fontid, &text, &text_length)) {
192 py_blf_draw_buffer_doc,
193 ".. function:: draw_buffer(fontid, text)\n"
195 " Draw text into the buffer bound to the fontid.\n"
197 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
199 " :type fontid: int\n"
200 " :arg text: the text to draw.\n"
201 " :type text: str\n");
205 Py_ssize_t text_length;
208 if (!PyArg_ParseTuple(args,
"is#:blf.draw_buffer", &fontid, &text, &text_length)) {
219 py_blf_dimensions_doc,
220 ".. function:: dimensions(fontid, text)\n"
222 " Return the width and height of the text.\n"
224 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
226 " :type fontid: int\n"
227 " :arg text: the text to draw.\n"
229 " :return: the width and height of the text.\n"
230 " :rtype: tuple[float, float]\n");
234 float r_width, r_height;
238 if (!PyArg_ParseTuple(args,
"is:blf.dimensions", &fontid, &text)) {
244 ret = PyTuple_New(2);
252 ".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n"
254 " Set the clipping, enable/disable using CLIPPING.\n"
256 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
258 " :type fontid: int\n"
259 " :arg xmin: Clip the drawing area by these bounds.\n"
260 " :type xmin: float\n"
261 " :arg ymin: Clip the drawing area by these bounds.\n"
262 " :type ymin: float\n"
263 " :arg xmax: Clip the drawing area by these bounds.\n"
264 " :type xmax: float\n"
265 " :arg ymax: Clip the drawing area by these bounds.\n"
266 " :type ymax: float\n");
269 float xmin, ymin, xmax, ymax;
272 if (!PyArg_ParseTuple(args,
"iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) {
283 py_blf_word_wrap_doc,
284 ".. function:: word_wrap(fontid, wrap_width)\n"
286 " Set the wrap width, enable/disable using WORD_WRAP.\n"
288 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
290 " :type fontid: int\n"
291 " :arg wrap_width: The width (in pixels) to wrap words at.\n"
292 " :type wrap_width: int\n");
298 if (!PyArg_ParseTuple(args,
"ii:blf.word_wrap", &fontid, &wrap_width)) {
310 ".. function:: disable(fontid, option)\n"
314 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
316 " :type fontid: int\n"
317 " :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
318 " :type option: int\n");
323 if (!PyArg_ParseTuple(args,
"ii:blf.disable", &fontid, &option)) {
335 ".. function:: enable(fontid, option)\n"
339 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
341 " :type fontid: int\n"
342 " :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
343 " :type option: int\n");
348 if (!PyArg_ParseTuple(args,
"ii:blf.enable", &fontid, &option)) {
360 ".. function:: rotation(fontid, angle)\n"
362 " Set the text rotation angle, enable/disable using ROTATION.\n"
364 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
366 " :type fontid: int\n"
367 " :arg angle: The angle for text drawing to use.\n"
368 " :type angle: float\n");
374 if (!PyArg_ParseTuple(args,
"if:blf.rotation", &fontid, &
angle)) {
386 ".. function:: shadow(fontid, level, r, g, b, a)\n"
388 " Shadow options, enable/disable using SHADOW .\n"
390 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
392 " :type fontid: int\n"
393 " :arg level: The blur level (0, 3, 5) or outline (6).\n"
394 " :type level: int\n"
395 " :arg r: Shadow color (red channel 0.0 - 1.0).\n"
397 " :arg g: Shadow color (green channel 0.0 - 1.0).\n"
399 " :arg b: Shadow color (blue channel 0.0 - 1.0).\n"
401 " :arg a: Shadow color (alpha channel 0.0 - 1.0).\n"
402 " :type a: float\n");
408 if (!PyArg_ParseTuple(
409 args,
"iiffff:blf.shadow", &fontid, &level, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
414 if (!
ELEM(level, 0, 3, 5, 6)) {
415 PyErr_SetString(PyExc_TypeError,
"blf.shadow expected arg to be in (0, 3, 5, 6)");
426 py_blf_shadow_offset_doc,
427 ".. function:: shadow_offset(fontid, x, y)\n"
429 " Set the offset for shadow text.\n"
431 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
433 " :type fontid: int\n"
434 " :arg x: Vertical shadow offset value in pixels.\n"
436 " :arg y: Horizontal shadow offset value in pixels.\n"
437 " :type y: float\n");
442 if (!PyArg_ParseTuple(args,
"iii:blf.shadow_offset", &fontid, &
x, &
y)) {
454 ".. function:: load(filepath)\n"
456 " Load a new font.\n"
458 " :arg filepath: the filepath of the font.\n"
459 " :type filepath: str | bytes\n"
460 " :return: the new font's fontid or -1 if there was an error.\n"
465 if (!PyArg_ParseTuple(args,
476 return PyLong_FromLong(font_id);
482 ".. function:: unload(filepath)\n"
484 " Unload an existing font.\n"
486 " :arg filepath: the filepath of the font.\n"
487 " :type filepath: str | bytes\n");
491 if (!PyArg_ParseTuple(args,
515 PyErr_SetString(PyExc_ValueError,
516 "BLFImBufContext.__enter__: unable to enter the same context more than once");
521 if (ibuf ==
nullptr) {
526 if (buffer_state ==
nullptr) {
527 PyErr_Format(PyExc_ValueError,
"bind_imbuf: unknown fontid %d",
self->fontid);
536 self->buffer_state = buffer_state;
544 self->buffer_state =
nullptr;
551 if (
self->buffer_state) {
559 PyObject_GC_UnTrack(
self);
560 Py_CLEAR(
self->py_imbuf);
561 PyObject_GC_Del(
self);
566 Py_VISIT(
self->py_imbuf);
572 Py_CLEAR(
self->py_imbuf);
578# pragma clang diagnostic push
579# pragma clang diagnostic ignored "-Wcast-function-type"
581# pragma GCC diagnostic push
582# pragma GCC diagnostic ignored "-Wcast-function-type"
594# pragma clang diagnostic pop
596# pragma GCC diagnostic pop
601 PyVarObject_HEAD_INIT(
nullptr, 0)
620 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
656 py_blf_bind_imbuf_doc,
657 ".. method:: bind_imbuf(fontid, image, display_name=None)\n"
659 " Context manager to draw text into an image buffer instead of the GPU's context.\n"
661 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
663 " :type fontid: int\n"
664 " :arg imbuf: The image to draw into.\n"
665 " :type imbuf: :class:`imbuf.types.ImBuf`\n"
666 " :arg display_name: The color management display name to use or None.\n"
667 " :type display_name: str | None\n"
669 " :return: The BLF ImBuf context manager.\n"
670 " :rtype: BLFImBufContext\n");
674 PyObject *py_imbuf =
nullptr;
675 const char *display_name =
nullptr;
677 static const char *_keywords[] = {
684 static _PyArg_Parser _parser = {
694 if (!_PyArg_ParseTupleAndKeywordsFast(
695 args, kwds, &_parser, &fontid, &
Py_ImBuf_Type, &py_imbuf, &display_name))
704 std::string display_names_all;
705 display_names_all.reserve(1024);
706 const char *ex =
nullptr;
710 display_names_all +=
", ";
712 display_names_all += ex;
714 PyErr_Format(PyExc_ValueError,
715 "bind_imbuf: color management \"%s\" not found in [%s]",
717 display_names_all.c_str());
724 ret->py_imbuf = Py_NewRef(py_imbuf);
725 ret->display = display;
727 ret->fontid = fontid;
728 ret->buffer_state =
nullptr;
730 PyObject_GC_Track(
ret);
732 return (PyObject *)
ret;
739# pragma clang diagnostic push
740# pragma clang diagnostic ignored "-Wcast-function-type"
742# pragma GCC diagnostic push
743# pragma GCC diagnostic ignored "-Wcast-function-type"
749 {
"aspect", (PyCFunction)
py_blf_aspect, METH_VARARGS, py_blf_aspect_doc},
750 {
"clipping", (PyCFunction)
py_blf_clipping, METH_VARARGS, py_blf_clipping_doc},
751 {
"word_wrap", (PyCFunction)
py_blf_word_wrap, METH_VARARGS, py_blf_word_wrap_doc},
752 {
"disable", (PyCFunction)
py_blf_disable, METH_VARARGS, py_blf_disable_doc},
753 {
"dimensions", (PyCFunction)
py_blf_dimensions, METH_VARARGS, py_blf_dimensions_doc},
754 {
"draw", (PyCFunction)
py_blf_draw, METH_VARARGS, py_blf_draw_doc},
755 {
"draw_buffer", (PyCFunction)
py_blf_draw_buffer, METH_VARARGS, py_blf_draw_buffer_doc},
756 {
"enable", (PyCFunction)
py_blf_enable, METH_VARARGS, py_blf_enable_doc},
757 {
"position", (PyCFunction)
py_blf_position, METH_VARARGS, py_blf_position_doc},
758 {
"rotation", (PyCFunction)
py_blf_rotation, METH_VARARGS, py_blf_rotation_doc},
759 {
"shadow", (PyCFunction)
py_blf_shadow, METH_VARARGS, py_blf_shadow_doc},
761 {
"size", (PyCFunction)
py_blf_size, METH_VARARGS, py_blf_size_doc},
762 {
"color", (PyCFunction)
py_blf_color, METH_VARARGS, py_blf_color_doc},
763 {
"load", (PyCFunction)
py_blf_load, METH_VARARGS, py_blf_load_doc},
764 {
"unload", (PyCFunction)
py_blf_unload, METH_VARARGS, py_blf_unload_doc},
768 METH_VARARGS | METH_KEYWORDS,
769 py_blf_bind_imbuf_doc},
771 {
nullptr,
nullptr, 0,
nullptr},
776# pragma clang diagnostic pop
778# pragma GCC diagnostic pop
785 "This module provides access to Blender's text drawing functions.");
804 PyModule_AddIntConstant(submodule,
"ROTATION",
BLF_ROTATION);
805 PyModule_AddIntConstant(submodule,
"CLIPPING",
BLF_CLIPPING);
806 PyModule_AddIntConstant(submodule,
"SHADOW",
BLF_SHADOW);
807 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_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_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)
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, const ColorManagedDisplay *display)
BLFBufferState * BLF_buffer_state_push(int fontid)
void BLF_disable(int fontid, int option)
void BLF_rotation(int fontid, float angle)
void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2)
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)
blender::ocio::Display ColorManagedDisplay
void BLF_enable(int fontid, int option)
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)
const char * IMB_colormanagement_display_get_indexed_name(int index)
const ColorManagedDisplay * IMB_colormanagement_display_get_named(const char *name)
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 ColorManagedDisplay * display
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer