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
4 changed files with 12 additions and 23 deletions
Showing only changes of commit a3bcd27678 - Show all commits

View File

@ -363,7 +363,7 @@ class DATA_PT_font(CurveButtonsPanelText, Panel):
if mode == 'EDIT_TEXT':
layout.separator()
if text.is_selected == False :
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)

View File

@ -44,7 +44,7 @@ typedef struct EditFont {
/* Combined styles (#CharInfo.flag) for selected string. A flag will be
* set only if ALL characters in the selected string have it. */
int selected_flag;
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.

View File

@ -1143,22 +1143,11 @@ static bool vfont_to_curve(Object *ob,
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->selected_flag = CU_CHINFO_BOLD | CU_CHINFO_ITALIC | CU_CHINFO_UNDERLINE |
ef->select_char_info_flag = CU_CHINFO_BOLD | CU_CHINFO_ITALIC | CU_CHINFO_UNDERLINE |
CU_CHINFO_SMALLCAPS;
for (int k = selstart; k <= selend && ef->selected_flag; k++) {
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];
if (!(info->flag & CU_CHINFO_BOLD)) {
ef->selected_flag &= ~CU_CHINFO_BOLD;
}
if (!(info->flag & CU_CHINFO_ITALIC)) {
ef->selected_flag &= ~CU_CHINFO_ITALIC;
}
if (!(info->flag & CU_CHINFO_UNDERLINE)) {
ef->selected_flag &= ~CU_CHINFO_UNDERLINE;
}
if (!(info->flag & CU_CHINFO_SMALLCAPS)) {
ef->selected_flag &= ~CU_CHINFO_SMALLCAPS;
}
ef->select_char_info_flag &= info->flag;
}
}

View File

@ -838,7 +838,7 @@ static bool rna_Curve_is_editmode_get(PointerRNA *ptr)
}
}
static bool rna_Curve_is_selected(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)
@ -1283,27 +1283,27 @@ static void rna_def_font(BlenderRNA *UNUSED(brna), StructRNA *srna)
RNA_def_property_update(prop, 0, "rna_Curve_update_data");
prop = RNA_def_property(srna, "select_is_underline", 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->selected_flag", CU_CHINFO_UNDERLINE);
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, "select_is_bold", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "editfont->selected_flag", CU_CHINFO_BOLD);
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, "select_is_italic", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "editfont->selected_flag", CU_CHINFO_ITALIC);
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, "select_is_smallcaps", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "editfont->selected_flag", CU_CHINFO_SMALLCAPS);
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, "is_selected", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_funcs(prop, "rna_Curve_is_selected", NULL);
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);
}