Blender  V2.93
Classes | Macros | Functions | Variables
font.c File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wctype.h>
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "BLI_vfontdata.h"
#include "BLT_translation.h"
#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_vfont_types.h"
#include "BKE_anim_path.h"
#include "BKE_curve.h"
#include "BKE_font.h"
#include "BKE_global.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_packedFile.h"
#include "BLO_read_write.h"

Go to the source code of this file.

Classes

struct  TempLineInfo
 
struct  VFontToCurveIter
 

Macros

#define ASCENT(vfd)   ((vfd)->ascender * (vfd)->em_height)
 
#define DESCENT(vfd)   ((vfd)->em_height - ASCENT(vfd))
 
#define MARGIN_X_MIN   (xof_scale + tb_scale.x)
 
#define MARGIN_Y_MIN   (yof_scale + tb_scale.y)
 

Functions

static PackedFileget_builtin_packedfile (void)
 
static void vfont_init_data (ID *id)
 
static void vfont_copy_data (Main *UNUSED(bmain), ID *id_dst, const ID *UNUSED(id_src), const int flag)
 
static void vfont_free_data (ID *id)
 
static void vfont_blend_write (BlendWriter *writer, ID *id, const void *id_address)
 
static void vfont_blend_read_data (BlendDataReader *reader, ID *id)
 
void BKE_vfont_free_data (struct VFont *vfont)
 
bool BKE_vfont_is_builtin (struct VFont *vfont)
 
void BKE_vfont_builtin_register (void *mem, int size)
 
static VFontDatavfont_get_data (VFont *vfont)
 
VFontBKE_vfont_load (Main *bmain, const char *filepath)
 
VFontBKE_vfont_load_exists_ex (struct Main *bmain, const char *filepath, bool *r_exists)
 
VFontBKE_vfont_load_exists (struct Main *bmain, const char *filepath)
 
static VFontwhich_vfont (Curve *cu, CharInfo *info)
 
VFontBKE_vfont_builtin_get (void)
 
static VCharfind_vfont_char (VFontData *vfd, unsigned int character)
 
static void build_underline (Curve *cu, ListBase *nubase, const rctf *rect, float yofs, float rot, int charidx, short mat_nr, const float font_size)
 
static void buildchar (Curve *cu, ListBase *nubase, unsigned int character, CharInfo *info, float ofsx, float ofsy, float rot, int charidx, const float fsize)
 
int BKE_vfont_select_get (Object *ob, int *r_start, int *r_end)
 
void BKE_vfont_select_clamp (Object *ob)
 
static float char_width (Curve *cu, VChar *che, CharInfo *info)
 
static void textbox_scale (TextBox *tb_dst, const TextBox *tb_src, float scale)
 
static bool vfont_to_curve (Object *ob, Curve *cu, int mode, VFontToCurveIter *iter_data, ListBase *r_nubase, const char32_t **r_text, int *r_text_len, bool *r_text_free, struct CharTrans **r_chartransdata)
 
bool BKE_vfont_to_curve_ex (Object *ob, Curve *cu, int mode, ListBase *r_nubase, const char32_t **r_text, int *r_text_len, bool *r_text_free, struct CharTrans **r_chartransdata)
 
bool BKE_vfont_to_curve_nubase (Object *ob, int mode, ListBase *r_nubase)
 
bool BKE_vfont_to_curve (Object *ob, int mode)
 

Variables

static CLG_LogRef LOG = {"bke.data_transfer"}
 
static ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER
 
IDTypeInfo IDType_ID_VF
 
static void * builtin_font_data = NULL
 
static int builtin_font_size = 0
 

VFont Scale Overflow

Scale the font to fit inside TextBox bounds.

  • Scale horizontally when TextBox.h is zero, otherwise scale vertically, allowing the text to wrap horizontally.
  • Never increase scale to fit, only ever scale on overflow.
#define FONT_TO_CURVE_SCALE_ITERATIONS   20
 
#define FONT_TO_CURVE_SCALE_THRESHOLD   0.0001f
 
enum  { VFONT_TO_CURVE_INIT = 0 , VFONT_TO_CURVE_BISECT , VFONT_TO_CURVE_SCALE_ONCE , VFONT_TO_CURVE_DONE }
 
typedef struct VFontToCurveIter VFontToCurveIter
 

VFont Clipboard

struct {
   char32_t *   text_buffer
 
   CharInfo *   info_buffer
 
   size_t   len_utf32
 
   size_t   len_utf8
 
g_vfont_clipboard = {NULL}
 
void BKE_vfont_clipboard_free (void)
 
void BKE_vfont_clipboard_set (const char32_t *text_buf, const CharInfo *info_buf, const size_t len)
 
void BKE_vfont_clipboard_get (char32_t **r_text_buf, CharInfo **r_info_buf, size_t *r_len_utf8, size_t *r_len_utf32)
 

Macro Definition Documentation

◆ ASCENT

#define ASCENT (   vfd)    ((vfd)->ascender * (vfd)->em_height)

Font metric values explained:

Baseline: Line where the text "rests", used as the origin vertical position for the glyphs. Em height: Space most glyphs should fit within. Ascent: the recommended distance above the baseline to fit most characters. Descent: the recommended distance below the baseline to fit most characters.

We obtain ascent and descent from the font itself (FT_Face->ascender / face->height). And in some cases it is even the same value as FT_Face->bbox.yMax/yMin (font top and bottom respectively).

The em_height here is relative to FT_Face->bbox.

Definition at line 757 of file font.c.

◆ DESCENT

#define DESCENT (   vfd)    ((vfd)->em_height - ASCENT(vfd))

Definition at line 758 of file font.c.

◆ FONT_TO_CURVE_SCALE_ITERATIONS

#define FONT_TO_CURVE_SCALE_ITERATIONS   20

Definition at line 738 of file font.c.

◆ FONT_TO_CURVE_SCALE_THRESHOLD

#define FONT_TO_CURVE_SCALE_THRESHOLD   0.0001f

Definition at line 739 of file font.c.

◆ MARGIN_X_MIN

#define MARGIN_X_MIN   (xof_scale + tb_scale.x)

◆ MARGIN_Y_MIN

#define MARGIN_Y_MIN   (yof_scale + tb_scale.y)

Typedef Documentation

◆ VFontToCurveIter

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
VFONT_TO_CURVE_INIT 
VFONT_TO_CURVE_BISECT 
VFONT_TO_CURVE_SCALE_ONCE 
VFONT_TO_CURVE_DONE 

Definition at line 731 of file font.c.

Function Documentation

◆ BKE_vfont_builtin_get()

VFont* BKE_vfont_builtin_get ( void  )

◆ BKE_vfont_builtin_register()

void BKE_vfont_builtin_register ( void *  mem,
int  size 
)

Definition at line 227 of file font.c.

References builtin_font_data, builtin_font_size, and size().

Referenced by main().

◆ BKE_vfont_clipboard_free()

void BKE_vfont_clipboard_free ( void  )

Definition at line 1761 of file font.c.

References g_vfont_clipboard, and MEM_SAFE_FREE.

Referenced by BKE_vfont_clipboard_set(), paste_text_exec(), and WM_exit_ex().

◆ BKE_vfont_clipboard_get()

void BKE_vfont_clipboard_get ( char32_t **  r_text_buf,
CharInfo **  r_info_buf,
size_t *  r_len_utf8,
size_t *  r_len_utf32 
)

Definition at line 1799 of file font.c.

References g_vfont_clipboard.

Referenced by copy_selection(), paste_selection(), and paste_text_exec().

◆ BKE_vfont_clipboard_set()

void BKE_vfont_clipboard_set ( const char32_t *  text_buf,
const CharInfo info_buf,
const size_t  len 
)

◆ BKE_vfont_free_data()

void BKE_vfont_free_data ( struct VFont vfont)

◆ BKE_vfont_is_builtin()

bool BKE_vfont_is_builtin ( struct VFont vfont)

◆ BKE_vfont_load()

VFont* BKE_vfont_load ( Main bmain,
const char *  filepath 
)

◆ BKE_vfont_load_exists()

VFont* BKE_vfont_load_exists ( struct Main bmain,
const char *  filepath 
)

Definition at line 393 of file font.c.

References BKE_vfont_load_exists_ex(), and NULL.

◆ BKE_vfont_load_exists_ex()

VFont* BKE_vfont_load_exists_ex ( struct Main bmain,
const char *  filepath,
bool *  r_exists 
)

◆ BKE_vfont_select_clamp()

void BKE_vfont_select_clamp ( Object ob)

◆ BKE_vfont_select_get()

int BKE_vfont_select_get ( Object ob,
int *  r_start,
int *  r_end 
)

◆ BKE_vfont_to_curve()

bool BKE_vfont_to_curve ( Object ob,
int  mode 
)

Warning: expects to have access to evaluated data (i.e. passed object should be evaluated one...).

Definition at line 1743 of file font.c.

References BKE_vfont_to_curve_ex(), Object::data, NULL, and Curve::nurb.

Referenced by move_cursor(), and text_update_edited().

◆ BKE_vfont_to_curve_ex()

bool BKE_vfont_to_curve_ex ( Object ob,
Curve cu,
int  mode,
ListBase r_nubase,
const char32_t **  r_text,
int *  r_text_len,
bool *  r_text_free,
struct CharTrans **  r_chartransdata 
)

◆ BKE_vfont_to_curve_nubase()

bool BKE_vfont_to_curve_nubase ( Object ob,
int  mode,
ListBase r_nubase 
)

◆ build_underline()

static void build_underline ( Curve cu,
ListBase nubase,
const rctf rect,
float  yofs,
float  rot,
int  charidx,
short  mat_nr,
const float  font_size 
)
static

◆ buildchar()

static void buildchar ( Curve cu,
ListBase nubase,
unsigned int  character,
CharInfo info,
float  ofsx,
float  ofsy,
float  rot,
int  charidx,
const float  fsize 
)
static

◆ char_width()

static float char_width ( Curve cu,
VChar che,
CharInfo info 
)
static

Definition at line 669 of file font.c.

References CU_CHINFO_SMALLCAPS_CHECK, CharInfo::flag, NULL, Curve::smallcaps_scale, and VChar::width.

Referenced by vfont_to_curve().

◆ find_vfont_char()

static VChar* find_vfont_char ( VFontData vfd,
unsigned int  character 
)
static

Definition at line 425 of file font.c.

References BLI_ghash_lookup(), VFontData::characters, and POINTER_FROM_UINT.

Referenced by buildchar(), and vfont_to_curve().

◆ get_builtin_packedfile()

static PackedFile * get_builtin_packedfile ( void  )
static

◆ textbox_scale()

static void textbox_scale ( TextBox tb_dst,
const TextBox tb_src,
float  scale 
)
static

Definition at line 682 of file font.c.

References TextBox::h, TextBox::w, TextBox::x, and TextBox::y.

Referenced by vfont_to_curve().

◆ vfont_blend_read_data()

static void vfont_blend_read_data ( BlendDataReader reader,
ID id 
)
static

Definition at line 148 of file font.c.

References BKE_packedfile_blend_read(), VFont::data, NULL, VFont::packedfile, and VFont::temp_pf.

◆ vfont_blend_write()

static void vfont_blend_write ( BlendWriter writer,
ID id,
const void *  id_address 
)
static

◆ vfont_copy_data()

static void vfont_copy_data ( Main UNUSEDbmain,
ID id_dst,
const ID UNUSEDid_src,
const int  flag 
)
static

◆ vfont_free_data()

static void vfont_free_data ( ID id)
static

Free (or release) any data used by this font (does not free the font itself).

Definition at line 114 of file font.c.

References BKE_packedfile_free(), BKE_vfont_free_data(), NULL, and VFont::packedfile.

◆ vfont_get_data()

static VFontData* vfont_get_data ( VFont vfont)
static

◆ vfont_init_data()

static void vfont_init_data ( ID id)
static

◆ vfont_to_curve()

static bool vfont_to_curve ( Object ob,
Curve cu,
int  mode,
VFontToCurveIter iter_data,
ListBase r_nubase,
const char32_t **  r_text,
int *  r_text_len,
bool *  r_text_free,
struct CharTrans **  r_chartransdata 
)
static

Definition at line 760 of file font.c.

References Curve::align_y, CurveCache::anim_path_accum_length, ASCENT, atan2f, VFontToCurveIter::bisect, BKE_anim_path_get_length(), BKE_nurbList_free(), BKE_vfont_is_builtin(), BKE_vfont_select_get(), BKE_where_on_path(), BLI_assert, BLI_rw_mutex_lock(), BLI_rw_mutex_unlock(), BLI_str_utf8_as_utf32(), BLI_vfontchar_from_freetypefont(), build_underline(), buildchar(), ceilf, TempLineInfo::char_nr, char_width(), CLAMP, CLAMP_MIN, compare_ff_relative(), copy_m3_m4(), cosf, CU_ALIGN_X_FLUSH, CU_ALIGN_X_JUSTIFY, CU_ALIGN_X_LEFT, CU_ALIGN_X_MIDDLE, CU_ALIGN_X_RIGHT, CU_ALIGN_Y_BOTTOM, CU_ALIGN_Y_BOTTOM_BASELINE, CU_ALIGN_Y_CENTER, CU_ALIGN_Y_TOP, CU_ALIGN_Y_TOP_BASELINE, CU_CHINFO_OVERFLOW, CU_CHINFO_SMALLCAPS, CU_CHINFO_SMALLCAPS_CHECK, CU_CHINFO_UNDERLINE, CU_CHINFO_WRAP, CU_OVERFLOW_NONE, CU_OVERFLOW_SCALE, CU_OVERFLOW_TRUNCATE, Object_Runtime::curve_cache, DESCENT, CharTrans::dobreak, Curve::editfont, ELEM, VFontData::em_height, find_vfont_char(), CharInfo::flag, float(), FO_CURSDOWN, FO_CURSUP, FO_EDIT, FO_PAGEDOWN, FO_PAGEUP, FO_SELCHANGE, FONT_TO_CURVE_SCALE_THRESHOLD, Curve::fsize, Curve::fsize_realtime, EditFontSelBox::h, TextBox::h, invert_m4_m4(), VFontToCurveIter::iteraction, CharInfo::kern, EditFont::len, Curve::len_char32, Curve::linedist, CharTrans::linenr, Curve::lines, M_PI, MARGIN_X_MIN, MARGIN_Y_MIN, CharInfo::mat_nr, VFontToCurveIter::max, MAX2, MAXTEXTBOX, MEM_calloc_arrayN, MEM_callocN, MEM_freeN, MEM_malloc_arrayN, VFontToCurveIter::min, Object::mode, mul_m3_m3m3(), mul_v3_fl(), normalize_v3(), NULL, OB_CURVE, OB_FONT, OB_MODE_EDIT, Object::obmat, Curve::overflow, EditFont::pos, EditFontSelBox::rot, Object::runtime, VFontToCurveIter::scale_to_fit, EditFont::selboxes, EditFont::selboxes_len, sinf, Curve::spacemode, Curve::spacing, VFontToCurveIter::status, Curve::str, Curve::strinfo, Curve::tb, textbox_scale(), EditFont::textbuf, EditFont::textbufinfo, EditFont::textcurs, Curve::textoncurve, THREAD_LOCK_READ, THREAD_LOCK_WRITE, Curve::totbox, Object::totcol, Object::type, Curve::ulheight, Curve::ulpos, unit_m4(), Curve::vfont, vfont_get_data(), vfont_rwlock, VFONT_TO_CURVE_BISECT, VFONT_TO_CURVE_DONE, VFONT_TO_CURVE_INIT, VFONT_TO_CURVE_SCALE_ONCE, EditFontSelBox::w, TextBox::w, which_vfont(), VFontToCurveIter::word_wrap, Curve::wordspace, TempLineInfo::wspace_nr, EditFontSelBox::x, TextBox::x, TempLineInfo::x_max, TempLineInfo::x_min, rctf::xmax, rctf::xmin, CharTrans::xof, Curve::xof, EditFontSelBox::y, TextBox::y, rctf::ymax, rctf::ymin, CharTrans::yof, and Curve::yof.

Referenced by BKE_vfont_to_curve_ex().

◆ which_vfont()

static VFont* which_vfont ( Curve cu,
CharInfo info 
)
static

Variable Documentation

◆ builtin_font_data

void* builtin_font_data = NULL
static

Definition at line 219 of file font.c.

Referenced by BKE_vfont_builtin_register(), and get_builtin_packedfile().

◆ builtin_font_size

int builtin_font_size = 0
static

Definition at line 220 of file font.c.

Referenced by BKE_vfont_builtin_register(), and get_builtin_packedfile().

◆ 

struct { ... } g_vfont_clipboard

◆ IDType_ID_VF

IDTypeInfo IDType_ID_VF
Initial value:
= {
.id_code = ID_VF,
.id_filter = FILTER_ID_VF,
.main_listbase_index = INDEX_ID_VF,
.struct_size = sizeof(VFont),
.name = "Font",
.name_plural = "fonts",
.translation_context = BLT_I18NCONTEXT_ID_VFONT,
.copy_data = vfont_copy_data,
.free_data = vfont_free_data,
.make_local = NULL,
.foreach_id = NULL,
.foreach_cache = NULL,
.owner_get = NULL,
.blend_write = vfont_blend_write,
.blend_read_data = vfont_blend_read_data,
.blend_read_lib = NULL,
.blend_read_expand = NULL,
.blend_read_undo_preserve = NULL,
.lib_override_apply_post = NULL,
}
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition: BKE_idtype.h:51
#define BLT_I18NCONTEXT_ID_VFONT
#define FILTER_ID_VF
Definition: DNA_ID.h:730
@ INDEX_ID_VF
Definition: DNA_ID.h:801
@ ID_VF
Definition: DNA_ID_enums.h:73
struct VFont VFont
static void init_data(ModifierData *md)
static void vfont_init_data(ID *id)
Definition: font.c:71
static void vfont_blend_read_data(BlendDataReader *reader, ID *id)
Definition: font.c:148
static void vfont_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: font.c:125
static void vfont_free_data(ID *id)
Definition: font.c:114
static void vfont_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *UNUSED(id_src), const int flag)
Definition: font.c:91

Definition at line 156 of file font.c.

◆ info_buffer

CharInfo* info_buffer

Definition at line 1756 of file font.c.

◆ len_utf32

size_t len_utf32

Definition at line 1757 of file font.c.

◆ len_utf8

size_t len_utf8

Definition at line 1758 of file font.c.

Referenced by copy_selection(), and paste_text_exec().

◆ LOG

CLG_LogRef LOG = {"bke.data_transfer"}
static

Definition at line 62 of file font.c.

Referenced by get_builtin_packedfile(), and vfont_get_data().

◆ text_buffer

char32_t* text_buffer

Definition at line 1755 of file font.c.

◆ vfont_rwlock

ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER
static

Definition at line 63 of file font.c.

Referenced by vfont_get_data(), and vfont_to_curve().