diff --git a/scripts/startup/bl_ui/properties_data_curve.py b/scripts/startup/bl_ui/properties_data_curve.py index bd239203123..a46e849b775 100644 --- a/scripts/startup/bl_ui/properties_data_curve.py +++ b/scripts/startup/bl_ui/properties_data_curve.py @@ -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: + 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): diff --git a/source/blender/blenkernel/BKE_vfont.h b/source/blender/blenkernel/BKE_vfont.h index aea662d6548..ca5cefbcdf8 100644 --- a/source/blender/blenkernel/BKE_vfont.h +++ b/source/blender/blenkernel/BKE_vfont.h @@ -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; + /** * ID data is older than edit-mode data. * Set #Main.is_memfile_undo_flush_needed when enabling. diff --git a/source/blender/blenkernel/intern/vfont.c b/source/blender/blenkernel/intern/vfont.c index b6f9a23a3cd..19cfe2a545f 100644 --- a/source/blender/blenkernel/intern/vfont.c +++ b/source/blender/blenkernel/intern/vfont.c @@ -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++) { + info = &custrinfo[k]; + ef->select_char_info_flag &= info->flag; + } + } if (cu->spacemode != CU_ALIGN_X_LEFT) { ct = chartransdata; diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index d384c3e69e2..f402dfb72c8 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -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) diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c index ab46b3bc7df..698cdc6639a 100644 --- a/source/blender/makesrna/intern/rna_curve.c +++ b/source/blender/makesrna/intern/rna_curve.c @@ -838,6 +838,15 @@ static bool rna_Curve_is_editmode_get(PointerRNA *ptr) } } +static bool rna_TextCurve_has_selection_get(PointerRNA *ptr) +{ + 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); + 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); + 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)