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 71 additions and 6 deletions
Showing only changes of commit 8472c05a88 - Show all commits

View File

@ -363,11 +363,18 @@ class DATA_PT_font(CurveButtonsPanelText, Panel):
if mode == 'EDIT_TEXT':
layout.separator()
row = layout.row(align=True)
row.operator("font.style_toggle", text="Bold", icon='BOLD' , depress = char.use_bold).style = 'BOLD'
row.operator("font.style_toggle", text="Italic", icon='ITALIC' , depress = char.use_italic).style = 'ITALIC'
row.operator("font.style_toggle", text="Underline", icon='UNDERLINE' , depress = char.use_underline).style = 'UNDERLINE'
row.operator("font.style_toggle", text="Small Caps", icon='SMALL_CAPS' , depress = char.use_small_caps).style = 'SMALL_CAPS'
if text.is_selected == False :

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.select_is_bold).style = 'BOLD'
row.operator("font.style_toggle", text="Italic", icon='ITALIC' , depress = text.select_is_italic).style = 'ITALIC'
row.operator("font.style_toggle", text="Underline", icon='UNDERLINE' , depress = text.select_is_underline).style = 'UNDERLINE'
row.operator("font.style_toggle", text="Small Caps", icon='SMALL_CAPS' , depress = text.select_is_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 selected_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,27 @@ 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->selected_flag = CU_CHINFO_BOLD | CU_CHINFO_ITALIC | CU_CHINFO_UNDERLINE |
CU_CHINFO_SMALLCAPS;
for (int k = selstart; k <= selend && ef->selected_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;
}
}
}
if (cu->spacemode != CU_ALIGN_X_LEFT) {
ct = chartransdata;

View File

@ -838,6 +838,15 @@ static bool rna_Curve_is_editmode_get(PointerRNA *ptr)
}
}
static bool rna_Curve_is_selected(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, "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_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_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_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_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);

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_Curve_is_selected", 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)