Blender V4.3
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
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
29struct ListBase;
30struct ResultBLF;
31struct rcti;
32
33enum class FontShadowType {
34 None = 0,
35 Blur3x3 = 3,
36 Blur5x5 = 5,
37 Outline = 6,
38};
39
40int BLF_init();
41void BLF_exit();
42
47void BLF_reset_fonts();
48
49void BLF_cache_clear();
50
54void BLF_cache_flush_set_fn(void (*cache_flush_fn)());
55
59int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
60int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT
61 ATTR_NONNULL(1, 2);
62
63bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
65
66int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
67int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size)
68 ATTR_NONNULL(1, 2);
69
70void BLF_unload(const char *filepath) ATTR_NONNULL(1);
71#if 0 /* Not needed at the moment. */
72void BLF_unload_mem(const char *name) ATTR_NONNULL(1);
73#endif
74
75void BLF_unload_id(int fontid);
76void BLF_unload_all();
77
79
80char *BLF_display_name_from_id(int fontid);
81
85bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale);
86
90float BLF_character_to_curves(int fontid,
91 unsigned int unicode,
92 ListBase *nurbsbase,
93 const float scale);
94
98bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT;
99
103void BLF_metrics_attach(int fontid, const unsigned char *mem, int mem_size) ATTR_NONNULL(2);
104
105void BLF_aspect(int fontid, float x, float y, float z);
106void BLF_position(int fontid, float x, float y, float z);
107void BLF_size(int fontid, float size);
108
112void BLF_character_weight(int fontid, int weight);
113
114/* Return the font's default design weight (100-900). */
116
117/* Return true if the font has a variable (multiple master) weight axis. */
119
120/* Goal: small but useful color API. */
121
122void BLF_color4ubv(int fontid, const unsigned char rgba[4]);
123void BLF_color3ubv(int fontid, const unsigned char rgb[3]);
124void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha);
125void BLF_color4ub(
126 int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha);
127void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b);
128void BLF_color4f(int fontid, float r, float g, float b, float a);
129void BLF_color4fv(int fontid, const float rgba[4]);
130void BLF_color3f(int fontid, float r, float g, float b);
131void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha);
132/* Also available: `UI_FontThemeColor(fontid, colorid)`. */
133
140void BLF_batch_draw_end();
141
145void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
146 ATTR_NONNULL(2);
147int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth, int tab_columns)
148 ATTR_NONNULL(2);
149
150void BLF_draw_svg_icon(uint icon_id,
151 float x,
152 float y,
153 float size,
154 const float color[4] = nullptr,
155 float outline_alpha = 1.0f,
156 bool multicolor = false,
157 blender::FunctionRef<void(std::string &)> edit_source_cb = nullptr);
158
160 uint icon_id,
161 float size,
162 int *r_width,
163 int *r_height,
164 bool multicolor = false,
165 blender::FunctionRef<void(std::string &)> edit_source_cb = nullptr);
166
167typedef bool (*BLF_GlyphBoundsFn)(const char *str,
168 size_t str_step_ofs,
169 const rcti *bounds,
170 void *user_data);
171
180void BLF_boundbox_foreach_glyph(int fontid,
181 const char *str,
182 size_t str_len,
183 BLF_GlyphBoundsFn user_fn,
184 void *user_data) ATTR_NONNULL(2);
185
190 const char *str,
191 size_t str_len,
192 int location_x) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
193
198 const char *str,
199 size_t str_offset,
200 rcti *r_glyph_bounds) ATTR_WARN_UNUSED_RESULT
201 ATTR_NONNULL(2, 4);
202
207 int fontid, const char *str, size_t str_len, size_t str_offset, int cursor_width);
208
213blender::Vector<blender::Bounds<int>> BLF_str_selection_boxes(
214 int fontid, const char *str, size_t str_len, size_t sel_start, size_t sel_length);
215
219size_t BLF_width_to_strlen(int fontid,
220 const char *str,
221 size_t str_len,
222 float width,
223 float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
227size_t BLF_width_to_rstrlen(int fontid,
228 const char *str,
229 size_t str_len,
230 float width,
231 float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
232
237void BLF_boundbox(int fontid,
238 const char *str,
239 size_t str_len,
240 rcti *r_box,
241 ResultBLF *r_info = nullptr) ATTR_NONNULL(2);
242
248float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
250float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
252
260
266 int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL();
267
273
278void BLF_rotation(int fontid, float angle);
279void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax);
280void BLF_wordwrap(int fontid, int wrap_width);
281
282blender::Vector<blender::StringRef> BLF_string_wrap(int fontid,
283 blender::StringRef str,
284 const int max_pixel_width);
285
286void BLF_enable(int fontid, int option);
287void BLF_disable(int fontid, int option);
288
292void BLF_shadow(int fontid, FontShadowType type, const float rgba[4] = nullptr);
293
300void BLF_shadow_offset(int fontid, int x, int y);
301
307void BLF_buffer(
308 int fontid, float *fbuf, unsigned char *cbuf, int w, int h, ColorManagedDisplay *display);
309
313void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2);
314
319void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
320 ATTR_NONNULL(2);
321
322/* `blf_thumbs.cc` */
323
329bool BLF_thumb_preview(const char *filepath, unsigned char *buf, int w, int h, int channels)
330 ATTR_NONNULL();
331
332/* `blf_default.cc` */
333
334void BLF_default_size(float size);
335void BLF_default_set(int fontid);
339int BLF_default();
343void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL();
347int BLF_set_default();
348
349/* `blf_font_default.cc` */
350
351int BLF_load_default(bool unique);
352int BLF_load_mono_default(bool unique);
354
355#ifndef NDEBUG
356void BLF_state_print(int fontid);
357#endif
358
360enum {
361 BLF_ROTATION = 1 << 0,
362 BLF_CLIPPING = 1 << 1,
363 BLF_SHADOW = 1 << 2,
364 // BLF_FLAG_UNUSED_3 = 1 << 3, /* dirty */
365 // BLF_MATRIX = 1 << 4,
366 BLF_ASPECT = 1 << 5,
373 BLF_BOLD = 1 << 11,
374 BLF_ITALIC = 1 << 12,
376 BLF_MONOSPACED = 1 << 13,
378 BLF_DEFAULT = 1 << 14,
382 BLF_BAD_FONT = 1 << 16,
384 BLF_CACHED = 1 << 17,
391};
392
393#define BLF_DRAW_STR_DUMMY_MAX 1024
394
395/* XXX, bad design */
396extern int blf_mono_font;
397extern int blf_mono_font_render; /* don't mess drawing with render threads. */
398
402struct ResultBLF {
406 int lines;
410 int width;
411};
bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:155
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:612
void BLF_state_print(int fontid)
Definition blf.cc:1072
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:426
void BLF_default_set(int fontid)
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:850
void BLF_reset_fonts()
Definition blf.cc:84
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
Definition blf.cc:902
void BLF_aspect(int fontid, float x, float y, float z)
Definition blf.cc:360
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:717
void BLF_unload_all()
Definition blf.cc:298
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:707
void BLF_color3ubv(int fontid, const unsigned char rgb[3])
Definition blf.cc:459
int BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:839
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:815
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:881
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:962
blender::Vector< blender::StringRef > BLF_string_wrap(int fontid, blender::StringRef str, const int max_pixel_width)
Definition blf.cc:978
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:778
void BLF_metrics_attach(int fontid, const unsigned char *mem, int mem_size) ATTR_NONNULL(2)
Definition blf.cc:217
void BLF_cache_flush_set_fn(void(*cache_flush_fn)())
Definition blf_font.cc:1523
void BLF_color3f(int fontid, float r, float g, float b)
Definition blf.cc:511
char * BLF_display_name_from_id(int fontid)
Definition blf.cc:1009
void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha)
Definition blf.cc:503
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:488
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:635
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:694
bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale)
Definition blf.cc:1019
int BLF_default_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:338
void BLF_shadow_offset(int fontid, int x, int y)
Definition blf.cc:914
void BLF_batch_draw_begin()
Definition blf.cc:517
int blf_mono_font_render
Definition blf.cc:52
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:761
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:804
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:321
void BLF_rotation(int fontid, float angle)
Definition blf.cc:872
int BLF_default()
void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2)
Definition blf.cc:937
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, ColorManagedDisplay *display)
Definition blf.cc:924
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:568
void BLF_batch_draw_end()
Definition blf.cc:530
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:653
void BLF_default_size(float size)
void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha)
Definition blf.cc:447
int BLF_load_mono_default(bool unique)
void BLF_unload_id(int fontid)
Definition blf.cc:284
int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:174
void BLF_exit()
Definition blf.cc:71
int blf_mono_font
Definition blf.cc:51
float BLF_character_to_curves(int fontid, unsigned int unicode, ListBase *nurbsbase, const float scale)
Definition blf.cc:1062
void BLF_cache_clear()
Definition blf.cc:99
bool BLF_is_loaded_mem(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:169
int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:187
int bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:164
void BLF_batch_draw_flush()
Definition blf.cc:523
void BLF_load_font_stack()
void BLF_enable(int fontid, int option)
Definition blf.cc:312
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:791
int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
bool(* BLF_GlyphBoundsFn)(const char *str, size_t str_step_ofs, const rcti *bounds, void *user_data)
Definition BLF_api.hh:167
bool BLF_has_variable_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:347
void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b)
Definition blf.cc:476
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:828
FontShadowType
Definition BLF_api.hh:33
int BLF_init()
Definition blf.cc:62
char * BLF_display_name_from_file(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:989
void BLF_color4f(int fontid, float r, float g, float b, float a)
Definition blf.cc:497
@ BLF_RENDER_SUBPIXELAA
Definition BLF_api.hh:390
@ BLF_ITALIC
Definition BLF_api.hh:374
@ BLF_ROTATION
Definition BLF_api.hh:361
@ BLF_HINTING_NONE
Definition BLF_api.hh:370
@ BLF_LAST_RESORT
Definition BLF_api.hh:380
@ BLF_MONOSPACED
Definition BLF_api.hh:376
@ BLF_CACHED
Definition BLF_api.hh:384
@ BLF_WORD_WRAP
Definition BLF_api.hh:367
@ BLF_MONOCHROME
Definition BLF_api.hh:369
@ BLF_BOLD
Definition BLF_api.hh:373
@ BLF_BAD_FONT
Definition BLF_api.hh:382
@ BLF_HINTING_FULL
Definition BLF_api.hh:372
@ BLF_HINTING_SLIGHT
Definition BLF_api.hh:371
@ BLF_ASPECT
Definition BLF_api.hh:366
@ BLF_SHADOW
Definition BLF_api.hh:363
@ BLF_CLIPPING
Definition BLF_api.hh:362
@ BLF_DEFAULT
Definition BLF_api.hh:378
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:669
void BLF_color4ubv(int fontid, const unsigned char rgba[4])
Definition blf.cc:435
int void BLF_unload(const char *filepath) ATTR_NONNULL(1)
Definition blf.cc:264
int BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:861
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:330
void BLF_color4ub(int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha)
Definition blf.cc:464
void BLF_wordwrap(int fontid, int wrap_width)
Definition blf.cc:893
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:371
int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth, int tab_columns) ATTR_NONNULL(2)
Definition blf.cc:594
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:739
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
unsigned char uchar
unsigned int uint
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
local_group_size(16, 16) .push_constant(Type b
#define str(s)
int lines
Definition BLF_api.hh:406
int width
Definition BLF_api.hh:410
int ymin
int ymax
int xmin
int xmax