Blender V5.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
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.hh"
16#include "BLI_function_ref.hh"
17#include "BLI_string_ref.hh"
18#include "BLI_sys_types.hh"
19#include "BLI_vector.hh"
20
21#include "DNA_listBase.h"
22
23namespace blender {
24
26#define BLF_DATAFILES_FONTS_DIR "fonts"
27
29#define BLF_DEFAULT_PROPORTIONAL_FONT "Inter.woff2"
30
32#define BLF_DEFAULT_MONOSPACED_FONT "DejaVuSansMono.woff2"
33
34struct Nurb;
35struct ResultBLF;
36struct rcti;
37struct rctf;
38
39namespace ocio {
40class ColorSpace;
41} // namespace ocio
43
44int BLF_init();
45void BLF_exit();
46
51void BLF_reset_fonts();
52
53void BLF_cache_clear();
54
58void BLF_cache_flush_set_fn(void (*cache_flush_fn)());
59
67int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
68int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT
69 ATTR_NONNULL(1, 2);
70
71bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
74
82int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
83int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size)
84 ATTR_NONNULL(1, 2);
85
89void BLF_unload(const char *filepath) ATTR_NONNULL(1);
90#if 0 /* Not needed at the moment. */
91void BLF_unload_mem(const char *name) ATTR_NONNULL(1);
92#endif
93
98bool BLF_unload_id(int fontid);
99
100void BLF_unload_all();
101
105void BLF_addref_id(int fontid);
106
108
109char *BLF_display_name_from_id(int fontid);
110
114bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale);
115
116#define BLF_VFONT_METRICS_SCALE_DEFAULT float(1.0 / 1000.0)
117#define BLF_VFONT_METRICS_EM_RATIO_DEFAULT 1.0f
118#define BLF_VFONT_METRICS_ASCEND_RATIO_DEFAULT 0.8f
119
124bool BLF_character_to_curves(int fontid,
125 unsigned int unicode,
126 ListBaseT<Nurb> *nurbsbase,
127 const float scale,
128 bool use_fallback,
129 float *r_advance,
130 rctf *r_bounds);
131
135bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT;
136
140void BLF_metrics_attach(int fontid, const unsigned char *mem, int mem_size) ATTR_NONNULL(2);
141
142void BLF_aspect(int fontid, float x, float y, float z);
143void BLF_position(int fontid, float x, float y, float z);
144void BLF_size(int fontid, float size);
145
149void BLF_character_weight(int fontid, int weight);
150
155
160
161/* Goal: small but useful color API. */
162
163void BLF_color4ubv(int fontid, const unsigned char rgba[4]);
164void BLF_color3ubv(int fontid, const unsigned char rgb[3]);
165void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha);
166void BLF_color4ub(
167 int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha);
168void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b);
169void BLF_color4f(int fontid, float r, float g, float b, float a);
170void BLF_color4fv(int fontid, const float rgba[4]);
171void BLF_color3f(int fontid, float r, float g, float b);
172void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha);
173/* Also available: `theme::font_theme_color_set(fontid, colorid)`. */
174
181void BLF_batch_draw_end();
182
183/* Discard any batching in process and restart.
184 * Only used as a workaround for glitchy driver sync. */
185void BLF_batch_discard();
186
190void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
191 ATTR_NONNULL(2);
192int BLF_draw_mono(int fontid, const char *str, size_t str_len, int char_width, int tab_columns)
193 ATTR_NONNULL(2);
194
195void BLF_draw_svg_icon(uint icon_id,
196 float x,
197 float y,
198 float size,
199 const float color[4] = nullptr,
200 float outline_alpha = 1.0f,
201 bool multicolor = false,
202 FunctionRef<void(std::string &)> edit_source_cb = nullptr);
203
204Array<uchar> BLF_svg_icon_bitmap(uint icon_id,
205 float size,
206 int *r_width,
207 int *r_height,
208 bool multicolor = false,
209 FunctionRef<void(std::string &)> edit_source_cb = nullptr);
210
211using BLF_GlyphBoundsFn = bool (*)(const char *str,
212 size_t str_step_ofs,
213 const rcti *bounds,
214 void *user_dataconst);
215
224void BLF_boundbox_foreach_glyph(int fontid,
225 const char *str,
226 size_t str_len,
227 BLF_GlyphBoundsFn user_fn,
228 void *user_data) ATTR_NONNULL(2);
229
231 int fontid,
232 const char *str,
233 size_t str_len,
234 FunctionRef<void(int index, size_t byte_offset, int byte_len, int advance_x)> callback);
235
240 const char *str,
241 size_t str_len,
242 int location_x) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
243
247bool BLF_str_offset_to_glyph_bounds(int fontid,
248 const char *str,
249 size_t str_offset,
250 rcti *r_glyph_bounds) ATTR_WARN_UNUSED_RESULT
251 ATTR_NONNULL(2, 4);
252
257 int fontid, const char *str, size_t str_len, size_t str_offset, int cursor_width);
258
264 int fontid, const char *str, size_t str_len, size_t sel_start, size_t sel_length);
265
269size_t BLF_width_to_strlen(int fontid,
270 const char *str,
271 size_t str_len,
272 float width,
273 float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
277size_t BLF_width_to_rstrlen(int fontid,
278 const char *str,
279 size_t str_len,
280 float width,
281 float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
282
287void BLF_boundbox(int fontid,
288 const char *str,
289 size_t str_len,
290 rcti *r_box,
291 ResultBLF *r_info = nullptr) ATTR_NONNULL(2);
292
298float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
300float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
302
310
320bool BLF_bounds_max(int fontid, rctf *r_bounds) ATTR_NONNULL(2);
321
327 int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL();
328
334
338int BLF_glyph_advance(int fontid, const char *str);
339
344void BLF_rotation(int fontid, float angle);
345void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax);
346void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode = BLFWrapMode::Minimal);
347
350 const int max_pixel_width,
351 BLFWrapMode mode = BLFWrapMode::Minimal);
352
353void BLF_enable(int fontid, FontFlags flag);
354void BLF_disable(int fontid, FontFlags flag);
355
359bool BLF_is_builtin(int fontid);
360
364void BLF_shadow(int fontid, FontShadowType type, const float rgba[4] = nullptr);
365
372void BLF_shadow_offset(int fontid, int x, int y);
373
379void BLF_buffer(int fontid,
380 float *fbuf,
381 unsigned char *cbuf,
382 int w,
383 int h,
384 int channel_count,
385 const ColorSpace *colorspace);
386
390struct BLFBufferState;
399void BLF_buffer_state_pop(BLFBufferState *buffer_state);
404void BLF_buffer_state_free(BLFBufferState *buffer_state);
405
410void BLF_buffer_col(int fontid, const float srgb_color[4]) ATTR_NONNULL(2);
411
416void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr)
417 ATTR_NONNULL(2);
418
419/* `blf_thumbs.cc` */
420
426bool BLF_thumb_preview(const char *filepath, unsigned char *buf, int w, int h, int channels)
427 ATTR_NONNULL();
428
429/* `blf_default.cc` */
430
431void BLF_default_size(float size);
432void BLF_default_set(int fontid);
436int BLF_default();
440void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL();
444int BLF_set_default();
445
446/* `blf_font_default.cc` */
447
448int BLF_load_default(bool unique);
449int BLF_load_mono_default(bool unique);
451
452#ifndef NDEBUG
453void BLF_state_print(int fontid);
454#endif
455
456#define BLF_DRAW_STR_DUMMY_MAX 1024
457
458/* XXX, bad design */
459extern int blf_mono_font;
460extern int blf_mono_font_render; /* don't mess drawing with render threads. */
461
465struct ResultBLF {
469 int lines;
473 int width;
474};
475
476} // namespace blender
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
These structs are the foundation for all linked lists in the library system.
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
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
#define str(s)
unsigned int uchar
float3x3 scale(float3x3 mat, float2 scale)
BMesh Iterators.
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:805
bool BLF_is_loaded_id(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:172
int BLF_glyph_advance(int fontid, const char *str)
Definition blf.cc:859
void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha)
Definition blf.cc:466
int BLF_load_default(bool unique)
void BLF_shadow_offset(int fontid, int x, int y)
Definition blf.cc:979
void BLF_aspect(int fontid, float x, float y, float z)
Definition blf.cc:379
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
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:835
void BLF_batch_draw_flush()
Definition blf.cc:542
bool BLF_thumb_preview(const char *filepath, unsigned char *buf, int w, int h, int channels) ATTR_NONNULL()
unsigned int uint
Definition BKE_text.h:55
int BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:894
int blf_mono_font_render
Definition blf.cc:51
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
Definition blf.cc:967
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, FunctionRef< void(std::string &)> edit_source_cb=nullptr)
Definition blf.cc:628
void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b)
Definition blf.cc:495
void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:957
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int channel_count, const ColorSpace *colorspace)
Definition blf.cc:989
int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
Definition blf.cc:227
bool BLF_get_vfont_metrics(int fontid, float *ascend_ratio, float *em_ratio, float *scale)
Definition blf.cc:1145
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:761
void BLF_default_set(int fontid)
void BLF_batch_draw_begin()
Definition blf.cc:536
int BLF_load_mono_default(bool unique)
void BLF_reset_fonts()
Definition blf.cc:85
bool BLF_is_loaded_mem(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:167
int bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:162
void BLF_cache_flush_set_fn(void(*cache_flush_fn)())
Definition blf_font.cc:1828
void BLF_character_weight(int fontid, int weight)
Definition blf.cc:349
void BLF_addref_id(int fontid)
Definition blf.cc:313
bool BLF_bounds_max(int fontid, rctf *r_bounds) ATTR_NONNULL(2)
Definition blf.cc:927
void BLF_load_font_stack()
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
void BLF_color4f(int fontid, float r, float g, float b, float a)
Definition blf.cc:516
void BLF_metrics_attach(int fontid, const unsigned char *mem, int mem_size) ATTR_NONNULL(2)
Definition blf.cc:218
int BLF_set_default()
void BLF_size(int fontid, float size)
Definition blf.cc:445
int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:177
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
Definition blf.cc:725
void BLF_color3ubv(int fontid, const unsigned char rgb[3])
Definition blf.cc:478
int BLF_default()
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:870
void BLF_buffer_state_pop(BLFBufferState *buffer_state)
Definition blf.cc:1035
int BLF_default_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:357
bool(*)(const char *str, size_t str_step_ofs, const rcti *bounds, void *user_dataconst) BLF_GlyphBoundsFn
Definition BLF_api.hh:211
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:783
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:945
Vector< StringRef > BLF_string_wrap(int fontid, StringRef str, const int max_pixel_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:1103
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:848
int void BLF_unload(const char *filepath) ATTR_NONNULL(1)
Definition blf.cc:261
void BLF_unload_all()
Definition blf.cc:299
bool BLF_has_variable_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:366
bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:153
void BLF_batch_draw_end()
Definition blf.cc:549
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
int BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:916
int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size) ATTR_NONNULL(1
Definition blf.cc:236
void BLF_color4ubv(int fontid, const unsigned char rgba[4])
Definition blf.cc:454
BLFBufferState * BLF_buffer_state_push(int fontid)
Definition blf.cc:1022
void BLF_state_print(int fontid)
Definition blf.cc:1205
void BLF_buffer_col(int fontid, const float srgb_color[4]) ATTR_NONNULL(2)
Definition blf.cc:1057
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
void BLF_color4ub(int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha)
Definition blf.cc:483
int BLF_draw_mono(int fontid, const char *str, size_t str_len, int char_width, int tab_columns) ATTR_NONNULL(2)
Definition blf.cc:609
bool BLF_character_to_curves(int fontid, unsigned int unicode, ListBaseT< Nurb > *nurbsbase, const float scale, bool use_fallback, float *r_advance, rctf *r_bounds)
Definition blf.cc:1188
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:883
int BLF_init()
Definition blf.cc:63
void BLF_color3f(int fontid, float r, float g, float b)
Definition blf.cc:530
char * BLF_display_name_from_file(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:1115
void BLF_cache_clear()
Definition blf.cc:100
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:905
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:738
int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:190
Array< uchar > BLF_svg_icon_bitmap(uint icon_id, float size, int *r_width, int *r_height, bool multicolor=false, FunctionRef< void(std::string &)> edit_source_cb=nullptr)
Definition blf.cc:667
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:713
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:685
void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:1087
void BLF_buffer_state_free(BLFBufferState *buffer_state)
Definition blf.cc:1052
int blf_mono_font
Definition blf.cc:50
void BLF_info_foreach_glyph(int fontid, const char *str, size_t str_len, FunctionRef< void(int index, size_t byte_offset, int byte_len, int advance_x)> callback)
Definition blf.cc:701
bool ATTR_WARN_UNUSED_RESULT
void ATTR_NONNULL(1, 2)
bool BLF_is_builtin(int fontid)
Definition blf.cc:340
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:822
void BLF_default_size(float size)
void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha)
Definition blf.cc:522
void BLF_rotation(int fontid, float angle)
Definition blf.cc:936
char * BLF_display_name_from_id(int fontid)
Definition blf.cc:1135
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
void BLF_batch_discard()
Definition blf_font.cc:348
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:507
ocio::ColorSpace ColorSpace
Definition BLF_api.hh:42
Vector< 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:751
bool BLF_unload_id(int fontid)
Definition blf.cc:282
void BLF_exit()
Definition blf.cc:72