|
@@ -29,6 +29,7 @@
|
|
|
/**************************************************************************/
|
|
|
|
|
|
#include "font.h"
|
|
|
+#include "font.compat.inc"
|
|
|
|
|
|
#include "core/io/image_loader.h"
|
|
|
#include "core/io/resource_loader.h"
|
|
@@ -50,7 +51,7 @@ void Font::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("get_fallbacks"), &Font::get_fallbacks);
|
|
|
|
|
|
// Output.
|
|
|
- ClassDB::bind_method(D_METHOD("find_variation", "variation_coordinates", "face_index", "strength", "transform"), &Font::find_variation, DEFVAL(0), DEFVAL(0.0), DEFVAL(Transform2D()));
|
|
|
+ ClassDB::bind_method(D_METHOD("find_variation", "variation_coordinates", "face_index", "strength", "transform", "spacing_top", "spacing_bottom", "spacing_space", "spacing_glyph"), &Font::find_variation, DEFVAL(0), DEFVAL(0.0), DEFVAL(Transform2D()), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0));
|
|
|
ClassDB::bind_method(D_METHOD("get_rids"), &Font::get_rids);
|
|
|
|
|
|
// Font metrics.
|
|
@@ -916,6 +917,9 @@ void FontFile::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_transform", "cache_index", "transform"), &FontFile::set_transform);
|
|
|
ClassDB::bind_method(D_METHOD("get_transform", "cache_index"), &FontFile::get_transform);
|
|
|
|
|
|
+ ClassDB::bind_method(D_METHOD("set_extra_spacing", "cache_index", "spacing", "value"), &FontFile::set_extra_spacing);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_extra_spacing", "cache_index", "spacing"), &FontFile::get_extra_spacing);
|
|
|
+
|
|
|
ClassDB::bind_method(D_METHOD("set_face_index", "cache_index", "face_index"), &FontFile::set_face_index);
|
|
|
ClassDB::bind_method(D_METHOD("get_face_index", "cache_index"), &FontFile::get_face_index);
|
|
|
|
|
@@ -1126,6 +1130,18 @@ bool FontFile::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
} else if (tokens.size() == 3 && tokens[2] == "transform") {
|
|
|
set_transform(cache_index, p_value);
|
|
|
return true;
|
|
|
+ } else if (tokens.size() == 3 && tokens[2] == "spacing_top") {
|
|
|
+ set_extra_spacing(cache_index, TextServer::SPACING_TOP, p_value);
|
|
|
+ return true;
|
|
|
+ } else if (tokens.size() == 3 && tokens[2] == "spacing_bottom") {
|
|
|
+ set_extra_spacing(cache_index, TextServer::SPACING_BOTTOM, p_value);
|
|
|
+ return true;
|
|
|
+ } else if (tokens.size() == 3 && tokens[2] == "spacing_space") {
|
|
|
+ set_extra_spacing(cache_index, TextServer::SPACING_SPACE, p_value);
|
|
|
+ return true;
|
|
|
+ } else if (tokens.size() == 3 && tokens[2] == "spacing_glyph") {
|
|
|
+ set_extra_spacing(cache_index, TextServer::SPACING_GLYPH, p_value);
|
|
|
+ return true;
|
|
|
}
|
|
|
if (tokens.size() >= 5) {
|
|
|
Vector2i sz = Vector2i(tokens[2].to_int(), tokens[3].to_int());
|
|
@@ -1205,6 +1221,18 @@ bool FontFile::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
} else if (tokens.size() == 3 && tokens[2] == "transform") {
|
|
|
r_ret = get_transform(cache_index);
|
|
|
return true;
|
|
|
+ } else if (tokens.size() == 3 && tokens[2] == "spacing_top") {
|
|
|
+ r_ret = get_extra_spacing(cache_index, TextServer::SPACING_TOP);
|
|
|
+ return true;
|
|
|
+ } else if (tokens.size() == 3 && tokens[2] == "spacing_bottom") {
|
|
|
+ r_ret = get_extra_spacing(cache_index, TextServer::SPACING_BOTTOM);
|
|
|
+ return true;
|
|
|
+ } else if (tokens.size() == 3 && tokens[2] == "spacing_space") {
|
|
|
+ r_ret = get_extra_spacing(cache_index, TextServer::SPACING_SPACE);
|
|
|
+ return true;
|
|
|
+ } else if (tokens.size() == 3 && tokens[2] == "spacing_glyph") {
|
|
|
+ r_ret = get_extra_spacing(cache_index, TextServer::SPACING_GLYPH);
|
|
|
+ return true;
|
|
|
}
|
|
|
if (tokens.size() >= 5) {
|
|
|
Vector2i sz = Vector2i(tokens[2].to_int(), tokens[3].to_int());
|
|
@@ -1276,6 +1304,10 @@ void FontFile::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, prefix + "face_index", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, prefix + "embolden", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
|
|
p_list->push_back(PropertyInfo(Variant::TRANSFORM2D, prefix + "transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
|
|
+ p_list->push_back(PropertyInfo(Variant::INT, prefix + "spacing_top", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
|
|
+ p_list->push_back(PropertyInfo(Variant::INT, prefix + "spacing_bottom", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
|
|
+ p_list->push_back(PropertyInfo(Variant::INT, prefix + "spacing_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
|
|
+ p_list->push_back(PropertyInfo(Variant::INT, prefix + "spacing_glyph", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
|
|
|
|
|
for (int j = 0; j < sizes.size(); j++) {
|
|
|
Vector2i sz = sizes[j];
|
|
@@ -2183,7 +2215,7 @@ real_t FontFile::get_oversampling() const {
|
|
|
return oversampling;
|
|
|
}
|
|
|
|
|
|
-RID FontFile::find_variation(const Dictionary &p_variation_coordinates, int p_face_index, float p_strength, Transform2D p_transform) const {
|
|
|
+RID FontFile::find_variation(const Dictionary &p_variation_coordinates, int p_face_index, float p_strength, Transform2D p_transform, int p_spacing_top, int p_spacing_bottom, int p_spacing_space, int p_spacing_glyph) const {
|
|
|
// Find existing variation cache.
|
|
|
const Dictionary &supported_coords = get_supported_variation_list();
|
|
|
for (int i = 0; i < cache.size(); i++) {
|
|
@@ -2193,6 +2225,10 @@ RID FontFile::find_variation(const Dictionary &p_variation_coordinates, int p_fa
|
|
|
match = match && (TS->font_get_face_index(cache[i]) == p_face_index);
|
|
|
match = match && (TS->font_get_embolden(cache[i]) == p_strength);
|
|
|
match = match && (TS->font_get_transform(cache[i]) == p_transform);
|
|
|
+ match = match && (TS->font_get_spacing(cache[i], TextServer::SPACING_TOP) == p_spacing_top);
|
|
|
+ match = match && (TS->font_get_spacing(cache[i], TextServer::SPACING_BOTTOM) == p_spacing_bottom);
|
|
|
+ match = match && (TS->font_get_spacing(cache[i], TextServer::SPACING_SPACE) == p_spacing_space);
|
|
|
+ match = match && (TS->font_get_spacing(cache[i], TextServer::SPACING_GLYPH) == p_spacing_glyph);
|
|
|
for (const Variant *V = supported_coords.next(nullptr); V && match; V = supported_coords.next(V)) {
|
|
|
const Vector3 &def = supported_coords[*V];
|
|
|
|
|
@@ -2231,6 +2267,10 @@ RID FontFile::find_variation(const Dictionary &p_variation_coordinates, int p_fa
|
|
|
TS->font_set_face_index(cache[idx], p_face_index);
|
|
|
TS->font_set_embolden(cache[idx], p_strength);
|
|
|
TS->font_set_transform(cache[idx], p_transform);
|
|
|
+ TS->font_set_spacing(cache[idx], TextServer::SPACING_TOP, p_spacing_top);
|
|
|
+ TS->font_set_spacing(cache[idx], TextServer::SPACING_BOTTOM, p_spacing_bottom);
|
|
|
+ TS->font_set_spacing(cache[idx], TextServer::SPACING_SPACE, p_spacing_space);
|
|
|
+ TS->font_set_spacing(cache[idx], TextServer::SPACING_GLYPH, p_spacing_glyph);
|
|
|
return cache[idx];
|
|
|
}
|
|
|
|
|
@@ -2312,6 +2352,18 @@ Transform2D FontFile::get_transform(int p_cache_index) const {
|
|
|
return TS->font_get_transform(cache[p_cache_index]);
|
|
|
}
|
|
|
|
|
|
+void FontFile::set_extra_spacing(int p_cache_index, TextServer::SpacingType p_spacing, int64_t p_value) {
|
|
|
+ ERR_FAIL_COND(p_cache_index < 0);
|
|
|
+ _ensure_rid(p_cache_index);
|
|
|
+ TS->font_set_spacing(cache[p_cache_index], p_spacing, p_value);
|
|
|
+}
|
|
|
+
|
|
|
+int64_t FontFile::get_extra_spacing(int p_cache_index, TextServer::SpacingType p_spacing) const {
|
|
|
+ ERR_FAIL_COND_V(p_cache_index < 0, 0);
|
|
|
+ _ensure_rid(p_cache_index);
|
|
|
+ return TS->font_get_spacing(cache[p_cache_index], p_spacing);
|
|
|
+}
|
|
|
+
|
|
|
void FontFile::set_face_index(int p_cache_index, int64_t p_index) {
|
|
|
ERR_FAIL_COND(p_cache_index < 0);
|
|
|
ERR_FAIL_COND(p_index < 0);
|
|
@@ -2848,10 +2900,10 @@ int FontVariation::get_spacing(TextServer::SpacingType p_spacing) const {
|
|
|
return extra_spacing[p_spacing];
|
|
|
}
|
|
|
|
|
|
-RID FontVariation::find_variation(const Dictionary &p_variation_coordinates, int p_face_index, float p_strength, Transform2D p_transform) const {
|
|
|
+RID FontVariation::find_variation(const Dictionary &p_variation_coordinates, int p_face_index, float p_strength, Transform2D p_transform, int p_spacing_top, int p_spacing_bottom, int p_spacing_space, int p_spacing_glyph) const {
|
|
|
Ref<Font> f = _get_base_font_or_default();
|
|
|
if (f.is_valid()) {
|
|
|
- return f->find_variation(p_variation_coordinates, p_face_index, p_strength, p_transform);
|
|
|
+ return f->find_variation(p_variation_coordinates, p_face_index, p_strength, p_transform, p_spacing_top, p_spacing_bottom, p_spacing_space, p_spacing_glyph);
|
|
|
}
|
|
|
return RID();
|
|
|
}
|
|
@@ -2859,7 +2911,7 @@ RID FontVariation::find_variation(const Dictionary &p_variation_coordinates, int
|
|
|
RID FontVariation::_get_rid() const {
|
|
|
Ref<Font> f = _get_base_font_or_default();
|
|
|
if (f.is_valid()) {
|
|
|
- return f->find_variation(variation.opentype, variation.face_index, variation.embolden, variation.transform);
|
|
|
+ return f->find_variation(variation.opentype, variation.face_index, variation.embolden, variation.transform, extra_spacing[TextServer::SPACING_TOP], extra_spacing[TextServer::SPACING_BOTTOM], extra_spacing[TextServer::SPACING_SPACE], extra_spacing[TextServer::SPACING_GLYPH]);
|
|
|
}
|
|
|
return RID();
|
|
|
}
|
|
@@ -3328,7 +3380,7 @@ int SystemFont::get_spacing(TextServer::SpacingType p_spacing) const {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-RID SystemFont::find_variation(const Dictionary &p_variation_coordinates, int p_face_index, float p_strength, Transform2D p_transform) const {
|
|
|
+RID SystemFont::find_variation(const Dictionary &p_variation_coordinates, int p_face_index, float p_strength, Transform2D p_transform, int p_spacing_top, int p_spacing_bottom, int p_spacing_space, int p_spacing_glyph) const {
|
|
|
Ref<Font> f = _get_base_font_or_default();
|
|
|
if (f.is_valid()) {
|
|
|
Dictionary var = p_variation_coordinates;
|
|
@@ -3344,9 +3396,9 @@ RID SystemFont::find_variation(const Dictionary &p_variation_coordinates, int p_
|
|
|
|
|
|
if (!face_indeces.is_empty()) {
|
|
|
int face_index = CLAMP(p_face_index, 0, face_indeces.size() - 1);
|
|
|
- return f->find_variation(var, face_indeces[face_index], p_strength, p_transform);
|
|
|
+ return f->find_variation(var, face_indeces[face_index], p_strength, p_transform, p_spacing_top, p_spacing_bottom, p_spacing_space, p_spacing_glyph);
|
|
|
} else {
|
|
|
- return f->find_variation(var, 0, p_strength, p_transform);
|
|
|
+ return f->find_variation(var, 0, p_strength, p_transform, p_spacing_top, p_spacing_bottom, p_spacing_space, p_spacing_glyph);
|
|
|
}
|
|
|
}
|
|
|
return RID();
|