[Complex Text Layouts] Add variable fonts support.
This commit is contained in:
parent
bbf7bb3838
commit
c1d261fdb0
16 changed files with 279 additions and 4 deletions
|
|
@ -53,6 +53,11 @@ void FontData::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &FontData::set_antialiased);
|
||||
ClassDB::bind_method(D_METHOD("get_antialiased"), &FontData::get_antialiased);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_variation_list"), &FontData::get_variation_list);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_variation", "tag", "value"), &FontData::set_variation);
|
||||
ClassDB::bind_method(D_METHOD("get_variation", "tag"), &FontData::get_variation);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_hinting", "hinting"), &FontData::set_hinting);
|
||||
ClassDB::bind_method(D_METHOD("get_hinting"), &FontData::get_hinting);
|
||||
|
||||
|
|
@ -115,6 +120,11 @@ bool FontData::_set(const StringName &p_name, const Variant &p_value) {
|
|||
set_script_support_override(scr, p_value);
|
||||
return true;
|
||||
}
|
||||
if (str.begins_with("variation/")) {
|
||||
String name = str.get_slicec('/', 1);
|
||||
set_variation(name, p_value);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -137,6 +147,12 @@ bool FontData::_get(const StringName &p_name, Variant &r_ret) const {
|
|||
r_ret = get_script_support_override(scr);
|
||||
return true;
|
||||
}
|
||||
if (str.begins_with("variation/")) {
|
||||
String name = str.get_slicec('/', 1);
|
||||
|
||||
r_ret = get_variation(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -153,6 +169,12 @@ void FontData::_get_property_list(List<PropertyInfo> *p_list) const {
|
|||
p_list->push_back(PropertyInfo(Variant::BOOL, "script_support_override/" + scr_over[i], PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE));
|
||||
}
|
||||
p_list->push_back(PropertyInfo(Variant::NIL, "script_support_override/_new", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
|
||||
|
||||
Dictionary variations = get_variation_list();
|
||||
for (const Variant *ftr = variations.next(nullptr); ftr != nullptr; ftr = variations.next(ftr)) {
|
||||
Vector3i v = variations[*ftr];
|
||||
p_list->push_back(PropertyInfo(Variant::FLOAT, "variation/" + TS->tag_to_name(*ftr), PROPERTY_HINT_RANGE, itos(v.x) + "," + itos(v.y), PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE));
|
||||
}
|
||||
}
|
||||
|
||||
RID FontData::get_rid() const {
|
||||
|
|
@ -239,6 +261,26 @@ float FontData::get_underline_thickness(int p_size) const {
|
|||
return TS->font_get_underline_thickness(rid, (p_size < 0) ? base_size : p_size);
|
||||
}
|
||||
|
||||
Dictionary FontData::get_variation_list() const {
|
||||
if (rid == RID()) {
|
||||
return Dictionary();
|
||||
}
|
||||
return TS->font_get_variation_list(rid);
|
||||
}
|
||||
|
||||
void FontData::set_variation(const String &p_name, double p_value) {
|
||||
ERR_FAIL_COND(rid == RID());
|
||||
TS->font_set_variation(rid, p_name, p_value);
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
double FontData::get_variation(const String &p_name) const {
|
||||
if (rid == RID()) {
|
||||
return 0;
|
||||
}
|
||||
return TS->font_get_variation(rid, p_name);
|
||||
}
|
||||
|
||||
void FontData::set_antialiased(bool p_antialiased) {
|
||||
ERR_FAIL_COND(rid == RID());
|
||||
TS->font_set_antialiased(rid, p_antialiased);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue