Text objects: make CharInfo mat_nr zero-based #112954

Merged
Philipp Oeser merged 2 commits from lichtwerk/blender:109491_b into blender-v4.0-release 2023-09-28 11:46:59 +02:00
7 changed files with 27 additions and 18 deletions
Showing only changes of commit 12b45b3d1c - Show all commits

View File

@ -29,7 +29,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 30
#define BLENDER_FILE_SUBVERSION 31
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@ -5427,11 +5427,7 @@ void BKE_curve_material_remap(Curve *cu, const uint *remap, uint remap_len)
}
for (i = 0; i <= charinfo_len; i++) {
if (strinfo[i].mat_nr > 0) {
strinfo[i].mat_nr -= 1;
MAT_NR_REMAP(strinfo[i].mat_nr);
strinfo[i].mat_nr += 1;
}
MAT_NR_REMAP(strinfo[i].mat_nr);
}
}
else {

View File

@ -448,8 +448,8 @@ static void build_underline(Curve *cu,
nu2->bezt = nullptr;
nu2->knotsu = nu2->knotsv = nullptr;
nu2->charidx = charidx + 1000;
if (mat_nr > 0) {
nu2->mat_nr = mat_nr - 1;
if (mat_nr >= 0) {
nu2->mat_nr = mat_nr;
}
nu2->pntsu = 4;
nu2->pntsv = 1;
@ -538,7 +538,7 @@ void BKE_vfont_build_char(Curve *cu,
nu2->flag = CU_SMOOTH;
nu2->charidx = charidx;
if (info->mat_nr > 0) {
nu2->mat_nr = info->mat_nr - 1;
nu2->mat_nr = info->mat_nr;
}
else {
nu2->mat_nr = 0;

View File

@ -18,6 +18,7 @@
#include "DNA_brush_types.h"
#include "DNA_camera_types.h"
#include "DNA_defaults.h"
#include "DNA_curve_types.h"
#include "DNA_light_types.h"
#include "DNA_lightprobe_types.h"
#include "DNA_modifier_types.h"
@ -42,6 +43,7 @@
#include "BKE_armature.h"
#include "BKE_attribute.h"
#include "BKE_curve.h"
#include "BKE_effect.h"
#include "BKE_grease_pencil.hh"
#include "BKE_idprop.hh"
@ -1614,6 +1616,20 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 31)) {
LISTBASE_FOREACH (Curve *, curve, &bmain->curves) {
const int curvetype = BKE_curve_type_get(curve);
if (curvetype == OB_FONT) {
CharInfo *info = curve->strinfo;
for (int i = curve->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr > 0) {
/** CharInfo mat_nr used to start at 1, unlike mesh & nurbs, now zero-based. */
info->mat_nr--;
}
}
}
}
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -385,7 +385,7 @@ static int insert_into_textbuf(Object *obedit, uintptr_t c)
ef->textbuf[ef->pos] = c;
ef->textbufinfo[ef->pos] = cu->curinfo;
ef->textbufinfo[ef->pos].kern = 0.0f;
ef->textbufinfo[ef->pos].mat_nr = obedit->actcol;
ef->textbufinfo[ef->pos].mat_nr = obedit->actcol - 1;
ef->pos++;
ef->len++;
@ -418,10 +418,7 @@ static void text_update_edited(bContext *C, Object *obedit, const eEditFontMode
cu->curinfo = ef->textbufinfo[ef->pos ? ef->pos - 1 : 0];
if (obedit->totcol > 0) {
obedit->actcol = cu->curinfo.mat_nr;
/* since this array is calloc'd, it can be 0 even though we try ensure
* (mat_nr > 0) almost everywhere */
obedit->actcol = cu->curinfo.mat_nr + 1;
if (obedit->actcol < 1) {
obedit->actcol = 1;
}
@ -1851,7 +1848,7 @@ static void font_cursor_set_apply(bContext *C, const wmEvent *event)
cu->curinfo = ef->textbufinfo[ef->pos ? ef->pos - 1 : 0];
if (ob->totcol > 0) {
ob->actcol = cu->curinfo.mat_nr;
ob->actcol = cu->curinfo.mat_nr + 1;
if (ob->actcol < 1) {
ob->actcol = 1;
}

View File

@ -347,7 +347,7 @@ static int material_slot_assign_exec(bContext *C, wmOperator * /*op*/)
if (ef && BKE_vfont_select_get(ob, &selstart, &selend)) {
for (i = selstart; i <= selend; i++) {
changed = true;
ef->textbufinfo[i].mat_nr = mat_nr_active + 1;
ef->textbufinfo[i].mat_nr = mat_nr_active;
}
}
}

View File

@ -318,13 +318,13 @@ static void rna_Curve_material_index_range(
static int rna_ChariInfo_material_index_get(PointerRNA *ptr)
{
CharInfo *info = static_cast<CharInfo *>(ptr->data);
return info->mat_nr ? info->mat_nr - 1 : 0;
return info->mat_nr ? info->mat_nr : 0;
}
static void rna_ChariInfo_material_index_set(PointerRNA *ptr, int value)
{
CharInfo *info = static_cast<CharInfo *>(ptr->data);
info->mat_nr = value + 1;
info->mat_nr = value;
}
static void rna_Curve_active_textbox_index_range(