Cleanup: pass a curve to BKE_vfont_select_* instead of an object

Let callers use a curve without depending on the object.
This commit is contained in:
Campbell Barton
2025-08-25 06:20:08 +00:00
parent 352575d620
commit 88129ffa6b
5 changed files with 28 additions and 28 deletions

View File

@@ -101,8 +101,8 @@ VFont *BKE_vfont_load(Main *bmain, const char *filepath);
VFont *BKE_vfont_load_exists_ex(Main *bmain, const char *filepath, bool *r_exists);
VFont *BKE_vfont_load_exists(Main *bmain, const char *filepath);
int BKE_vfont_select_get(Object *ob, int *r_start, int *r_end);
void BKE_vfont_select_clamp(Object *ob);
int BKE_vfont_select_get(const Curve *cu, int *r_start, int *r_end);
void BKE_vfont_select_clamp(Curve *cu);
void BKE_vfont_clipboard_free();
void BKE_vfont_clipboard_set(const char32_t *text_buf, const CharInfo *info_buf, size_t len);

View File

@@ -404,13 +404,12 @@ VFont *BKE_vfont_builtin_ensure()
/** \name VFont Selection
* \{ */
int BKE_vfont_select_get(Object *ob, int *r_start, int *r_end)
int BKE_vfont_select_get(const Curve *cu, int *r_start, int *r_end)
{
Curve *cu = static_cast<Curve *>(ob->data);
EditFont *ef = cu->editfont;
int start, end, direction;
if ((ob->type != OB_FONT) || (ef == nullptr)) {
if (ef == nullptr || (cu->ob_type != OB_FONT)) {
return 0;
}
@@ -444,12 +443,11 @@ int BKE_vfont_select_get(Object *ob, int *r_start, int *r_end)
return direction;
}
void BKE_vfont_select_clamp(Object *ob)
void BKE_vfont_select_clamp(Curve *cu)
{
Curve *cu = static_cast<Curve *>(ob->data);
EditFont *ef = cu->editfont;
BLI_assert((ob->type == OB_FONT) && ef);
BLI_assert((cu->ob_type == OB_FONT) && ef);
CLAMP_MAX(ef->pos, ef->len);
CLAMP_MAX(ef->selstart, ef->len + 1);

View File

@@ -778,7 +778,7 @@ static bool vfont_to_curve(Object *ob,
MEM_freeN(ef->selboxes);
}
if (BKE_vfont_select_get(ob, &selstart, &selend)) {
if (BKE_vfont_select_get(cu, &selstart, &selend)) {
ef->selboxes_len = (selend - selstart) + 1;
ef->selboxes = MEM_calloc_arrayN<EditFontSelBox>(ef->selboxes_len, "font selboxes");
}

View File

@@ -437,7 +437,7 @@ static int kill_selection(Object *obedit, int ins) /* ins == new character len *
int selend, selstart, direction;
int getfrom;
direction = BKE_vfont_select_get(obedit, &selstart, &selend);
direction = BKE_vfont_select_get(cu, &selstart, &selend);
if (direction) {
int size;
if (ef->pos >= selstart) {
@@ -491,7 +491,7 @@ static bool font_paste_wchar(Object *obedit,
EditFont *ef = cu->editfont;
int selend, selstart;
if (BKE_vfont_select_get(obedit, &selstart, &selend) == 0) {
if (BKE_vfont_select_get(cu, &selstart, &selend) == 0) {
selstart = selend = 0;
}
@@ -559,11 +559,11 @@ static bool font_paste_utf8(bContext *C, const char *str, const size_t str_len)
static char *font_select_to_buffer(Object *obedit)
{
Curve *cu = static_cast<Curve *>(obedit->data);
int selstart, selend;
if (!BKE_vfont_select_get(obedit, &selstart, &selend)) {
if (!BKE_vfont_select_get(cu, &selstart, &selend)) {
return nullptr;
}
Curve *cu = static_cast<Curve *>(obedit->data);
EditFont *ef = cu->editfont;
const char32_t *text_buf = ef->textbuf + selstart;
const size_t text_buf_len = selend - selstart;
@@ -952,7 +952,7 @@ static wmOperatorStatus set_style(bContext *C, const int style, const bool clear
EditFont *ef = cu->editfont;
int i, selstart, selend;
if (!BKE_vfont_select_get(obedit, &selstart, &selend)) {
if (!BKE_vfont_select_get(cu, &selstart, &selend)) {
return OPERATOR_CANCELLED;
}
@@ -1013,7 +1013,7 @@ static wmOperatorStatus toggle_style_exec(bContext *C, wmOperator *op)
style = RNA_enum_get(op->ptr, "style");
cu->curinfo.flag ^= style;
if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
if (BKE_vfont_select_get(cu, &selstart, &selend)) {
clear = (cu->curinfo.flag & style) == 0;
return set_style(C, style, clear);
}
@@ -1087,10 +1087,10 @@ void FONT_OT_select_all(wmOperatorType *ot)
static void copy_selection(Object *obedit)
{
Curve *cu = static_cast<Curve *>(obedit->data);
int selstart, selend;
if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (BKE_vfont_select_get(cu, &selstart, &selend)) {
EditFont *ef = cu->editfont;
char *buf = nullptr;
char32_t *text_buf;
@@ -1141,9 +1141,10 @@ void FONT_OT_text_copy(wmOperatorType *ot)
static wmOperatorStatus cut_text_exec(bContext *C, wmOperator * /*op*/)
{
Object *obedit = CTX_data_edit_object(C);
Curve *cu = static_cast<Curve *>(obedit->data);
int selstart, selend;
if (!BKE_vfont_select_get(obedit, &selstart, &selend)) {
if (!BKE_vfont_select_get(cu, &selstart, &selend)) {
return OPERATOR_CANCELLED;
}
@@ -1314,12 +1315,12 @@ static const EnumPropertyItem move_type_items[] = {
*/
static bool move_cursor_drop_select(Object *obedit, int dir)
{
Curve *cu = static_cast<Curve *>(obedit->data);
int selstart, selend;
if (!BKE_vfont_select_get(obedit, &selstart, &selend)) {
if (!BKE_vfont_select_get(cu, &selstart, &selend)) {
return false;
}
Curve *cu = static_cast<Curve *>(obedit->data);
EditFont *ef = cu->editfont;
if (dir == -1) {
ef->pos = selstart;
@@ -1566,7 +1567,7 @@ static wmOperatorStatus change_spacing_exec(bContext *C, wmOperator *op)
int selstart, selend;
bool changed = false;
const bool has_select = BKE_vfont_select_get(obedit, &selstart, &selend);
const bool has_select = BKE_vfont_select_get(cu, &selstart, &selend);
if (has_select) {
selstart -= 1;
}
@@ -1742,7 +1743,7 @@ static wmOperatorStatus delete_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
if (BKE_vfont_select_get(cu, &selstart, &selend)) {
if (type == DEL_NEXT_SEL) {
type = DEL_SELECTION;
}
@@ -1835,7 +1836,7 @@ static wmOperatorStatus delete_exec(bContext *C, wmOperator *op)
ef->len -= len_remove;
ef->textbuf[ef->len] = '\0';
BKE_vfont_select_clamp(obedit);
BKE_vfont_select_clamp(cu);
}
text_update_edited(C, obedit, FO_EDIT);
@@ -2284,7 +2285,7 @@ void ED_curve_editfont_make(Object *obedit)
ef->selend = cu->selend;
/* text may have been modified by Python */
BKE_vfont_select_clamp(obedit);
BKE_vfont_select_clamp(cu);
}
void ED_curve_editfont_load(Object *obedit)
@@ -2339,10 +2340,10 @@ static const EnumPropertyItem case_items[] = {
static wmOperatorStatus set_case(bContext *C, int ccase)
{
Object *obedit = CTX_data_edit_object(C);
Curve *cu = static_cast<Curve *>(obedit->data);
int selstart, selend;
if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
Curve *cu = (Curve *)obedit->data;
if (BKE_vfont_select_get(cu, &selstart, &selend)) {
EditFont *ef = cu->editfont;
char32_t *str = &ef->textbuf[selstart];

View File

@@ -368,10 +368,11 @@ static wmOperatorStatus material_slot_assign_exec(bContext *C, wmOperator * /*op
}
}
else if (ob->type == OB_FONT) {
EditFont *ef = ((Curve *)ob->data)->editfont;
const Curve *cu =static_cast<const Curve *>(ob->data);
EditFont *ef = cu->editfont;
int i, selstart, selend;
if (ef && BKE_vfont_select_get(ob, &selstart, &selend)) {
if (ef && BKE_vfont_select_get(cu, &selstart, &selend)) {
for (i = selstart; i <= selend; i++) {
changed = true;
ef->textbufinfo[i].mat_nr = mat_nr_active;