Blender V4.5
blf_py_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11/* Future-proof, See https://docs.python.org/3/c-api/arg.html#strings-and-buffers */
12#define PY_SSIZE_T_CLEAN
13
14#include "blf_py_api.hh"
15
16#include "py_capi_utils.hh"
17
18#include <Python.h>
19
21
22#include "BLI_utildefines.h"
23
27
28#include "python_compat.hh" /* IWYU pragma: keep. */
29
30#include "python_utildefines.hh"
31
32#include "imbuf_py_api.hh"
33
35 PyObject_HEAD /* Required Python macro. */
36 PyObject *py_imbuf;
38
39 int fontid;
41};
42
44 /* Wrap. */
45 py_blf_position_doc,
46 ".. function:: position(fontid, x, y, z)\n"
47 "\n"
48 " Set the position for drawing text.\n"
49 "\n"
50 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
51 "font use 0.\n"
52 " :type fontid: int\n"
53 " :arg x: X axis position to draw the text.\n"
54 " :type x: float\n"
55 " :arg y: Y axis position to draw the text.\n"
56 " :type y: float\n"
57 " :arg z: Z axis position to draw the text.\n"
58 " :type z: float\n");
59
60static PyObject *py_blf_position(PyObject * /*self*/, PyObject *args)
61{
62 int fontid;
63 float x, y, z;
64
65 if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z)) {
66 return nullptr;
67 }
68
69 BLF_position(fontid, x, y, z);
70
71 Py_RETURN_NONE;
72}
73
75 /* Wrap. */
76 py_blf_size_doc,
77 ".. function:: size(fontid, size)\n"
78 "\n"
79 " Set the size for drawing text.\n"
80 "\n"
81 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
82 "font use 0.\n"
83 " :type fontid: int\n"
84 " :arg size: Point size of the font.\n"
85 " :type size: float\n");
86static PyObject *py_blf_size(PyObject * /*self*/, PyObject *args)
87{
88 int fontid;
89 float size;
90
91 if (!PyArg_ParseTuple(args, "if:blf.size", &fontid, &size)) {
92 return nullptr;
93 }
94
95 BLF_size(fontid, size);
96
97 Py_RETURN_NONE;
98}
99
101 /* Wrap. */
102 py_blf_aspect_doc,
103 ".. function:: aspect(fontid, aspect)\n"
104 "\n"
105 " Set the aspect for drawing text.\n"
106 "\n"
107 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
108 "font use 0.\n"
109 " :type fontid: int\n"
110 " :arg aspect: The aspect ratio for text drawing to use.\n"
111 " :type aspect: float\n");
112static PyObject *py_blf_aspect(PyObject * /*self*/, PyObject *args)
113{
114 float aspect;
115 int fontid;
116
117 if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect)) {
118 return nullptr;
119 }
120
121 BLF_aspect(fontid, aspect, aspect, 1.0);
122
123 Py_RETURN_NONE;
124}
125
127 /* Wrap. */
128 py_blf_color_doc,
129 ".. function:: color(fontid, r, g, b, a)\n"
130 "\n"
131 " Set the color for drawing text.\n"
132 "\n"
133 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
134 "font use 0.\n"
135 " :type fontid: int\n"
136 " :arg r: red channel 0.0 - 1.0.\n"
137 " :type r: float\n"
138 " :arg g: green channel 0.0 - 1.0.\n"
139 " :type g: float\n"
140 " :arg b: blue channel 0.0 - 1.0.\n"
141 " :type b: float\n"
142 " :arg a: alpha channel 0.0 - 1.0.\n"
143 " :type a: float\n");
144static PyObject *py_blf_color(PyObject * /*self*/, PyObject *args)
145{
146 int fontid;
147 float rgba[4];
148
149 if (!PyArg_ParseTuple(args, "iffff:blf.color", &fontid, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
150 {
151 return nullptr;
152 }
153
154 BLF_color4fv(fontid, rgba);
155
156 /* NOTE(@ideasman42): that storing these colors separately looks like something that could
157 * be refactored away if the font's internal color format was changed from `uint8` to `float`. */
158 BLF_buffer_col(fontid, rgba);
159
160 Py_RETURN_NONE;
161}
162
164 /* Wrap. */
165 py_blf_draw_doc,
166 ".. function:: draw(fontid, text)\n"
167 "\n"
168 " Draw text in the current context.\n"
169 "\n"
170 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
171 "font use 0.\n"
172 " :type fontid: int\n"
173 " :arg text: the text to draw.\n"
174 " :type text: str\n");
175static PyObject *py_blf_draw(PyObject * /*self*/, PyObject *args)
176{
177 const char *text;
178 Py_ssize_t text_length;
179 int fontid;
180
181 if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length)) {
182 return nullptr;
183 }
184
185 BLF_draw(fontid, text, uint(text_length));
186
187 Py_RETURN_NONE;
188}
189
191 /* Wrap. */
192 py_blf_draw_buffer_doc,
193 ".. function:: draw_buffer(fontid, text)\n"
194 "\n"
195 " Draw text into the buffer bound to the fontid.\n"
196 "\n"
197 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
198 "font use 0.\n"
199 " :type fontid: int\n"
200 " :arg text: the text to draw.\n"
201 " :type text: str\n");
202static PyObject *py_blf_draw_buffer(PyObject * /*self*/, PyObject *args)
203{
204 const char *text;
205 Py_ssize_t text_length;
206 int fontid;
207
208 if (!PyArg_ParseTuple(args, "is#:blf.draw_buffer", &fontid, &text, &text_length)) {
209 return nullptr;
210 }
211
212 BLF_draw_buffer(fontid, text, uint(text_length));
213
214 Py_RETURN_NONE;
215}
216
218 /* Wrap. */
219 py_blf_dimensions_doc,
220 ".. function:: dimensions(fontid, text)\n"
221 "\n"
222 " Return the width and height of the text.\n"
223 "\n"
224 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
225 "font use 0.\n"
226 " :type fontid: int\n"
227 " :arg text: the text to draw.\n"
228 " :type text: str\n"
229 " :return: the width and height of the text.\n"
230 " :rtype: tuple[float, float]\n");
231static PyObject *py_blf_dimensions(PyObject * /*self*/, PyObject *args)
232{
233 const char *text;
234 float r_width, r_height;
235 PyObject *ret;
236 int fontid;
237
238 if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) {
239 return nullptr;
240 }
241
242 BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height);
243
244 ret = PyTuple_New(2);
245 PyTuple_SET_ITEMS(ret, PyFloat_FromDouble(r_width), PyFloat_FromDouble(r_height));
246 return ret;
247}
248
250 /* Wrap. */
251 py_blf_clipping_doc,
252 ".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n"
253 "\n"
254 " Set the clipping, enable/disable using CLIPPING.\n"
255 "\n"
256 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
257 "font use 0.\n"
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");
267static PyObject *py_blf_clipping(PyObject * /*self*/, PyObject *args)
268{
269 float xmin, ymin, xmax, ymax;
270 int fontid;
271
272 if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) {
273 return nullptr;
274 }
275
276 BLF_clipping(fontid, xmin, ymin, xmax, ymax);
277
278 Py_RETURN_NONE;
279}
280
282 /* Wrap. */
283 py_blf_word_wrap_doc,
284 ".. function:: word_wrap(fontid, wrap_width)\n"
285 "\n"
286 " Set the wrap width, enable/disable using WORD_WRAP.\n"
287 "\n"
288 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
289 "font use 0.\n"
290 " :type fontid: int\n"
291 " :arg wrap_width: The width (in pixels) to wrap words at.\n"
292 " :type wrap_width: int\n");
293static PyObject *py_blf_word_wrap(PyObject * /*self*/, PyObject *args)
294{
295 int wrap_width;
296 int fontid;
297
298 if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width)) {
299 return nullptr;
300 }
301
302 BLF_wordwrap(fontid, wrap_width);
303
304 Py_RETURN_NONE;
305}
306
308 /* Wrap. */
309 py_blf_disable_doc,
310 ".. function:: disable(fontid, option)\n"
311 "\n"
312 " Disable option.\n"
313 "\n"
314 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
315 "font use 0.\n"
316 " :type fontid: int\n"
317 " :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
318 " :type option: int\n");
319static PyObject *py_blf_disable(PyObject * /*self*/, PyObject *args)
320{
321 int option, fontid;
322
323 if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option)) {
324 return nullptr;
325 }
326
327 BLF_disable(fontid, option);
328
329 Py_RETURN_NONE;
330}
331
333 /* Wrap. */
334 py_blf_enable_doc,
335 ".. function:: enable(fontid, option)\n"
336 "\n"
337 " Enable option.\n"
338 "\n"
339 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
340 "font use 0.\n"
341 " :type fontid: int\n"
342 " :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
343 " :type option: int\n");
344static PyObject *py_blf_enable(PyObject * /*self*/, PyObject *args)
345{
346 int option, fontid;
347
348 if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) {
349 return nullptr;
350 }
351
352 BLF_enable(fontid, option);
353
354 Py_RETURN_NONE;
355}
356
358 /* Wrap. */
359 py_blf_rotation_doc,
360 ".. function:: rotation(fontid, angle)\n"
361 "\n"
362 " Set the text rotation angle, enable/disable using ROTATION.\n"
363 "\n"
364 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
365 "font use 0.\n"
366 " :type fontid: int\n"
367 " :arg angle: The angle for text drawing to use.\n"
368 " :type angle: float\n");
369static PyObject *py_blf_rotation(PyObject * /*self*/, PyObject *args)
370{
371 float angle;
372 int fontid;
373
374 if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle)) {
375 return nullptr;
376 }
377
378 BLF_rotation(fontid, angle);
379
380 Py_RETURN_NONE;
381}
382
384 /* Wrap. */
385 py_blf_shadow_doc,
386 ".. function:: shadow(fontid, level, r, g, b, a)\n"
387 "\n"
388 " Shadow options, enable/disable using SHADOW .\n"
389 "\n"
390 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
391 "font use 0.\n"
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"
396 " :type r: float\n"
397 " :arg g: Shadow color (green channel 0.0 - 1.0).\n"
398 " :type g: float\n"
399 " :arg b: Shadow color (blue channel 0.0 - 1.0).\n"
400 " :type b: float\n"
401 " :arg a: Shadow color (alpha channel 0.0 - 1.0).\n"
402 " :type a: float\n");
403static PyObject *py_blf_shadow(PyObject * /*self*/, PyObject *args)
404{
405 int level, fontid;
406 float rgba[4];
407
408 if (!PyArg_ParseTuple(
409 args, "iiffff:blf.shadow", &fontid, &level, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
410 {
411 return nullptr;
412 }
413
414 if (!ELEM(level, 0, 3, 5, 6)) {
415 PyErr_SetString(PyExc_TypeError, "blf.shadow expected arg to be in (0, 3, 5, 6)");
416 return nullptr;
417 }
418
419 BLF_shadow(fontid, FontShadowType(level), rgba);
420
421 Py_RETURN_NONE;
422}
423
425 /* Wrap. */
426 py_blf_shadow_offset_doc,
427 ".. function:: shadow_offset(fontid, x, y)\n"
428 "\n"
429 " Set the offset for shadow text.\n"
430 "\n"
431 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
432 "font use 0.\n"
433 " :type fontid: int\n"
434 " :arg x: Vertical shadow offset value in pixels.\n"
435 " :type x: float\n"
436 " :arg y: Horizontal shadow offset value in pixels.\n"
437 " :type y: float\n");
438static PyObject *py_blf_shadow_offset(PyObject * /*self*/, PyObject *args)
439{
440 int x, y, fontid;
441
442 if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y)) {
443 return nullptr;
444 }
445
446 BLF_shadow_offset(fontid, x, y);
447
448 Py_RETURN_NONE;
449}
450
452 /* Wrap. */
453 py_blf_load_doc,
454 ".. function:: load(filepath)\n"
455 "\n"
456 " Load a new font.\n"
457 "\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"
461 " :rtype: int\n");
462static PyObject *py_blf_load(PyObject * /*self*/, PyObject *args)
463{
464 PyC_UnicodeAsBytesAndSize_Data filepath_data = {nullptr};
465 if (!PyArg_ParseTuple(args,
466 "O&" /* `filepath` */
467 ":blf.load",
469 &filepath_data))
470 {
471 return nullptr;
472 }
473 const int font_id = BLF_load(filepath_data.value);
474 Py_XDECREF(filepath_data.value_coerce);
475
476 return PyLong_FromLong(font_id);
477}
478
480 /* Wrap. */
481 py_blf_unload_doc,
482 ".. function:: unload(filepath)\n"
483 "\n"
484 " Unload an existing font.\n"
485 "\n"
486 " :arg filepath: the filepath of the font.\n"
487 " :type filepath: str | bytes\n");
488static PyObject *py_blf_unload(PyObject * /*self*/, PyObject *args)
489{
490 PyC_UnicodeAsBytesAndSize_Data filepath_data = {nullptr};
491 if (!PyArg_ParseTuple(args,
492 "O&" /* `filepath` */
493 ":blf.unload",
495 &filepath_data))
496 {
497 return nullptr;
498 }
499
500 BLF_unload(filepath_data.value);
501 Py_XDECREF(filepath_data.value_coerce);
502
503 Py_RETURN_NONE;
504}
505
506/* -------------------------------------------------------------------- */
511
513{
514 if (UNLIKELY(self->buffer_state)) {
515 PyErr_SetString(PyExc_ValueError,
516 "BLFImBufContext.__enter__: unable to enter the same context more than once");
517 return nullptr;
518 }
519
520 ImBuf *ibuf = BPy_ImBuf_FromPyObject(self->py_imbuf);
521 if (ibuf == nullptr) {
522 /* The error will have been set. */
523 return nullptr;
524 }
525 BLFBufferState *buffer_state = BLF_buffer_state_push(self->fontid);
526 if (buffer_state == nullptr) {
527 PyErr_Format(PyExc_ValueError, "bind_imbuf: unknown fontid %d", self->fontid);
528 return nullptr;
529 }
530 BLF_buffer(self->fontid,
531 ibuf->float_buffer.data,
532 ibuf->byte_buffer.data,
533 ibuf->x,
534 ibuf->y,
535 self->display);
536 self->buffer_state = buffer_state;
537
538 Py_RETURN_NONE;
539}
540
541static PyObject *py_blf_bind_imbuf_exit(BPyBLFImBufContext *self, PyObject * /*args*/)
542{
543 BLF_buffer_state_pop(self->buffer_state);
544 self->buffer_state = nullptr;
545
546 Py_RETURN_NONE;
547}
548
550{
551 if (self->buffer_state) {
552 /* This should practically never happen since it implies
553 * `__enter__` is called without a matching `__exit__`.
554 * Do this mainly for correctness:
555 * if the process somehow exits before exiting the context manager. */
556 BLF_buffer_state_free(self->buffer_state);
557 }
558
559 PyObject_GC_UnTrack(self);
560 Py_CLEAR(self->py_imbuf);
561 PyObject_GC_Del(self);
562}
563
564static int py_blf_bind_imbuf_traverse(BPyBLFImBufContext *self, visitproc visit, void *arg)
565{
566 Py_VISIT(self->py_imbuf);
567 return 0;
568}
569
571{
572 Py_CLEAR(self->py_imbuf);
573 return 0;
574}
575
576#ifdef __GNUC__
577# ifdef __clang__
578# pragma clang diagnostic push
579# pragma clang diagnostic ignored "-Wcast-function-type"
580# else
581# pragma GCC diagnostic push
582# pragma GCC diagnostic ignored "-Wcast-function-type"
583# endif
584#endif
585
586static PyMethodDef py_blf_bind_imbuf_methods[] = {
587 {"__enter__", (PyCFunction)py_blf_bind_imbuf_enter, METH_NOARGS},
588 {"__exit__", (PyCFunction)py_blf_bind_imbuf_exit, METH_VARARGS},
589 {nullptr},
590};
591
592#ifdef __GNUC__
593# ifdef __clang__
594# pragma clang diagnostic pop
595# else
596# pragma GCC diagnostic pop
597# endif
598#endif
599
600static PyTypeObject BPyBLFImBufContext_Type = {
601 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
602 /*tp_name*/ "BLFImBufContext",
603 /*tp_basicsize*/ sizeof(BPyBLFImBufContext),
604 /*tp_itemsize*/ 0,
605 /*tp_dealloc*/ (destructor)py_blf_bind_imbuf_dealloc,
606 /*tp_vectorcall_offset*/ 0,
607 /*tp_getattr*/ nullptr,
608 /*tp_setattr*/ nullptr,
609 /*tp_as_async*/ nullptr,
610 /*tp_repr*/ nullptr,
611 /*tp_as_number*/ nullptr,
612 /*tp_as_sequence*/ nullptr,
613 /*tp_as_mapping*/ nullptr,
614 /*tp_hash*/ nullptr,
615 /*tp_call*/ nullptr,
616 /*tp_str*/ nullptr,
617 /*tp_getattro*/ nullptr,
618 /*tp_setattro*/ nullptr,
619 /*tp_as_buffer*/ nullptr,
620 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
621 /*tp_doc*/ nullptr,
622 /*tp_traverse*/ (traverseproc)py_blf_bind_imbuf_traverse,
623 /*tp_clear*/ (inquiry)py_blf_bind_imbuf_clear,
624 /*tp_richcompare*/ nullptr,
625 /*tp_weaklistoffset*/ 0,
626 /*tp_iter*/ nullptr,
627 /*tp_iternext*/ nullptr,
628 /*tp_methods*/ py_blf_bind_imbuf_methods,
629 /*tp_members*/ nullptr,
630 /*tp_getset*/ nullptr,
631 /*tp_base*/ nullptr,
632 /*tp_dict*/ nullptr,
633 /*tp_descr_get*/ nullptr,
634 /*tp_descr_set*/ nullptr,
635 /*tp_dictoffset*/ 0,
636 /*tp_init*/ nullptr,
637 /*tp_alloc*/ nullptr,
638 /*tp_new*/ nullptr,
639 /*tp_free*/ nullptr,
640 /*tp_is_gc*/ nullptr,
641 /*tp_bases*/ nullptr,
642 /*tp_mro*/ nullptr,
643 /*tp_cache*/ nullptr,
644 /*tp_subclasses*/ nullptr,
645 /*tp_weaklist*/ nullptr,
646 /*tp_del*/ nullptr,
647 /*tp_version_tag*/ 0,
648 /*tp_finalize*/ nullptr,
649 /*tp_vectorcall*/ nullptr,
650};
651
652/* NOTE(@ideasman42): `BLFImBufContext` isn't accessible from (without creating an instance),
653 * it should be exposed although it doesn't seem especially important either. */
655 /* Wrap. */
656 py_blf_bind_imbuf_doc,
657 ".. method:: bind_imbuf(fontid, image, display_name=None)\n"
658 "\n"
659 " Context manager to draw text into an image buffer instead of the GPU's context.\n"
660 "\n"
661 " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
662 "font use 0.\n"
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"
668
669 " :return: The BLF ImBuf context manager.\n"
670 " :rtype: BLFImBufContext\n");
671static PyObject *py_blf_bind_imbuf(PyObject * /*self*/, PyObject *args, PyObject *kwds)
672{
673 int fontid;
674 PyObject *py_imbuf = nullptr;
675 const char *display_name = nullptr;
676
677 static const char *_keywords[] = {
678 "",
679 "",
680 "display_name",
681 nullptr,
682 };
683
684 static _PyArg_Parser _parser = {
686 "i" /* `fontid` */
687 "O!" /* `image` */
688 "|" /* Optional arguments. */
689 "z" /* `display_name` */
690 ":bind_imbuf",
691 _keywords,
692 nullptr,
693 };
694 if (!_PyArg_ParseTupleAndKeywordsFast(
695 args, kwds, &_parser, &fontid, &Py_ImBuf_Type, &py_imbuf, &display_name))
696 {
697 return nullptr;
698 }
699
700 const ColorManagedDisplay *display = nullptr;
701 if (display_name) {
702 display = IMB_colormanagement_display_get_named(display_name);
703 if (UNLIKELY(display == nullptr)) {
704 std::string display_names_all;
705 display_names_all.reserve(1024);
706 const char *ex = nullptr;
707 /* 1 based index. */
708 for (int i = 1; (ex = IMB_colormanagement_display_get_indexed_name(i)); i++) {
709 if (i > 1) {
710 display_names_all += ", ";
711 }
712 display_names_all += ex;
713 }
714 PyErr_Format(PyExc_ValueError,
715 "bind_imbuf: color management \"%s\" not found in [%s]",
716 display_name,
717 display_names_all.c_str());
718 return nullptr;
719 }
720 }
721
723
724 ret->py_imbuf = Py_NewRef(py_imbuf);
725 ret->display = display;
726
727 ret->fontid = fontid;
728 ret->buffer_state = nullptr;
729
730 PyObject_GC_Track(ret);
731
732 return (PyObject *)ret;
733}
734
736
737#ifdef __GNUC__
738# ifdef __clang__
739# pragma clang diagnostic push
740# pragma clang diagnostic ignored "-Wcast-function-type"
741# else
742# pragma GCC diagnostic push
743# pragma GCC diagnostic ignored "-Wcast-function-type"
744# endif
745#endif
746
747/*----------------------------MODULE INIT-------------------------*/
748static PyMethodDef BLF_methods[] = {
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},
760 {"shadow_offset", (PyCFunction)py_blf_shadow_offset, METH_VARARGS, py_blf_shadow_offset_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},
765
766 {"bind_imbuf",
767 (PyCFunction)py_blf_bind_imbuf,
768 METH_VARARGS | METH_KEYWORDS,
769 py_blf_bind_imbuf_doc},
770
771 {nullptr, nullptr, 0, nullptr},
772};
773
774#ifdef __GNUC__
775# ifdef __clang__
776# pragma clang diagnostic pop
777# else
778# pragma GCC diagnostic pop
779# endif
780#endif
781
783 /* Wrap. */
784 BLF_doc,
785 "This module provides access to Blender's text drawing functions.");
786static PyModuleDef BLF_module_def = {
787 /*m_base*/ PyModuleDef_HEAD_INIT,
788 /*m_name*/ "blf",
789 /*m_doc*/ BLF_doc,
790 /*m_size*/ 0,
791 /*m_methods*/ BLF_methods,
792 /*m_slots*/ nullptr,
793 /*m_traverse*/ nullptr,
794 /*m_clear*/ nullptr,
795 /*m_free*/ nullptr,
796};
797
798PyObject *BPyInit_blf()
799{
800 PyObject *submodule;
801
802 submodule = PyModule_Create(&BLF_module_def);
803
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);
808 PyModule_AddIntConstant(submodule, "MONOCHROME", BLF_MONOCHROME);
809
810 return submodule;
811}
void BLF_size(int fontid, float size)
Definition blf.cc:440
void BLF_buffer_state_free(BLFBufferState *buffer_state)
Definition blf.cc:1005
void BLF_buffer_state_pop(BLFBufferState *buffer_state)
Definition blf.cc:988
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
Definition blf.cc:928
void BLF_aspect(int fontid, float x, float y, float z)
Definition blf.cc:374
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:906
void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:1035
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
Definition blf.cc:792
@ BLF_ROTATION
Definition BLF_api.hh:433
@ BLF_WORD_WRAP
Definition BLF_api.hh:439
@ BLF_MONOCHROME
Definition BLF_api.hh:441
@ BLF_SHADOW
Definition BLF_api.hh:435
@ BLF_CLIPPING
Definition BLF_api.hh:434
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:502
void BLF_shadow_offset(int fontid, int x, int y)
Definition blf.cc:940
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, const ColorManagedDisplay *display)
Definition blf.cc:950
BLFBufferState * BLF_buffer_state_push(int fontid)
Definition blf.cc:975
void BLF_disable(int fontid, int option)
Definition blf.cc:329
void BLF_rotation(int fontid, float angle)
Definition blf.cc:897
void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2)
Definition blf.cc:1010
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:582
void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:918
int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:175
blender::ocio::Display ColorManagedDisplay
Definition BLF_api.hh:35
void BLF_enable(int fontid, int option)
Definition blf.cc:320
FontShadowType
Definition BLF_api.hh:37
int void BLF_unload(const char *filepath) ATTR_NONNULL(1)
Definition blf.cc:259
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:385
unsigned int uint
#define UNLIKELY(x)
#define ELEM(...)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
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)
PyObject * BPyInit_blf()
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)
Definition blf_py_api.cc:86
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)
Definition blf_py_api.cc:60
static PyMethodDef py_blf_bind_imbuf_methods[]
PyObject * self
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
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()
header-only utilities
#define PyTuple_SET_ITEMS(op_arg,...)
return ret
BLFBufferState * buffer_state
Definition blf_py_api.cc:40
PyObject_HEAD PyObject * py_imbuf
Definition blf_py_api.cc:36
const ColorManagedDisplay * display
Definition blf_py_api.cc:37
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
i
Definition text_draw.cc:230