Blender V5.0
vfont_curve.cc File Reference
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cwctype>
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
#include "BLI_listbase.h"
#include "BLI_math_base_safe.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_rect.h"
#include "BLI_string_utf8.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_vfont_types.h"
#include "BKE_anim_path.h"
#include "BKE_curve.hh"
#include "BKE_object_types.hh"
#include "BKE_vfont.hh"
#include "BKE_vfontdata.hh"

Go to the source code of this file.

Classes

struct  VCharPlaceHolder
struct  VFontToCurveIter
struct  VFontCursor_Params
struct  VFontInfoContext
struct  TextBoxBounds_ForCursor
struct  TempLineInfo

Macros

#define MARGIN_X_MIN   (cu_offset_scale.x + tb_scale.x)
#define MARGIN_Y_MIN   (cu_offset_scale.y + tb_scale.y)

Functions

Private Utilities
static void mid_v2v2 (float a[2], float b[2])
static float vfont_metrics_ascent (const VFontData_Metrics *metrics)
static float vfont_metrics_descent (const VFontData_Metrics *metrics)
static VFontvfont_from_charinfo (const Curve &cu, const CharInfo *info)
static VFontDatavfont_data_ensure_with_lock (VFont *vfont)
static bool vfont_char_find (const VFontData *vfd, char32_t charcode, VChar **r_che)
static VCharvfont_char_ensure_with_lock (VFont *vfont, char32_t charcode)
VFont to Curve: Character Placeholder

Simple utility to create a dummy VChar on demand which can be used when the character's glyph isn't available.

static VCharvfont_placeholder_ensure (VCharPlaceHolder &che_placeholder, char32_t charcode)
static VCharvfont_char_find_or_placeholder (const VFontData *vfd, char32_t charcode, VCharPlaceHolder &che_placeholder)
VFont Build Character
static Nurbbuild_underline (const Curve &cu, ListBase *nubase, const rctf *rect, const float yofs, const float rotate, const int charidx, const short mat_nr, const float font_size, Nurb *ul_prev_nu)
static void vfont_char_build_impl (const Curve &cu, ListBase *nubase, const VChar *che, const CharInfo *info, const bool is_smallcaps, const blender::float2 &offset, const float rotate, const int charidx, const float fsize)
void BKE_vfont_char_build (const Curve &cu, ListBase *nubase, uint charcode, const CharInfo *info, const bool is_smallcaps, const blender::float2 &offset, float rotate, int charidx, const float fsize)
static float vfont_char_width (const Curve &cu, VChar *che, const bool is_smallcaps)
static char32_t vfont_char_apply_smallcaps (char32_t charcode, const bool is_smallcaps)
static void textbox_scale (TextBox *tb_dst, const TextBox *tb_src, float scale)
VFont to Curve: Info Context
static void vfont_info_context_init (VFontInfoContext *vfinfo_ctx, const Curve &cu)
static void vfont_info_context_update (VFontInfoContext *vfinfo_ctx, const Curve &cu, const CharInfo *info)
VFont to Curve: 3D Text Layout Implementation
static bool vfont_to_curve (Object *ob, const Curve &cu, const eEditFontMode mode, VFontToCurveIter &iter_data, VFontCursor_Params *cursor_params, ListBase *r_nubase, const char32_t **r_text, int *r_text_len, bool *r_text_free, CharTrans **r_chartransdata, float *r_font_size_eval)
VFont to Curve Public API

Access to 3D text layout.

bool BKE_vfont_to_curve_ex (Object *ob, const Curve &cu, const eEditFontMode mode, ListBase *r_nubase, const char32_t **r_text, int *r_text_len, bool *r_text_free, CharTrans **r_chartransdata, float *r_font_size_eval)
int BKE_vfont_cursor_to_text_index (Object *ob, const blender::float2 &cursor_location)
bool BKE_vfont_to_curve_nubase (Object *ob, const eEditFontMode mode, ListBase *r_nubase)
bool BKE_vfont_to_curve (Object *ob, const eEditFontMode mode)

Variables

static ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER

VFont to Curve: Mouse Cursor to Text Offset

This is an optional argument to vfont_to_curve for getting the text offset into the string at a mouse cursor location. Used for getting text cursor (caret) position or selection range.

#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 }

Detailed Description

Utilities relating to converting VFont's to curves as well as 3D text object layout.

Definition in file vfont_curve.cc.

Macro Definition Documentation

◆ FONT_TO_CURVE_SCALE_ITERATIONS

#define FONT_TO_CURVE_SCALE_ITERATIONS   20

Definition at line 595 of file vfont_curve.cc.

Referenced by BKE_vfont_cursor_to_text_index(), and BKE_vfont_to_curve_ex().

◆ FONT_TO_CURVE_SCALE_THRESHOLD

#define FONT_TO_CURVE_SCALE_THRESHOLD   0.0001f

Definition at line 596 of file vfont_curve.cc.

Referenced by vfont_to_curve().

◆ MARGIN_X_MIN

#define MARGIN_X_MIN   (cu_offset_scale.x + tb_scale.x)

Referenced by vfont_to_curve().

◆ MARGIN_Y_MIN

#define MARGIN_Y_MIN   (cu_offset_scale.y + tb_scale.y)

Referenced by vfont_to_curve().

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 588 of file vfont_curve.cc.

Function Documentation

◆ BKE_vfont_char_build()

void BKE_vfont_char_build ( const Curve & cu,
ListBase * nubase,
uint charcode,
const CharInfo * info,
const bool is_smallcaps,
const blender::float2 & offset,
float rotate,
int charidx,
const float fsize )

◆ BKE_vfont_cursor_to_text_index()

◆ BKE_vfont_to_curve()

bool BKE_vfont_to_curve ( Object * ob,
eEditFontMode mode )
Warning
Expects to have access to evaluated data (i.e. passed object should be evaluated one).

Definition at line 1921 of file vfont_curve.cc.

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

Referenced by move_cursor(), and text_update_edited().

◆ BKE_vfont_to_curve_ex()

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

◆ BKE_vfont_to_curve_nubase()

bool BKE_vfont_to_curve_nubase ( Object * ob,
const eEditFontMode mode,
ListBase * r_nubase )

◆ build_underline()

Nurb * build_underline ( const Curve & cu,
ListBase * nubase,
const rctf * rect,
const float yofs,
const float rotate,
const int charidx,
const short mat_nr,
const float font_size,
Nurb * ul_prev_nu )
static
Parameters
ul_prev_nuThe previous adjacent underline which has it's right edge welded with this underlines left edge to prevent gaps or overlapping geometry which can cause Z-fighting.
Returns
The shape used for the underline which may be passed in as the ul_prev_nu in future calls to this function.

Definition at line 301 of file vfont_curve.cc.

References Nurb::bezt, BLI_addtail(), Nurb::bp, Nurb::charidx, copy_v4_fl4(), cosf, CU_NURB_CYCLIC, Nurb::flagu, i, Nurb::knotsu, Nurb::knotsv, Nurb::mat_nr, MEM_calloc_arrayN(), MEM_callocN(), mid_v2v2(), mul_v2_fl(), Nurb::orderu, Nurb::orderv, Nurb::pntsu, Nurb::pntsv, BPoint::radius, Curve::resolu, Nurb::resolu, rotate(), sinf, BPoint::vec, x, rctf::xmax, rctf::xmin, y, rctf::ymax, and rctf::ymin.

Referenced by vfont_to_curve().

◆ mid_v2v2()

void mid_v2v2 ( float a[2],
float b[2] )
static

Calculate the mid-point between two points and assign it to both of them.

Definition at line 55 of file vfont_curve.cc.

References b.

Referenced by build_underline().

◆ textbox_scale()

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

Definition at line 529 of file vfont_curve.cc.

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

Referenced by vfont_to_curve().

◆ vfont_char_apply_smallcaps()

char32_t vfont_char_apply_smallcaps ( char32_t charcode,
const bool is_smallcaps )
static

Definition at line 521 of file vfont_curve.cc.

References UNLIKELY.

Referenced by vfont_to_curve().

◆ vfont_char_build_impl()

void vfont_char_build_impl ( const Curve & cu,
ListBase * nubase,
const VChar * che,
const CharInfo * info,
const bool is_smallcaps,
const blender::float2 & offset,
const float rotate,
const int charidx,
const float fsize )
static

◆ vfont_char_ensure_with_lock()

VChar * vfont_char_ensure_with_lock ( VFont * vfont,
char32_t charcode )
static

Find the character or lazily initialize it.

The intended use-case for this function is that characters are initialized once. Any future access can then use vfont_char_find or vfont_char_find_or_placeholder.

Definition at line 127 of file vfont_curve.cc.

References BKE_vfontdata_char_from_freetypefont(), BLI_rw_mutex_lock(), BLI_rw_mutex_unlock(), VFont::data, THREAD_LOCK_READ, THREAD_LOCK_WRITE, vfont_char_find(), and vfont_rwlock.

Referenced by vfont_to_curve().

◆ vfont_char_find()

bool vfont_char_find ( const VFontData * vfd,
char32_t charcode,
VChar ** r_che )
static

◆ vfont_char_find_or_placeholder()

VChar * vfont_char_find_or_placeholder ( const VFontData * vfd,
char32_t charcode,
VCharPlaceHolder & che_placeholder )
static

A version of vfont_char_find that returns a place-holder if the glyph cannot be found.

Definition at line 273 of file vfont_curve.cc.

References UNLIKELY, vfont_char_find(), and vfont_placeholder_ensure().

Referenced by vfont_to_curve().

◆ vfont_char_width()

float vfont_char_width ( const Curve & cu,
VChar * che,
const bool is_smallcaps )
static

Definition at line 508 of file vfont_curve.cc.

References Curve::smallcaps_scale, and VChar::width.

Referenced by vfont_to_curve().

◆ vfont_data_ensure_with_lock()

◆ vfont_from_charinfo()

VFont * vfont_from_charinfo ( const Curve & cu,
const CharInfo * info )
static

◆ vfont_info_context_init()

void vfont_info_context_init ( VFontInfoContext * vfinfo_ctx,
const Curve & cu )
static

◆ vfont_info_context_update()

void vfont_info_context_update ( VFontInfoContext * vfinfo_ctx,
const Curve & cu,
const CharInfo * info )
static

◆ vfont_metrics_ascent()

float vfont_metrics_ascent ( const VFontData_Metrics * metrics)
static

◆ vfont_metrics_descent()

float vfont_metrics_descent ( const VFontData_Metrics * metrics)
static

Definition at line 65 of file vfont_curve.cc.

References VFontData_Metrics::em_ratio, and vfont_metrics_ascent().

Referenced by vfont_to_curve().

◆ vfont_placeholder_ensure()

VChar * vfont_placeholder_ensure ( VCharPlaceHolder & che_placeholder,
char32_t charcode )
static

◆ vfont_to_curve()

bool vfont_to_curve ( Object * ob,
const Curve & cu,
const eEditFontMode mode,
VFontToCurveIter & iter_data,
VFontCursor_Params * cursor_params,
ListBase * r_nubase,
const char32_t ** r_text,
int * r_text_len,
bool * r_text_free,
CharTrans ** r_chartransdata,
float * r_font_size_eval )
static

This function implements text layout & formatting with font styles, text boxes as well as text cursor placement.

Definition at line 669 of file vfont_curve.cc.

References Curve::align_y, atan2f, VFontToCurveIter::bisect, BKE_anim_path_get_length(), BKE_nurbList_free(), BKE_vfont_select_get(), BKE_vfontdata_metrics_get_defaults(), BKE_where_on_path(), BLI_assert, BLI_assert_msg, BLI_rctf_mul(), BLI_str_utf8_as_utf32(), bounds(), TextBoxBounds_ForCursor::bounds, build_underline(), ceilf, TextBoxBounds_ForCursor::char_index_last, TempLineInfo::char_nr, CLAMP, clamp_f(), 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_SMALLCAPS, CU_CHINFO_STYLE_ALL, CU_CHINFO_UNDERLINE, CU_OVERFLOW_NONE, CU_OVERFLOW_SCALE, CU_OVERFLOW_TRUNCATE, VFontCursor_Params::cursor_location, blender::math::distance_squared(), CharTrans::do_break, Curve::editfont, ELEM, VFontData_Metrics::em_ratio, CharInfo::flag, flag, float, FLT_MAX, FO_CURS, FO_CURS_IS_MOTION, FO_CURSDOWN, FO_CURSUP, FO_DUPLI, FO_EDIT, FO_LINE_BEGIN, FO_LINE_END, FO_PAGEDOWN, FO_PAGEUP, FO_SELCHANGE, EditFont::font_size_eval, FONT_TO_CURVE_SCALE_THRESHOLD, Curve::fsize, EditFontSelBox::h, TextBox::h, i, invert_m4_m4(), VFontToCurveIter::iteration, CharInfo::kern, EditFont::len, Curve::len_char32, Curve::linedist, CharTrans::linenr, M_PI, MARGIN_X_MIN, MARGIN_Y_MIN, CharInfo::mat_nr, VFontToCurveIter::max, max_ff(), max_ii(), MEM_calloc_arrayN(), MEM_freeN(), MEM_malloc_arrayN(), VFontData::metrics, VFontToCurveIter::min, min_ff(), min_ii(), Object::mode, mul_m3_m3m3(), mul_v3_fl(), normalize_v3(), OB_CURVES_LEGACY, OB_FONT, OB_MODE_EDIT, CharTrans::offset, Curve::overflow, EditFont::pos, VFontCursor_Params::r_string_offset, CharTrans::rotate, EditFontSelBox::rotate, rotate_v2_v2fl(), Object::runtime, safe_divide(), VFontToCurveIter::scale_to_fit, EditFont::selboxes, EditFont::selboxes_len, EditFont::select_char_info_flag, EditFont::selend, EditFont::selstart, sinf, Curve::spacemode, Curve::spacing, VFontToCurveIter::status, Curve::str, Curve::strinfo, Curve::tb, textbox_scale(), EditFont::textbuf, EditFont::textbufinfo, EditFont::textcurs, Curve::textoncurve, Curve::totbox, Object::type, Curve::ulheight, Curve::ulpos, unit_m4(), UNLIKELY, VFontInfoContext::vfd, VFontInfoContext::vfont, vfont_char_apply_smallcaps(), vfont_char_build_impl(), vfont_char_ensure_with_lock(), vfont_char_find_or_placeholder(), vfont_char_width(), vfont_info_context_init(), vfont_info_context_update(), vfont_metrics_ascent(), vfont_metrics_descent(), vfont_placeholder_ensure(), VFONT_TO_CURVE_BISECT, VFONT_TO_CURVE_DONE, VFONT_TO_CURVE_INIT, VFONT_TO_CURVE_SCALE_ONCE, EditFontSelBox::w, TextBox::w, VFontToCurveIter::word_wrap, Curve::wordspace, TempLineInfo::wspace_nr, EditFontSelBox::x, TextBox::x, TempLineInfo::x_max, TempLineInfo::x_min, rctf::xmax, rctf::xmin, Curve::xof, EditFontSelBox::y, TextBox::y, rctf::ymax, rctf::ymin, and Curve::yof.

Referenced by BKE_vfont_cursor_to_text_index(), and BKE_vfont_to_curve_ex().

Variable Documentation

◆ vfont_rwlock

ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER
static

Locking on when manipulating the VFont because multiple objects may share a VFont. Depsgraph evaluation can evaluate multiple objects in different threads, so any changes to the VFont (such as glyph cache) must use locking.

Definition at line 46 of file vfont_curve.cc.

Referenced by vfont_char_ensure_with_lock(), and vfont_data_ensure_with_lock().