feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -32,8 +32,6 @@
|
|||
#include "font.compat.inc"
|
||||
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/string/translation.h"
|
||||
#include "core/templates/hash_map.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
#include "scene/resources/image_texture.h"
|
||||
|
|
@ -102,23 +100,24 @@ void Font::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, MAKE_RESOURCE_TYPE_HINT("Font")), "set_fallbacks", "get_fallbacks");
|
||||
}
|
||||
|
||||
void Font::_update_rids_fb(const Ref<Font> &p_f, int p_depth) const {
|
||||
void Font::_update_rids_fb(const Font *p_f, int p_depth) const {
|
||||
ERR_FAIL_COND(p_depth > MAX_FALLBACK_DEPTH);
|
||||
if (p_f.is_valid()) {
|
||||
if (p_f != nullptr) {
|
||||
RID rid = p_f->_get_rid();
|
||||
if (rid.is_valid()) {
|
||||
rids.push_back(rid);
|
||||
}
|
||||
const TypedArray<Font> &_fallbacks = p_f->get_fallbacks();
|
||||
for (int i = 0; i < _fallbacks.size(); i++) {
|
||||
_update_rids_fb(_fallbacks[i], p_depth + 1);
|
||||
Ref<Font> fb_font = _fallbacks[i];
|
||||
_update_rids_fb(fb_font.ptr(), p_depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Font::_update_rids() const {
|
||||
rids.clear();
|
||||
_update_rids_fb(const_cast<Font *>(this), 0);
|
||||
_update_rids_fb(this, 0);
|
||||
dirty_rids = false;
|
||||
}
|
||||
|
||||
|
|
@ -211,9 +210,10 @@ real_t Font::get_height(int p_font_size) const {
|
|||
if (dirty_rids) {
|
||||
_update_rids();
|
||||
}
|
||||
|
||||
real_t ret = 0.f;
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
ret = MAX(ret, TS->font_get_ascent(rids[i], p_font_size) + TS->font_get_descent(rids[i], p_font_size));
|
||||
ret = MAX(ret, TS->font_get_ascent(rids.get(i), p_font_size) + TS->font_get_descent(rids.get(i), p_font_size));
|
||||
}
|
||||
return ret + get_spacing(TextServer::SPACING_BOTTOM) + get_spacing(TextServer::SPACING_TOP);
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ real_t Font::get_ascent(int p_font_size) const {
|
|||
}
|
||||
real_t ret = 0.f;
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
ret = MAX(ret, TS->font_get_ascent(rids[i], p_font_size));
|
||||
ret = MAX(ret, TS->font_get_ascent(rids.get(i), p_font_size));
|
||||
}
|
||||
return ret + get_spacing(TextServer::SPACING_TOP);
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ real_t Font::get_descent(int p_font_size) const {
|
|||
}
|
||||
real_t ret = 0.f;
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
ret = MAX(ret, TS->font_get_descent(rids[i], p_font_size));
|
||||
ret = MAX(ret, TS->font_get_descent(rids.get(i), p_font_size));
|
||||
}
|
||||
return ret + get_spacing(TextServer::SPACING_BOTTOM);
|
||||
}
|
||||
|
|
@ -246,7 +246,7 @@ real_t Font::get_underline_position(int p_font_size) const {
|
|||
}
|
||||
real_t ret = 0.f;
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
ret = MAX(ret, TS->font_get_underline_position(rids[i], p_font_size));
|
||||
ret = MAX(ret, TS->font_get_underline_position(rids.get(i), p_font_size));
|
||||
}
|
||||
return ret + get_spacing(TextServer::SPACING_TOP);
|
||||
}
|
||||
|
|
@ -257,7 +257,7 @@ real_t Font::get_underline_thickness(int p_font_size) const {
|
|||
}
|
||||
real_t ret = 0.f;
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
ret = MAX(ret, TS->font_get_underline_thickness(rids[i], p_font_size));
|
||||
ret = MAX(ret, TS->font_get_underline_thickness(rids.get(i), p_font_size));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -477,9 +477,9 @@ Size2 Font::get_char_size(char32_t p_char, int p_font_size) const {
|
|||
_update_rids();
|
||||
}
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
if (TS->font_has_char(rids[i], p_char)) {
|
||||
int32_t glyph = TS->font_get_glyph_index(rids[i], p_font_size, p_char, 0);
|
||||
return Size2(TS->font_get_glyph_advance(rids[i], p_font_size, glyph).x, get_height(p_font_size));
|
||||
if (TS->font_has_char(rids.get(i), p_char)) {
|
||||
int32_t glyph = TS->font_get_glyph_index(rids.get(i), p_font_size, p_char, 0);
|
||||
return Size2(TS->font_get_glyph_advance(rids.get(i), p_font_size, glyph).x, get_height(p_font_size));
|
||||
}
|
||||
}
|
||||
return Size2();
|
||||
|
|
@ -490,10 +490,10 @@ real_t Font::draw_char(RID p_canvas_item, const Point2 &p_pos, char32_t p_char,
|
|||
_update_rids();
|
||||
}
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
if (TS->font_has_char(rids[i], p_char)) {
|
||||
int32_t glyph = TS->font_get_glyph_index(rids[i], p_font_size, p_char, 0);
|
||||
TS->font_draw_glyph(rids[i], p_canvas_item, p_font_size, p_pos, glyph, p_modulate);
|
||||
return TS->font_get_glyph_advance(rids[i], p_font_size, glyph).x;
|
||||
if (TS->font_has_char(rids.get(i), p_char)) {
|
||||
int32_t glyph = TS->font_get_glyph_index(rids.get(i), p_font_size, p_char, 0);
|
||||
TS->font_draw_glyph(rids.get(i), p_canvas_item, p_font_size, p_pos, glyph, p_modulate);
|
||||
return TS->font_get_glyph_advance(rids.get(i), p_font_size, glyph).x;
|
||||
}
|
||||
}
|
||||
return 0.f;
|
||||
|
|
@ -504,10 +504,10 @@ real_t Font::draw_char_outline(RID p_canvas_item, const Point2 &p_pos, char32_t
|
|||
_update_rids();
|
||||
}
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
if (TS->font_has_char(rids[i], p_char)) {
|
||||
int32_t glyph = TS->font_get_glyph_index(rids[i], p_font_size, p_char, 0);
|
||||
TS->font_draw_glyph_outline(rids[i], p_canvas_item, p_font_size, p_size, p_pos, glyph, p_modulate);
|
||||
return TS->font_get_glyph_advance(rids[i], p_font_size, glyph).x;
|
||||
if (TS->font_has_char(rids.get(i), p_char)) {
|
||||
int32_t glyph = TS->font_get_glyph_index(rids.get(i), p_font_size, p_char, 0);
|
||||
TS->font_draw_glyph_outline(rids.get(i), p_canvas_item, p_font_size, p_size, p_pos, glyph, p_modulate);
|
||||
return TS->font_get_glyph_advance(rids.get(i), p_font_size, glyph).x;
|
||||
}
|
||||
}
|
||||
return 0.f;
|
||||
|
|
@ -519,7 +519,7 @@ bool Font::has_char(char32_t p_char) const {
|
|||
_update_rids();
|
||||
}
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
if (TS->font_has_char(rids[i], p_char)) {
|
||||
if (TS->font_has_char(rids.get(i), p_char)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -532,7 +532,7 @@ String Font::get_supported_chars() const {
|
|||
}
|
||||
String chars;
|
||||
for (int i = 0; i < rids.size(); i++) {
|
||||
String data_chars = TS->font_get_supported_chars(rids[i]);
|
||||
String data_chars = TS->font_get_supported_chars(rids.get(i));
|
||||
for (int j = 0; j < data_chars.length(); j++) {
|
||||
if (chars.find_char(data_chars[j]) == -1) {
|
||||
chars += data_chars[j];
|
||||
|
|
@ -605,6 +605,7 @@ _FORCE_INLINE_ void FontFile::_ensure_rid(int p_cache_index, int p_make_linked_f
|
|||
TS->font_set_allow_system_fallback(cache[p_cache_index], allow_system_fallback);
|
||||
TS->font_set_hinting(cache[p_cache_index], hinting);
|
||||
TS->font_set_subpixel_positioning(cache[p_cache_index], subpixel_positioning);
|
||||
TS->font_set_keep_rounding_remainders(cache[p_cache_index], keep_rounding_remainders);
|
||||
TS->font_set_oversampling(cache[p_cache_index], oversampling);
|
||||
}
|
||||
}
|
||||
|
|
@ -647,13 +648,13 @@ void FontFile::_convert_packed_8bit(Ref<Image> &p_source, int p_page, int p_sz)
|
|||
wa[ofs_dst + 1] = r[ofs_src + 3];
|
||||
}
|
||||
}
|
||||
Ref<Image> img_r = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_r));
|
||||
Ref<Image> img_r = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_r));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 0, img_r);
|
||||
Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_g));
|
||||
Ref<Image> img_g = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_g));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 1, img_g);
|
||||
Ref<Image> img_b = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_b));
|
||||
Ref<Image> img_b = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_b));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 2, img_b);
|
||||
Ref<Image> img_a = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_a));
|
||||
Ref<Image> img_a = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_a));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 3, img_a);
|
||||
}
|
||||
|
||||
|
|
@ -738,22 +739,22 @@ void FontFile::_convert_packed_4bit(Ref<Image> &p_source, int p_page, int p_sz)
|
|||
}
|
||||
}
|
||||
}
|
||||
Ref<Image> img_r = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_r));
|
||||
Ref<Image> img_r = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_r));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 0, img_r);
|
||||
Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_g));
|
||||
Ref<Image> img_g = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_g));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 1, img_g);
|
||||
Ref<Image> img_b = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_b));
|
||||
Ref<Image> img_b = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_b));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 2, img_b);
|
||||
Ref<Image> img_a = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_a));
|
||||
Ref<Image> img_a = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_a));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 3, img_a);
|
||||
|
||||
Ref<Image> img_ro = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_ro));
|
||||
Ref<Image> img_ro = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_ro));
|
||||
set_texture_image(0, Vector2i(p_sz, 1), p_page * 4 + 0, img_ro);
|
||||
Ref<Image> img_go = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_go));
|
||||
Ref<Image> img_go = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_go));
|
||||
set_texture_image(0, Vector2i(p_sz, 1), p_page * 4 + 1, img_go);
|
||||
Ref<Image> img_bo = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_bo));
|
||||
Ref<Image> img_bo = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_bo));
|
||||
set_texture_image(0, Vector2i(p_sz, 1), p_page * 4 + 2, img_bo);
|
||||
Ref<Image> img_ao = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_ao));
|
||||
Ref<Image> img_ao = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_ao));
|
||||
set_texture_image(0, Vector2i(p_sz, 1), p_page * 4 + 3, img_ao);
|
||||
}
|
||||
|
||||
|
|
@ -806,10 +807,10 @@ void FontFile::_convert_rgba_4bit(Ref<Image> &p_source, int p_page, int p_sz) {
|
|||
}
|
||||
}
|
||||
}
|
||||
Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_RGBA8, imgdata_g));
|
||||
Ref<Image> img_g = memnew(Image(w, h, false, Image::FORMAT_RGBA8, imgdata_g));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page, img_g);
|
||||
|
||||
Ref<Image> img_o = memnew(Image(w, h, 0, Image::FORMAT_RGBA8, imgdata_o));
|
||||
Ref<Image> img_o = memnew(Image(w, h, false, Image::FORMAT_RGBA8, imgdata_o));
|
||||
set_texture_image(0, Vector2i(p_sz, 1), p_page, img_o);
|
||||
}
|
||||
|
||||
|
|
@ -838,7 +839,7 @@ void FontFile::_convert_mono_8bit(Ref<Image> &p_source, int p_page, int p_ch, in
|
|||
wg[ofs_dst + 1] = r[ofs_src + p_ch];
|
||||
}
|
||||
}
|
||||
Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_g));
|
||||
Ref<Image> img_g = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_g));
|
||||
set_texture_image(0, Vector2i(p_sz, p_ol), p_page, img_g);
|
||||
}
|
||||
|
||||
|
|
@ -878,10 +879,10 @@ void FontFile::_convert_mono_4bit(Ref<Image> &p_source, int p_page, int p_ch, in
|
|||
}
|
||||
}
|
||||
}
|
||||
Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_g));
|
||||
Ref<Image> img_g = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_g));
|
||||
set_texture_image(0, Vector2i(p_sz, 0), p_page, img_g);
|
||||
|
||||
Ref<Image> img_o = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_o));
|
||||
Ref<Image> img_o = memnew(Image(w, h, false, Image::FORMAT_LA8, imgdata_o));
|
||||
set_texture_image(0, Vector2i(p_sz, p_ol), p_page, img_o);
|
||||
}
|
||||
|
||||
|
|
@ -934,6 +935,9 @@ void FontFile::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_subpixel_positioning", "subpixel_positioning"), &FontFile::set_subpixel_positioning);
|
||||
ClassDB::bind_method(D_METHOD("get_subpixel_positioning"), &FontFile::get_subpixel_positioning);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_keep_rounding_remainders", "keep_rounding_remainders"), &FontFile::set_keep_rounding_remainders);
|
||||
ClassDB::bind_method(D_METHOD("get_keep_rounding_remainders"), &FontFile::get_keep_rounding_remainders);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_oversampling", "oversampling"), &FontFile::set_oversampling);
|
||||
ClassDB::bind_method(D_METHOD("get_oversampling"), &FontFile::get_oversampling);
|
||||
|
||||
|
|
@ -1044,6 +1048,7 @@ void FontFile::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "font_stretch", PROPERTY_HINT_RANGE, "50,200,25", PROPERTY_USAGE_STORAGE), "set_font_stretch", "get_font_stretch");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel", PROPERTY_USAGE_STORAGE), "set_subpixel_positioning", "get_subpixel_positioning");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_rounding_remainders", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_keep_rounding_remainders", "get_keep_rounding_remainders");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_multichannel_signed_distance_field", "is_multichannel_signed_distance_field");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_msdf_pixel_range", "get_msdf_pixel_range");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_msdf_size", "get_msdf_size");
|
||||
|
|
@ -1094,7 +1099,7 @@ bool FontFile::_set(const StringName &p_name, const Variant &p_value) {
|
|||
Array textures = p_value;
|
||||
for (int i = 0; i < textures.size(); i++) {
|
||||
Ref<ImageTexture> tex = textures[i];
|
||||
ERR_CONTINUE(!tex.is_valid());
|
||||
ERR_CONTINUE(tex.is_null());
|
||||
set_texture_image(0, Vector2i(16, 0), i, tex->get_image());
|
||||
}
|
||||
} else if (tokens.size() == 1 && tokens[0] == "chars") {
|
||||
|
|
@ -1411,6 +1416,7 @@ void FontFile::reset_state() {
|
|||
allow_system_fallback = true;
|
||||
hinting = TextServer::HINTING_LIGHT;
|
||||
subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED;
|
||||
keep_rounding_remainders = true;
|
||||
msdf_pixel_range = 14;
|
||||
msdf_size = 128;
|
||||
fixed_size = 0;
|
||||
|
|
@ -1482,8 +1488,8 @@ Error FontFile::_load_bitmap_font(const String &p_path, List<String> *r_image_fi
|
|||
switch (block_type) {
|
||||
case 1: /* info */ {
|
||||
ERR_FAIL_COND_V_MSG(block_size < 15, ERR_CANT_CREATE, "Invalid BMFont info block size.");
|
||||
base_size = f->get_16();
|
||||
if (base_size <= 0) {
|
||||
base_size = ABS(static_cast<int16_t>(f->get_16()));
|
||||
if (base_size == 0) {
|
||||
base_size = 16;
|
||||
}
|
||||
uint8_t flags = f->get_8();
|
||||
|
|
@ -1734,7 +1740,7 @@ Error FontFile::_load_bitmap_font(const String &p_path, List<String> *r_image_fi
|
|||
while (true) {
|
||||
String line = f->get_line();
|
||||
|
||||
int delimiter = line.find(" ");
|
||||
int delimiter = line.find_char(' ');
|
||||
String type = line.substr(0, delimiter);
|
||||
int pos = delimiter + 1;
|
||||
HashMap<String, String> keys;
|
||||
|
|
@ -1744,7 +1750,7 @@ Error FontFile::_load_bitmap_font(const String &p_path, List<String> *r_image_fi
|
|||
}
|
||||
|
||||
while (pos < line.size()) {
|
||||
int eq = line.find("=", pos);
|
||||
int eq = line.find_char('=', pos);
|
||||
if (eq == -1) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -1752,14 +1758,14 @@ Error FontFile::_load_bitmap_font(const String &p_path, List<String> *r_image_fi
|
|||
int end = -1;
|
||||
String value;
|
||||
if (line[eq + 1] == '"') {
|
||||
end = line.find("\"", eq + 2);
|
||||
end = line.find_char('"', eq + 2);
|
||||
if (end == -1) {
|
||||
break;
|
||||
}
|
||||
value = line.substr(eq + 2, end - 1 - eq - 1);
|
||||
pos = end + 1;
|
||||
} else {
|
||||
end = line.find(" ", eq + 1);
|
||||
end = line.find_char(' ', eq + 1);
|
||||
if (end == -1) {
|
||||
end = line.size();
|
||||
}
|
||||
|
|
@ -1776,7 +1782,10 @@ Error FontFile::_load_bitmap_font(const String &p_path, List<String> *r_image_fi
|
|||
|
||||
if (type == "info") {
|
||||
if (keys.has("size")) {
|
||||
base_size = keys["size"].to_int();
|
||||
base_size = ABS(keys["size"].to_int());
|
||||
if (base_size == 0) {
|
||||
base_size = 16;
|
||||
}
|
||||
}
|
||||
if (keys.has("outline")) {
|
||||
outline = keys["outline"].to_int();
|
||||
|
|
@ -2081,9 +2090,8 @@ void FontFile::set_data(const PackedByteArray &p_data) {
|
|||
|
||||
PackedByteArray FontFile::get_data() const {
|
||||
if (unlikely((size_t)data.size() != data_size)) {
|
||||
PackedByteArray *data_w = const_cast<PackedByteArray *>(&data);
|
||||
data_w->resize(data_size);
|
||||
memcpy(data_w->ptrw(), data_ptr, data_size);
|
||||
data.resize(data_size);
|
||||
memcpy(data.ptrw(), data_ptr, data_size);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
|
@ -2293,6 +2301,21 @@ TextServer::SubpixelPositioning FontFile::get_subpixel_positioning() const {
|
|||
return subpixel_positioning;
|
||||
}
|
||||
|
||||
void FontFile::set_keep_rounding_remainders(bool p_keep_rounding_remainders) {
|
||||
if (keep_rounding_remainders != p_keep_rounding_remainders) {
|
||||
keep_rounding_remainders = p_keep_rounding_remainders;
|
||||
for (int i = 0; i < cache.size(); i++) {
|
||||
_ensure_rid(i);
|
||||
TS->font_set_keep_rounding_remainders(cache[i], keep_rounding_remainders);
|
||||
}
|
||||
emit_changed();
|
||||
}
|
||||
}
|
||||
|
||||
bool FontFile::get_keep_rounding_remainders() const {
|
||||
return keep_rounding_remainders;
|
||||
}
|
||||
|
||||
void FontFile::set_oversampling(real_t p_oversampling) {
|
||||
if (oversampling != p_oversampling) {
|
||||
oversampling = p_oversampling;
|
||||
|
|
@ -2850,10 +2873,11 @@ void FontVariation::_update_rids() const {
|
|||
|
||||
const TypedArray<Font> &base_fallbacks = f->get_fallbacks();
|
||||
for (int i = 0; i < base_fallbacks.size(); i++) {
|
||||
_update_rids_fb(base_fallbacks[i], 0);
|
||||
Ref<Font> fb_font = base_fallbacks[i];
|
||||
_update_rids_fb(fb_font.ptr(), 0);
|
||||
}
|
||||
} else {
|
||||
_update_rids_fb(const_cast<FontVariation *>(this), 0);
|
||||
_update_rids_fb(this, 0);
|
||||
}
|
||||
dirty_rids = false;
|
||||
}
|
||||
|
|
@ -2900,7 +2924,7 @@ Ref<Font> FontVariation::get_base_font() const {
|
|||
|
||||
Ref<Font> FontVariation::_get_base_font_or_default() const {
|
||||
if (theme_font.is_valid()) {
|
||||
theme_font->disconnect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids));
|
||||
theme_font->disconnect_changed(callable_mp(static_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids));
|
||||
theme_font.unref();
|
||||
}
|
||||
|
||||
|
|
@ -2909,13 +2933,13 @@ Ref<Font> FontVariation::_get_base_font_or_default() const {
|
|||
}
|
||||
|
||||
StringName theme_name = "font";
|
||||
List<StringName> theme_types;
|
||||
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
|
||||
Vector<StringName> theme_types;
|
||||
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), theme_types);
|
||||
|
||||
ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
|
||||
List<Ref<Theme>> themes = global_context->get_themes();
|
||||
Vector<Ref<Theme>> themes = global_context->get_themes();
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
themes.push_front(ThemeDB::get_singleton()->get_project_theme());
|
||||
themes.insert(0, ThemeDB::get_singleton()->get_project_theme());
|
||||
}
|
||||
|
||||
for (const Ref<Theme> &theme : themes) {
|
||||
|
|
@ -2934,7 +2958,7 @@ Ref<Font> FontVariation::_get_base_font_or_default() const {
|
|||
}
|
||||
if (f.is_valid()) {
|
||||
theme_font = f;
|
||||
theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
|
||||
theme_font->connect_changed(callable_mp(static_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
|
@ -2944,7 +2968,7 @@ Ref<Font> FontVariation::_get_base_font_or_default() const {
|
|||
if (!_is_base_cyclic(f, 0)) {
|
||||
if (f.is_valid()) {
|
||||
theme_font = f;
|
||||
theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
|
||||
theme_font->connect_changed(callable_mp(static_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
|
@ -3082,6 +3106,9 @@ void SystemFont::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_subpixel_positioning", "subpixel_positioning"), &SystemFont::set_subpixel_positioning);
|
||||
ClassDB::bind_method(D_METHOD("get_subpixel_positioning"), &SystemFont::get_subpixel_positioning);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_keep_rounding_remainders", "keep_rounding_remainders"), &SystemFont::set_keep_rounding_remainders);
|
||||
ClassDB::bind_method(D_METHOD("get_keep_rounding_remainders"), &SystemFont::get_keep_rounding_remainders);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_multichannel_signed_distance_field", "msdf"), &SystemFont::set_multichannel_signed_distance_field);
|
||||
ClassDB::bind_method(D_METHOD("is_multichannel_signed_distance_field"), &SystemFont::is_multichannel_signed_distance_field);
|
||||
|
||||
|
|
@ -3113,6 +3140,7 @@ void SystemFont::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_autohinter"), "set_force_autohinter", "is_force_autohinter");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), "set_hinting", "get_hinting");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel"), "set_subpixel_positioning", "get_subpixel_positioning");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), "set_keep_rounding_remainders", "get_keep_rounding_remainders");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field"), "set_multichannel_signed_distance_field", "is_multichannel_signed_distance_field");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_pixel_range"), "set_msdf_pixel_range", "get_msdf_pixel_range");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_size"), "set_msdf_size", "get_msdf_size");
|
||||
|
|
@ -3131,10 +3159,11 @@ void SystemFont::_update_rids() const {
|
|||
|
||||
const TypedArray<Font> &base_fallbacks = f->get_fallbacks();
|
||||
for (int i = 0; i < base_fallbacks.size(); i++) {
|
||||
_update_rids_fb(base_fallbacks[i], 0);
|
||||
Ref<Font> fb_font = base_fallbacks[i];
|
||||
_update_rids_fb(fb_font.ptr(), 0);
|
||||
}
|
||||
} else {
|
||||
_update_rids_fb(const_cast<SystemFont *>(this), 0);
|
||||
_update_rids_fb(this, 0);
|
||||
}
|
||||
dirty_rids = false;
|
||||
}
|
||||
|
|
@ -3145,7 +3174,7 @@ void SystemFont::_update_base_font() {
|
|||
base_font.unref();
|
||||
}
|
||||
|
||||
face_indeces.clear();
|
||||
face_indices.clear();
|
||||
ftr_weight = 0;
|
||||
ftr_stretch = 0;
|
||||
ftr_italic = 0;
|
||||
|
|
@ -3183,17 +3212,17 @@ void SystemFont::_update_base_font() {
|
|||
score += 30;
|
||||
}
|
||||
if (score > best_score) {
|
||||
face_indeces.clear();
|
||||
face_indices.clear();
|
||||
}
|
||||
if (score >= best_score) {
|
||||
best_score = score;
|
||||
face_indeces.push_back(i);
|
||||
face_indices.push_back(i);
|
||||
}
|
||||
}
|
||||
if (face_indeces.is_empty()) {
|
||||
face_indeces.push_back(0);
|
||||
if (face_indices.is_empty()) {
|
||||
face_indices.push_back(0);
|
||||
}
|
||||
file->set_face_index(0, face_indeces[0]);
|
||||
file->set_face_index(0, face_indices[0]);
|
||||
|
||||
// If it's a variable font, apply weight, stretch and italic coordinates to match requested style.
|
||||
if (best_score != 150) {
|
||||
|
|
@ -3217,6 +3246,7 @@ void SystemFont::_update_base_font() {
|
|||
file->set_allow_system_fallback(allow_system_fallback);
|
||||
file->set_hinting(hinting);
|
||||
file->set_subpixel_positioning(subpixel_positioning);
|
||||
file->set_keep_rounding_remainders(keep_rounding_remainders);
|
||||
file->set_multichannel_signed_distance_field(msdf);
|
||||
file->set_msdf_pixel_range(msdf_pixel_range);
|
||||
file->set_msdf_size(msdf_size);
|
||||
|
|
@ -3246,7 +3276,7 @@ void SystemFont::reset_state() {
|
|||
}
|
||||
|
||||
names.clear();
|
||||
face_indeces.clear();
|
||||
face_indices.clear();
|
||||
ftr_weight = 0;
|
||||
ftr_stretch = 0;
|
||||
ftr_italic = 0;
|
||||
|
|
@ -3260,6 +3290,7 @@ void SystemFont::reset_state() {
|
|||
allow_system_fallback = true;
|
||||
hinting = TextServer::HINTING_LIGHT;
|
||||
subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED;
|
||||
keep_rounding_remainders = true;
|
||||
oversampling = 0.f;
|
||||
msdf = false;
|
||||
|
||||
|
|
@ -3268,7 +3299,7 @@ void SystemFont::reset_state() {
|
|||
|
||||
Ref<Font> SystemFont::_get_base_font_or_default() const {
|
||||
if (theme_font.is_valid()) {
|
||||
theme_font->disconnect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids));
|
||||
theme_font->disconnect_changed(callable_mp(static_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids));
|
||||
theme_font.unref();
|
||||
}
|
||||
|
||||
|
|
@ -3277,8 +3308,8 @@ Ref<Font> SystemFont::_get_base_font_or_default() const {
|
|||
}
|
||||
|
||||
StringName theme_name = "font";
|
||||
List<StringName> theme_types;
|
||||
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
|
||||
Vector<StringName> theme_types;
|
||||
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), theme_types);
|
||||
|
||||
ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
|
||||
for (const Ref<Theme> &theme : global_context->get_themes()) {
|
||||
|
|
@ -3297,7 +3328,7 @@ Ref<Font> SystemFont::_get_base_font_or_default() const {
|
|||
}
|
||||
if (f.is_valid()) {
|
||||
theme_font = f;
|
||||
theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
|
||||
theme_font->connect_changed(callable_mp(static_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
|
@ -3307,7 +3338,7 @@ Ref<Font> SystemFont::_get_base_font_or_default() const {
|
|||
if (!_is_base_cyclic(f, 0)) {
|
||||
if (f.is_valid()) {
|
||||
theme_font = f;
|
||||
theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
|
||||
theme_font->connect_changed(callable_mp(static_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
|
@ -3413,6 +3444,20 @@ TextServer::SubpixelPositioning SystemFont::get_subpixel_positioning() const {
|
|||
return subpixel_positioning;
|
||||
}
|
||||
|
||||
void SystemFont::set_keep_rounding_remainders(bool p_keep_rounding_remainders) {
|
||||
if (keep_rounding_remainders != p_keep_rounding_remainders) {
|
||||
keep_rounding_remainders = p_keep_rounding_remainders;
|
||||
if (base_font.is_valid()) {
|
||||
base_font->set_keep_rounding_remainders(keep_rounding_remainders);
|
||||
}
|
||||
emit_changed();
|
||||
}
|
||||
}
|
||||
|
||||
bool SystemFont::get_keep_rounding_remainders() const {
|
||||
return keep_rounding_remainders;
|
||||
}
|
||||
|
||||
void SystemFont::set_multichannel_signed_distance_field(bool p_msdf) {
|
||||
if (msdf != p_msdf) {
|
||||
msdf = p_msdf;
|
||||
|
|
@ -3535,9 +3580,9 @@ RID SystemFont::find_variation(const Dictionary &p_variation_coordinates, int p_
|
|||
var[TS->name_to_tag("italic")] = ftr_italic;
|
||||
}
|
||||
|
||||
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, p_spacing_top, p_spacing_bottom, p_spacing_space, p_spacing_glyph, p_baseline_offset);
|
||||
if (!face_indices.is_empty()) {
|
||||
int face_index = CLAMP(p_face_index, 0, face_indices.size() - 1);
|
||||
return f->find_variation(var, face_indices[face_index], p_strength, p_transform, p_spacing_top, p_spacing_bottom, p_spacing_space, p_spacing_glyph, p_baseline_offset);
|
||||
} else {
|
||||
return f->find_variation(var, 0, p_strength, p_transform, p_spacing_top, p_spacing_bottom, p_spacing_space, p_spacing_glyph, p_baseline_offset);
|
||||
}
|
||||
|
|
@ -3548,7 +3593,7 @@ RID SystemFont::find_variation(const Dictionary &p_variation_coordinates, int p_
|
|||
RID SystemFont::_get_rid() const {
|
||||
Ref<Font> f = _get_base_font_or_default();
|
||||
if (f.is_valid()) {
|
||||
if (!face_indeces.is_empty()) {
|
||||
if (!face_indices.is_empty()) {
|
||||
Dictionary var;
|
||||
if (ftr_weight > 0) {
|
||||
var[TS->name_to_tag("weight")] = ftr_weight;
|
||||
|
|
@ -3559,7 +3604,7 @@ RID SystemFont::_get_rid() const {
|
|||
if (ftr_italic > 0) {
|
||||
var[TS->name_to_tag("italic")] = ftr_italic;
|
||||
}
|
||||
return f->find_variation(var, face_indeces[0]);
|
||||
return f->find_variation(var, face_indices[0]);
|
||||
} else {
|
||||
return f->_get_rid();
|
||||
}
|
||||
|
|
@ -3568,7 +3613,7 @@ RID SystemFont::_get_rid() const {
|
|||
}
|
||||
|
||||
int64_t SystemFont::get_face_count() const {
|
||||
return face_indeces.size();
|
||||
return face_indices.size();
|
||||
}
|
||||
|
||||
SystemFont::SystemFont() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue