* Restored font selection functionality with open font and unlink font operators,
so you can change the font of 3D text objects.
This commit is contained in:
@@ -282,10 +282,12 @@ class DATA_PT_font(DataButtonsPanel):
|
||||
char = context.curve.edit_format
|
||||
wide_ui = context.region.width > narrowui
|
||||
|
||||
if wide_ui:
|
||||
layout.prop(text, "font")
|
||||
else:
|
||||
layout.prop(text, "font", text="")
|
||||
layout.template_ID(text, "font", open="font.open", unlink="font.unlink")
|
||||
|
||||
#if wide_ui:
|
||||
# layout.prop(text, "font")
|
||||
#else:
|
||||
# layout.prop(text, "font", text="")
|
||||
|
||||
split = layout.split()
|
||||
|
||||
|
@@ -398,7 +398,11 @@ VFont *load_vfont(char *name)
|
||||
if (vfd) {
|
||||
vfont = alloc_libblock(&G.main->vfont, ID_VF, filename);
|
||||
vfont->data = vfd;
|
||||
|
||||
|
||||
/* if there's a font name, use it for the ID name */
|
||||
if (strcmp(vfd->name, "")!=0) {
|
||||
BLI_strncpy(vfont->id.name+2, vfd->name, 21);
|
||||
}
|
||||
BLI_strncpy(vfont->name, name, sizeof(vfont->name));
|
||||
|
||||
// if autopack is on store the packedfile in de font structure
|
||||
|
@@ -359,7 +359,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
|
||||
|
||||
// get the name
|
||||
fontname = FT_Get_Postscript_Name(face);
|
||||
strcpy(vfd->name, (fontname == NULL) ? "Fontname not available" : fontname);
|
||||
strcpy(vfd->name, (fontname == NULL) ? "" : fontname);
|
||||
|
||||
// Extract the first 256 character from TTF
|
||||
lcode= charcode= FT_Get_First_Char(face, &glyph_index);
|
||||
|
@@ -63,6 +63,9 @@ void FONT_OT_delete(struct wmOperatorType *ot);
|
||||
void FONT_OT_change_character(struct wmOperatorType *ot);
|
||||
void FONT_OT_change_spacing(struct wmOperatorType *ot);
|
||||
|
||||
void FONT_OT_open(struct wmOperatorType *ot);
|
||||
void FONT_OT_unlink(struct wmOperatorType *ot);
|
||||
|
||||
/* editcurve.c */
|
||||
void CURVE_OT_hide(struct wmOperatorType *ot);
|
||||
void CURVE_OT_reveal(struct wmOperatorType *ot);
|
||||
|
@@ -87,6 +87,9 @@ void ED_operatortypes_curve(void)
|
||||
|
||||
WM_operatortype_append(FONT_OT_change_character);
|
||||
WM_operatortype_append(FONT_OT_change_spacing);
|
||||
|
||||
WM_operatortype_append(FONT_OT_open);
|
||||
WM_operatortype_append(FONT_OT_unlink);
|
||||
|
||||
WM_operatortype_append(CURVE_OT_hide);
|
||||
WM_operatortype_append(CURVE_OT_reveal);
|
||||
|
@@ -54,6 +54,7 @@
|
||||
#include "BKE_depsgraph.h"
|
||||
#include "BKE_font.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_report.h"
|
||||
@@ -70,6 +71,8 @@
|
||||
#include "ED_screen.h"
|
||||
#include "ED_util.h"
|
||||
|
||||
#include "UI_interface.h"
|
||||
|
||||
#include "curve_intern.h"
|
||||
|
||||
#define MAXTEXT 32766
|
||||
@@ -1538,6 +1541,169 @@ void FONT_OT_case_toggle(wmOperatorType *ot)
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
/* **************** Open Font ************** */
|
||||
|
||||
static void open_init(bContext *C, wmOperator *op)
|
||||
{
|
||||
PropertyPointerRNA *pprop;
|
||||
|
||||
op->customdata= pprop= MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
|
||||
uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
|
||||
}
|
||||
|
||||
static int open_cancel(bContext *C, wmOperator *op)
|
||||
{
|
||||
MEM_freeN(op->customdata);
|
||||
op->customdata= NULL;
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
static int open_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
Curve *cu;
|
||||
VFont *font;
|
||||
PropertyPointerRNA *pprop;
|
||||
PointerRNA idptr;
|
||||
char str[FILE_MAX];
|
||||
|
||||
RNA_string_get(op->ptr, "path", str);
|
||||
|
||||
font = load_vfont(str);
|
||||
|
||||
if(!font) {
|
||||
if(op->customdata) MEM_freeN(op->customdata);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
if(!op->customdata)
|
||||
open_init(C, op);
|
||||
|
||||
/* hook into UI */
|
||||
pprop= op->customdata;
|
||||
|
||||
if(pprop->prop) {
|
||||
/* when creating new ID blocks, use is already 1, but RNA
|
||||
* pointer se also increases user, so this compensates it */
|
||||
font->id.us--;
|
||||
|
||||
RNA_id_pointer_create(&font->id, &idptr);
|
||||
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
|
||||
RNA_property_update(C, &pprop->ptr, pprop->prop);
|
||||
} else if(ob && ob->type == OB_FONT) {
|
||||
cu = ob->data;
|
||||
id_us_min(&cu->vfont->id);
|
||||
cu->vfont = font;
|
||||
}
|
||||
|
||||
DAG_id_flush_update(ob->data, OB_RECALC_DATA);
|
||||
WM_event_add_notifier(C, NC_GEOM|ND_DATA|NA_EDITED, ob->data);
|
||||
|
||||
MEM_freeN(op->customdata);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
Curve *cu;
|
||||
VFont *font=NULL;
|
||||
char *path;
|
||||
if (ob && ob->type == OB_FONT) {
|
||||
cu = ob->data;
|
||||
font = cu->vfont;
|
||||
}
|
||||
path = (font && font->name)? font->name: U.fontdir;
|
||||
|
||||
if(RNA_property_is_set(op->ptr, "path"))
|
||||
return open_exec(C, op);
|
||||
|
||||
open_init(C, op);
|
||||
|
||||
RNA_string_set(op->ptr, "path", path);
|
||||
WM_event_add_fileselect(C, op);
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
||||
void FONT_OT_open(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Open";
|
||||
ot->idname= "FONT_OT_open";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= open_exec;
|
||||
ot->invoke= open_invoke;
|
||||
ot->cancel= open_cancel;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
WM_operator_properties_filesel(ot, FOLDERFILE|FTFONTFILE, FILE_SPECIAL);
|
||||
}
|
||||
|
||||
/******************* delete operator *********************/
|
||||
static int font_unlink_poll(bContext *C)
|
||||
{
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
Curve *cu;
|
||||
|
||||
if (!ED_operator_object_active_editable(C) ) return 0;
|
||||
if (ob->type != OB_FONT) return 0;
|
||||
|
||||
cu = ob->data;
|
||||
if (cu && strcmp(cu->vfont->name, "<builtin>")==0) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int font_unlink_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
Curve *cu;
|
||||
VFont *font, *builtin_font;
|
||||
|
||||
cu = ob->data;
|
||||
font = cu->vfont;
|
||||
|
||||
if (!font) {
|
||||
BKE_report(op->reports, RPT_ERROR, "No font datablock available to unlink.");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
if (strcmp(font->name, "<builtin>")==0) {
|
||||
BKE_report(op->reports, RPT_WARNING, "Can't unlink the default builtin font.");
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
/* revert back to builtin font */
|
||||
builtin_font = get_builtin_font();
|
||||
|
||||
cu->vfont = builtin_font;
|
||||
id_us_plus(&cu->vfont->id);
|
||||
id_us_min(&font->id);
|
||||
|
||||
DAG_id_flush_update(ob->data, OB_RECALC_DATA);
|
||||
WM_event_add_notifier(C, NC_GEOM|ND_DATA|NA_EDITED, ob->data);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void FONT_OT_unlink(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Unlink";
|
||||
ot->idname= "FONT_OT_unlink";
|
||||
ot->description= "Unlink active font data block.";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= font_unlink_exec;
|
||||
ot->poll= font_unlink_poll;
|
||||
}
|
||||
|
||||
|
||||
/* **************** undo for font object ************** */
|
||||
|
||||
static void undoFont_to_editFont(void *strv, void *ecu)
|
||||
@@ -1595,4 +1761,3 @@ void undo_push_font(bContext *C, char *name)
|
||||
{
|
||||
undo_editmode_push(C, name, get_undoFont, free_undoFont, undoFont_to_editFont, editFont_to_undoFont, NULL);
|
||||
}
|
||||
|
||||
|
@@ -483,6 +483,11 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
|
||||
ED_region_tag_redraw(ar);
|
||||
break;
|
||||
}
|
||||
switch(wmn->action) {
|
||||
case NA_EDITED:
|
||||
ED_region_tag_redraw(ar);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NC_GROUP:
|
||||
/* all group ops for now */
|
||||
|
@@ -93,6 +93,18 @@ void rna_ID_name_set(PointerRNA *ptr, const char *value)
|
||||
test_idbutton(id->name+2);
|
||||
}
|
||||
|
||||
static int rna_ID_name_editable(PointerRNA *ptr)
|
||||
{
|
||||
ID *id= (ID*)ptr->data;
|
||||
|
||||
if (GS(id->name) == ID_VF) {
|
||||
if (strcmp(id->name+2, "<builtin>")==0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
short RNA_type_to_ID_code(StructRNA *type)
|
||||
{
|
||||
if(RNA_struct_is_a(type, &RNA_Action)) return ID_AC;
|
||||
@@ -365,6 +377,7 @@ static void rna_def_ID(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Name", "Unique datablock ID name.");
|
||||
RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
|
||||
RNA_def_property_string_maxlength(prop, sizeof(((ID*)NULL)->name)-2);
|
||||
RNA_def_property_editable_func(prop, "rna_ID_name_editable");
|
||||
RNA_def_property_update(prop, NC_ID|NA_RENAME, NULL);
|
||||
RNA_def_struct_name_property(srna, prop);
|
||||
|
||||
|
@@ -73,7 +73,7 @@ static StructRNA *rna_Curve_refine(PointerRNA *ptr)
|
||||
{
|
||||
Curve *cu= (Curve*)ptr->data;
|
||||
short obtype= curve_type(cu);
|
||||
|
||||
|
||||
if(obtype == OB_FONT) return &RNA_TextCurve;
|
||||
else if(obtype == OB_SURF) return &RNA_SurfaceCurve;
|
||||
else return &RNA_Curve;
|
||||
@@ -634,6 +634,7 @@ static void rna_def_font(BlenderRNA *brna, StructRNA *srna)
|
||||
prop= RNA_def_property(srna, "font", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "vfont");
|
||||
RNA_def_property_ui_text(prop, "Font", "");
|
||||
RNA_def_property_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_update(prop, 0, "rna_Curve_update_data");
|
||||
|
||||
prop= RNA_def_property(srna, "edit_format", PROP_POINTER, PROP_NONE);
|
||||
|
@@ -43,7 +43,7 @@ void RNA_def_vfont(BlenderRNA *brna)
|
||||
srna= RNA_def_struct(brna, "VectorFont", "ID");
|
||||
RNA_def_struct_ui_text(srna, "Vector Font", "Vector font for Text objects.");
|
||||
RNA_def_struct_sdna(srna, "VFont");
|
||||
RNA_def_struct_ui_icon(srna, ICON_FONT_DATA);
|
||||
RNA_def_struct_ui_icon(srna, ICON_FILE_FONT);
|
||||
|
||||
prop= RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
|
Reference in New Issue
Block a user