19 #include FT_FREETYPE_H
21 #include FT_TRUETYPE_TABLES_H
22 #include FT_MULTIPLE_MASTERS_H
47 # define FT_New_Face FT_New_Face__win32_compat
73 FT_Long
scaled = FT_MulFix(value, font->
face->size->metrics.x_scale);
77 if (font->
face->size->metrics.x_ppem < 25) {
165 if (mat_changed || font_changed || shader_changed) {
199 int remain = gc->
bitmap_len - bitmap_len_landed;
200 int offset_x = bitmap_len_landed % tex_width;
201 int offset_y = bitmap_len_landed / tex_width;
205 int remain_row = tex_width - offset_x;
206 int width = remain > remain_row ? remain_row : remain;
217 bitmap_len_landed +=
width;
295 adjustment +=
g->lsb_delta - ((g_prev) ? g_prev->
rsb_delta : 0);
297 if (FT_HAS_KERNING(font->
face) && g_prev) {
308 FT_Get_Kerning(font->
face, g_prev->
idx,
g->idx, FT_KERNING_UNSCALED, &delta);
334 const size_t str_len,
349 while ((i < str_len) &&
str[i]) {
381 int col, columns = 0;
382 ft_pix pen_x = 0, pen_y = 0;
391 while ((i < str_len) &&
str[i]) {
406 pen_x += cwidth_fpx *
col;
425 const size_t str_len,
436 const float *b_col_float = buf_info->
col_float;
437 const unsigned char *b_col_char = buf_info->
col_char;
443 while ((i < str_len) &&
str[i]) {
461 if ((chx +
g->dims[0]) >= 0 && chx < buf_info->dims[0] &&
464 int width_clip =
g->dims[0];
465 int height_clip =
g->dims[1];
466 int yb_start =
g->pitch < 0 ? 0 :
g->dims[1] - 1;
468 if (width_clip + chx > buf_info->
dims[0]) {
469 width_clip -= chx + width_clip - buf_info->
dims[0];
485 if (buf_info->
fbuf) {
487 for (
y = ((chy >= 0) ? 0 : -chy);
y < height_clip;
y++) {
488 for (
x = ((chx >= 0) ? 0 : -chx);
x < width_clip;
x++) {
489 const char a_byte = *(
g->bitmap +
x + (yb *
g->pitch));
491 const float a = (a_byte / 255.0f) * b_col_float[3];
492 const size_t buf_ofs = (((size_t)(chx +
x) +
493 ((size_t)(pen_y_px +
y) * (size_t)buf_info->
dims[0])) *
494 (
size_t)buf_info->
ch);
495 float *fbuf = buf_info->
fbuf + buf_ofs;
498 font_pixel[0] = b_col_float[0] *
a;
499 font_pixel[1] = b_col_float[1] *
a;
500 font_pixel[2] = b_col_float[2] *
a;
515 if (buf_info->
cbuf) {
517 for (
y = ((chy >= 0) ? 0 : -chy);
y < height_clip;
y++) {
518 for (
x = ((chx >= 0) ? 0 : -chx);
x < width_clip;
x++) {
519 const char a_byte = *(
g->bitmap +
x + (yb *
g->pitch));
522 const float a = (a_byte / 255.0f) * b_col_float[3];
523 const size_t buf_ofs = (((size_t)(chx +
x) +
524 ((size_t)(pen_y_px +
y) * (size_t)buf_info->
dims[0])) *
525 (
size_t)buf_info->
ch);
526 unsigned char *cbuf = buf_info->
cbuf + buf_ofs;
529 font_pixel[0] = b_col_char[0];
530 font_pixel[1] = b_col_char[1];
531 font_pixel[2] = b_col_char[2];
559 const size_t str_len,
591 FontBLF *font,
const char *
str,
const size_t str_len,
int width,
int *r_width)
599 const int width_i = (int)
width;
601 for (i_prev = i = 0, width_new = pen_x = 0, g_prev =
NULL; (i < str_len) &&
str[i];
602 i_prev = i, width_new = pen_x, g_prev =
g) {
619 FontBLF *font,
const char *
str,
const size_t str_len,
int width,
int *r_width)
623 size_t i, i_prev, i_tmp;
624 const char *s, *s_prev;
630 i = (size_t)(s -
str);
632 i_prev = (size_t)(s_prev -
str);
636 for (width_new = pen_x = 0; (s !=
NULL);
637 i = i_prev, s = s_prev,
g = g_prev, g_prev =
NULL, width_new = pen_x) {
639 i_prev = (size_t)(s_prev -
str);
641 if (s_prev !=
NULL) {
669 const size_t str_len,
683 while ((i < str_len) &&
str[i]) {
692 const ft_pix gbox_xmin = pen_x;
693 const ft_pix gbox_xmax = pen_x_next;
694 const ft_pix gbox_ymin =
g->box_ymin + pen_y;
695 const ft_pix gbox_ymax =
g->box_ymax + pen_y;
697 if (gbox_xmin < box_xmin) {
698 box_xmin = gbox_xmin;
700 if (gbox_ymin < box_ymin) {
701 box_ymin = gbox_ymin;
704 if (gbox_xmax > box_xmax) {
705 box_xmax = gbox_xmax;
707 if (gbox_ymax > box_ymax) {
708 box_ymax = gbox_ymax;
715 if (box_xmin > box_xmax) {
742 const size_t str_len,
771 const size_t str_len,
795 const size_t str_len,
828 const size_t str_len,
836 size_t i = 0, i_curr;
844 while ((i < str_len) &&
str[i]) {
857 gbox_px.
ymax = gbox_px.
ymin -
g->dims[1];
858 const int advance_x_px = gbox_px.
xmax - gbox_px.
xmin;
868 if (user_fn(
str, i_curr, &gbox_px, advance_x_px, &box_px,
g->pos,
user_data) ==
false) {
882 const size_t str_len,
909 const size_t str_len,
914 const size_t str_len,
931 struct WordWrapVars {
933 size_t start, last[2];
937 while ((i < str_len) &&
str[i]) {
941 bool do_draw =
false;
962 else if (
UNLIKELY(((i < str_len) &&
str[i]) == 0)) {
964 wrap.last[0] = i + ((
g->c !=
'\n') ? 1 : 0);
969 wrap.last[0] = i_curr + 1;
973 else if (
UNLIKELY(
g->c !=
' ' && (g_prev ? g_prev->
c ==
' ' :
false))) {
974 wrap.last[0] = i_curr;
975 wrap.last[1] = i_curr;
986 pen_y -= line_height;
999 r_info->
lines = lines;
1011 const size_t str_len,
1019 const size_t str_len,
1029 const size_t str_len,
1033 rcti *box = userdata;
1054 const size_t str_len,
1062 const size_t str_len,
1076 const size_t str_len,
1083 while (i < str_len) {
1091 if (FT_Get_Char_Index((font)->face,
c) == 0) {
1109 FT_Face face = font->
face;
1110 if (FT_IS_SCALABLE(face)) {
1111 height_max =
ft_pix_from_int((
int)(face->ascender - face->descender) *
1112 (
int)face->size->metrics.y_ppem) /
1113 (
ft_pix)face->units_per_EM;
1116 height_max = (
ft_pix)face->size->metrics.height;
1130 const FT_Face face = font->
face;
1131 if (FT_IS_SCALABLE(face)) {
1132 width_max =
ft_pix_from_int((
int)(face->bbox.xMax - face->bbox.xMin) *
1133 (
int)face->size->metrics.x_ppem) /
1134 (
ft_pix)face->units_per_EM;
1137 width_max = (
ft_pix)face->size->metrics.max_advance;
1160 if (!font->
face->family_name) {
1177 return FT_Init_FreeType(&
ft_lib);
1182 FT_Done_FreeType(
ft_lib);
1208 for (
int i = 0; i < 16; i++) {
1213 font->
color[0] = 255;
1214 font->
color[1] = 255;
1216 font->
color[3] = 255;
1256 if (
ELEM(
err, FT_Err_Unknown_File_Format, FT_Err_Unimplemented_Feature)) {
1257 printf(
"Format of this font file is not supported\n");
1260 printf(
"Error encountered while opening font file\n");
1266 err = FT_Select_Charmap(font->
face, FT_ENCODING_UNICODE);
1268 err = FT_Select_Charmap(font->
face, FT_ENCODING_APPLE_ROMAN);
1270 if (
err && font->
face->num_charmaps > 0) {
1271 err = FT_Select_Charmap(font->
face, font->
face->charmaps[0]->encoding);
1274 printf(
"Can't set a character map!\n");
1275 FT_Done_Face(font->
face);
1282 err = FT_Attach_File(font->
face, mfile);
1284 fprintf(stderr,
"FT_Attach_File failed to load '%s' with error %d\n", filepath, (
int)
err);
1289 if (FT_HAS_MULTIPLE_MASTERS(font->
face)) {
1298 TT_OS2 *os2_table = (TT_OS2 *)FT_Get_Sfnt_Table(font->
face, FT_SFNT_OS2);
1312 if (FT_IS_FIXED_WIDTH(font->
face)) {
1316 if (FT_HAS_KERNING(font->
face)) {
1333 open.flags = FT_OPEN_MEMORY;
1334 open.memory_base = (
const FT_Byte *)mem;
1335 open.memory_size = mem_size;
1336 FT_Attach_Stream(font->
face, &open);
1345 err = FT_New_Memory_Face(
ft_lib, mem, mem_size, 0, &font->
face);
1351 err = FT_Select_Charmap(font->
face, ft_encoding_unicode);
1353 printf(
"Can't set the unicode character map!\n");
1354 FT_Done_Face(font->
face);
1363 if (FT_HAS_MULTIPLE_MASTERS(font->
face)) {
1367 if (FT_HAS_KERNING(font->
face)) {
1392 FT_Done_Face(font->
face);
1411 FT_F26Dot6 ft_size = lroundf(
size * 64.0f);
1416 if (FT_Set_Char_Size(font->
face, 0, ft_size, dpi, dpi) == FT_Err_Ok) {
1421 printf(
"The current font does not support the size, %f and DPI, %u\n",
size, dpi);
typedef float(TangentPoint)[2]
bool(* BLF_GlyphBoundsFn)(const char *str, size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rcti *glyph_bounds, const int glyph_bearing[2], void *user_data)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
MINLINE void blend_color_mix_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_mix_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
void BLI_rcti_union(struct rcti *rct_a, const struct rcti *rct_b)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Strict compiler flags for areas of code we want to ensure don't do conversions without us knowing abo...
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
size_t size_t int BLI_wcwidth(char32_t ucs) ATTR_WARN_UNUSED_RESULT
pthread_spinlock_t SpinLock
void BLI_spin_init(SpinLock *spin)
void BLI_spin_end(SpinLock *spin)
#define GPU_batch_texture_bind(batch, name, tex)
void GPU_batch_program_set_builtin(GPUBatch *batch, eGPUBuiltinShader shader_id)
#define GPU_BATCH_DISCARD_SAFE(batch)
void GPU_batch_instbuf_set(GPUBatch *, GPUVertBuf *, bool own_vbo)
GPUBatch * GPU_batch_create_ex(GPUPrimType prim, GPUVertBuf *vert, GPUIndexBuf *elem, eGPUBatchFlag owns_flag)
void GPU_batch_draw(GPUBatch *batch)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
void GPU_matrix_pop(void)
#define GPU_matrix_model_view_get(x)
#define GPU_matrix_set(x)
void GPU_matrix_push(void)
void GPU_blend(eGPUBlend blend)
void GPU_texture_update_sub(GPUTexture *tex, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
struct GPUTexture GPUTexture
int GPU_texture_width(const GPUTexture *tex)
void GPU_texture_unbind(GPUTexture *tex)
#define GPU_vertbuf_create_with_format(format)
struct GPUVertBuf GPUVertBuf
void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len)
void GPU_vertbuf_use(GPUVertBuf *)
GPUVertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat *, GPUUsageType)
void GPU_vertbuf_data_len_set(GPUVertBuf *, uint v_len)
void GPU_vertbuf_attr_get_raw_data(GPUVertBuf *, uint a_idx, GPUVertBufRaw *access)
Read Guarded memory(de)allocation.
char * blf_dir_metrics_search(const char *filepath)
static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, BLF_GlyphBoundsFn user_fn, void *user_data, struct ResultBLF *r_info, ft_pix pen_y)
float blf_font_height(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info)
size_t blf_font_width_to_rstrlen(FontBLF *font, const char *str, const size_t str_len, int width, int *r_width)
void blf_batch_draw(void)
static void blf_font_fill(FontBLF *font)
int blf_font_ascender(FontBLF *font)
static void blf_font_draw_buffer__wrap_cb(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, ft_pix pen_y, void *UNUSED(userdata))
static GPUTexture * blf_batch_cache_texture_load(void)
int blf_font_count_missing_chars(FontBLF *font, const char *str, const size_t str_len, int *r_tot_chars)
static SpinLock ft_lib_mutex
static void blf_font_wrap_apply(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info, void(*callback)(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, ft_pix pen_y, void *userdata), void *userdata)
void blf_font_draw_buffer(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info)
BLI_INLINE GlyphBLF * blf_glyph_from_utf8_and_step(FontBLF *font, GlyphCacheBLF *gc, const char *str, size_t str_len, size_t *i_p)
char * blf_display_name(FontBLF *font)
void blf_font_free(FontBLF *font)
void blf_font_boundbox_foreach_glyph(FontBLF *font, const char *str, const size_t str_len, BLF_GlyphBoundsFn user_fn, void *user_data, struct ResultBLF *r_info)
int blf_font_draw_mono(FontBLF *font, const char *str, const size_t str_len, int cwidth)
FontBLF * blf_font_new_from_mem(const char *name, const unsigned char *mem, int mem_size)
static void blf_font_draw_buffer_ex(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, struct ResultBLF *r_info, ft_pix pen_y)
float blf_font_fixed_width(FontBLF *font)
static void blf_font_boundbox_wrap_cb(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, ft_pix pen_y, void *userdata)
static void(* blf_draw_cache_flush)(void)
static void blf_batch_draw_end(void)
void blf_font_boundbox__wrap(FontBLF *font, const char *str, const size_t str_len, rcti *box, struct ResultBLF *r_info)
static void blf_font_boundbox_ex(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, rcti *box, struct ResultBLF *r_info, ft_pix pen_y)
void BLF_cache_flush_set_fn(void(*cache_flush_fn)(void))
FontBLF * blf_font_new(const char *name, const char *filepath)
int blf_font_width_max(FontBLF *font)
void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, int mem_size)
static bool blf_font_width_to_strlen_glyph_process(FontBLF *font, GlyphBLF *g_prev, GlyphBLF *g, ft_pix *pen_x, const int width_i)
static void blf_batch_draw_exit(void)
void blf_batch_draw_begin(FontBLF *font)
bool blf_font_size(FontBLF *font, float size, unsigned int dpi)
static ft_pix blf_font_width_max_ft_pix(struct FontBLF *font)
static void blf_font_draw__wrap_cb(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, ft_pix pen_y, void *UNUSED(userdata))
void blf_font_draw(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info)
void blf_font_width_and_height(FontBLF *font, const char *str, const size_t str_len, float *r_width, float *r_height, struct ResultBLF *r_info)
static ft_pix blf_unscaled_F26Dot6_to_pixels(FontBLF *font, FT_Pos value)
void blf_font_boundbox(FontBLF *font, const char *str, const size_t str_len, rcti *r_box, struct ResultBLF *r_info)
static SpinLock blf_glyph_cache_mutex
void blf_font_draw_buffer__wrap(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info)
static void blf_batch_draw_init(void)
BLI_INLINE ft_pix blf_kerning(FontBLF *font, const GlyphBLF *g_prev, const GlyphBLF *g)
float blf_font_width(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info)
void blf_font_draw__wrap(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info)
size_t blf_font_width_to_strlen(FontBLF *font, const char *str, const size_t str_len, int width, int *r_width)
int blf_font_descender(FontBLF *font)
int blf_font_height_max(FontBLF *font)
static void blf_font_draw_ex(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, struct ResultBLF *r_info, ft_pix pen_y)
static ft_pix blf_font_height_max_ft_pix(struct FontBLF *font)
void blf_glyph_cache_clear(FontBLF *font)
void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, const int x, const int y)
GlyphBLF * blf_glyph_ensure(FontBLF *font, GlyphCacheBLF *gc, uint charcode)
void blf_glyph_cache_release(FontBLF *font)
GlyphCacheBLF * blf_glyph_cache_acquire(FontBLF *font)
BLI_INLINE int ft_pix_to_int_floor(ft_pix v)
#define GLYPH_ASCII_TABLE_SIZE
BLI_INLINE ft_pix ft_pix_from_int(int v)
#define BLF_BATCH_DRAW_LEN_MAX
#define KERNING_CACHE_TABLE_SIZE
BLI_INLINE ft_pix ft_pix_round_advance(ft_pix v, ft_pix step)
BLI_INLINE int ft_pix_to_int(ft_pix v)
#define KERNING_ENTRY_UNSET
BLI_INLINE int ft_pix_to_int_ceil(ft_pix v)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
btMatrix3x3 scaled(const btVector3 &s) const
Create a scaled copy of the matrix.
DEGForeachIDComponentCallback callback
SyclQueue void void size_t num_bytes void
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
MINLINE void zero_v2_int(int r[2])
static struct PartialUpdateUser * wrap(PartialUpdateUserImpl *user)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
struct GPUVertBuf * verts
struct GPUVertBufRaw pos_step col_step offset_step glyph_size_step
struct GlyphCacheBLF * glyph_cache
unsigned int glyph_size_loc
KerningCacheBLF * kerning_cache
SpinLock * glyph_cache_mutex
unsigned char col_char[4]
int ascii_table[KERNING_CACHE_TABLE_SIZE][KERNING_CACHE_TABLE_SIZE]
int wrap_width(const struct SpaceText *st, struct ARegion *region)