Blender V5.0
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 "BLF_enums.hh"
12
13#include "BLI_array.hh"
14#include "BLI_bounds_types.hh"
15#include "BLI_compiler_attrs.h"
16#include "BLI_function_ref.hh"
17#include "BLI_string_ref.hh"
18#include "BLI_sys_types.h"
19#include "BLI_vector.hh"
20
22#define BLF_DATAFILES_FONTS_DIR "fonts"
23
25#define BLF_DEFAULT_PROPORTIONAL_FONT "Inter.woff2"
26
28#define BLF_DEFAULT_MONOSPACED_FONT "DejaVuSansMono.woff2"
29
30struct ListBase;
31struct ResultBLF;
32struct rcti;
33struct rctf;
34
35namespace blender::ocio {
36class ColorSpace;
37} // namespace blender::ocio
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
63int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
64int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT
65 ATTR_NONNULL(1, 2);
66
67bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
70
78int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
79int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size)
80 ATTR_NONNULL(1, 2);
81
85void BLF_unload(const char *filepath) ATTR_NONNULL(1);
86#if 0 /* Not needed at the moment. */
87void BLF_unload_mem(const char *name) ATTR_NONNULL(1);
88#endif
89
94bool BLF_unload_id(int fontid);
95
96void BLF_unload_all();
97
101void BLF_addref_id(int fontid);
102
104
105char *BLF_display_name_from_id(int fontid);
106
110bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale);
111
112#define BLF_VFONT_METRICS_SCALE_DEFAULT float(1.0 / 1000.0)
113#define BLF_VFONT_METRICS_EM_RATIO_DEFAULT 1.0f
114#define BLF_VFONT_METRICS_ASCEND_RATIO_DEFAULT 0.8f
115
120bool BLF_character_to_curves(int fontid,
121 unsigned int unicode,
122 ListBase *nurbsbase,
123 const float scale,
124 bool use_fallback,
125 float *r_advance);
126
130bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT;
131
135void BLF_metrics_attach(int fontid, const unsigned char *mem, int mem_size) ATTR_NONNULL(2);
136
137void BLF_aspect(int fontid, float x, float y, float z);
138void BLF_position(int fontid, float x, float y, float z);
139void BLF_size(int fontid, float size);
140
144void BLF_character_weight(int fontid, int weight);
145
150
155
156/* Goal: small but useful color API. */
157
158void BLF_color4ubv(int fontid, const unsigned char rgba[4]);
159void BLF_color3ubv(int fontid, const unsigned char rgb[3]);
160void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha);
161void BLF_color4ub(
162 int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha);
163void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b);
164void BLF_color4f(int fontid, float r, float g, float b, float a);
165void BLF_color4fv(int fontid, const float rgba[4]);
166void BLF_color3f(int fontid, float r, float g, float b);
167void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha);
168/* Also available: `UI_FontThemeColor(fontid, colorid)`. */
169
176void BLF_batch_draw_end();
177
178/* Discard any batching in process and restart.
179 * Only used as a workaround for glitchy driver sync. */
180void BLF_batch_discard();
181
185void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
186 ATTR_NONNULL(2);
187int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth, int tab_columns)
188 ATTR_NONNULL(2);
189
190void BLF_draw_svg_icon(uint icon_id,
191 float x,
192 float y,
193 float size,
194 const float color[4] = nullptr,
195 float outline_alpha = 1.0f,
196 bool multicolor = false,
197 blender::FunctionRef<void(std::string &)> edit_source_cb = nullptr);
198
200 uint icon_id,
201 float size,
202 int *r_width,
203 int *r_height,
204 bool multicolor = false,
205 blender::FunctionRef<void(std::string &)> edit_source_cb = nullptr);
206
207using BLF_GlyphBoundsFn = bool (*)(const char *str,
208 size_t str_step_ofs,
209 const rcti *bounds,
210 void *user_dataconst);
211
220void BLF_boundbox_foreach_glyph(int fontid,
221 const char *str,
222 size_t str_len,
223 BLF_GlyphBoundsFn user_fn,
224 void *user_data) ATTR_NONNULL(2);
225
230 const char *str,
231 size_t str_len,
232 int location_x) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
233
238 const char *str,
239 size_t str_offset,
240 rcti *r_glyph_bounds) ATTR_WARN_UNUSED_RESULT
241 ATTR_NONNULL(2, 4);
242
247 int fontid, const char *str, size_t str_len, size_t str_offset, int cursor_width);
248
254 int fontid, const char *str, size_t str_len, size_t sel_start, size_t sel_length);
255
259size_t BLF_width_to_strlen(int fontid,
260 const char *str,
261 size_t str_len,
262 float width,
263 float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
267size_t BLF_width_to_rstrlen(int fontid,
268 const char *str,
269 size_t str_len,
270 float width,
271 float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
272
277void BLF_boundbox(int fontid,
278 const char *str,
279 size_t str_len,
280 rcti *r_box,
281 ResultBLF *r_info = nullptr) ATTR_NONNULL(2);
282
288float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
290float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
292
300
310bool BLF_bounds_max(int fontid, rctf *r_bounds) ATTR_NONNULL(2);
311
317 int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL();
318
324
328int BLF_glyph_advance(int fontid, const char *str);
329
334void BLF_rotation(int fontid, float angle);
335void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax);
336void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode = BLFWrapMode::Minimal);
337
340 const int max_pixel_width,
342
343void BLF_enable(int fontid, FontFlags flag);
344void BLF_disable(int fontid, FontFlags flag);
345
349bool BLF_is_builtin(int fontid);
350
354void BLF_shadow(int fontid, FontShadowType type, const float rgba[4] = nullptr);
355
362void BLF_shadow_offset(int fontid, int x, int y);
363
369void BLF_buffer(
370 int fontid, float *fbuf, unsigned char *cbuf, int w, int h, const ColorSpace *colorspace);
371
375struct BLFBufferState;
384void BLF_buffer_state_pop(BLFBufferState *buffer_state);
389void BLF_buffer_state_free(BLFBufferState *buffer_state);
390
394void BLF_buffer_col(int fontid, const float srgb_color[4]) ATTR_NONNULL(2);
395
400void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
401 ATTR_NONNULL(2);
402
403/* `blf_thumbs.cc` */
404
410bool BLF_thumb_preview(const char *filepath, unsigned char *buf, int w, int h, int channels)
411 ATTR_NONNULL();
412
413/* `blf_default.cc` */
414
415void BLF_default_size(float size);
416void BLF_default_set(int fontid);
420int BLF_default();
424void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL();
428int BLF_set_default();
429
430/* `blf_font_default.cc` */
431
432int BLF_load_default(bool unique);
433int BLF_load_mono_default(bool unique);
435
436#ifndef NDEBUG
437void BLF_state_print(int fontid);
438#endif
439
440#define BLF_DRAW_STR_DUMMY_MAX 1024
441
442/* XXX, bad design */
443extern int blf_mono_font;
444extern int blf_mono_font_render; /* don't mess drawing with render threads. */
445
449struct ResultBLF {
453 int lines;
457 int width;
458};
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:625
void BLF_state_print(int fontid)
Definition blf.cc:1161
bool BLF_character_to_curves(int fontid, unsigned int unicode, ListBase *nurbsbase, const float scale, bool use_fallback, float *r_advance)
Definition blf.cc:1146
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:443
void BLF_default_set(int fontid)
void BLF_buffer_state_free(BLFBufferState *buffer_state)
Definition blf.cc:1010
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:872
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:320
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:993
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
Definition blf.cc:934
void BLF_aspect(int fontid, float x, float y, float z)
Definition blf.cc:377
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:728
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, const ColorSpace *colorspace)
Definition blf.cc:956
blender::Vector< blender::StringRef > BLF_string_wrap(int fontid, blender::StringRef str, const int max_pixel_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:1061
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:718
void BLF_color3ubv(int fontid, const unsigned char rgb[3])
Definition blf.cc:476
int BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:861
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:837
bool BLF_bounds_max(int fontid, rctf *r_bounds) ATTR_NONNULL(2)
Definition blf.cc:894
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:912
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:1045
void BLF_batch_discard()
Definition blf_font.cc:346
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:789
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:1633
void BLF_color3f(int fontid, float r, float g, float b)
Definition blf.cc:528
char * BLF_display_name_from_id(int fontid)
Definition blf.cc:1093
void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha)
Definition blf.cc:520
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:505
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:646
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:705
bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale)
Definition blf.cc:1103
int BLF_default_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:355
void BLF_shadow_offset(int fontid, int x, int y)
Definition blf.cc:946
void BLF_batch_draw_begin()
Definition blf.cc:534
int blf_mono_font_render
Definition blf.cc:49
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:772
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:815
BLFBufferState * BLF_buffer_state_push(int fontid)
Definition blf.cc:980
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_rotation(int fontid, float angle)
Definition blf.cc:903
int BLF_default()
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:585
void BLF_batch_draw_end()
Definition blf.cc:547
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:664
int BLF_glyph_advance(int fontid, const char *str)
Definition blf.cc:826
void BLF_default_size(float size)
void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:924
void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha)
Definition blf.cc:464
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:207
void BLF_exit()
Definition blf.cc:70
void BLF_buffer_col(int fontid, const float srgb_color[4]) ATTR_NONNULL(2)
Definition blf.cc:1015
int blf_mono_font
Definition blf.cc:48
void BLF_cache_clear()
Definition blf.cc:98
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:540
void BLF_load_font_stack()
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:802
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:329
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:364
void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b)
Definition blf.cc:493
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:850
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:1073
void BLF_color4f(int fontid, float r, float g, float b, float a)
Definition blf.cc:514
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:680
void BLF_color4ubv(int fontid, const unsigned char rgba[4])
Definition blf.cc:452
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:883
blender::ocio::ColorSpace ColorSpace
Definition BLF_api.hh:38
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:347
void BLF_color4ub(int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha)
Definition blf.cc:481
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:388
int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth, int tab_columns) ATTR_NONNULL(2)
Definition blf.cc:607
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:750
BLFWrapMode
Definition BLF_enums.hh:20
FontFlags
Definition BLF_enums.hh:31
FontShadowType
Definition BLF_enums.hh:13
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
unsigned char uchar
unsigned int uint
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)
const char * name
int lines
Definition BLF_api.hh:453
int width
Definition BLF_api.hh:457
uint8_t flag
Definition wm_window.cc:145