Font objects: Support proper auto-space
Annoyingly, need to convert vfont to nurbs, do minmax and toss nurbs away.
This is likely to be fine, since this function is not intended to be used
a lot, and this is the only way to get more meaningful result.
However, it's not very clear what to do with font on curve.
This fixes rendering of font object with auto texture space in Cycles
introduced in c34f3c7.
It is probably possible to introduce new mode to vfont_to_curve which
will do boundbox without extra allocations, but that's more like an
optimization.
Reviewers: campbellbarton, mano-wii
Reviewed By: campbellbarton
Subscribers: zeauro
Differential Revision: https://developer.blender.org/D2971
This commit is contained in:
@@ -86,7 +86,7 @@ struct VFont *BKE_vfont_load_exists(struct Main *bmain, const char *filepath);
|
||||
|
||||
void BKE_vfont_make_local(struct Main *bmain, struct VFont *vfont, const bool lib_local);
|
||||
|
||||
bool BKE_vfont_to_curve_ex(struct Main *bmain, struct Object *ob, int mode,
|
||||
bool BKE_vfont_to_curve_ex(struct Main *bmain, struct Object *ob, struct Curve *cu, int mode,
|
||||
struct ListBase *r_nubase,
|
||||
const wchar_t **r_text, int *r_text_len, bool *r_text_free,
|
||||
struct CharTrans **r_chartransdata);
|
||||
|
||||
@@ -4933,12 +4933,27 @@ void BKE_curve_nurb_vert_active_validate(Curve *cu)
|
||||
bool BKE_curve_minmax(Curve *cu, bool use_radius, float min[3], float max[3])
|
||||
{
|
||||
ListBase *nurb_lb = BKE_curve_nurbs_get(cu);
|
||||
Nurb *nu;
|
||||
|
||||
for (nu = nurb_lb->first; nu; nu = nu->next)
|
||||
ListBase temp_nurb_lb = {NULL, NULL};
|
||||
const bool is_font = (BLI_listbase_is_empty(nurb_lb)) && (cu->len != 0);
|
||||
/* For font curves we generate temp list of splines.
|
||||
*
|
||||
* This is likely to be fine, this function is not supposed to be called
|
||||
* often, and it's the only way to get meaningful bounds for fonts.
|
||||
*/
|
||||
if (is_font) {
|
||||
nurb_lb = &temp_nurb_lb;
|
||||
BKE_vfont_to_curve_ex(G.main, NULL, cu, FO_EDIT, nurb_lb,
|
||||
NULL, NULL, NULL, NULL);
|
||||
use_radius = false;
|
||||
}
|
||||
/* Do bounding box based on splines. */
|
||||
for (Nurb *nu = nurb_lb->first; nu; nu = nu->next) {
|
||||
BKE_nurb_minmax(nu, use_radius, min, max);
|
||||
|
||||
return (BLI_listbase_is_empty(nurb_lb) == false);
|
||||
}
|
||||
const bool result = (BLI_listbase_is_empty(nurb_lb) == false);
|
||||
/* Cleanup if needed. */
|
||||
BKE_nurbList_free(&temp_nurb_lb);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool BKE_curve_center_median(Curve *cu, float cent[3])
|
||||
|
||||
@@ -635,11 +635,10 @@ struct TempLineInfo {
|
||||
int wspace_nr; /* number of whitespaces of line */
|
||||
};
|
||||
|
||||
bool BKE_vfont_to_curve_ex(Main *bmain, Object *ob, int mode, ListBase *r_nubase,
|
||||
bool BKE_vfont_to_curve_ex(Main *bmain, Object *ob, Curve *cu, int mode, ListBase *r_nubase,
|
||||
const wchar_t **r_text, int *r_text_len, bool *r_text_free,
|
||||
struct CharTrans **r_chartransdata)
|
||||
{
|
||||
Curve *cu = ob->data;
|
||||
EditFont *ef = cu->editfont;
|
||||
EditFontSelBox *selboxes = NULL;
|
||||
VFont *vfont, *oldvfont;
|
||||
@@ -670,7 +669,7 @@ bool BKE_vfont_to_curve_ex(Main *bmain, Object *ob, int mode, ListBase *r_nubase
|
||||
/* remark: do calculations including the trailing '\0' of a string
|
||||
* because the cursor can be at that location */
|
||||
|
||||
BLI_assert(ob->type == OB_FONT);
|
||||
BLI_assert(ob == NULL || ob->type == OB_FONT);
|
||||
|
||||
/* Set font data */
|
||||
vfont = cu->vfont;
|
||||
@@ -708,7 +707,7 @@ bool BKE_vfont_to_curve_ex(Main *bmain, Object *ob, int mode, ListBase *r_nubase
|
||||
if (cu->tb == NULL)
|
||||
cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "TextBox compat");
|
||||
|
||||
if (ef) {
|
||||
if (ef != NULL && ob != NULL) {
|
||||
if (ef->selboxes)
|
||||
MEM_freeN(ef->selboxes);
|
||||
|
||||
@@ -1258,7 +1257,7 @@ makebreak:
|
||||
cha = towupper(cha);
|
||||
}
|
||||
|
||||
if (info->mat_nr > (ob->totcol)) {
|
||||
if (ob == NULL || info->mat_nr > (ob->totcol)) {
|
||||
/* printf("Error: Illegal material index (%d) in text object, setting to 0\n", info->mat_nr); */
|
||||
info->mat_nr = 0;
|
||||
}
|
||||
@@ -1334,7 +1333,7 @@ bool BKE_vfont_to_curve_nubase(Main *bmain, Object *ob, int mode, ListBase *r_nu
|
||||
{
|
||||
BLI_assert(ob->type == OB_FONT);
|
||||
|
||||
return BKE_vfont_to_curve_ex(bmain, ob, mode, r_nubase,
|
||||
return BKE_vfont_to_curve_ex(bmain, ob, ob->data, mode, r_nubase,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -1342,7 +1341,7 @@ bool BKE_vfont_to_curve(Main *bmain, Object *ob, int mode)
|
||||
{
|
||||
Curve *cu = ob->data;
|
||||
|
||||
return BKE_vfont_to_curve_ex(bmain, ob, mode, &cu->nurb, NULL, NULL, NULL, NULL);
|
||||
return BKE_vfont_to_curve_ex(bmain, ob, ob->data, mode, &cu->nurb, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -630,7 +630,7 @@ static void make_duplis_font(const DupliContext *ctx)
|
||||
|
||||
/* in par the family name is stored, use this to find the other objects */
|
||||
|
||||
BKE_vfont_to_curve_ex(G.main, par, FO_DUPLI, NULL,
|
||||
BKE_vfont_to_curve_ex(G.main, par, par->data, FO_DUPLI, NULL,
|
||||
&text, &text_len, &text_free, &chartransdata);
|
||||
|
||||
if (text == NULL || chartransdata == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user