Fix #107009: Setting Text Object Styles #107048

Merged
Harley Acheson merged 5 commits from Harley/blender:CurveStyles into main 2023-04-18 21:24:48 +02:00
5 changed files with 65 additions and 14 deletions

View File

@ -363,11 +363,18 @@ class DATA_PT_font(CurveButtonsPanelText, Panel):
if mode == 'EDIT_TEXT':
layout.separator()
row = layout.row(align=True)
row.prop(char, "use_bold", toggle=True)
row.prop(char, "use_italic", toggle=True)
row.prop(char, "use_underline", toggle=True)
row.prop(char, "use_small_caps", toggle=True)
if not text.has_selection:

if not text.is_selected: ...

`if not text.is_selected:` ...
row = layout.row(align=True)
row.prop(char, "use_bold", toggle=True)
row.prop(char, "use_italic", toggle=True)
row.prop(char, "use_underline", toggle=True)
row.prop(char, "use_small_caps", toggle=True)
else:
row = layout.row(align=True)
row.operator("font.style_toggle", text="Bold", icon='BOLD' , depress = text.is_select_bold).style = 'BOLD'
row.operator("font.style_toggle", text="Italic", icon='ITALIC' , depress = text.is_select_italic).style = 'ITALIC'
row.operator("font.style_toggle", text="Underline", icon='UNDERLINE' , depress = text.is_select_underline).style = 'UNDERLINE'
row.operator("font.style_toggle", text="Small Caps", icon='SMALL_CAPS' , depress = text.is_select_smallcaps).style = 'SMALL_CAPS'
class DATA_PT_font_transform(CurveButtonsPanelText, Panel):

View File

@ -42,6 +42,10 @@ typedef struct EditFont {
int len, pos;
int selstart, selend;
/* Combined styles (#CharInfo.flag) for selected string. A flag will be
* set only if ALL characters in the selected string have it. */
int select_char_info_flag;

Prefer this includes the term char_info or style, e.g. select_char_info_flag

Prefer this includes the term char_info or style, e.g. `select_char_info_flag`
/**
* ID data is older than edit-mode data.
* Set #Main.is_memfile_undo_flush_needed when enabling.

View File

@ -1140,7 +1140,16 @@ static bool vfont_to_curve(Object *ob,
}
}
/* Line-data is now: width of line. */
if (ef && ef->selboxes) {
/* Set combined style flags for the selected string. Start with all styles then
* remove one if ANY characters do not have it. Break out if we've removed them all. */
ef->select_char_info_flag = CU_CHINFO_BOLD | CU_CHINFO_ITALIC | CU_CHINFO_UNDERLINE |
CU_CHINFO_SMALLCAPS;
for (int k = selstart; k <= selend && ef->select_char_info_flag; k++) {

Checking each flag isn't needed. ef->selected_flag &= info->flag; masks out flags as intended.

Checking each flag isn't needed. `ef->selected_flag &= info->flag;` masks out flags as intended.
info = &custrinfo[k];
ef->select_char_info_flag &= info->flag;
}
}
if (cu->spacemode != CU_ALIGN_X_LEFT) {
ct = chartransdata;

View File

@ -854,16 +854,13 @@ static int toggle_style_exec(bContext *C, wmOperator *op)
Curve *cu = obedit->data;
int style, clear, selstart, selend;
if (!BKE_vfont_select_get(obedit, &selstart, &selend)) {
return OPERATOR_CANCELLED;
}
style = RNA_enum_get(op->ptr, "style");
cu->curinfo.flag ^= style;
clear = (cu->curinfo.flag & style) == 0;
return set_style(C, style, clear);
if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
clear = (cu->curinfo.flag & style) == 0;
return set_style(C, style, clear);
}
return true;
}
void FONT_OT_style_toggle(wmOperatorType *ot)

View File

@ -838,6 +838,15 @@ static bool rna_Curve_is_editmode_get(PointerRNA *ptr)
}
}
static bool rna_TextCurve_has_selection_get(PointerRNA *ptr)

The name is misleading, rna_TextCurve_has_selection (RNA terms this a TextCurve).

The name is misleading, `rna_TextCurve_has_selection` (RNA terms this a `TextCurve`).
{
Curve *cu = (Curve *)ptr->owner_id;
if (cu->editfont != NULL)
return (cu->editfont->selboxes != NULL);
else
return false;
}
#else
static const float tilt_limit = DEG2RADF(21600.0f);
@ -1272,6 +1281,31 @@ static void rna_def_font(BlenderRNA *UNUSED(brna), StructRNA *srna)
RNA_def_property_boolean_sdna(prop, NULL, "flag", CU_FAST);
RNA_def_property_ui_text(prop, "Fast Editing", "Don't fill polygons while editing");
RNA_def_property_update(prop, 0, "rna_Curve_update_data");
prop = RNA_def_property(srna, "is_select_bold", PROP_BOOLEAN, PROP_NONE);
Harley marked this conversation as resolved Outdated

Generally is_/has_ ... etc are prefixes. is_select_bold ... etc.

Generally `is_/has_` ... etc are prefixes. `is_select_bold` ... etc.
RNA_def_property_boolean_sdna(prop, NULL, "editfont->select_char_info_flag", CU_CHINFO_BOLD);
RNA_def_property_ui_text(prop, "Selected Bold", "Whether the selected text is bold");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "is_select_italic", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "editfont->select_char_info_flag", CU_CHINFO_ITALIC);
RNA_def_property_ui_text(prop, "Selected Italic", "Whether the selected text is italics");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "is_select_underline", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "editfont->select_char_info_flag", CU_CHINFO_UNDERLINE);
RNA_def_property_ui_text(prop, "Selected Underline", "Whether the selected text is underlined");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "is_select_smallcaps", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "editfont->select_char_info_flag", CU_CHINFO_SMALLCAPS);
RNA_def_property_ui_text(prop, "Selected Smallcaps", "Whether the selected text is small caps");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "has_selection", PROP_BOOLEAN, PROP_NONE);

Prefer has_selection as is_selected makes it seem it might be the object selection.

Prefer `has_selection` as `is_selected` makes it seem it might be the object selection.
RNA_def_property_boolean_funcs(prop, "rna_TextCurve_has_selection_get", NULL);
RNA_def_property_ui_text(prop, "Text Selected", "Whether there is any text selected");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
}
static void rna_def_textbox(BlenderRNA *brna)