| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  text_server_fb.cpp                                                   */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                      https://godotengine.org                          */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2022-01-03 21:27:34 +01:00
										 |  |  | /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "text_server_fb.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | #ifdef GDEXTENSION
 | 
					
						
							|  |  |  | // Headers for building as GDExtension plug-in.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <godot_cpp/classes/file.hpp>
 | 
					
						
							|  |  |  | #include <godot_cpp/classes/rendering_server.hpp>
 | 
					
						
							|  |  |  | #include <godot_cpp/classes/translation_server.hpp>
 | 
					
						
							|  |  |  | #include <godot_cpp/core/error_macros.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace godot; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | // Headers for building as built-in module.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-15 10:11:31 +02:00
										 |  |  | #include "core/error/error_macros.h"
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | #include "core/string/print_string.h"
 | 
					
						
							| 
									
										
										
										
											2022-01-17 10:54:45 +02:00
										 |  |  | #include "core/string/ucaps.h"
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-12 13:42:58 +01:00
										 |  |  | #include "modules/modules_enabled.gen.h" // For freetype, msdfgen.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Thirdparty headers.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | #ifdef MODULE_MSDFGEN_ENABLED
 | 
					
						
							|  |  |  | #include "core/ShapeDistanceFinder.h"
 | 
					
						
							|  |  |  | #include "core/contour-combiners.h"
 | 
					
						
							|  |  |  | #include "core/edge-selectors.h"
 | 
					
						
							|  |  |  | #include "msdfgen.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | #define OT_TAG(c1, c2, c3, c4) ((int32_t)((((uint32_t)(c1)&0xff) << 24) | (((uint32_t)(c2)&0xff) << 16) | (((uint32_t)(c3)&0xff) << 8) | ((uint32_t)(c4)&0xff)))
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | bool TextServerFallback::has_feature(Feature p_feature) const { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	switch (p_feature) { | 
					
						
							|  |  |  | 		case FEATURE_SIMPLE_LAYOUT: | 
					
						
							|  |  |  | 		case FEATURE_FONT_BITMAP: | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 		case FEATURE_FONT_DYNAMIC: | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifdef MODULE_MSDFGEN_ENABLED
 | 
					
						
							|  |  |  | 		case FEATURE_FONT_MSDF: | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		default: { | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String TextServerFallback::get_name() const { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | #ifdef GDEXTENSION
 | 
					
						
							|  |  |  | 	return "Fallback (GDExtension)"; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	return "Fallback (Built-in)"; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::get_features() const { | 
					
						
							|  |  |  | 	int64_t interface_features = FEATURE_SIMPLE_LAYOUT | FEATURE_FONT_BITMAP; | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 	interface_features |= FEATURE_FONT_DYNAMIC; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifdef MODULE_MSDFGEN_ENABLED
 | 
					
						
							|  |  |  | 	interface_features |= FEATURE_FONT_MSDF; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	return interface_features; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::free_rid(const RID &p_rid) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	_THREAD_SAFE_METHOD_ | 
					
						
							|  |  |  | 	if (font_owner.owns(p_rid)) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 		FontDataFallback *fd = font_owner.get_or_null(p_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		font_owner.free(p_rid); | 
					
						
							|  |  |  | 		memdelete(fd); | 
					
						
							|  |  |  | 	} else if (shaped_owner.owns(p_rid)) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 		ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		shaped_owner.free(p_rid); | 
					
						
							|  |  |  | 		memdelete(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::has(const RID &p_rid) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	_THREAD_SAFE_METHOD_ | 
					
						
							|  |  |  | 	return font_owner.owns(p_rid) || shaped_owner.owns(p_rid); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TextServerFallback::load_support_data(const String &p_filename) { | 
					
						
							|  |  |  | 	return false; // No extra data used.
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | bool TextServerFallback::save_support_data(const String &p_filename) const { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return false; // No extra data used.
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | bool TextServerFallback::is_locale_right_to_left(const String &p_locale) const { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return false; // No RTL support.
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | _FORCE_INLINE_ void TextServerFallback::_insert_feature(const StringName &p_name, int32_t p_tag) { | 
					
						
							|  |  |  | 	feature_sets.insert(p_name, p_tag); | 
					
						
							|  |  |  | 	feature_sets_inv.insert(p_tag, p_name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:45:54 +03:00
										 |  |  | void TextServerFallback::_insert_feature_sets() { | 
					
						
							|  |  |  | 	// Registered OpenType variation tag.
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	_insert_feature("italic", OT_TAG('i', 't', 'a', 'l')); | 
					
						
							|  |  |  | 	_insert_feature("optical_size", OT_TAG('o', 'p', 's', 'z')); | 
					
						
							|  |  |  | 	_insert_feature("slant", OT_TAG('s', 'l', 'n', 't')); | 
					
						
							|  |  |  | 	_insert_feature("width", OT_TAG('w', 'd', 't', 'h')); | 
					
						
							|  |  |  | 	_insert_feature("weight", OT_TAG('w', 'g', 'h', 't')); | 
					
						
							| 
									
										
										
										
											2021-10-12 08:45:54 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | _FORCE_INLINE_ int32_t ot_tag_from_string(const char *p_str, int p_len) { | 
					
						
							|  |  |  | 	char tag[4]; | 
					
						
							|  |  |  | 	uint32_t i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-27 10:34:33 -06:00
										 |  |  | 	if (!p_str || !p_len || !*p_str) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		return OT_TAG(0, 0, 0, 0); | 
					
						
							| 
									
										
										
										
											2022-01-27 10:34:33 -06:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_len < 0 || p_len > 4) { | 
					
						
							|  |  |  | 		p_len = 4; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for (i = 0; i < (uint32_t)p_len && p_str[i]; i++) { | 
					
						
							|  |  |  | 		tag[i] = p_str[i]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (; i < 4; i++) { | 
					
						
							|  |  |  | 		tag[i] = ' '; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OT_TAG(tag[0], tag[1], tag[2], tag[3]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::name_to_tag(const String &p_name) const { | 
					
						
							| 
									
										
										
										
											2021-10-12 08:45:54 +03:00
										 |  |  | 	if (feature_sets.has(p_name)) { | 
					
						
							|  |  |  | 		return feature_sets[p_name]; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// No readable name, use tag string.
 | 
					
						
							|  |  |  | 	return ot_tag_from_string(p_name.replace("custom_", "").ascii().get_data(), -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _FORCE_INLINE_ void ot_tag_to_string(int32_t p_tag, char *p_buf) { | 
					
						
							|  |  |  | 	p_buf[0] = (char)(uint8_t)(p_tag >> 24); | 
					
						
							|  |  |  | 	p_buf[1] = (char)(uint8_t)(p_tag >> 16); | 
					
						
							|  |  |  | 	p_buf[2] = (char)(uint8_t)(p_tag >> 8); | 
					
						
							|  |  |  | 	p_buf[3] = (char)(uint8_t)(p_tag >> 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | String TextServerFallback::tag_to_name(int64_t p_tag) const { | 
					
						
							|  |  |  | 	if (feature_sets_inv.has(p_tag)) { | 
					
						
							|  |  |  | 		return feature_sets_inv[p_tag]; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// No readable name, use tag string.
 | 
					
						
							|  |  |  | 	char name[5]; | 
					
						
							|  |  |  | 	memset(name, 0, 5); | 
					
						
							|  |  |  | 	ot_tag_to_string(p_tag, name); | 
					
						
							|  |  |  | 	return String("custom_") + String(name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | /* Font Glyph Rendering                                                  */ | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | _FORCE_INLINE_ TextServerFallback::FontTexturePosition TextServerFallback::find_texture_pos_for_glyph(FontDataForSizeFallback *p_data, int p_color_size, Image::Format p_image_format, int p_width, int p_height, bool p_msdf) const { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	FontTexturePosition ret; | 
					
						
							|  |  |  | 	ret.index = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int mw = p_width; | 
					
						
							|  |  |  | 	int mh = p_height; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < p_data->textures.size(); i++) { | 
					
						
							|  |  |  | 		const FontTexture &ct = p_data->textures[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (mw > ct.texture_w || mh > ct.texture_h) { // Too big for this texture.
 | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 18:36:00 +03:00
										 |  |  | 		if (ct.offsets.size() < ct.texture_w) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		ret.y = 0x7fffffff; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		ret.x = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int j = 0; j < ct.texture_w - mw; j++) { | 
					
						
							|  |  |  | 			int max_y = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (int k = j; k < j + mw; k++) { | 
					
						
							|  |  |  | 				int y = ct.offsets[k]; | 
					
						
							|  |  |  | 				if (y > max_y) { | 
					
						
							|  |  |  | 					max_y = y; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (max_y < ret.y) { | 
					
						
							|  |  |  | 				ret.y = max_y; | 
					
						
							|  |  |  | 				ret.x = j; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		if (ret.y == 0x7fffffff || ret.y + mh > ct.texture_h) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			continue; // Fail, could not fit it here.
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ret.index = i; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ret.index == -1) { | 
					
						
							|  |  |  | 		// Could not find texture to fit, create one.
 | 
					
						
							|  |  |  | 		ret.x = 0; | 
					
						
							|  |  |  | 		ret.y = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int texsize = MAX(p_data->size.x * p_data->oversampling * 8, 256); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | #ifdef GDEXTENSION
 | 
					
						
							|  |  |  | 		texsize = Math::next_power_of_2(texsize); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		texsize = next_power_of_2(texsize); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 		if (p_msdf) { | 
					
						
							|  |  |  | 			texsize = MIN(texsize, 2048); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			texsize = MIN(texsize, 1024); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 		if (mw > texsize) { // Special case, adapt to it?
 | 
					
						
							|  |  |  | #ifdef GDEXTENSION
 | 
					
						
							|  |  |  | 			texsize = Math::next_power_of_2(mw); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 			texsize = next_power_of_2(mw); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (mh > texsize) { // Special case, adapt to it?
 | 
					
						
							|  |  |  | #ifdef GDEXTENSION
 | 
					
						
							|  |  |  | 			texsize = Math::next_power_of_2(mh); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 			texsize = next_power_of_2(mh); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		FontTexture tex; | 
					
						
							|  |  |  | 		tex.texture_w = texsize; | 
					
						
							|  |  |  | 		tex.texture_h = texsize; | 
					
						
							|  |  |  | 		tex.format = p_image_format; | 
					
						
							|  |  |  | 		tex.imgdata.resize(texsize * texsize * p_color_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			// Zero texture.
 | 
					
						
							|  |  |  | 			uint8_t *w = tex.imgdata.ptrw(); | 
					
						
							|  |  |  | 			ERR_FAIL_COND_V(texsize * texsize * p_color_size > tex.imgdata.size(), ret); | 
					
						
							|  |  |  | 			// Initialize the texture to all-white pixels to prevent artifacts when the
 | 
					
						
							|  |  |  | 			// font is displayed at a non-default scale with filtering enabled.
 | 
					
						
							|  |  |  | 			if (p_color_size == 2) { | 
					
						
							|  |  |  | 				for (int i = 0; i < texsize * texsize * p_color_size; i += 2) { // FORMAT_LA8, BW font.
 | 
					
						
							|  |  |  | 					w[i + 0] = 255; | 
					
						
							|  |  |  | 					w[i + 1] = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else if (p_color_size == 4) { | 
					
						
							|  |  |  | 				for (int i = 0; i < texsize * texsize * p_color_size; i += 4) { // FORMAT_RGBA8, Color font, Multichannel(+True) SDF.
 | 
					
						
							|  |  |  | 					w[i + 0] = 255; | 
					
						
							|  |  |  | 					w[i + 1] = 255; | 
					
						
							|  |  |  | 					w[i + 2] = 255; | 
					
						
							|  |  |  | 					w[i + 3] = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ERR_FAIL_V(ret); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		tex.offsets.resize(texsize); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		int32_t *offw = tex.offsets.ptrw(); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		for (int i = 0; i < texsize; i++) { // Zero offsets.
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			offw[i] = 0; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		p_data->textures.push_back(tex); | 
					
						
							|  |  |  | 		ret.index = p_data->textures.size() - 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef MODULE_MSDFGEN_ENABLED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct MSContext { | 
					
						
							|  |  |  | 	msdfgen::Point2 position; | 
					
						
							| 
									
										
										
										
											2022-05-02 16:28:25 +02:00
										 |  |  | 	msdfgen::Shape *shape = nullptr; | 
					
						
							|  |  |  | 	msdfgen::Contour *contour = nullptr; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DistancePixelConversion { | 
					
						
							|  |  |  | 	double invRange; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	_FORCE_INLINE_ explicit DistancePixelConversion(double range) : | 
					
						
							|  |  |  | 			invRange(1 / range) {} | 
					
						
							|  |  |  | 	_FORCE_INLINE_ void operator()(float *pixels, const msdfgen::MultiAndTrueDistance &distance) const { | 
					
						
							|  |  |  | 		pixels[0] = float(invRange * distance.r + .5); | 
					
						
							|  |  |  | 		pixels[1] = float(invRange * distance.g + .5); | 
					
						
							|  |  |  | 		pixels[2] = float(invRange * distance.b + .5); | 
					
						
							|  |  |  | 		pixels[3] = float(invRange * distance.a + .5); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct MSDFThreadData { | 
					
						
							|  |  |  | 	msdfgen::Bitmap<float, 4> *output; | 
					
						
							|  |  |  | 	msdfgen::Shape *shape; | 
					
						
							|  |  |  | 	msdfgen::Projection *projection; | 
					
						
							|  |  |  | 	DistancePixelConversion *distancePixelConversion; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static msdfgen::Point2 ft_point2(const FT_Vector &vector) { | 
					
						
							|  |  |  | 	return msdfgen::Point2(vector.x / 60.0f, vector.y / 60.0f); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | static int ft_move_to(const FT_Vector *to, void *user) { | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 	MSContext *context = static_cast<MSContext *>(user); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	if (!(context->contour && context->contour->edges.empty())) { | 
					
						
							|  |  |  | 		context->contour = &context->shape->addContour(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	context->position = ft_point2(*to); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ft_line_to(const FT_Vector *to, void *user) { | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 	MSContext *context = static_cast<MSContext *>(user); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	msdfgen::Point2 endpoint = ft_point2(*to); | 
					
						
							|  |  |  | 	if (endpoint != context->position) { | 
					
						
							|  |  |  | 		context->contour->addEdge(new msdfgen::LinearSegment(context->position, endpoint)); | 
					
						
							|  |  |  | 		context->position = endpoint; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ft_conic_to(const FT_Vector *control, const FT_Vector *to, void *user) { | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 	MSContext *context = static_cast<MSContext *>(user); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	context->contour->addEdge(new msdfgen::QuadraticSegment(context->position, ft_point2(*control), ft_point2(*to))); | 
					
						
							|  |  |  | 	context->position = ft_point2(*to); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ft_cubic_to(const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to, void *user) { | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 	MSContext *context = static_cast<MSContext *>(user); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	context->contour->addEdge(new msdfgen::CubicSegment(context->position, ft_point2(*control1), ft_point2(*control2), ft_point2(*to))); | 
					
						
							|  |  |  | 	context->position = ft_point2(*to); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TextServerFallback::_generateMTSDF_threaded(uint32_t y, void *p_td) const { | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 	MSDFThreadData *td = static_cast<MSDFThreadData *>(p_td); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	msdfgen::ShapeDistanceFinder<msdfgen::OverlappingContourCombiner<msdfgen::MultiAndTrueDistanceSelector>> distanceFinder(*td->shape); | 
					
						
							|  |  |  | 	int row = td->shape->inverseYAxis ? td->output->height() - y - 1 : y; | 
					
						
							|  |  |  | 	for (int col = 0; col < td->output->width(); ++col) { | 
					
						
							|  |  |  | 		int x = (y % 2) ? td->output->width() - col - 1 : col; | 
					
						
							|  |  |  | 		msdfgen::Point2 p = td->projection->unproject(msdfgen::Point2(x + .5, y + .5)); | 
					
						
							|  |  |  | 		msdfgen::MultiAndTrueDistance distance = distanceFinder.distance(p); | 
					
						
							|  |  |  | 		td->distancePixelConversion->operator()(td->output->operator()(x, row), distance); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _FORCE_INLINE_ TextServerFallback::FontGlyph TextServerFallback::rasterize_msdf(FontDataFallback *p_font_data, FontDataForSizeFallback *p_data, int p_pixel_range, int p_rect_margin, FT_Outline *outline, const Vector2 &advance) const { | 
					
						
							|  |  |  | 	msdfgen::Shape shape; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	shape.contours.clear(); | 
					
						
							|  |  |  | 	shape.inverseYAxis = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MSContext context = {}; | 
					
						
							|  |  |  | 	context.shape = &shape; | 
					
						
							|  |  |  | 	FT_Outline_Funcs ft_functions; | 
					
						
							|  |  |  | 	ft_functions.move_to = &ft_move_to; | 
					
						
							|  |  |  | 	ft_functions.line_to = &ft_line_to; | 
					
						
							|  |  |  | 	ft_functions.conic_to = &ft_conic_to; | 
					
						
							|  |  |  | 	ft_functions.cubic_to = &ft_cubic_to; | 
					
						
							|  |  |  | 	ft_functions.shift = 0; | 
					
						
							|  |  |  | 	ft_functions.delta = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int error = FT_Outline_Decompose(outline, &ft_functions, &context); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V_MSG(error, FontGlyph(), "FreeType: Outline decomposition error: '" + String(FT_Error_String(error)) + "'."); | 
					
						
							|  |  |  | 	if (!shape.contours.empty() && shape.contours.back().edges.empty()) { | 
					
						
							|  |  |  | 		shape.contours.pop_back(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (FT_Outline_Get_Orientation(outline) == 1) { | 
					
						
							|  |  |  | 		for (int i = 0; i < (int)shape.contours.size(); ++i) { | 
					
						
							|  |  |  | 			shape.contours[i].reverse(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	shape.inverseYAxis = true; | 
					
						
							|  |  |  | 	shape.normalize(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	msdfgen::Shape::Bounds bounds = shape.getBounds(p_pixel_range); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	FontGlyph chr; | 
					
						
							|  |  |  | 	chr.found = true; | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 	chr.advance = advance; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (shape.validate() && shape.contours.size() > 0) { | 
					
						
							|  |  |  | 		int w = (bounds.r - bounds.l); | 
					
						
							|  |  |  | 		int h = (bounds.t - bounds.b); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 		int mw = w + p_rect_margin * 4; | 
					
						
							|  |  |  | 		int mh = h + p_rect_margin * 4; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 		ERR_FAIL_COND_V(mw > 4096, FontGlyph()); | 
					
						
							|  |  |  | 		ERR_FAIL_COND_V(mh > 4096, FontGlyph()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 		FontTexturePosition tex_pos = find_texture_pos_for_glyph(p_data, 4, Image::FORMAT_RGBA8, mw, mh, true); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		ERR_FAIL_COND_V(tex_pos.index < 0, FontGlyph()); | 
					
						
							|  |  |  | 		FontTexture &tex = p_data->textures.write[tex_pos.index]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		edgeColoringSimple(shape, 3.0); // Max. angle.
 | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 		msdfgen::Bitmap<float, 4> image(w, h); // Texture size.
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		DistancePixelConversion distancePixelConversion(p_pixel_range); | 
					
						
							|  |  |  | 		msdfgen::Projection projection(msdfgen::Vector2(1.0, 1.0), msdfgen::Vector2(-bounds.l, -bounds.b)); | 
					
						
							|  |  |  | 		msdfgen::MSDFGeneratorConfig config(true, msdfgen::ErrorCorrectionConfig()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MSDFThreadData td; | 
					
						
							|  |  |  | 		td.output = ℑ | 
					
						
							|  |  |  | 		td.shape = &shape; | 
					
						
							|  |  |  | 		td.projection = &projection; | 
					
						
							|  |  |  | 		td.distancePixelConversion = &distancePixelConversion; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_font_data->work_pool.get_thread_count() == 0) { | 
					
						
							|  |  |  | 			p_font_data->work_pool.init(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		p_font_data->work_pool.do_work(h, this, &TextServerFallback::_generateMTSDF_threaded, &td); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		msdfgen::msdfErrorCorrection(image, shape, projection, p_pixel_range, config); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			uint8_t *wr = tex.imgdata.ptrw(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (int i = 0; i < h; i++) { | 
					
						
							|  |  |  | 				for (int j = 0; j < w; j++) { | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 					int ofs = ((i + tex_pos.y + p_rect_margin * 2) * tex.texture_w + j + tex_pos.x + p_rect_margin * 2) * 4; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					ERR_FAIL_COND_V(ofs >= tex.imgdata.size(), FontGlyph()); | 
					
						
							|  |  |  | 					wr[ofs + 0] = (uint8_t)(CLAMP(image(j, i)[0] * 256.f, 0.f, 255.f)); | 
					
						
							|  |  |  | 					wr[ofs + 1] = (uint8_t)(CLAMP(image(j, i)[1] * 256.f, 0.f, 255.f)); | 
					
						
							|  |  |  | 					wr[ofs + 2] = (uint8_t)(CLAMP(image(j, i)[2] * 256.f, 0.f, 255.f)); | 
					
						
							|  |  |  | 					wr[ofs + 3] = (uint8_t)(CLAMP(image(j, i)[3] * 256.f, 0.f, 255.f)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 		tex.dirty = true; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Update height array.
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		int32_t *offw = tex.offsets.ptrw(); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		for (int k = tex_pos.x; k < tex_pos.x + mw; k++) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			offw[k] = tex_pos.y + mh; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		chr.texture_idx = tex_pos.index; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 		chr.uv_rect = Rect2(tex_pos.x + p_rect_margin, tex_pos.y + p_rect_margin, w + p_rect_margin * 2, h + p_rect_margin * 2); | 
					
						
							|  |  |  | 		chr.rect.position = Vector2(bounds.l - p_rect_margin, -bounds.t - p_rect_margin); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		chr.rect.size = chr.uv_rect.size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return chr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | _FORCE_INLINE_ TextServerFallback::FontGlyph TextServerFallback::rasterize_bitmap(FontDataForSizeFallback *p_data, int p_rect_margin, FT_Bitmap bitmap, int yofs, int xofs, const Vector2 &advance) const { | 
					
						
							|  |  |  | 	int w = bitmap.width; | 
					
						
							|  |  |  | 	int h = bitmap.rows; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 	int mw = w + p_rect_margin * 4; | 
					
						
							|  |  |  | 	int mh = h + p_rect_margin * 4; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 	ERR_FAIL_COND_V(mw > 4096, FontGlyph()); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(mh > 4096, FontGlyph()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int color_size = bitmap.pixel_mode == FT_PIXEL_MODE_BGRA ? 4 : 2; | 
					
						
							|  |  |  | 	Image::Format require_format = color_size == 4 ? Image::FORMAT_RGBA8 : Image::FORMAT_LA8; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 	FontTexturePosition tex_pos = find_texture_pos_for_glyph(p_data, color_size, require_format, mw, mh, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(tex_pos.index < 0, FontGlyph()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Fit character in char texture.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	FontTexture &tex = p_data->textures.write[tex_pos.index]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		uint8_t *wr = tex.imgdata.ptrw(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = 0; i < h; i++) { | 
					
						
							|  |  |  | 			for (int j = 0; j < w; j++) { | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 				int ofs = ((i + tex_pos.y + p_rect_margin * 2) * tex.texture_w + j + tex_pos.x + p_rect_margin * 2) * color_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				ERR_FAIL_COND_V(ofs >= tex.imgdata.size(), FontGlyph()); | 
					
						
							|  |  |  | 				switch (bitmap.pixel_mode) { | 
					
						
							|  |  |  | 					case FT_PIXEL_MODE_MONO: { | 
					
						
							|  |  |  | 						int byte = i * bitmap.pitch + (j >> 3); | 
					
						
							|  |  |  | 						int bit = 1 << (7 - (j % 8)); | 
					
						
							| 
									
										
										
										
											2021-10-12 08:45:54 +03:00
										 |  |  | 						wr[ofs + 0] = 255; // grayscale as 1
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 						wr[ofs + 1] = (bitmap.buffer[byte] & bit) ? 255 : 0; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case FT_PIXEL_MODE_GRAY: | 
					
						
							| 
									
										
										
										
											2021-10-12 08:45:54 +03:00
										 |  |  | 						wr[ofs + 0] = 255; // grayscale as 1
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 						wr[ofs + 1] = bitmap.buffer[i * bitmap.pitch + j]; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case FT_PIXEL_MODE_BGRA: { | 
					
						
							|  |  |  | 						int ofs_color = i * bitmap.pitch + (j << 2); | 
					
						
							|  |  |  | 						wr[ofs + 2] = bitmap.buffer[ofs_color + 0]; | 
					
						
							|  |  |  | 						wr[ofs + 1] = bitmap.buffer[ofs_color + 1]; | 
					
						
							|  |  |  | 						wr[ofs + 0] = bitmap.buffer[ofs_color + 2]; | 
					
						
							|  |  |  | 						wr[ofs + 3] = bitmap.buffer[ofs_color + 3]; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					default: | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 						ERR_FAIL_V_MSG(FontGlyph(), "Font uses unsupported pixel format: " + String::num_int64(bitmap.pixel_mode) + "."); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 	tex.dirty = true; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Update height array.
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	int32_t *offw = tex.offsets.ptrw(); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	for (int k = tex_pos.x; k < tex_pos.x + mw; k++) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		offw[k] = tex_pos.y + mh; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	FontGlyph chr; | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 	chr.advance = advance * p_data->scale / p_data->oversampling; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	chr.texture_idx = tex_pos.index; | 
					
						
							|  |  |  | 	chr.found = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 	chr.uv_rect = Rect2(tex_pos.x + p_rect_margin, tex_pos.y + p_rect_margin, w + p_rect_margin * 2, h + p_rect_margin * 2); | 
					
						
							|  |  |  | 	chr.rect.position = Vector2(xofs - p_rect_margin, -yofs - p_rect_margin) * p_data->scale / p_data->oversampling; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	chr.rect.size = chr.uv_rect.size * p_data->scale / p_data->oversampling; | 
					
						
							|  |  |  | 	return chr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /* Font Cache                                                            */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _FORCE_INLINE_ bool TextServerFallback::_ensure_glyph(FontDataFallback *p_font_data, const Vector2i &p_size, int32_t p_glyph) const { | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(p_font_data, p_size), false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	int32_t glyph_index = p_glyph & 0xffffff; // Remove subpixel shifts.
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	FontDataForSizeFallback *fd = p_font_data->cache[p_size]; | 
					
						
							|  |  |  | 	if (fd->glyph_map.has(p_glyph)) { | 
					
						
							|  |  |  | 		return fd->glyph_map[p_glyph].found; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	if (glyph_index == 0) { // Non graphical or invalid glyph, do not render.
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		fd->glyph_map[p_glyph] = FontGlyph(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 15:45:28 +02:00
										 |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	FontGlyph gl; | 
					
						
							|  |  |  | 	if (fd->face) { | 
					
						
							|  |  |  | 		FT_Int32 flags = FT_LOAD_DEFAULT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool outline = p_size.y > 0; | 
					
						
							|  |  |  | 		switch (p_font_data->hinting) { | 
					
						
							|  |  |  | 			case TextServer::HINTING_NONE: | 
					
						
							|  |  |  | 				flags |= FT_LOAD_NO_HINTING; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case TextServer::HINTING_LIGHT: | 
					
						
							|  |  |  | 				flags |= FT_LOAD_TARGET_LIGHT; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				flags |= FT_LOAD_TARGET_NORMAL; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (p_font_data->force_autohinter) { | 
					
						
							|  |  |  | 			flags |= FT_LOAD_FORCE_AUTOHINT; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (outline) { | 
					
						
							|  |  |  | 			flags |= FT_LOAD_NO_BITMAP; | 
					
						
							|  |  |  | 		} else if (FT_HAS_COLOR(fd->face)) { | 
					
						
							|  |  |  | 			flags |= FT_LOAD_COLOR; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 		glyph_index = FT_Get_Char_Index(fd->face, glyph_index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		FT_Fixed v, h; | 
					
						
							| 
									
										
										
										
											2021-09-29 18:51:44 +03:00
										 |  |  | 		FT_Get_Advance(fd->face, glyph_index, flags, &h); | 
					
						
							|  |  |  | 		FT_Get_Advance(fd->face, glyph_index, flags | FT_LOAD_VERTICAL_LAYOUT, &v); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 18:51:44 +03:00
										 |  |  | 		int error = FT_Load_Glyph(fd->face, glyph_index, flags); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		if (error) { | 
					
						
							|  |  |  | 			fd->glyph_map[p_glyph] = FontGlyph(); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 		if (!p_font_data->msdf) { | 
					
						
							|  |  |  | 			if ((p_font_data->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (p_font_data->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && p_size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) { | 
					
						
							|  |  |  | 				FT_Pos xshift = (int)((p_glyph >> 27) & 3) << 4; | 
					
						
							|  |  |  | 				FT_Outline_Translate(&fd->face->glyph->outline, xshift, 0); | 
					
						
							|  |  |  | 			} else if ((p_font_data->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (p_font_data->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && p_size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { | 
					
						
							|  |  |  | 				FT_Pos xshift = (int)((p_glyph >> 27) & 3) << 5; | 
					
						
							|  |  |  | 				FT_Outline_Translate(&fd->face->glyph->outline, xshift, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 		if (p_font_data->embolden != 0.f) { | 
					
						
							|  |  |  | 			FT_Pos strength = p_font_data->embolden * p_size.x * 4; // 26.6 fractional units (1 / 64).
 | 
					
						
							|  |  |  | 			FT_Outline_Embolden(&fd->face->glyph->outline, strength); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_font_data->transform != Transform2D()) { | 
					
						
							|  |  |  | 			FT_Matrix mat = { FT_Fixed(p_font_data->transform[0][0] * 65536), FT_Fixed(p_font_data->transform[0][1] * 65536), FT_Fixed(p_font_data->transform[1][0] * 65536), FT_Fixed(p_font_data->transform[1][1] * 65536) }; // 16.16 fractional units (1 / 65536).
 | 
					
						
							|  |  |  | 			FT_Outline_Transform(&fd->face->glyph->outline, &mat); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		if (!outline) { | 
					
						
							|  |  |  | 			if (!p_font_data->msdf) { | 
					
						
							|  |  |  | 				error = FT_Render_Glyph(fd->face->glyph, p_font_data->antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			FT_GlyphSlot slot = fd->face->glyph; | 
					
						
							|  |  |  | 			if (!error) { | 
					
						
							|  |  |  | 				if (p_font_data->msdf) { | 
					
						
							|  |  |  | #ifdef MODULE_MSDFGEN_ENABLED
 | 
					
						
							|  |  |  | 					gl = rasterize_msdf(p_font_data, fd, p_font_data->msdf_range, rect_range, &slot->outline, Vector2((h + (1 << 9)) >> 10, (v + (1 << 9)) >> 10) / 64.0); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 					fd->glyph_map[p_glyph] = FontGlyph(); | 
					
						
							|  |  |  | 					ERR_FAIL_V_MSG(false, "Compiled without MSDFGEN support!"); | 
					
						
							| 
									
										
										
										
											2021-02-18 15:45:28 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					gl = rasterize_bitmap(fd, rect_range, slot->bitmap, slot->bitmap_top, slot->bitmap_left, Vector2((h + (1 << 9)) >> 10, (v + (1 << 9)) >> 10) / 64.0); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			FT_Stroker stroker; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			if (FT_Stroker_New(ft_library, &stroker) != 0) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				fd->glyph_map[p_glyph] = FontGlyph(); | 
					
						
							|  |  |  | 				ERR_FAIL_V_MSG(false, "FreeType: Failed to load glyph stroker."); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			FT_Stroker_Set(stroker, (int)(fd->size.y * fd->oversampling * 16.0), FT_STROKER_LINECAP_BUTT, FT_STROKER_LINEJOIN_ROUND, 0); | 
					
						
							|  |  |  | 			FT_Glyph glyph; | 
					
						
							|  |  |  | 			FT_BitmapGlyph glyph_bitmap; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (FT_Get_Glyph(fd->face->glyph, &glyph) != 0) { | 
					
						
							|  |  |  | 				goto cleanup_stroker; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0) { | 
					
						
							|  |  |  | 				goto cleanup_glyph; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (FT_Glyph_To_Bitmap(&glyph, p_font_data->antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, nullptr, 1) != 0) { | 
					
						
							|  |  |  | 				goto cleanup_glyph; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			glyph_bitmap = (FT_BitmapGlyph)glyph; | 
					
						
							|  |  |  | 			gl = rasterize_bitmap(fd, rect_range, glyph_bitmap->bitmap, glyph_bitmap->top, glyph_bitmap->left, Vector2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		cleanup_glyph: | 
					
						
							|  |  |  | 			FT_Done_Glyph(glyph); | 
					
						
							|  |  |  | 		cleanup_stroker: | 
					
						
							|  |  |  | 			FT_Stroker_Done(stroker); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		fd->glyph_map[p_glyph] = gl; | 
					
						
							|  |  |  | 		return gl.found; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	fd->glyph_map[p_glyph] = FontGlyph(); | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontDataFallback *p_font_data, const Vector2i &p_size) const { | 
					
						
							| 
									
										
										
										
											2021-10-25 11:49:18 +03:00
										 |  |  | 	ERR_FAIL_COND_V(p_size.x <= 0, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	if (p_font_data->cache.has(p_size)) { | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	FontDataForSizeFallback *fd = memnew(FontDataForSizeFallback); | 
					
						
							|  |  |  | 	fd->size = p_size; | 
					
						
							| 
									
										
										
										
											2021-10-15 18:36:00 +03:00
										 |  |  | 	if (p_font_data->data_ptr && (p_font_data->data_size > 0)) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		// Init dynamic font.
 | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 		int error = 0; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		if (!ft_library) { | 
					
						
							|  |  |  | 			error = FT_Init_FreeType(&ft_library); | 
					
						
							| 
									
										
										
										
											2021-09-15 10:11:31 +02:00
										 |  |  | 			ERR_FAIL_COND_V_MSG(error != 0, false, "FreeType: Error initializing library: '" + String(FT_Error_String(error)) + "'."); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memset(&fd->stream, 0, sizeof(FT_StreamRec)); | 
					
						
							|  |  |  | 		fd->stream.base = (unsigned char *)p_font_data->data_ptr; | 
					
						
							|  |  |  | 		fd->stream.size = p_font_data->data_size; | 
					
						
							|  |  |  | 		fd->stream.pos = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		FT_Open_Args fargs; | 
					
						
							|  |  |  | 		memset(&fargs, 0, sizeof(FT_Open_Args)); | 
					
						
							|  |  |  | 		fargs.memory_base = (unsigned char *)p_font_data->data_ptr; | 
					
						
							|  |  |  | 		fargs.memory_size = p_font_data->data_size; | 
					
						
							|  |  |  | 		fargs.flags = FT_OPEN_MEMORY; | 
					
						
							|  |  |  | 		fargs.stream = &fd->stream; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		error = FT_Open_Face(ft_library, &fargs, 0, &fd->face); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		if (error) { | 
					
						
							|  |  |  | 			FT_Done_Face(fd->face); | 
					
						
							|  |  |  | 			fd->face = nullptr; | 
					
						
							| 
									
										
										
										
											2021-09-15 10:11:31 +02:00
										 |  |  | 			ERR_FAIL_V_MSG(false, "FreeType: Error loading font: '" + String(FT_Error_String(error)) + "'."); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_font_data->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			fd->oversampling = 1.0; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			fd->size.x = p_font_data->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		} else if (p_font_data->oversampling <= 0.0) { | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 			fd->oversampling = font_get_global_oversampling(); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			fd->oversampling = p_font_data->oversampling; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (FT_HAS_COLOR(fd->face) && fd->face->num_fixed_sizes > 0) { | 
					
						
							|  |  |  | 			int best_match = 0; | 
					
						
							|  |  |  | 			int diff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			fd->scale = double(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			for (int i = 1; i < fd->face->num_fixed_sizes; i++) { | 
					
						
							|  |  |  | 				int ndiff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); | 
					
						
							|  |  |  | 				if (ndiff < diff) { | 
					
						
							|  |  |  | 					best_match = i; | 
					
						
							|  |  |  | 					diff = ndiff; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 					fd->scale = double(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			FT_Select_Size(fd->face, best_match); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 			FT_Set_Pixel_Sizes(fd->face, 0, Math::round(fd->size.x * fd->oversampling)); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			fd->scale = ((double)fd->size.x * fd->oversampling) / (double)fd->face->size->metrics.y_ppem; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		fd->ascent = (fd->face->size->metrics.ascender / 64.0) / fd->oversampling * fd->scale; | 
					
						
							|  |  |  | 		fd->descent = (-fd->face->size->metrics.descender / 64.0) / fd->oversampling * fd->scale; | 
					
						
							|  |  |  | 		fd->underline_position = (-FT_MulFix(fd->face->underline_position, fd->face->size->metrics.y_scale) / 64.0) / fd->oversampling * fd->scale; | 
					
						
							|  |  |  | 		fd->underline_thickness = (FT_MulFix(fd->face->underline_thickness, fd->face->size->metrics.y_scale) / 64.0) / fd->oversampling * fd->scale; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!p_font_data->face_init) { | 
					
						
							| 
									
										
										
										
											2021-10-26 09:40:11 +03:00
										 |  |  | 			// Get style flags and name.
 | 
					
						
							|  |  |  | 			if (fd->face->family_name != nullptr) { | 
					
						
							|  |  |  | 				p_font_data->font_name = String::utf8((const char *)fd->face->family_name); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (fd->face->style_name != nullptr) { | 
					
						
							|  |  |  | 				p_font_data->style_name = String::utf8((const char *)fd->face->style_name); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			p_font_data->style_flags = 0; | 
					
						
							|  |  |  | 			if (fd->face->style_flags & FT_STYLE_FLAG_BOLD) { | 
					
						
							|  |  |  | 				p_font_data->style_flags |= FONT_BOLD; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (fd->face->style_flags & FT_STYLE_FLAG_ITALIC) { | 
					
						
							|  |  |  | 				p_font_data->style_flags |= FONT_ITALIC; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (fd->face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) { | 
					
						
							|  |  |  | 				p_font_data->style_flags |= FONT_FIXED_WIDTH; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			// Read OpenType variations.
 | 
					
						
							|  |  |  | 			p_font_data->supported_varaitions.clear(); | 
					
						
							|  |  |  | 			if (fd->face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) { | 
					
						
							|  |  |  | 				FT_MM_Var *amaster; | 
					
						
							|  |  |  | 				FT_Get_MM_Var(fd->face, &amaster); | 
					
						
							|  |  |  | 				for (FT_UInt i = 0; i < amaster->num_axis; i++) { | 
					
						
							|  |  |  | 					p_font_data->supported_varaitions[(int32_t)amaster->axis[i].tag] = Vector3i(amaster->axis[i].minimum / 65536, amaster->axis[i].maximum / 65536, amaster->axis[i].def / 65536); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 				FT_Done_MM_Var(ft_library, amaster); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			p_font_data->face_init = true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Write variations.
 | 
					
						
							|  |  |  | 		if (fd->face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) { | 
					
						
							|  |  |  | 			FT_MM_Var *amaster; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			FT_Get_MM_Var(fd->face, &amaster); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Vector<FT_Fixed> coords; | 
					
						
							|  |  |  | 			coords.resize(amaster->num_axis); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			FT_Get_Var_Design_Coordinates(fd->face, coords.size(), coords.ptrw()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (FT_UInt i = 0; i < amaster->num_axis; i++) { | 
					
						
							|  |  |  | 				// Reset to default.
 | 
					
						
							|  |  |  | 				int32_t var_tag = amaster->axis[i].tag; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 				double var_value = (double)amaster->axis[i].def / 65536.0; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				coords.write[i] = amaster->axis[i].def; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (p_font_data->variation_coordinates.has(var_tag)) { | 
					
						
							|  |  |  | 					var_value = p_font_data->variation_coordinates[var_tag]; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 					coords.write[i] = CLAMP(var_value * 65536.0, amaster->axis[i].minimum, amaster->axis[i].maximum); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (p_font_data->variation_coordinates.has(tag_to_name(var_tag))) { | 
					
						
							|  |  |  | 					var_value = p_font_data->variation_coordinates[tag_to_name(var_tag)]; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 					coords.write[i] = CLAMP(var_value * 65536.0, amaster->axis[i].minimum, amaster->axis[i].maximum); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			FT_Set_Var_Design_Coordinates(fd->face, coords.size(), coords.ptrw()); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			FT_Done_MM_Var(ft_library, amaster); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2021-09-15 10:11:31 +02:00
										 |  |  | 		ERR_FAIL_V_MSG(false, "FreeType: Can't load dynamic font, engine is compiled without FreeType support!"); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p_font_data->cache[p_size] = fd; | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _FORCE_INLINE_ void TextServerFallback::_font_clear_cache(FontDataFallback *p_font_data) { | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 	for (const KeyValue<Vector2i, FontDataForSizeFallback *> &E : p_font_data->cache) { | 
					
						
							|  |  |  | 		memdelete(E.value); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	p_font_data->cache.clear(); | 
					
						
							|  |  |  | 	p_font_data->face_init = false; | 
					
						
							|  |  |  | 	p_font_data->supported_varaitions.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RID TextServerFallback::create_font() { | 
					
						
							| 
									
										
										
										
											2022-05-18 10:17:55 +03:00
										 |  |  | 	_THREAD_SAFE_METHOD_ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	FontDataFallback *fd = memnew(FontDataFallback); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return font_owner.make_rid(fd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_data(const RID &p_font_rid, const PackedByteArray &p_data) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	_font_clear_cache(fd); | 
					
						
							|  |  |  | 	fd->data = p_data; | 
					
						
							|  |  |  | 	fd->data_ptr = fd->data.ptr(); | 
					
						
							|  |  |  | 	fd->data_size = fd->data.size(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_data_ptr(const RID &p_font_rid, const uint8_t *p_data_ptr, int64_t p_data_size) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	_font_clear_cache(fd); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	fd->data.resize(0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	fd->data_ptr = p_data_ptr; | 
					
						
							|  |  |  | 	fd->data_size = p_data_size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_style(const RID &p_font_rid, int64_t /*FontStyle*/ p_style) { | 
					
						
							| 
									
										
										
										
											2021-10-26 09:40:11 +03:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->style_flags = p_style; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t /*FontStyle*/ TextServerFallback::font_get_style(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-10-26 09:40:11 +03:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0); | 
					
						
							|  |  |  | 	return fd->style_flags; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_style_name(const RID &p_font_rid, const String &p_name) { | 
					
						
							| 
									
										
										
										
											2021-10-26 09:40:11 +03:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->style_name = p_name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | String TextServerFallback::font_get_style_name(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-10-26 09:40:11 +03:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, String()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), String()); | 
					
						
							|  |  |  | 	return fd->style_name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_name(const RID &p_font_rid, const String &p_name) { | 
					
						
							| 
									
										
										
										
											2021-10-26 09:40:11 +03:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->font_name = p_name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | String TextServerFallback::font_get_name(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-10-26 09:40:11 +03:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, String()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), String()); | 
					
						
							|  |  |  | 	return fd->font_name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_antialiased(const RID &p_font_rid, bool p_antialiased) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->antialiased != p_antialiased) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->antialiased = p_antialiased; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::font_is_antialiased(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->antialiased; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | void TextServerFallback::font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) { | 
					
						
							|  |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->mipmaps != p_generate_mipmaps) { | 
					
						
							|  |  |  | 		for (KeyValue<Vector2i, FontDataForSizeFallback *> &E : fd->cache) { | 
					
						
							|  |  |  | 			for (int i = 0; i < E.value->textures.size(); i++) { | 
					
						
							|  |  |  | 				E.value->textures.write[i].dirty = true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		fd->mipmaps = p_generate_mipmaps; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TextServerFallback::font_get_generate_mipmaps(const RID &p_font_rid) const { | 
					
						
							|  |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->mipmaps; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_multichannel_signed_distance_field(const RID &p_font_rid, bool p_msdf) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->msdf != p_msdf) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->msdf = p_msdf; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::font_is_multichannel_signed_distance_field(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->msdf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_msdf_pixel_range(const RID &p_font_rid, int64_t p_msdf_pixel_range) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->msdf_range != p_msdf_pixel_range) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->msdf_range = p_msdf_pixel_range; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::font_get_msdf_pixel_range(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->msdf_range; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_msdf_size(const RID &p_font_rid, int64_t p_msdf_size) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->msdf_source_size != p_msdf_size) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->msdf_source_size = p_msdf_size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::font_get_msdf_size(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->msdf_source_size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_fixed_size(const RID &p_font_rid, int64_t p_fixed_size) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 	fd->fixed_size = p_fixed_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::font_get_fixed_size(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->fixed_size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_force_autohinter(const RID &p_font_rid, bool p_force_autohinter) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->force_autohinter != p_force_autohinter) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->force_autohinter = p_force_autohinter; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::font_is_force_autohinter(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->force_autohinter; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_hinting(const RID &p_font_rid, TextServer::Hinting p_hinting) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->hinting != p_hinting) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->hinting = p_hinting; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | TextServer::Hinting TextServerFallback::font_get_hinting(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, HINTING_NONE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->hinting; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_subpixel_positioning(const RID &p_font_rid, TextServer::SubpixelPositioning p_subpixel) { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 	fd->subpixel_positioning = p_subpixel; | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | TextServer::SubpixelPositioning TextServerFallback::font_get_subpixel_positioning(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, SUBPIXEL_POSITIONING_DISABLED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->subpixel_positioning; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_embolden(const RID &p_font_rid, double p_strength) { | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->embolden != p_strength) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->embolden = p_strength; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::font_get_embolden(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0.0); | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->embolden; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_transform(const RID &p_font_rid, const Transform2D &p_transform) { | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->transform != p_transform) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->transform = p_transform; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Transform2D TextServerFallback::font_get_transform(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2022-03-11 09:31:16 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, Transform2D()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->transform; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_variation_coordinates(const RID &p_font_rid, const Dictionary &p_variation_coordinates) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->variation_coordinates != p_variation_coordinates) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->variation_coordinates = p_variation_coordinates; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Dictionary TextServerFallback::font_get_variation_coordinates(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Dictionary()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->variation_coordinates; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_oversampling(const RID &p_font_rid, double p_oversampling) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->oversampling != p_oversampling) { | 
					
						
							|  |  |  | 		_font_clear_cache(fd); | 
					
						
							|  |  |  | 		fd->oversampling = p_oversampling; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::font_get_oversampling(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->oversampling; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Array TextServerFallback::font_get_size_cache_list(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Array()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Array ret; | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 	for (const KeyValue<Vector2i, FontDataForSizeFallback *> &E : fd->cache) { | 
					
						
							|  |  |  | 		ret.push_back(E.key); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_clear_size_cache(const RID &p_font_rid) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 	for (const KeyValue<Vector2i, FontDataForSizeFallback *> &E : fd->cache) { | 
					
						
							|  |  |  | 		memdelete(E.value); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	fd->cache.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_remove_size_cache(const RID &p_font_rid, const Vector2i &p_size) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->cache.has(p_size)) { | 
					
						
							|  |  |  | 		memdelete(fd->cache[p_size]); | 
					
						
							|  |  |  | 		fd->cache.erase(p_size); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_ascent(const RID &p_font_rid, int64_t p_size, double p_ascent) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->cache[size]->ascent = p_ascent; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::font_get_ascent(const RID &p_font_rid, int64_t p_size) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		return fd->cache[size]->ascent * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return fd->cache[size]->ascent; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_descent(const RID &p_font_rid, int64_t p_size, double p_descent) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->cache[size]->descent = p_descent; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::font_get_descent(const RID &p_font_rid, int64_t p_size) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		return fd->cache[size]->descent * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return fd->cache[size]->descent; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_underline_position(const RID &p_font_rid, int64_t p_size, double p_underline_position) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->cache[size]->underline_position = p_underline_position; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::font_get_underline_position(const RID &p_font_rid, int64_t p_size) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		return fd->cache[size]->underline_position * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return fd->cache[size]->underline_position; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_underline_thickness(const RID &p_font_rid, int64_t p_size, double p_underline_thickness) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->cache[size]->underline_thickness = p_underline_thickness; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::font_get_underline_thickness(const RID &p_font_rid, int64_t p_size) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		return fd->cache[size]->underline_thickness * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return fd->cache[size]->underline_thickness; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_scale(const RID &p_font_rid, int64_t p_size, double p_scale) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							| 
									
										
										
										
											2022-05-10 13:57:18 +03:00
										 |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 	if (fd->cache[size]->face) { | 
					
						
							|  |  |  | 		return; // Do not override scale for dynamic fonts, it's calculated automatically.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	fd->cache[size]->scale = p_scale; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::font_get_scale(const RID &p_font_rid, int64_t p_size) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		return fd->cache[size]->scale * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return fd->cache[size]->scale / fd->cache[size]->oversampling; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_spacing(const RID &p_font_rid, int64_t p_size, TextServer::SpacingType p_spacing, int64_t p_value) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	switch (p_spacing) { | 
					
						
							|  |  |  | 		case TextServer::SPACING_GLYPH: { | 
					
						
							|  |  |  | 			fd->cache[size]->spacing_glyph = p_value; | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TextServer::SPACING_SPACE: { | 
					
						
							|  |  |  | 			fd->cache[size]->spacing_space = p_value; | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		default: { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			ERR_FAIL_MSG("Invalid spacing type: " + String::num_int64(p_spacing)); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::font_get_spacing(const RID &p_font_rid, int64_t p_size, TextServer::SpacingType p_spacing) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (p_spacing) { | 
					
						
							|  |  |  | 		case TextServer::SPACING_GLYPH: { | 
					
						
							|  |  |  | 			if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 				return fd->cache[size]->spacing_glyph * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				return fd->cache[size]->spacing_glyph; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TextServer::SPACING_SPACE: { | 
					
						
							|  |  |  | 			if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 				return fd->cache[size]->spacing_space * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				return fd->cache[size]->spacing_space; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		default: { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			ERR_FAIL_V_MSG(0, "Invalid spacing type: " + String::num_int64(p_spacing)); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::font_get_texture_count(const RID &p_font_rid, const Vector2i &p_size) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return fd->cache[size]->textures.size(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_clear_textures(const RID &p_font_rid, const Vector2i &p_size) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->cache[size]->textures.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_remove_texture(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	ERR_FAIL_INDEX(p_texture_index, fd->cache[size]->textures.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 16:17:03 -06:00
										 |  |  | 	fd->cache[size]->textures.remove_at(p_texture_index); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const Ref<Image> &p_image) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_image.is_null()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_texture_index < 0); | 
					
						
							|  |  |  | 	if (p_texture_index >= fd->cache[size]->textures.size()) { | 
					
						
							|  |  |  | 		fd->cache[size]->textures.resize(p_texture_index + 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	FontTexture &tex = fd->cache[size]->textures.write[p_texture_index]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tex.imgdata = p_image->get_data(); | 
					
						
							|  |  |  | 	tex.texture_w = p_image->get_width(); | 
					
						
							|  |  |  | 	tex.texture_h = p_image->get_height(); | 
					
						
							|  |  |  | 	tex.format = p_image->get_format(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	Ref<Image> img; | 
					
						
							|  |  |  | 	img.instantiate(); | 
					
						
							| 
									
										
										
										
											2022-04-04 18:49:05 +02:00
										 |  |  | 	img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 	if (fd->mipmaps) { | 
					
						
							|  |  |  | 		img->generate_mipmaps(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	tex.texture = Ref<ImageTexture>(); | 
					
						
							|  |  |  | 	tex.texture.instantiate(); | 
					
						
							|  |  |  | 	tex.texture->create_from_image(img); | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 	tex.dirty = false; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Ref<Image> TextServerFallback::font_get_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Ref<Image>()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Ref<Image>()); | 
					
						
							|  |  |  | 	ERR_FAIL_INDEX_V(p_texture_index, fd->cache[size]->textures.size(), Ref<Image>()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	const FontTexture &tex = fd->cache[size]->textures[p_texture_index]; | 
					
						
							|  |  |  | 	Ref<Image> img; | 
					
						
							|  |  |  | 	img.instantiate(); | 
					
						
							| 
									
										
										
										
											2022-04-04 18:49:05 +02:00
										 |  |  | 	img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return img; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const PackedInt32Array &p_offset) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							| 
									
										
										
										
											2021-10-15 18:36:00 +03:00
										 |  |  | 	ERR_FAIL_COND(p_texture_index < 0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	if (p_texture_index >= fd->cache[size]->textures.size()) { | 
					
						
							|  |  |  | 		fd->cache[size]->textures.resize(p_texture_index + 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	FontTexture &tex = fd->cache[size]->textures.write[p_texture_index]; | 
					
						
							|  |  |  | 	tex.offsets = p_offset; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | PackedInt32Array TextServerFallback::font_get_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, PackedInt32Array()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), PackedInt32Array()); | 
					
						
							|  |  |  | 	ERR_FAIL_INDEX_V(p_texture_index, fd->cache[size]->textures.size(), PackedInt32Array()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	const FontTexture &tex = fd->cache[size]->textures[p_texture_index]; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	return tex.offsets; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Array TextServerFallback::font_get_glyph_list(const RID &p_font_rid, const Vector2i &p_size) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Array()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Array()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Array ret; | 
					
						
							|  |  |  | 	const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							| 
									
										
										
										
											2022-05-08 10:09:19 +02:00
										 |  |  | 	for (const KeyValue<int32_t, FontGlyph> &E : gl) { | 
					
						
							|  |  |  | 		ret.push_back(E.key); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_clear_glyphs(const RID &p_font_rid, const Vector2i &p_size) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fd->cache[size]->glyph_map.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_remove_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fd->cache[size]->glyph_map.erase(p_glyph); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Vector2 TextServerFallback::font_get_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Vector2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2()); | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, p_glyph)) { | 
					
						
							|  |  |  | 		return Vector2(); // Invalid or non graphicl glyph, do not display errors.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-13 14:50:36 +02:00
										 |  |  | 	Vector2 ea; | 
					
						
							|  |  |  | 	if (fd->embolden != 0.0) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		ea.x = fd->embolden * double(size.x) / 64.0; | 
					
						
							| 
									
										
										
										
											2022-03-13 14:50:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		return (gl[p_glyph].advance + ea) * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_DISABLED) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x > SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { | 
					
						
							| 
									
										
										
										
											2022-03-13 14:50:36 +02:00
										 |  |  | 		return (gl[p_glyph].advance + ea).round(); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2022-03-13 14:50:36 +02:00
										 |  |  | 		return gl[p_glyph].advance + ea; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph, const Vector2 &p_advance) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gl[p_glyph].advance = p_advance; | 
					
						
							|  |  |  | 	gl[p_glyph].found = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Vector2 TextServerFallback::font_get_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Vector2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2()); | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, p_glyph)) { | 
					
						
							|  |  |  | 		return Vector2(); // Invalid or non graphicl glyph, do not display errors.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		return gl[p_glyph].rect.position * (double)p_size.x / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return gl[p_glyph].rect.position; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_offset) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gl[p_glyph].rect.position = p_offset; | 
					
						
							|  |  |  | 	gl[p_glyph].found = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Vector2 TextServerFallback::font_get_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Vector2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2()); | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, p_glyph)) { | 
					
						
							|  |  |  | 		return Vector2(); // Invalid or non graphicl glyph, do not display errors.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		return gl[p_glyph].rect.size * (double)p_size.x / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return gl[p_glyph].rect.size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_gl_size) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gl[p_glyph].rect.size = p_gl_size; | 
					
						
							|  |  |  | 	gl[p_glyph].found = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Rect2 TextServerFallback::font_get_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Rect2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Rect2()); | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, p_glyph)) { | 
					
						
							|  |  |  | 		return Rect2(); // Invalid or non graphicl glyph, do not display errors.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 	return gl[p_glyph].uv_rect; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Rect2 &p_uv_rect) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gl[p_glyph].uv_rect = p_uv_rect; | 
					
						
							|  |  |  | 	gl[p_glyph].found = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::font_get_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, -1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), -1); | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, p_glyph)) { | 
					
						
							|  |  |  | 		return -1; // Invalid or non graphicl glyph, do not display errors.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 	return gl[p_glyph].texture_idx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, int64_t p_texture_idx) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gl[p_glyph].texture_idx = p_texture_idx; | 
					
						
							|  |  |  | 	gl[p_glyph].found = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | RID TextServerFallback::font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { | 
					
						
							|  |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, RID()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), RID()); | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, p_glyph)) { | 
					
						
							|  |  |  | 		return RID(); // Invalid or non graphicl glyph, do not display errors.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(gl[p_glyph].texture_idx < -1 || gl[p_glyph].texture_idx >= fd->cache[size]->textures.size(), RID()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (RenderingServer::get_singleton() != nullptr) { | 
					
						
							|  |  |  | 		if (gl[p_glyph].texture_idx != -1) { | 
					
						
							|  |  |  | 			if (fd->cache[size]->textures[gl[p_glyph].texture_idx].dirty) { | 
					
						
							|  |  |  | 				FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph].texture_idx]; | 
					
						
							|  |  |  | 				Ref<Image> img; | 
					
						
							|  |  |  | 				img.instantiate(); | 
					
						
							|  |  |  | 				img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); | 
					
						
							|  |  |  | 				if (fd->mipmaps) { | 
					
						
							|  |  |  | 					img->generate_mipmaps(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (tex.texture.is_null()) { | 
					
						
							|  |  |  | 					tex.texture.instantiate(); | 
					
						
							|  |  |  | 					tex.texture->create_from_image(img); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					tex.texture->update(img); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				tex.dirty = false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return fd->cache[size]->textures[gl[p_glyph].texture_idx].texture->get_rid(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return RID(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Size2 TextServerFallback::font_get_glyph_texture_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { | 
					
						
							|  |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, Size2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Size2()); | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, p_glyph)) { | 
					
						
							|  |  |  | 		return Size2(); // Invalid or non graphicl glyph, do not display errors.
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(gl[p_glyph].texture_idx < -1 || gl[p_glyph].texture_idx >= fd->cache[size]->textures.size(), Size2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (RenderingServer::get_singleton() != nullptr) { | 
					
						
							|  |  |  | 		if (gl[p_glyph].texture_idx != -1) { | 
					
						
							|  |  |  | 			if (fd->cache[size]->textures[gl[p_glyph].texture_idx].dirty) { | 
					
						
							|  |  |  | 				FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph].texture_idx]; | 
					
						
							|  |  |  | 				Ref<Image> img; | 
					
						
							|  |  |  | 				img.instantiate(); | 
					
						
							|  |  |  | 				img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); | 
					
						
							|  |  |  | 				if (fd->mipmaps) { | 
					
						
							|  |  |  | 					img->generate_mipmaps(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (tex.texture.is_null()) { | 
					
						
							|  |  |  | 					tex.texture.instantiate(); | 
					
						
							|  |  |  | 					tex.texture->create_from_image(img); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					tex.texture->update(img); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				tex.dirty = false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return fd->cache[size]->textures[gl[p_glyph].texture_idx].texture->get_size(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Size2(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Dictionary TextServerFallback::font_get_glyph_contours(const RID &p_font_rid, int64_t p_size, int64_t p_index) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Dictionary()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	PackedVector3Array points; | 
					
						
							|  |  |  | 	PackedInt32Array contours; | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	int32_t index = p_index & 0xffffff; // Remove subpixel shifts.
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	int error = FT_Load_Glyph(fd->cache[size]->face, FT_Get_Char_Index(fd->cache[size]->face, index), FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(error, Dictionary()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-25 13:14:30 +03:00
										 |  |  | 	if (fd->embolden != 0.f) { | 
					
						
							|  |  |  | 		FT_Pos strength = fd->embolden * p_size * 4; // 26.6 fractional units (1 / 64).
 | 
					
						
							|  |  |  | 		FT_Outline_Embolden(&fd->cache[size]->face->glyph->outline, strength); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (fd->transform != Transform2D()) { | 
					
						
							|  |  |  | 		FT_Matrix mat = { FT_Fixed(fd->transform[0][0] * 65536), FT_Fixed(fd->transform[0][1] * 65536), FT_Fixed(fd->transform[1][0] * 65536), FT_Fixed(fd->transform[1][1] * 65536) }; // 16.16 fractional units (1 / 65536).
 | 
					
						
							|  |  |  | 		FT_Outline_Transform(&fd->cache[size]->face->glyph->outline, &mat); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	double scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		scale = scale * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_points; i++) { | 
					
						
							| 
									
										
										
										
											2022-04-25 13:14:30 +03:00
										 |  |  | 		points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, -fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_contours; i++) { | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 		contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | 	bool orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary out; | 
					
						
							|  |  |  | 	out["points"] = points; | 
					
						
							|  |  |  | 	out["contours"] = contours; | 
					
						
							|  |  |  | 	out["orientation"] = orientation; | 
					
						
							|  |  |  | 	return out; | 
					
						
							| 
									
										
										
										
											2022-04-05 13:40:26 +03:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	return Dictionary(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Array TextServerFallback::font_get_kerning_list(const RID &p_font_rid, int64_t p_size) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Array()); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Array()); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	Array ret; | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 	for (const KeyValue<Vector2i, Vector2> &E : fd->cache[size]->kerning_map) { | 
					
						
							|  |  |  | 		ret.push_back(E.key); | 
					
						
							| 
									
										
										
										
											2021-02-06 16:34:06 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2021-02-06 16:34:06 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_clear_kerning_map(const RID &p_font_rid, int64_t p_size) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2021-02-06 16:34:06 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->cache[size]->kerning_map.clear(); | 
					
						
							| 
									
										
										
										
											2021-02-06 16:34:06 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_remove_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2021-02-06 16:34:06 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->cache[size]->kerning_map.erase(p_glyph_pair); | 
					
						
							| 
									
										
										
										
											2021-02-06 16:34:06 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2021-02-06 16:34:06 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->cache[size]->kerning_map[p_glyph_pair] = p_kerning; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Vector2 TextServerFallback::font_get_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Vector2()); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2()); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-08 21:03:20 +03:00
										 |  |  | 	const HashMap<Vector2i, Vector2, VariantHasher, VariantComparator> &kern = fd->cache[size]->kerning_map; | 
					
						
							| 
									
										
										
										
											2021-02-15 10:46:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	if (kern.has(p_glyph_pair)) { | 
					
						
							|  |  |  | 		if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			return kern[p_glyph_pair] * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			return kern[p_glyph_pair]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 		if (fd->cache[size]->face) { | 
					
						
							|  |  |  | 			FT_Vector delta; | 
					
						
							| 
									
										
										
										
											2021-09-29 18:51:44 +03:00
										 |  |  | 			int32_t glyph_a = FT_Get_Char_Index(fd->cache[size]->face, p_glyph_pair.x); | 
					
						
							|  |  |  | 			int32_t glyph_b = FT_Get_Char_Index(fd->cache[size]->face, p_glyph_pair.y); | 
					
						
							|  |  |  | 			FT_Get_Kerning(fd->cache[size]->face, glyph_a, glyph_b, FT_KERNING_DEFAULT, &delta); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			if (fd->msdf) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 				return Vector2(delta.x, delta.y) * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				return Vector2(delta.x, delta.y); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return Vector2(); | 
					
						
							| 
									
										
										
										
											2021-02-15 10:46:23 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::font_get_glyph_index(const RID &p_font_rid, int64_t p_size, int64_t p_char, int64_t p_variation_selector) const { | 
					
						
							| 
									
										
										
										
											2021-10-15 18:36:00 +03:00
										 |  |  | 	ERR_FAIL_COND_V_MSG((p_char >= 0xd800 && p_char <= 0xdfff) || (p_char > 0x10ffff), 0, "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_char, 16) + "."); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	return (int64_t)p_char; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::font_has_char(const RID &p_font_rid, int64_t p_char) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							| 
									
										
										
										
											2021-10-15 18:36:00 +03:00
										 |  |  | 	ERR_FAIL_COND_V_MSG((p_char >= 0xd800 && p_char <= 0xdfff) || (p_char > 0x10ffff), false, "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_char, 16) + "."); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->cache.is_empty()) { | 
					
						
							|  |  |  | 		ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), false); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-05-08 21:03:20 +03:00
										 |  |  | 	FontDataForSizeFallback *at_size = fd->cache.begin()->value; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 	if (at_size && at_size->face) { | 
					
						
							|  |  |  | 		return FT_Get_Char_Index(at_size->face, p_char) != 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	return (at_size) ? at_size->glyph_map.has((int32_t)p_char) : false; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | String TextServerFallback::font_get_supported_chars(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, String()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->cache.is_empty()) { | 
					
						
							|  |  |  | 		ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), String()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-05-08 21:03:20 +03:00
										 |  |  | 	FontDataForSizeFallback *at_size = fd->cache.begin()->value; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String chars; | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 	if (at_size && at_size->face) { | 
					
						
							|  |  |  | 		FT_UInt gindex; | 
					
						
							|  |  |  | 		FT_ULong charcode = FT_Get_First_Char(at_size->face, &gindex); | 
					
						
							|  |  |  | 		while (gindex != 0) { | 
					
						
							|  |  |  | 			if (charcode != 0) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 				chars = chars + String::chr(charcode); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			charcode = FT_Get_Next_Char(at_size->face, charcode, &gindex); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return chars; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	if (at_size) { | 
					
						
							|  |  |  | 		const HashMap<int32_t, FontGlyph> &gl = at_size->glyph_map; | 
					
						
							| 
									
										
										
										
											2022-05-08 10:09:19 +02:00
										 |  |  | 		for (const KeyValue<int32_t, FontGlyph> &E : gl) { | 
					
						
							|  |  |  | 			chars = chars + String::chr(E.key); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return chars; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_render_range(const RID &p_font_rid, const Vector2i &p_size, int64_t p_start, int64_t p_end) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							| 
									
										
										
										
											2021-10-15 18:36:00 +03:00
										 |  |  | 	ERR_FAIL_COND_MSG((p_start >= 0xd800 && p_start <= 0xdfff) || (p_start > 0x10ffff), "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_start, 16) + "."); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_MSG((p_end >= 0xd800 && p_end <= 0xdfff) || (p_end > 0x10ffff), "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_end, 16) + "."); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	for (int64_t i = p_start; i <= p_end; i++) { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 		int32_t idx = i; | 
					
						
							|  |  |  | 		if (fd->cache[size]->face) { | 
					
						
							|  |  |  | 			if (fd->msdf) { | 
					
						
							|  |  |  | 				_ensure_glyph(fd, size, (int32_t)idx); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) { | 
					
						
							|  |  |  | 					_ensure_glyph(fd, size, (int32_t)idx | (0 << 27)); | 
					
						
							|  |  |  | 					_ensure_glyph(fd, size, (int32_t)idx | (1 << 27)); | 
					
						
							|  |  |  | 					_ensure_glyph(fd, size, (int32_t)idx | (2 << 27)); | 
					
						
							|  |  |  | 					_ensure_glyph(fd, size, (int32_t)idx | (3 << 27)); | 
					
						
							|  |  |  | 				} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { | 
					
						
							|  |  |  | 					_ensure_glyph(fd, size, (int32_t)idx | (1 << 27)); | 
					
						
							|  |  |  | 					_ensure_glyph(fd, size, (int32_t)idx | (0 << 27)); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					_ensure_glyph(fd, size, (int32_t)idx); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_render_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_index) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	int32_t idx = p_index & 0xffffff; // Remove subpixel shifts.
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	if (fd->cache[size]->face) { | 
					
						
							|  |  |  | 		if (fd->msdf) { | 
					
						
							|  |  |  | 			_ensure_glyph(fd, size, (int32_t)idx); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) { | 
					
						
							|  |  |  | 				_ensure_glyph(fd, size, (int32_t)idx | (0 << 27)); | 
					
						
							|  |  |  | 				_ensure_glyph(fd, size, (int32_t)idx | (1 << 27)); | 
					
						
							|  |  |  | 				_ensure_glyph(fd, size, (int32_t)idx | (2 << 27)); | 
					
						
							|  |  |  | 				_ensure_glyph(fd, size, (int32_t)idx | (3 << 27)); | 
					
						
							|  |  |  | 			} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { | 
					
						
							|  |  |  | 				_ensure_glyph(fd, size, (int32_t)idx | (1 << 27)); | 
					
						
							|  |  |  | 				_ensure_glyph(fd, size, (int32_t)idx | (0 << 27)); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				_ensure_glyph(fd, size, (int32_t)idx); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_draw_glyph(const RID &p_font_rid, const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, p_size); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	int32_t index = p_index & 0xffffff; // Remove subpixel shifts.
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 	if (!fd->msdf && fd->cache[size]->face) { | 
					
						
							|  |  |  | 		if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) { | 
					
						
							|  |  |  | 			int xshift = (int)(Math::floor(4 * (p_pos.x + 0.125)) - 4 * Math::floor(p_pos.x + 0.125)); | 
					
						
							|  |  |  | 			index = index | (xshift << 27); | 
					
						
							|  |  |  | 		} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { | 
					
						
							|  |  |  | 			int xshift = (int)(Math::floor(2 * (p_pos.x + 0.25)) - 2 * Math::floor(p_pos.x + 0.25)); | 
					
						
							|  |  |  | 			index = index | (xshift << 27); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, index)) { | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 		return; // Invalid or non-graphical glyph, do not display errors, nothing to draw.
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	const FontGlyph &gl = fd->cache[size]->glyph_map[index]; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	if (gl.found) { | 
					
						
							|  |  |  | 		ERR_FAIL_COND(gl.texture_idx < -1 || gl.texture_idx >= fd->cache[size]->textures.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (gl.texture_idx != -1) { | 
					
						
							|  |  |  | 			Color modulate = p_color; | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 			if (fd->cache[size]->face && FT_HAS_COLOR(fd->cache[size]->face)) { | 
					
						
							|  |  |  | 				modulate.r = modulate.g = modulate.b = 1.0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			if (RenderingServer::get_singleton() != nullptr) { | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 				if (fd->cache[size]->textures[gl.texture_idx].dirty) { | 
					
						
							|  |  |  | 					FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx]; | 
					
						
							|  |  |  | 					Ref<Image> img; | 
					
						
							|  |  |  | 					img.instantiate(); | 
					
						
							|  |  |  | 					img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 					if (fd->mipmaps) { | 
					
						
							|  |  |  | 						img->generate_mipmaps(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 					if (tex.texture.is_null()) { | 
					
						
							|  |  |  | 						tex.texture.instantiate(); | 
					
						
							|  |  |  | 						tex.texture->create_from_image(img); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						tex.texture->update(img); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					tex.dirty = false; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); | 
					
						
							|  |  |  | 				if (fd->msdf) { | 
					
						
							|  |  |  | 					Point2 cpos = p_pos; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 					cpos += gl.rect.position * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							|  |  |  | 					Size2 csize = gl.rect.size * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, 0, fd->msdf_range); | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 					Point2 cpos = p_pos; | 
					
						
							|  |  |  | 					cpos.y = Math::floor(cpos.y); | 
					
						
							|  |  |  | 					if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) { | 
					
						
							|  |  |  | 						cpos.x = ((int)Math::floor(cpos.x + 0.125)); | 
					
						
							|  |  |  | 					} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { | 
					
						
							|  |  |  | 						cpos.x = ((int)Math::floor(cpos.x + 0.25)); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						cpos.x = Math::floor(cpos.x); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					cpos += gl.rect.position; | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 					Size2 csize = gl.rect.size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, false, false); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_draw_glyph_outline(const RID &p_font_rid, const RID &p_canvas, int64_t p_size, int64_t p_outline_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size_outline(fd, Vector2i(p_size, p_outline_size)); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	int32_t index = p_index & 0xffffff; // Remove subpixel shifts.
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 	if (!fd->msdf && fd->cache[size]->face) { | 
					
						
							|  |  |  | 		if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) { | 
					
						
							|  |  |  | 			int xshift = (int)(Math::floor(4 * (p_pos.x + 0.125)) - 4 * Math::floor(p_pos.x + 0.125)); | 
					
						
							|  |  |  | 			index = index | (xshift << 27); | 
					
						
							|  |  |  | 		} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { | 
					
						
							|  |  |  | 			int xshift = (int)(Math::floor(2 * (p_pos.x + 0.25)) - 2 * Math::floor(p_pos.x + 0.25)); | 
					
						
							|  |  |  | 			index = index | (xshift << 27); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!_ensure_glyph(fd, size, index)) { | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 		return; // Invalid or non-graphical glyph, do not display errors, nothing to draw.
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	const FontGlyph &gl = fd->cache[size]->glyph_map[index]; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	if (gl.found) { | 
					
						
							|  |  |  | 		ERR_FAIL_COND(gl.texture_idx < -1 || gl.texture_idx >= fd->cache[size]->textures.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (gl.texture_idx != -1) { | 
					
						
							|  |  |  | 			Color modulate = p_color; | 
					
						
							|  |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							|  |  |  | 			if (fd->cache[size]->face && FT_HAS_COLOR(fd->cache[size]->face)) { | 
					
						
							|  |  |  | 				modulate.r = modulate.g = modulate.b = 1.0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			if (RenderingServer::get_singleton() != nullptr) { | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 				if (fd->cache[size]->textures[gl.texture_idx].dirty) { | 
					
						
							|  |  |  | 					FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx]; | 
					
						
							|  |  |  | 					Ref<Image> img; | 
					
						
							|  |  |  | 					img.instantiate(); | 
					
						
							|  |  |  | 					img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); | 
					
						
							| 
									
										
										
										
											2022-04-19 13:27:18 +03:00
										 |  |  | 					if (fd->mipmaps) { | 
					
						
							|  |  |  | 						img->generate_mipmaps(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2022-04-04 10:31:07 +03:00
										 |  |  | 					if (tex.texture.is_null()) { | 
					
						
							|  |  |  | 						tex.texture.instantiate(); | 
					
						
							|  |  |  | 						tex.texture->create_from_image(img); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						tex.texture->update(img); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					tex.dirty = false; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); | 
					
						
							|  |  |  | 				if (fd->msdf) { | 
					
						
							|  |  |  | 					Point2 cpos = p_pos; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 					cpos += gl.rect.position * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							|  |  |  | 					Size2 csize = gl.rect.size * (double)p_size / (double)fd->msdf_source_size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, p_outline_size * 2, fd->msdf_range); | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 					Point2 cpos = p_pos; | 
					
						
							|  |  |  | 					cpos.y = Math::floor(cpos.y); | 
					
						
							|  |  |  | 					if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) { | 
					
						
							|  |  |  | 						cpos.x = ((int)Math::floor(cpos.x + 0.125)); | 
					
						
							|  |  |  | 					} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { | 
					
						
							|  |  |  | 						cpos.x = ((int)Math::floor(cpos.x + 0.25)); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						cpos.x = Math::floor(cpos.x); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					cpos += gl.rect.position; | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 					Size2 csize = gl.rect.size; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, false, false); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::font_is_language_supported(const RID &p_font_rid, const String &p_language) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	if (fd->language_support_overrides.has(p_language)) { | 
					
						
							|  |  |  | 		return fd->language_support_overrides[p_language]; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_language_support_override(const RID &p_font_rid, const String &p_language, bool p_supported) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	fd->language_support_overrides[p_language] = p_supported; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::font_get_language_support_override(const RID &p_font_rid, const String &p_language) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->language_support_overrides[p_language]; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_remove_language_support_override(const RID &p_font_rid, const String &p_language) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	fd->language_support_overrides.erase(p_language); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | PackedStringArray TextServerFallback::font_get_language_support_overrides(const RID &p_font_rid) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, PackedStringArray()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	PackedStringArray out; | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 	for (const KeyValue<String, bool> &E : fd->language_support_overrides) { | 
					
						
							|  |  |  | 		out.push_back(E.key); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	return out; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::font_is_script_supported(const RID &p_font_rid, const String &p_script) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (fd->script_support_overrides.has(p_script)) { | 
					
						
							|  |  |  | 		return fd->script_support_overrides[p_script]; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_script_support_override(const RID &p_font_rid, const String &p_script, bool p_supported) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	fd->script_support_overrides[p_script] = p_supported; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::font_get_script_support_override(const RID &p_font_rid, const String &p_script) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return fd->script_support_overrides[p_script]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_remove_script_support_override(const RID &p_font_rid, const String &p_script) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	fd->script_support_overrides.erase(p_script); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | PackedStringArray TextServerFallback::font_get_script_support_overrides(const RID &p_font_rid) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, PackedStringArray()); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	PackedStringArray out; | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 	for (const KeyValue<String, bool> &E : fd->script_support_overrides) { | 
					
						
							|  |  |  | 		out.push_back(E.key); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return out; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_opentype_feature_overrides(const RID &p_font_rid, const Dictionary &p_overrides) { | 
					
						
							| 
									
										
										
										
											2021-11-18 23:36:22 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); | 
					
						
							|  |  |  | 	fd->feature_overrides = p_overrides; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Dictionary TextServerFallback::font_get_opentype_feature_overrides(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-11-18 23:36:22 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!fd, Dictionary()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	return fd->feature_overrides; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Dictionary TextServerFallback::font_supported_feature_list(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	return Dictionary(); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Dictionary TextServerFallback::font_supported_variation_list(const RID &p_font_rid) const { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 	FontDataFallback *fd = font_owner.get_or_null(p_font_rid); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!fd, Dictionary()); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(fd->mutex); | 
					
						
							|  |  |  | 	Vector2i size = _get_size(fd, 16); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary()); | 
					
						
							|  |  |  | 	return fd->supported_varaitions; | 
					
						
							| 
									
										
										
										
											2020-12-10 17:30:25 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::font_get_global_oversampling() const { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return oversampling; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::font_set_global_oversampling(double p_oversampling) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	_THREAD_SAFE_METHOD_ | 
					
						
							|  |  |  | 	if (oversampling != p_oversampling) { | 
					
						
							|  |  |  | 		oversampling = p_oversampling; | 
					
						
							|  |  |  | 		List<RID> fonts; | 
					
						
							|  |  |  | 		font_owner.get_owned_list(&fonts); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		bool font_cleared = false; | 
					
						
							| 
									
										
										
										
											2021-07-24 15:46:25 +02:00
										 |  |  | 		for (const RID &E : fonts) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			if (!font_is_multichannel_signed_distance_field(E) && font_get_oversampling(E) <= 0) { | 
					
						
							|  |  |  | 				font_clear_size_cache(E); | 
					
						
							|  |  |  | 				font_cleared = true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 		if (font_cleared) { | 
					
						
							|  |  |  | 			List<RID> text_bufs; | 
					
						
							|  |  |  | 			shaped_owner.get_owned_list(&text_bufs); | 
					
						
							|  |  |  | 			for (const RID &E : text_bufs) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 				invalidate(shaped_owner.get_or_null(E)); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /* Shaped text buffer interface                                          */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | void TextServerFallback::invalidate(ShapedTextDataFallback *p_shaped) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	p_shaped->valid = false; | 
					
						
							|  |  |  | 	p_shaped->sort_valid = false; | 
					
						
							|  |  |  | 	p_shaped->line_breaks_valid = false; | 
					
						
							|  |  |  | 	p_shaped->justification_ops_valid = false; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	p_shaped->ascent = 0.0; | 
					
						
							|  |  |  | 	p_shaped->descent = 0.0; | 
					
						
							|  |  |  | 	p_shaped->width = 0.0; | 
					
						
							|  |  |  | 	p_shaped->upos = 0.0; | 
					
						
							|  |  |  | 	p_shaped->uthk = 0.0; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	p_shaped->glyphs.clear(); | 
					
						
							|  |  |  | 	p_shaped->glyphs_logical.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | void TextServerFallback::full_copy(ShapedTextDataFallback *p_shaped) { | 
					
						
							|  |  |  | 	ShapedTextDataFallback *parent = shaped_owner.get_or_null(p_shaped->parent); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	for (const KeyValue<Variant, ShapedTextDataFallback::EmbeddedObject> &E : parent->objects) { | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 		if (E.value.pos >= p_shaped->start && E.value.pos < p_shaped->end) { | 
					
						
							|  |  |  | 			p_shaped->objects[E.key] = E.value; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int k = 0; k < parent->spans.size(); k++) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 		ShapedTextDataFallback::Span span = parent->spans[k]; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		if (span.start >= p_shaped->end || span.end <= p_shaped->start) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		span.start = MAX(p_shaped->start, span.start); | 
					
						
							|  |  |  | 		span.end = MIN(p_shaped->end, span.end); | 
					
						
							|  |  |  | 		p_shaped->spans.push_back(span); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p_shaped->parent = RID(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RID TextServerFallback::create_shaped_text(TextServer::Direction p_direction, TextServer::Orientation p_orientation) { | 
					
						
							|  |  |  | 	_THREAD_SAFE_METHOD_ | 
					
						
							| 
									
										
										
										
											2022-05-18 10:17:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = memnew(ShapedTextDataFallback); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	sd->direction = p_direction; | 
					
						
							|  |  |  | 	sd->orientation = p_orientation; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return shaped_owner.make_rid(sd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_text_clear(const RID &p_shaped) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!sd); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	sd->parent = RID(); | 
					
						
							|  |  |  | 	sd->start = 0; | 
					
						
							|  |  |  | 	sd->end = 0; | 
					
						
							|  |  |  | 	sd->text = String(); | 
					
						
							|  |  |  | 	sd->spans.clear(); | 
					
						
							|  |  |  | 	sd->objects.clear(); | 
					
						
							|  |  |  | 	invalidate(sd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_text_set_direction(const RID &p_shaped, TextServer::Direction p_direction) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (p_direction == DIRECTION_RTL) { | 
					
						
							|  |  |  | 		ERR_PRINT_ONCE("Right-to-left layout is not supported by this text server."); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | TextServer::Direction TextServerFallback::shaped_text_get_direction(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return TextServer::DIRECTION_LTR; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | TextServer::Direction TextServerFallback::shaped_text_get_inferred_direction(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 	return TextServer::DIRECTION_LTR; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_text_set_custom_punctuation(const RID &p_shaped, const String &p_punct) { | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 	_THREAD_SAFE_METHOD_ | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 	ERR_FAIL_COND(!sd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sd->custom_punct != p_punct) { | 
					
						
							|  |  |  | 		if (sd->parent != RID()) { | 
					
						
							|  |  |  | 			full_copy(sd); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		sd->custom_punct = p_punct; | 
					
						
							|  |  |  | 		invalidate(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | String TextServerFallback::shaped_text_get_custom_punctuation(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 	_THREAD_SAFE_METHOD_ | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, String()); | 
					
						
							|  |  |  | 	return sd->custom_punct; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_text_set_orientation(const RID &p_shaped, TextServer::Orientation p_orientation) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!sd); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (sd->orientation != p_orientation) { | 
					
						
							|  |  |  | 		if (sd->parent != RID()) { | 
					
						
							|  |  |  | 			full_copy(sd); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		sd->orientation = p_orientation; | 
					
						
							|  |  |  | 		invalidate(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_text_set_bidi_override(const RID &p_shaped, const Array &p_override) { | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	// No BiDi support, ignore.
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | TextServer::Orientation TextServerFallback::shaped_text_get_orientation(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, TextServer::ORIENTATION_HORIZONTAL); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return sd->orientation; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_text_set_preserve_invalid(const RID &p_shaped, bool p_enabled) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!sd); | 
					
						
							|  |  |  | 	if (sd->preserve_invalid != p_enabled) { | 
					
						
							|  |  |  | 		if (sd->parent != RID()) { | 
					
						
							|  |  |  | 			full_copy(sd); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		sd->preserve_invalid = p_enabled; | 
					
						
							|  |  |  | 		invalidate(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_get_preserve_invalid(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return sd->preserve_invalid; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_text_set_preserve_control(const RID &p_shaped, bool p_enabled) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND(!sd); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (sd->preserve_control != p_enabled) { | 
					
						
							|  |  |  | 		if (sd->parent != RID()) { | 
					
						
							|  |  |  | 			full_copy(sd); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		sd->preserve_control = p_enabled; | 
					
						
							|  |  |  | 		invalidate(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_get_preserve_control(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return sd->preserve_control; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::shaped_get_span_count(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!sd, 0); | 
					
						
							|  |  |  | 	return sd->spans.size(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Variant TextServerFallback::shaped_get_span_meta(const RID &p_shaped, int64_t p_index) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!sd, Variant()); | 
					
						
							|  |  |  | 	ERR_FAIL_INDEX_V(p_index, sd->spans.size(), Variant()); | 
					
						
							|  |  |  | 	return sd->spans[p_index].meta; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_set_span_update_font(const RID &p_shaped, int64_t p_index, const Array &p_fonts, int64_t p_size, const Dictionary &p_opentype_features) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!sd); | 
					
						
							|  |  |  | 	ERR_FAIL_INDEX(p_index, sd->spans.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ShapedTextDataFallback::Span &span = sd->spans.ptrw()[p_index]; | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	span.fonts.clear(); | 
					
						
							|  |  |  | 	// Pre-sort fonts, push fonts with the language support first.
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	Array fonts_no_match; | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	int font_count = p_fonts.size(); | 
					
						
							|  |  |  | 	for (int i = 0; i < font_count; i++) { | 
					
						
							|  |  |  | 		if (font_is_language_supported(p_fonts[i], span.language)) { | 
					
						
							|  |  |  | 			span.fonts.push_back(p_fonts[i]); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			fonts_no_match.push_back(p_fonts[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	span.fonts.append_array(fonts_no_match); | 
					
						
							|  |  |  | 	span.font_size = p_size; | 
					
						
							|  |  |  | 	span.features = p_opentype_features; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sd->valid = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_add_string(const RID &p_shaped, const String &p_text, const Array &p_fonts, int64_t p_size, const Dictionary &p_opentype_features, const String &p_language, const Variant &p_meta) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(p_size <= 0, false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	for (int i = 0; i < p_fonts.size(); i++) { | 
					
						
							| 
									
										
										
										
											2021-09-29 19:08:41 +02:00
										 |  |  | 		ERR_FAIL_COND_V(!font_owner.get_or_null(p_fonts[i]), false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-29 09:54:59 +01:00
										 |  |  | 	if (p_text.is_empty()) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sd->parent != RID()) { | 
					
						
							|  |  |  | 		full_copy(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback::Span span; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	span.start = sd->text.length(); | 
					
						
							|  |  |  | 	span.end = span.start + p_text.length(); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	// Pre-sort fonts, push fonts with the language support first.
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	Array fonts_no_match; | 
					
						
							| 
									
										
										
										
											2021-06-10 22:25:32 +03:00
										 |  |  | 	int font_count = p_fonts.size(); | 
					
						
							|  |  |  | 	for (int i = 0; i < font_count; i++) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		if (font_is_language_supported(p_fonts[i], p_language)) { | 
					
						
							|  |  |  | 			span.fonts.push_back(p_fonts[i]); | 
					
						
							| 
									
										
										
										
											2021-06-10 22:25:32 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			fonts_no_match.push_back(p_fonts[i]); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-06-10 22:25:32 +03:00
										 |  |  | 	span.fonts.append_array(fonts_no_match); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-29 09:54:59 +01:00
										 |  |  | 	ERR_FAIL_COND_V(span.fonts.is_empty(), false); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	span.font_size = p_size; | 
					
						
							|  |  |  | 	span.language = p_language; | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	span.meta = p_meta; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	sd->spans.push_back(span); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	sd->text = sd->text + p_text; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	sd->end += p_text.length(); | 
					
						
							|  |  |  | 	invalidate(sd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_add_object(const RID &p_shaped, const Variant &p_key, const Size2 &p_size, InlineAlignment p_inline_align, int64_t p_length) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(p_key == Variant(), false); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(sd->objects.has(p_key), false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sd->parent != RID()) { | 
					
						
							|  |  |  | 		full_copy(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback::Span span; | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 	span.start = sd->start + sd->text.length(); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	span.end = span.start + p_length; | 
					
						
							|  |  |  | 	span.embedded_key = p_key; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback::EmbeddedObject obj; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	obj.inline_align = p_inline_align; | 
					
						
							|  |  |  | 	obj.rect.size = p_size; | 
					
						
							|  |  |  | 	obj.pos = span.start; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sd->spans.push_back(span); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	sd->text = sd->text + String::chr(0xfffc).repeat(p_length); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	sd->end += p_length; | 
					
						
							|  |  |  | 	sd->objects[p_key] = obj; | 
					
						
							|  |  |  | 	invalidate(sd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_resize_object(const RID &p_shaped, const Variant &p_key, const Size2 &p_size, InlineAlignment p_inline_align) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd->objects.has(p_key), false); | 
					
						
							|  |  |  | 	sd->objects[p_key].rect.size = p_size; | 
					
						
							|  |  |  | 	sd->objects[p_key].inline_align = p_inline_align; | 
					
						
							|  |  |  | 	if (sd->valid) { | 
					
						
							|  |  |  | 		// Recalc string metrics.
 | 
					
						
							|  |  |  | 		sd->ascent = 0; | 
					
						
							|  |  |  | 		sd->descent = 0; | 
					
						
							|  |  |  | 		sd->width = 0; | 
					
						
							|  |  |  | 		sd->upos = 0; | 
					
						
							|  |  |  | 		sd->uthk = 0; | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 		int sd_size = sd->glyphs.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = 0; i < sd_size; i++) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			Glyph gl = sd->glyphs[i]; | 
					
						
							|  |  |  | 			Variant key; | 
					
						
							|  |  |  | 			if (gl.count == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 				for (const KeyValue<Variant, ShapedTextDataFallback::EmbeddedObject> &E : sd->objects) { | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 					if (E.value.pos == gl.start) { | 
					
						
							|  |  |  | 						key = E.key; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (key != Variant()) { | 
					
						
							|  |  |  | 				if (sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							|  |  |  | 					sd->objects[key].rect.position.x = sd->width; | 
					
						
							|  |  |  | 					sd->width += sd->objects[key].rect.size.x; | 
					
						
							|  |  |  | 					sd->glyphs.write[i].advance = sd->objects[key].rect.size.x; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					sd->objects[key].rect.position.y = sd->width; | 
					
						
							|  |  |  | 					sd->width += sd->objects[key].rect.size.y; | 
					
						
							|  |  |  | 					sd->glyphs.write[i].advance = sd->objects[key].rect.size.y; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				if (gl.font_rid.is_valid()) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 					if (sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 						sd->ascent = MAX(sd->ascent, font_get_ascent(gl.font_rid, gl.font_size)); | 
					
						
							|  |  |  | 						sd->descent = MAX(sd->descent, font_get_descent(gl.font_rid, gl.font_size)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 						sd->ascent = MAX(sd->ascent, Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5)); | 
					
						
							|  |  |  | 						sd->descent = MAX(sd->descent, Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					sd->upos = MAX(sd->upos, font_get_underline_position(gl.font_rid, gl.font_size)); | 
					
						
							|  |  |  | 					sd->uthk = MAX(sd->uthk, font_get_underline_thickness(gl.font_rid, gl.font_size)); | 
					
						
							|  |  |  | 				} else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) { | 
					
						
							|  |  |  | 					// Glyph not found, replace with hex code box.
 | 
					
						
							|  |  |  | 					if (sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 						sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 						sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5)); | 
					
						
							|  |  |  | 						sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				sd->width += gl.advance * gl.repeat; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 		_realign(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | void TextServerFallback::_realign(ShapedTextDataFallback *p_sd) const { | 
					
						
							|  |  |  | 	// Align embedded objects to baseline.
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	double full_ascent = p_sd->ascent; | 
					
						
							|  |  |  | 	double full_descent = p_sd->descent; | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	for (KeyValue<Variant, ShapedTextDataFallback::EmbeddedObject> &E : p_sd->objects) { | 
					
						
							|  |  |  | 		if ((E.value.pos >= p_sd->start) && (E.value.pos < p_sd->end)) { | 
					
						
							|  |  |  | 			if (p_sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							|  |  |  | 				switch (E.value.inline_align & INLINE_ALIGNMENT_TEXT_MASK) { | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TO_TOP: { | 
					
						
							|  |  |  | 						E.value.rect.position.y = -p_sd->ascent; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TO_CENTER: { | 
					
						
							|  |  |  | 						E.value.rect.position.y = (-p_sd->ascent + p_sd->descent) / 2; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TO_BASELINE: { | 
					
						
							|  |  |  | 						E.value.rect.position.y = 0; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TO_BOTTOM: { | 
					
						
							|  |  |  | 						E.value.rect.position.y = p_sd->descent; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				switch (E.value.inline_align & INLINE_ALIGNMENT_IMAGE_MASK) { | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_BOTTOM_TO: { | 
					
						
							|  |  |  | 						E.value.rect.position.y -= E.value.rect.size.y; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_CENTER_TO: { | 
					
						
							|  |  |  | 						E.value.rect.position.y -= E.value.rect.size.y / 2; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TOP_TO: { | 
					
						
							|  |  |  | 						// NOP
 | 
					
						
							|  |  |  | 					} break; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 				full_ascent = MAX(full_ascent, -E.value.rect.position.y); | 
					
						
							|  |  |  | 				full_descent = MAX(full_descent, E.value.rect.position.y + E.value.rect.size.y); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				switch (E.value.inline_align & INLINE_ALIGNMENT_TEXT_MASK) { | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TO_TOP: { | 
					
						
							|  |  |  | 						E.value.rect.position.x = -p_sd->ascent; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TO_CENTER: { | 
					
						
							|  |  |  | 						E.value.rect.position.x = (-p_sd->ascent + p_sd->descent) / 2; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TO_BASELINE: { | 
					
						
							|  |  |  | 						E.value.rect.position.x = 0; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TO_BOTTOM: { | 
					
						
							|  |  |  | 						E.value.rect.position.x = p_sd->descent; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				switch (E.value.inline_align & INLINE_ALIGNMENT_IMAGE_MASK) { | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_BOTTOM_TO: { | 
					
						
							|  |  |  | 						E.value.rect.position.x -= E.value.rect.size.x; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_CENTER_TO: { | 
					
						
							|  |  |  | 						E.value.rect.position.x -= E.value.rect.size.x / 2; | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case INLINE_ALIGNMENT_TOP_TO: { | 
					
						
							|  |  |  | 						// NOP
 | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				full_ascent = MAX(full_ascent, -E.value.rect.position.x); | 
					
						
							|  |  |  | 				full_descent = MAX(full_descent, E.value.rect.position.x + E.value.rect.size.x); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	p_sd->ascent = full_ascent; | 
					
						
							|  |  |  | 	p_sd->descent = full_descent; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | RID TextServerFallback::shaped_text_substr(const RID &p_shaped, int64_t p_start, int64_t p_length) const { | 
					
						
							| 
									
										
										
										
											2022-05-18 10:17:55 +03:00
										 |  |  | 	_THREAD_SAFE_METHOD_ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, RID()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (sd->parent != RID()) { | 
					
						
							|  |  |  | 		return shaped_text_substr(sd->parent, p_start, p_length); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(p_start < 0 || p_length < 0, RID()); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(sd->start > p_start || sd->end < p_start, RID()); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(sd->end < p_start + p_length, RID()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *new_sd = memnew(ShapedTextDataFallback); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	new_sd->parent = p_shaped; | 
					
						
							|  |  |  | 	new_sd->start = p_start; | 
					
						
							|  |  |  | 	new_sd->end = p_start + p_length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	new_sd->orientation = sd->orientation; | 
					
						
							|  |  |  | 	new_sd->direction = sd->direction; | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 	new_sd->custom_punct = sd->custom_punct; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	new_sd->para_direction = sd->para_direction; | 
					
						
							|  |  |  | 	new_sd->line_breaks_valid = sd->line_breaks_valid; | 
					
						
							|  |  |  | 	new_sd->justification_ops_valid = sd->justification_ops_valid; | 
					
						
							|  |  |  | 	new_sd->sort_valid = false; | 
					
						
							|  |  |  | 	new_sd->upos = sd->upos; | 
					
						
							|  |  |  | 	new_sd->uthk = sd->uthk; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_length > 0) { | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 		new_sd->text = sd->text.substr(p_start - sd->start, p_length); | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 		int sd_size = sd->glyphs.size(); | 
					
						
							|  |  |  | 		const Glyph *sd_glyphs = sd->glyphs.ptr(); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 		for (int i = 0; i < sd_size; i++) { | 
					
						
							|  |  |  | 			if ((sd_glyphs[i].start >= new_sd->start) && (sd_glyphs[i].end <= new_sd->end)) { | 
					
						
							|  |  |  | 				Glyph gl = sd_glyphs[i]; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 				Variant key; | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 				bool find_embedded = false; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 				if (gl.count == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 					for (const KeyValue<Variant, ShapedTextDataFallback::EmbeddedObject> &E : sd->objects) { | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 						if (E.value.pos == gl.start) { | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 							find_embedded = true; | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 							key = E.key; | 
					
						
							|  |  |  | 							new_sd->objects[key] = E.value; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 							break; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 				if (find_embedded) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 					if (new_sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							|  |  |  | 						new_sd->objects[key].rect.position.x = new_sd->width; | 
					
						
							|  |  |  | 						new_sd->width += new_sd->objects[key].rect.size.x; | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						new_sd->objects[key].rect.position.y = new_sd->width; | 
					
						
							|  |  |  | 						new_sd->width += new_sd->objects[key].rect.size.y; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					if (gl.font_rid.is_valid()) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						if (new_sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 							new_sd->ascent = MAX(new_sd->ascent, font_get_ascent(gl.font_rid, gl.font_size)); | 
					
						
							|  |  |  | 							new_sd->descent = MAX(new_sd->descent, font_get_descent(gl.font_rid, gl.font_size)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 							new_sd->ascent = MAX(new_sd->ascent, Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5)); | 
					
						
							|  |  |  | 							new_sd->descent = MAX(new_sd->descent, Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} else if (new_sd->preserve_invalid || (new_sd->preserve_control && is_control(gl.index))) { | 
					
						
							|  |  |  | 						// Glyph not found, replace with hex code box.
 | 
					
						
							|  |  |  | 						if (new_sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 							new_sd->ascent = MAX(new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 							new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5)); | 
					
						
							|  |  |  | 							new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					new_sd->width += gl.advance * gl.repeat; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				new_sd->glyphs.push_back(gl); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		_realign(new_sd); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	new_sd->valid = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return shaped_owner.make_rid(new_sd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | RID TextServerFallback::shaped_text_get_parent(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, RID()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return sd->parent; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::shaped_text_fit_to_width(const RID &p_shaped, double p_width, int64_t /*JustificationFlag*/ p_jst_flags) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!sd->justification_ops_valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_update_justification_ops(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int start_pos = 0; | 
					
						
							|  |  |  | 	int end_pos = sd->glyphs.size() - 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((p_jst_flags & JUSTIFICATION_AFTER_LAST_TAB) == JUSTIFICATION_AFTER_LAST_TAB) { | 
					
						
							|  |  |  | 		int start, end, delta; | 
					
						
							|  |  |  | 		if (sd->para_direction == DIRECTION_LTR) { | 
					
						
							|  |  |  | 			start = sd->glyphs.size() - 1; | 
					
						
							|  |  |  | 			end = -1; | 
					
						
							|  |  |  | 			delta = -1; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			start = 0; | 
					
						
							|  |  |  | 			end = sd->glyphs.size(); | 
					
						
							|  |  |  | 			delta = +1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = start; i != end; i += delta) { | 
					
						
							|  |  |  | 			if ((sd->glyphs[i].flags & GRAPHEME_IS_TAB) == GRAPHEME_IS_TAB) { | 
					
						
							|  |  |  | 				if (sd->para_direction == DIRECTION_LTR) { | 
					
						
							|  |  |  | 					start_pos = i; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					end_pos = i; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	double justification_width; | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 	if ((p_jst_flags & JUSTIFICATION_CONSTRAIN_ELLIPSIS) == JUSTIFICATION_CONSTRAIN_ELLIPSIS) { | 
					
						
							|  |  |  | 		if (sd->overrun_trim_data.trim_pos >= 0) { | 
					
						
							|  |  |  | 			end_pos = sd->overrun_trim_data.trim_pos; | 
					
						
							|  |  |  | 			justification_width = sd->width_trimmed; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 			return Math::ceil(sd->width); | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		justification_width = sd->width; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if ((p_jst_flags & JUSTIFICATION_TRIM_EDGE_SPACES) == JUSTIFICATION_TRIM_EDGE_SPACES) { | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 		// Trim spaces.
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 			justification_width -= sd->glyphs[start_pos].advance * sd->glyphs[start_pos].repeat; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			sd->glyphs.write[start_pos].advance = 0; | 
					
						
							|  |  |  | 			start_pos += sd->glyphs[start_pos].count; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 			justification_width -= sd->glyphs[end_pos].advance * sd->glyphs[end_pos].repeat; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			sd->glyphs.write[end_pos].advance = 0; | 
					
						
							|  |  |  | 			end_pos -= sd->glyphs[end_pos].count; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		// Skip breaks, but do not reset size.
 | 
					
						
							|  |  |  | 		while ((start_pos < end_pos) && ((sd->glyphs[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD)) { | 
					
						
							|  |  |  | 			start_pos += sd->glyphs[start_pos].count; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		while ((start_pos < end_pos) && ((sd->glyphs[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD)) { | 
					
						
							|  |  |  | 			end_pos -= sd->glyphs[end_pos].count; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int space_count = 0; | 
					
						
							|  |  |  | 	for (int i = start_pos; i <= end_pos; i++) { | 
					
						
							|  |  |  | 		const Glyph &gl = sd->glyphs[i]; | 
					
						
							|  |  |  | 		if (gl.count > 0) { | 
					
						
							|  |  |  | 			if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE) { | 
					
						
							|  |  |  | 				space_count++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((space_count > 0) && ((p_jst_flags & JUSTIFICATION_WORD_BOUND) == JUSTIFICATION_WORD_BOUND)) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		double delta_width_per_space = (p_width - justification_width) / space_count; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		for (int i = start_pos; i <= end_pos; i++) { | 
					
						
							|  |  |  | 			Glyph &gl = sd->glyphs.write[i]; | 
					
						
							|  |  |  | 			if (gl.count > 0) { | 
					
						
							|  |  |  | 				if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 					double old_adv = gl.advance; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					gl.advance = MAX(gl.advance + delta_width_per_space, Math::round(0.1 * gl.font_size)); | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 					justification_width += (gl.advance - old_adv); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 	if (Math::floor(p_width) < Math::floor(justification_width)) { | 
					
						
							|  |  |  | 		sd->fit_width_minimum_reached = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((p_jst_flags & JUSTIFICATION_CONSTRAIN_ELLIPSIS) != JUSTIFICATION_CONSTRAIN_ELLIPSIS) { | 
					
						
							|  |  |  | 		sd->width = justification_width; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	return Math::ceil(justification_width); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::shaped_text_tab_align(const RID &p_shaped, const PackedFloat32Array &p_tab_stops) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!sd->line_breaks_valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_update_breaks(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 12:19:29 +02:00
										 |  |  | 	for (int i = 0; i < p_tab_stops.size(); i++) { | 
					
						
							|  |  |  | 		if (p_tab_stops[i] <= 0) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			return 0.0; | 
					
						
							| 
									
										
										
										
											2022-01-10 12:19:29 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	int tab_index = 0; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	double off = 0.0; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int start, end, delta; | 
					
						
							|  |  |  | 	if (sd->para_direction == DIRECTION_LTR) { | 
					
						
							|  |  |  | 		start = 0; | 
					
						
							|  |  |  | 		end = sd->glyphs.size(); | 
					
						
							|  |  |  | 		delta = +1; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		start = sd->glyphs.size() - 1; | 
					
						
							|  |  |  | 		end = -1; | 
					
						
							|  |  |  | 		delta = -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 	Glyph *gl = sd->glyphs.ptrw(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	for (int i = start; i != end; i += delta) { | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 		if ((gl[i].flags & GRAPHEME_IS_TAB) == GRAPHEME_IS_TAB) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			double tab_off = 0.0; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			while (tab_off <= off) { | 
					
						
							|  |  |  | 				tab_off += p_tab_stops[tab_index]; | 
					
						
							|  |  |  | 				tab_index++; | 
					
						
							|  |  |  | 				if (tab_index >= p_tab_stops.size()) { | 
					
						
							|  |  |  | 					tab_index = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 			double old_adv = gl[i].advance; | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 			gl[i].advance = tab_off - off; | 
					
						
							|  |  |  | 			sd->width += gl[i].advance - old_adv; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			off = 0; | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 		off += gl[i].advance * gl[i].repeat; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	return 0.0; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_update_breaks(const RID &p_shaped) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sd->line_breaks_valid) { | 
					
						
							| 
									
										
										
										
											2021-03-12 19:05:16 +05:30
										 |  |  | 		return true; // Nothing to do.
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 	int sd_size = sd->glyphs.size(); | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 	Glyph *sd_glyphs = sd->glyphs.ptrw(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int c_punct_size = sd->custom_punct.length(); | 
					
						
							|  |  |  | 	const char32_t *c_punct = sd->custom_punct.ptr(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-01 15:03:31 +02:00
										 |  |  | 	for (int i = 0; i < sd_size; i++) { | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 		if (sd_glyphs[i].count > 0) { | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 			char32_t c = sd->text[sd_glyphs[i].start - sd->start]; | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 			if (c_punct_size == 0) { | 
					
						
							| 
									
										
										
										
											2021-11-04 14:33:37 +02:00
										 |  |  | 				if (is_punct(c) && c != 0x005F) { | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 					sd_glyphs[i].flags |= GRAPHEME_IS_PUNCTUATION; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				for (int j = 0; j < c_punct_size; j++) { | 
					
						
							|  |  |  | 					if (c_punct[j] == c) { | 
					
						
							|  |  |  | 						sd_glyphs[i].flags |= GRAPHEME_IS_PUNCTUATION; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-12-14 10:30:32 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-04-03 12:17:51 -03:00
										 |  |  | 			if (is_underscore(c)) { | 
					
						
							|  |  |  | 				sd->glyphs.write[i].flags |= GRAPHEME_IS_UNDERSCORE; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			if (is_whitespace(c) && !is_linebreak(c)) { | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 				sd_glyphs[i].flags |= GRAPHEME_IS_SPACE; | 
					
						
							|  |  |  | 				sd_glyphs[i].flags |= GRAPHEME_IS_BREAK_SOFT; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (is_linebreak(c)) { | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 				sd_glyphs[i].flags |= GRAPHEME_IS_SPACE; | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 				sd_glyphs[i].flags |= GRAPHEME_IS_BREAK_HARD; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (c == 0x0009 || c == 0x000b) { | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 				sd_glyphs[i].flags |= GRAPHEME_IS_TAB; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 			i += (sd_glyphs[i].count - 1); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	sd->line_breaks_valid = true; | 
					
						
							|  |  |  | 	return sd->line_breaks_valid; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_update_justification_ops(const RID &p_shaped) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!sd->line_breaks_valid) { | 
					
						
							|  |  |  | 		shaped_text_update_breaks(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sd->justification_ops_valid = true; // Not supported by fallback server.
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | void TextServerFallback::shaped_text_overrun_trim_to_width(const RID &p_shaped_line, double p_width, int64_t p_trim_flags) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped_line); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	ERR_FAIL_COND_MSG(!sd, "ShapedTextDataFallback invalid."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		shaped_text_shape(p_shaped_line); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 21:51:18 +03:00
										 |  |  | 	sd->text_trimmed = false; | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	sd->overrun_trim_data.ellipsis_glyph_buf.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool add_ellipsis = (p_trim_flags & OVERRUN_ADD_ELLIPSIS) == OVERRUN_ADD_ELLIPSIS; | 
					
						
							|  |  |  | 	bool cut_per_word = (p_trim_flags & OVERRUN_TRIM_WORD_ONLY) == OVERRUN_TRIM_WORD_ONLY; | 
					
						
							|  |  |  | 	bool enforce_ellipsis = (p_trim_flags & OVERRUN_ENFORCE_ELLIPSIS) == OVERRUN_ENFORCE_ELLIPSIS; | 
					
						
							|  |  |  | 	bool justification_aware = (p_trim_flags & OVERRUN_JUSTIFICATION_AWARE) == OVERRUN_JUSTIFICATION_AWARE; | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Glyph *sd_glyphs = sd->glyphs.ptrw(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	if ((p_trim_flags & OVERRUN_TRIM) == OVERRUN_NO_TRIMMING || sd_glyphs == nullptr || p_width <= 0 || !(sd->width > p_width || enforce_ellipsis)) { | 
					
						
							|  |  |  | 		sd->overrun_trim_data.trim_pos = -1; | 
					
						
							|  |  |  | 		sd->overrun_trim_data.ellipsis_pos = -1; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (justification_aware && !sd->fit_width_minimum_reached) { | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	Vector<ShapedTextDataFallback::Span> &spans = sd->spans; | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 	if (sd->parent != RID()) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 		ShapedTextDataFallback *parent_sd = shaped_owner.get_or_null(sd->parent); | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 		ERR_FAIL_COND(!parent_sd->valid); | 
					
						
							|  |  |  | 		spans = parent_sd->spans; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (spans.size() == 0) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 	int sd_size = sd->glyphs.size(); | 
					
						
							|  |  |  | 	int last_gl_font_size = sd_glyphs[sd_size - 1].font_size; | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Find usable fonts, if fonts from the last glyph do not have required chars.
 | 
					
						
							|  |  |  | 	RID dot_gl_font_rid = sd_glyphs[sd_size - 1].font_rid; | 
					
						
							|  |  |  | 	if (!font_has_char(dot_gl_font_rid, '.')) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		const Array &fonts = spans[spans.size() - 1].fonts; | 
					
						
							|  |  |  | 		for (int i = 0; i < fonts.size(); i++) { | 
					
						
							|  |  |  | 			if (font_has_char(fonts[i], '.')) { | 
					
						
							|  |  |  | 				dot_gl_font_rid = fonts[i]; | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	RID whitespace_gl_font_rid = sd_glyphs[sd_size - 1].font_rid; | 
					
						
							|  |  |  | 	if (!font_has_char(whitespace_gl_font_rid, '.')) { | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 		const Array &fonts = spans[spans.size() - 1].fonts; | 
					
						
							|  |  |  | 		for (int i = 0; i < fonts.size(); i++) { | 
					
						
							|  |  |  | 			if (font_has_char(fonts[i], ' ')) { | 
					
						
							|  |  |  | 				whitespace_gl_font_rid = fonts[i]; | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int32_t dot_gl_idx = dot_gl_font_rid.is_valid() ? font_get_glyph_index(dot_gl_font_rid, last_gl_font_size, '.') : -10; | 
					
						
							|  |  |  | 	Vector2 dot_adv = dot_gl_font_rid.is_valid() ? font_get_glyph_advance(dot_gl_font_rid, last_gl_font_size, dot_gl_idx) : Vector2(); | 
					
						
							|  |  |  | 	int32_t whitespace_gl_idx = whitespace_gl_font_rid.is_valid() ? font_get_glyph_index(whitespace_gl_font_rid, last_gl_font_size, ' ') : -10; | 
					
						
							|  |  |  | 	Vector2 whitespace_adv = whitespace_gl_font_rid.is_valid() ? font_get_glyph_advance(whitespace_gl_font_rid, last_gl_font_size, whitespace_gl_idx) : Vector2(); | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	int ellipsis_width = 0; | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 	if (add_ellipsis && whitespace_gl_font_rid.is_valid()) { | 
					
						
							|  |  |  | 		ellipsis_width = 3 * dot_adv.x + font_get_spacing(whitespace_gl_font_rid, last_gl_font_size, SPACING_GLYPH) + (cut_per_word ? whitespace_adv.x : 0); | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int ell_min_characters = 6; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	double width = sd->width; | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	int trim_pos = 0; | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 	int ellipsis_pos = (enforce_ellipsis) ? 0 : -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int last_valid_cut = 0; | 
					
						
							|  |  |  | 	bool found = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	for (int i = sd_size - 1; i != -1; i--) { | 
					
						
							|  |  |  | 		width -= sd_glyphs[i].advance * sd_glyphs[i].repeat; | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (sd_glyphs[i].count > 0) { | 
					
						
							| 
									
										
										
										
											2021-10-31 22:11:42 +07:00
										 |  |  | 			bool above_min_char_threshold = (i >= ell_min_characters); | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 22:11:42 +07:00
										 |  |  | 			if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_width : 0) <= p_width) { | 
					
						
							|  |  |  | 				if (cut_per_word && above_min_char_threshold) { | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 					if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) { | 
					
						
							|  |  |  | 						last_valid_cut = i; | 
					
						
							|  |  |  | 						found = true; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					last_valid_cut = i; | 
					
						
							|  |  |  | 					found = true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (found) { | 
					
						
							|  |  |  | 					trim_pos = last_valid_cut; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 22:11:42 +07:00
										 |  |  | 					if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis) && width - ellipsis_width <= p_width) { | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 						ellipsis_pos = trim_pos; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sd->overrun_trim_data.trim_pos = trim_pos; | 
					
						
							|  |  |  | 	sd->overrun_trim_data.ellipsis_pos = ellipsis_pos; | 
					
						
							|  |  |  | 	if (trim_pos == 0 && enforce_ellipsis && add_ellipsis) { | 
					
						
							|  |  |  | 		sd->overrun_trim_data.ellipsis_pos = 0; | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((trim_pos >= 0 && sd->width > p_width) || enforce_ellipsis) { | 
					
						
							|  |  |  | 		if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) { | 
					
						
							|  |  |  | 			// Insert an additional space when cutting word bound for aesthetics.
 | 
					
						
							|  |  |  | 			if (cut_per_word && (ellipsis_pos > 0)) { | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 				Glyph gl; | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 				gl.count = 1; | 
					
						
							|  |  |  | 				gl.advance = whitespace_adv.x; | 
					
						
							|  |  |  | 				gl.index = whitespace_gl_idx; | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 				gl.font_rid = whitespace_gl_font_rid; | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 				gl.font_size = last_gl_font_size; | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 				gl.flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_BREAK_SOFT | GRAPHEME_IS_VIRTUAL; | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 				sd->overrun_trim_data.ellipsis_glyph_buf.append(gl); | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			// Add ellipsis dots.
 | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 			if (dot_gl_idx != 0) { | 
					
						
							|  |  |  | 				Glyph gl; | 
					
						
							|  |  |  | 				gl.count = 1; | 
					
						
							|  |  |  | 				gl.repeat = 3; | 
					
						
							|  |  |  | 				gl.advance = dot_adv.x; | 
					
						
							|  |  |  | 				gl.index = dot_gl_idx; | 
					
						
							|  |  |  | 				gl.font_rid = dot_gl_font_rid; | 
					
						
							|  |  |  | 				gl.font_size = last_gl_font_size; | 
					
						
							|  |  |  | 				gl.flags = GRAPHEME_IS_PUNCTUATION | GRAPHEME_IS_VIRTUAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				sd->overrun_trim_data.ellipsis_glyph_buf.append(gl); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 		sd->text_trimmed = true; | 
					
						
							|  |  |  | 		sd->width_trimmed = width + ((ellipsis_pos != -1) ? ellipsis_width : 0); | 
					
						
							| 
									
										
										
										
											2021-07-04 16:43:55 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::shaped_text_get_trim_pos(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataFallback invalid."); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							|  |  |  | 	return sd->overrun_trim_data.trim_pos; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::shaped_text_get_ellipsis_pos(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataFallback invalid."); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							|  |  |  | 	return sd->overrun_trim_data.ellipsis_pos; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | const Glyph *TextServerFallback::shaped_text_get_ellipsis_glyphs(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V_MSG(!sd, nullptr, "ShapedTextDataFallback invalid."); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							|  |  |  | 	return sd->overrun_trim_data.ellipsis_glyph_buf.ptr(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::shaped_text_get_ellipsis_glyph_count(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V_MSG(!sd, 0, "ShapedTextDataFallback invalid."); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	return sd->overrun_trim_data.ellipsis_glyph_buf.size(); | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_shape(const RID &p_shaped) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (sd->valid) { | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sd->parent != RID()) { | 
					
						
							|  |  |  | 		full_copy(sd); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Cleanup.
 | 
					
						
							|  |  |  | 	sd->justification_ops_valid = false; | 
					
						
							|  |  |  | 	sd->line_breaks_valid = false; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	sd->ascent = 0.0; | 
					
						
							|  |  |  | 	sd->descent = 0.0; | 
					
						
							|  |  |  | 	sd->width = 0.0; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	sd->glyphs.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sd->text.length() == 0) { | 
					
						
							|  |  |  | 		sd->valid = true; | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// "Shape" string.
 | 
					
						
							|  |  |  | 	for (int i = 0; i < sd->spans.size(); i++) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 		const ShapedTextDataFallback::Span &span = sd->spans[i]; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 		if (span.embedded_key != Variant()) { | 
					
						
							|  |  |  | 			// Embedded object.
 | 
					
						
							|  |  |  | 			if (sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							|  |  |  | 				sd->objects[span.embedded_key].rect.position.x = sd->width; | 
					
						
							|  |  |  | 				sd->width += sd->objects[span.embedded_key].rect.size.x; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				sd->objects[span.embedded_key].rect.position.y = sd->width; | 
					
						
							|  |  |  | 				sd->width += sd->objects[span.embedded_key].rect.size.y; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			Glyph gl; | 
					
						
							|  |  |  | 			gl.start = span.start; | 
					
						
							|  |  |  | 			gl.end = span.end; | 
					
						
							|  |  |  | 			gl.count = 1; | 
					
						
							|  |  |  | 			gl.index = 0; | 
					
						
							|  |  |  | 			gl.flags = GRAPHEME_IS_VALID | GRAPHEME_IS_VIRTUAL; | 
					
						
							|  |  |  | 			if (sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							|  |  |  | 				gl.advance = sd->objects[span.embedded_key].rect.size.x; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				gl.advance = sd->objects[span.embedded_key].rect.size.y; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			sd->glyphs.push_back(gl); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// Text span.
 | 
					
						
							|  |  |  | 			for (int j = span.start; j < span.end; j++) { | 
					
						
							|  |  |  | 				Glyph gl; | 
					
						
							|  |  |  | 				gl.start = j; | 
					
						
							|  |  |  | 				gl.end = j + 1; | 
					
						
							|  |  |  | 				gl.count = 1; | 
					
						
							|  |  |  | 				gl.font_size = span.font_size; | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 				gl.index = (int32_t)sd->text[j - sd->start]; // Use codepoint.
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 				if (gl.index == 0x0009 || gl.index == 0x000b) { | 
					
						
							|  |  |  | 					gl.index = 0x0020; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (!sd->preserve_control && is_control(gl.index)) { | 
					
						
							|  |  |  | 					gl.index = 0x0020; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				// Select first font which has character (font are already sorted by span language).
 | 
					
						
							|  |  |  | 				for (int k = 0; k < span.fonts.size(); k++) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					if (font_has_char(span.fonts[k], gl.index)) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						gl.font_rid = span.fonts[k]; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 				if (gl.font_rid.is_valid()) { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 					bool subpos = (font_get_subpixel_positioning(gl.font_rid) == SUBPIXEL_POSITIONING_ONE_HALF) || (font_get_subpixel_positioning(gl.font_rid) == SUBPIXEL_POSITIONING_ONE_QUARTER) || (font_get_subpixel_positioning(gl.font_rid) == SUBPIXEL_POSITIONING_AUTO && gl.font_size <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE); | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 					if (sd->text[j - sd->start] != 0 && !is_linebreak(sd->text[j - sd->start])) { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						if (sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 							gl.advance = Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 							gl.x_off = 0; | 
					
						
							|  |  |  | 							gl.y_off = 0; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 							sd->ascent = MAX(sd->ascent, font_get_ascent(gl.font_rid, gl.font_size)); | 
					
						
							|  |  |  | 							sd->descent = MAX(sd->descent, font_get_descent(gl.font_rid, gl.font_size)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2022-01-10 17:24:03 +02:00
										 |  |  | 							gl.advance = Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).y); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 							gl.x_off = -Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5); | 
					
						
							|  |  |  | 							gl.y_off = font_get_ascent(gl.font_rid, gl.font_size); | 
					
						
							|  |  |  | 							sd->ascent = MAX(sd->ascent, Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5)); | 
					
						
							|  |  |  | 							sd->descent = MAX(sd->descent, Math::round(font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2021-12-13 18:31:16 +02:00
										 |  |  | 					if (font_get_spacing(gl.font_rid, gl.font_size, TextServer::SPACING_SPACE) && is_whitespace(sd->text[j - sd->start])) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 						gl.advance += font_get_spacing(gl.font_rid, gl.font_size, TextServer::SPACING_SPACE); | 
					
						
							| 
									
										
										
										
											2021-02-15 10:46:23 +02:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 						gl.advance += font_get_spacing(gl.font_rid, gl.font_size, TextServer::SPACING_GLYPH); | 
					
						
							| 
									
										
										
										
											2021-02-15 10:46:23 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 					sd->upos = MAX(sd->upos, font_get_underline_position(gl.font_rid, gl.font_size)); | 
					
						
							|  |  |  | 					sd->uthk = MAX(sd->uthk, font_get_underline_thickness(gl.font_rid, gl.font_size)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					// Add kerning to previous glyph.
 | 
					
						
							|  |  |  | 					if (sd->glyphs.size() > 0) { | 
					
						
							|  |  |  | 						Glyph &prev_gl = sd->glyphs.write[sd->glyphs.size() - 1]; | 
					
						
							|  |  |  | 						if (prev_gl.font_rid == gl.font_rid && prev_gl.font_size == gl.font_size) { | 
					
						
							|  |  |  | 							if (sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 								prev_gl.advance += font_get_kerning(gl.font_rid, gl.font_size, Vector2i(prev_gl.index, gl.index)).x; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 							} else { | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 								prev_gl.advance += font_get_kerning(gl.font_rid, gl.font_size, Vector2i(prev_gl.index, gl.index)).y; | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 					if (sd->orientation == ORIENTATION_HORIZONTAL && !subpos) { | 
					
						
							|  |  |  | 						gl.advance = Math::round(gl.advance); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 				} else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) { | 
					
						
							|  |  |  | 					// Glyph not found, replace with hex code box.
 | 
					
						
							|  |  |  | 					if (sd->orientation == ORIENTATION_HORIZONTAL) { | 
					
						
							|  |  |  | 						gl.advance = get_hex_code_box_size(gl.font_size, gl.index).x; | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 						sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						gl.advance = get_hex_code_box_size(gl.font_size, gl.index).y; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 						sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5)); | 
					
						
							|  |  |  | 						sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5)); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				sd->width += gl.advance; | 
					
						
							|  |  |  | 				sd->glyphs.push_back(gl); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Align embedded objects to baseline.
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	_realign(sd); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	sd->valid = true; | 
					
						
							|  |  |  | 	return sd->valid; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | bool TextServerFallback::shaped_text_is_ready(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, false); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	return sd->valid; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | const Glyph *TextServerFallback::shaped_text_get_glyphs(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, nullptr); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	return sd->glyphs.ptr(); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | int64_t TextServerFallback::shaped_text_get_glyph_count(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, 0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return sd->glyphs.size(); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | const Glyph *TextServerFallback::shaped_text_sort_logical(const RID &p_shaped) { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, nullptr); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	return sd->glyphs.ptr(); // Already in the logical order, return as is.
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Vector2i TextServerFallback::shaped_text_get_range(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, Vector2i()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							|  |  |  | 	return Vector2(sd->start, sd->end); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Array TextServerFallback::shaped_text_get_objects(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	Array ret; | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, ret); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	for (const KeyValue<Variant, ShapedTextDataFallback::EmbeddedObject> &E : sd->objects) { | 
					
						
							| 
									
										
										
										
											2021-08-09 14:13:42 -06:00
										 |  |  | 		ret.push_back(E.key); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Rect2 TextServerFallback::shaped_text_get_object_rect(const RID &p_shaped, const Variant &p_key) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, Rect2()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd->objects.has(p_key), Rect2()); | 
					
						
							|  |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return sd->objects[p_key].rect; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | Size2 TextServerFallback::shaped_text_get_size(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, Size2()); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (sd->orientation == TextServer::ORIENTATION_HORIZONTAL) { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 		return Size2(sd->width, sd->ascent + sd->descent).ceil(); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 		return Size2(sd->ascent + sd->descent, sd->width).ceil(); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::shaped_text_get_ascent(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return sd->ascent; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::shaped_text_get_descent(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return sd->descent; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::shaped_text_get_width(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-10 10:13:22 +02:00
										 |  |  | 	return Math::ceil(sd->width); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::shaped_text_get_underline_position(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return sd->upos; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | double TextServerFallback::shaped_text_get_underline_thickness(const RID &p_shaped) const { | 
					
						
							| 
									
										
										
										
											2022-01-20 09:30:42 +02:00
										 |  |  | 	const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	ERR_FAIL_COND_V(!sd, 0.0); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MutexLock lock(sd->mutex); | 
					
						
							| 
									
										
										
										
											2020-08-05 09:25:28 +03:00
										 |  |  | 	if (!sd->valid) { | 
					
						
							|  |  |  | 		const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return sd->uthk; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-17 10:54:45 +02:00
										 |  |  | String TextServerFallback::string_to_upper(const String &p_string, const String &p_language) const { | 
					
						
							|  |  |  | 	String upper = p_string; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	for (int i = 0; i <= upper.length(); i++) { | 
					
						
							| 
									
										
										
										
											2022-01-17 10:54:45 +02:00
										 |  |  | 		const char32_t s = upper[i]; | 
					
						
							|  |  |  | 		const char32_t t = _find_upper(s); | 
					
						
							|  |  |  | 		if (s != t) { // avoid copy on write
 | 
					
						
							|  |  |  | 			upper[i] = t; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return upper; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String TextServerFallback::string_to_lower(const String &p_string, const String &p_language) const { | 
					
						
							|  |  |  | 	String lower = p_string; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	for (int i = 0; i <= lower.length(); i++) { | 
					
						
							| 
									
										
										
										
											2022-01-17 10:54:45 +02:00
										 |  |  | 		const char32_t s = lower[i]; | 
					
						
							|  |  |  | 		const char32_t t = _find_lower(s); | 
					
						
							|  |  |  | 		if (s != t) { // avoid copy on write
 | 
					
						
							|  |  |  | 			lower[i] = t; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return lower; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 14:33:37 +02:00
										 |  |  | PackedInt32Array TextServerFallback::string_get_word_breaks(const String &p_string, const String &p_language) const { | 
					
						
							|  |  |  | 	PackedInt32Array ret; | 
					
						
							|  |  |  | 	for (int i = 0; i < p_string.length(); i++) { | 
					
						
							|  |  |  | 		char32_t c = p_string[i]; | 
					
						
							|  |  |  | 		if (c == 0xfffc) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (is_punct(c) && c != 0x005F) { | 
					
						
							|  |  |  | 			ret.push_back(i); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (is_underscore(c)) { | 
					
						
							|  |  |  | 			ret.push_back(i); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (is_whitespace(c) || is_linebreak(c)) { | 
					
						
							|  |  |  | 			ret.push_back(i); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:45:54 +03:00
										 |  |  | TextServerFallback::TextServerFallback() { | 
					
						
							|  |  |  | 	_insert_feature_sets(); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | TextServerFallback::~TextServerFallback() { | 
					
						
							| 
									
										
										
										
											2021-11-12 09:30:34 -06:00
										 |  |  | #ifdef MODULE_FREETYPE_ENABLED
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:41:29 +02:00
										 |  |  | 	if (ft_library != nullptr) { | 
					
						
							|  |  |  | 		FT_Done_FreeType(ft_library); | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-11-12 09:30:34 -06:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-12-27 15:30:33 +02:00
										 |  |  | }; |