Blender V4.5
BLF_api.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_array.hh"
12#include "BLI_bounds_types.hh"
13#include "BLI_compiler_attrs.h"
14#include "BLI_function_ref.hh"
15#include "BLI_string_ref.hh"
16#include "BLI_sys_types.h"
17#include "BLI_vector.hh"
18
19/* Name of sub-directory inside #BLENDER_DATAFILES that contains font files. */
20#define BLF_DATAFILES_FONTS_DIR "fonts"
21
22/* File name of the default variable-width font. */
23#define BLF_DEFAULT_PROPORTIONAL_FONT "Inter.woff2"
24
25/* File name of the default fixed-pitch font. */
26#define BLF_DEFAULT_MONOSPACED_FONT "DejaVuSansMono.woff2"
27
28struct ListBase;
29struct ResultBLF;
30struct rcti;
31
32namespace blender::ocio {
33class Display;
34} // namespace blender::ocio
36
37enum class FontShadowType {
38 None = 0,
42};
43
44enum class BLFWrapMode : int {
45 Minimal = 0, /* Only on ASCII space and line feed. Legacy and invariant. */
46 Typographical = 1 << 0, /* Multilingual, informed by Unicode Standard Annex #14. */
47 Path = 1 << 1, /* Wrap on file path separators, space, underscores. */
48 HardLimit = 1 << 2, /* Line break at limit. */
49};
50
51int BLF_init();
52void BLF_exit();
53
58void BLF_reset_fonts();
59
60void BLF_cache_clear();
61
65void BLF_cache_flush_set_fn(void (*cache_flush_fn)());
66
74int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
75int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT
76 ATTR_NONNULL(1, 2);
77
78bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
81
89int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
90int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size)
91 ATTR_NONNULL(1, 2);
92
96void BLF_unload(const char *filepath) ATTR_NONNULL(1);
97#if 0 /* Not needed at the moment. */
98void BLF_unload_mem(const char *name) ATTR_NONNULL(1);
99#endif
100
105bool BLF_unload_id(int fontid);
106
107void BLF_unload_all();
108
112void BLF_addref_id(int fontid);
113
115
116char *BLF_display_name_from_id(int fontid);
117
121bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale);
122
123#define BLF_VFONT_METRICS_SCALE_DEFAULT float(1.0 / 1000.0)
124#define BLF_VFONT_METRICS_EM_RATIO_DEFAULT 1.0f
125#define BLF_VFONT_METRICS_ASCEND_RATIO_DEFAULT 0.8f
126
131 int fontid, unsigned int unicode, ListBase *nurbsbase, const float scale, bool use_fallback);
132
136bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT;
137
141void BLF_metrics_attach(int fontid, const unsigned char *mem, int mem_size) ATTR_NONNULL(2);
142
143void BLF_aspect(int fontid, float x, float y, float z);
144void BLF_position(int fontid, float x, float y, float z);
145void BLF_size(int fontid, float size);
146
150void BLF_character_weight(int fontid, int weight);
151
152/* Return the font's default design weight (100-900). */
154
155/* Return true if the font has a variable (multiple master) weight axis. */
157
158/* Goal: small but useful color API. */
159
160void BLF_color4ubv(int fontid, const unsigned char rgba[4]);
161void BLF_color3ubv(int fontid, const unsigned char rgb[3]);
162void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha);
163void BLF_color4ub(
164 int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha);
165void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b);
166void BLF_color4f(int fontid, float r, float g, float b, float a);
167void BLF_color4fv(int fontid, const float rgba[4]);
168void BLF_color3f(int fontid, float r, float g, float b);
169void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha);
170/* Also available: `UI_FontThemeColor(fontid, colorid)`. */
171
178void BLF_batch_draw_end();
179
183void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
184 ATTR_NONNULL(2);
185int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth, int tab_columns)
186 ATTR_NONNULL(2);
187
188void BLF_draw_svg_icon(uint icon_id,
189 float x,
190 float y,
191 float size,
192 const float color[4] = nullptr,
193 float outline_alpha = 1.0f,
194 bool multicolor = false,
195 blender::FunctionRef<void(std::string &)> edit_source_cb = nullptr);
196
198 uint icon_id,
199 float size,
200 int *r_width,
201 int *r_height,
202 bool multicolor = false,
203 blender::FunctionRef<void(std::string &)> edit_source_cb = nullptr);
204
205using BLF_GlyphBoundsFn = bool (*)(const char *str,
206 size_t str_step_ofs,
207 const rcti *bounds,
208 void *user_dataconst);
209
218void BLF_boundbox_foreach_glyph(int fontid,
219 const char *str,
220 size_t str_len,
221 BLF_GlyphBoundsFn user_fn,
222 void *user_data) ATTR_NONNULL(2);
223
228 const char *str,
229 size_t str_len,
230 int location_x) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
231
236 const char *str,
237 size_t str_offset,
238 rcti *r_glyph_bounds) ATTR_WARN_UNUSED_RESULT
239 ATTR_NONNULL(2, 4);
240
245 int fontid, const char *str, size_t str_len, size_t str_offset, int cursor_width);
246
252 int fontid, const char *str, size_t str_len, size_t sel_start, size_t sel_length);
253
257size_t BLF_width_to_strlen(int fontid,
258 const char *str,
259 size_t str_len,
260 float width,
261 float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
265size_t BLF_width_to_rstrlen(int fontid,
266 const char *str,
267 size_t str_len,
268 float width,
269 float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
270
275void BLF_boundbox(int fontid,
276 const char *str,
277 size_t str_len,
278 rcti *r_box,
279 ResultBLF *r_info = nullptr) ATTR_NONNULL(2);
280
286float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
288float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
290
298
304 int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL();
305
311
315int BLF_glyph_advance(int fontid, const char *str);
316
321void BLF_rotation(int fontid, float angle);
322void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax);
323void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode = BLFWrapMode::Minimal);
324
327 const int max_pixel_width,
329
330void BLF_enable(int fontid, int option);
331void BLF_disable(int fontid, int option);
332
336bool BLF_is_builtin(int fontid);
337
341void BLF_shadow(int fontid, FontShadowType type, const float rgba[4] = nullptr);
342
349void BLF_shadow_offset(int fontid, int x, int y);
350
356void BLF_buffer(int fontid,
357 float *fbuf,
358 unsigned char *cbuf,
359 int w,
360 int h,
361 const ColorManagedDisplay *display);
362
366struct BLFBufferState;
375void BLF_buffer_state_pop(BLFBufferState *buffer_state);
380void BLF_buffer_state_free(BLFBufferState *buffer_state);
381
385void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2);
386
391void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
392 ATTR_NONNULL(2);
393
394/* `blf_thumbs.cc` */
395
401bool BLF_thumb_preview(const char *filepath, unsigned char *buf, int w, int h, int channels)
402 ATTR_NONNULL();
403
404/* `blf_default.cc` */
405
406void BLF_default_size(float size);
407void BLF_default_set(int fontid);
411int BLF_default();
415void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL();
419int BLF_set_default();
420
421/* `blf_font_default.cc` */
422
423int BLF_load_default(bool unique);
424int BLF_load_mono_default(bool unique);
426
427#ifndef NDEBUG
428void BLF_state_print(int fontid);
429#endif
430
432enum {
433 BLF_ROTATION = 1 << 0,
434 BLF_CLIPPING = 1 << 1,
435 BLF_SHADOW = 1 << 2,
436 // BLF_FLAG_UNUSED_3 = 1 << 3, /* dirty */
437 // BLF_MATRIX = 1 << 4,
438 BLF_ASPECT = 1 << 5,
445 BLF_BOLD = 1 << 11,
446 BLF_ITALIC = 1 << 12,
448 BLF_MONOSPACED = 1 << 13,
450 BLF_DEFAULT = 1 << 14,
454 BLF_BAD_FONT = 1 << 16,
456 BLF_CACHED = 1 << 17,
463
464 /* Do not look in other fonts when a glyph is not found in this font. */
466};
467
468#define BLF_DRAW_STR_DUMMY_MAX 1024
469
470/* XXX, bad design */
471extern int blf_mono_font;
472extern int blf_mono_font_render; /* don't mess drawing with render threads. */
473
477struct ResultBLF {
481 int lines;
485 int width;
486};
bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:151
void BLF_draw_svg_icon(uint icon_id, float x, float y, float size, const float color[4]=nullptr, float outline_alpha=1.0f, bool multicolor=false, blender::FunctionRef< void(std::string &)> edit_source_cb=nullptr)
Definition blf.cc:626
void BLF_state_print(int fontid)
Definition blf.cc:1147
int BLF_set_default()
int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size) ATTR_NONNULL(1
void BLF_size(int fontid, float size)
Definition blf.cc:440
BLFWrapMode
Definition BLF_api.hh:44
@ Typographical
Definition BLF_api.hh:46
void BLF_default_set(int fontid)
void BLF_buffer_state_free(BLFBufferState *buffer_state)
Definition blf.cc:1005
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:875
void BLF_reset_fonts()
Definition blf.cc:83
void BLF_addref_id(int fontid)
Definition blf.cc:311
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
size_t BLF_width_to_strlen(int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:731
blender::Vector< blender::StringRef > BLF_string_wrap(int fontid, blender::StringRef str, const int max_pixel_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:1051
void BLF_unload_all()
Definition blf.cc:297
blender::Vector< blender::Bounds< int > > BLF_str_selection_boxes(int fontid, const char *str, size_t str_len, size_t sel_start, size_t sel_length)
Definition blf.cc:721
void BLF_color3ubv(int fontid, const unsigned char rgb[3])
Definition blf.cc:473
int BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:864
float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:840
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:906
int BLF_load_default(bool unique)
void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:1035
bool BLF_is_loaded_id(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:170
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
void BLF_metrics_attach(int fontid, const unsigned char *mem, int mem_size) ATTR_NONNULL(2)
Definition blf.cc:216
void BLF_cache_flush_set_fn(void(*cache_flush_fn)())
Definition blf_font.cc:1635
void BLF_color3f(int fontid, float r, float g, float b)
Definition blf.cc:525
char * BLF_display_name_from_id(int fontid)
Definition blf.cc:1083
void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha)
Definition blf.cc:517
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:502
blender::Array< uchar > BLF_svg_icon_bitmap(uint icon_id, float size, int *r_width, int *r_height, bool multicolor=false, blender::FunctionRef< void(std::string &)> edit_source_cb=nullptr)
Definition blf.cc:649
bool int BLF_str_offset_to_cursor(int fontid, const char *str, size_t str_len, size_t str_offset, int cursor_width)
Definition blf.cc:708
bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale)
Definition blf.cc:1093
int BLF_default_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:352
void BLF_shadow_offset(int fontid, int x, int y)
Definition blf.cc:940
void BLF_batch_draw_begin()
Definition blf.cc:531
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, const ColorManagedDisplay *display)
Definition blf.cc:950
int blf_mono_font_render
Definition blf.cc:49
@ BLF_RENDER_SUBPIXELAA
Definition BLF_api.hh:462
@ BLF_ITALIC
Definition BLF_api.hh:446
@ BLF_ROTATION
Definition BLF_api.hh:433
@ BLF_HINTING_NONE
Definition BLF_api.hh:442
@ BLF_LAST_RESORT
Definition BLF_api.hh:452
@ BLF_MONOSPACED
Definition BLF_api.hh:448
@ BLF_CACHED
Definition BLF_api.hh:456
@ BLF_WORD_WRAP
Definition BLF_api.hh:439
@ BLF_MONOCHROME
Definition BLF_api.hh:441
@ BLF_BOLD
Definition BLF_api.hh:445
@ BLF_NO_FALLBACK
Definition BLF_api.hh:465
@ BLF_BAD_FONT
Definition BLF_api.hh:454
@ BLF_HINTING_FULL
Definition BLF_api.hh:444
@ BLF_HINTING_SLIGHT
Definition BLF_api.hh:443
@ BLF_ASPECT
Definition BLF_api.hh:438
@ BLF_SHADOW
Definition BLF_api.hh:435
@ BLF_CLIPPING
Definition BLF_api.hh:434
@ BLF_DEFAULT
Definition BLF_api.hh:450
void BLF_boundbox(int fontid, const char *str, size_t str_len, rcti *r_box, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:775
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:818
BLFBufferState * BLF_buffer_state_push(int fontid)
Definition blf.cc:975
bool BLF_str_offset_to_glyph_bounds(int fontid, const char *str, size_t str_offset, rcti *r_glyph_bounds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2
void BLF_disable(int fontid, int option)
Definition blf.cc:329
void BLF_rotation(int fontid, float angle)
Definition blf.cc:897
int BLF_default()
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_batch_draw_end()
Definition blf.cc:544
void BLF_boundbox_foreach_glyph(int fontid, const char *str, size_t str_len, BLF_GlyphBoundsFn user_fn, void *user_data) ATTR_NONNULL(2)
Definition blf.cc:667
int BLF_glyph_advance(int fontid, const char *str)
Definition blf.cc:829
void BLF_default_size(float size)
void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:918
void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha)
Definition blf.cc:461
int BLF_load_mono_default(bool unique)
int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:175
bool(*)(const char *str, size_t str_step_ofs, const rcti *bounds, void *user_dataconst) BLF_GlyphBoundsFn
Definition BLF_api.hh:205
void BLF_exit()
Definition blf.cc:70
int blf_mono_font
Definition blf.cc:48
void BLF_cache_clear()
Definition blf.cc:98
blender::ocio::Display ColorManagedDisplay
Definition BLF_api.hh:35
bool BLF_is_loaded_mem(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:165
int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:188
int bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:160
void BLF_batch_draw_flush()
Definition blf.cc:537
void BLF_load_font_stack()
void BLF_enable(int fontid, int option)
Definition blf.cc:320
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:805
bool BLF_unload_id(int fontid)
Definition blf.cc:280
int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
bool BLF_is_builtin(int fontid)
Definition blf.cc:338
bool BLF_has_variable_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:361
void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b)
Definition blf.cc:490
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:853
FontShadowType
Definition BLF_api.hh:37
int BLF_init()
Definition blf.cc:61
char * BLF_display_name_from_file(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:1063
void BLF_color4f(int fontid, float r, float g, float b, float a)
Definition blf.cc:511
size_t BLF_str_offset_from_cursor_position(int fontid, const char *str, size_t str_len, int location_x) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:683
void BLF_color4ubv(int fontid, const unsigned char rgba[4])
Definition blf.cc:449
int void BLF_unload(const char *filepath) ATTR_NONNULL(1)
Definition blf.cc:259
int BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:886
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
bool BLF_thumb_preview(const char *filepath, unsigned char *buf, int w, int h, int channels) ATTR_NONNULL()
void BLF_character_weight(int fontid, int weight)
Definition blf.cc:344
void BLF_color4ub(int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha)
Definition blf.cc:478
float BLF_character_to_curves(int fontid, unsigned int unicode, ListBase *nurbsbase, const float scale, bool use_fallback)
Definition blf.cc:1136
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:385
int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth, int tab_columns) ATTR_NONNULL(2)
Definition blf.cc:608
size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:753
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
unsigned char uchar
unsigned int uint
float[3] Vector
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition btDbvt.cpp:299
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define str(s)
int lines
Definition BLF_api.hh:481
int width
Definition BLF_api.hh:485