[Complex Text Layouts] Refactor Font class, default themes and controls to use Text Server interface.

Implement interface mirroring.
Add TextLine and TextParagraph classes.
Handle UTF-16 input on macOS and Windows.
This commit is contained in:
bruvzg 2020-09-03 14:22:16 +03:00
parent 07d14f5bb8
commit 99666de00f
No known key found for this signature in database
GPG key ID: FCED35F1CECE0D3A
162 changed files with 7008 additions and 3564 deletions

View file

@ -37,7 +37,7 @@
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/resources/bit_map.h"
#include "scene/resources/dynamic_font.h"
#include "scene/resources/font.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
#include "servers/audio/audio_stream.h"
@ -798,25 +798,79 @@ void EditorFontPreviewPlugin::_bind_methods() {
}
bool EditorFontPreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "DynamicFontData") || ClassDB::is_parent_class(p_type, "DynamicFont");
return ClassDB::is_parent_class(p_type, "FontData") || ClassDB::is_parent_class(p_type, "Font");
}
struct FSample {
String script;
String sample;
};
static FSample _samples[] = {
{ "hani", U"漢語" },
{ "armn", U"Աբ" },
{ "copt", U"Αα" },
{ "cyrl", U"Аб" },
{ "grek", U"Αα" },
{ "hebr", U"אב" },
{ "arab", U"اب" },
{ "syrc", U"ܐܒ" },
{ "thaa", U"ހށ" },
{ "deva", U"" },
{ "beng", U"" },
{ "guru", U"" },
{ "gujr", U"" },
{ "orya", U"" },
{ "taml", U"" },
{ "telu", U"" },
{ "knda", U"" },
{ "mylm", U"" },
{ "sinh", U"" },
{ "thai", U"กิ" },
{ "laoo", U"ກິ" },
{ "tibt", U"" },
{ "mymr", U"က" },
{ "geor", U"Ⴀა" },
{ "hang", U"한글" },
{ "ethi", U"" },
{ "cher", U"" },
{ "cans", U"" },
{ "ogam", U"" },
{ "runr", U"" },
{ "tglg", U"" },
{ "hano", U"" },
{ "buhd", U"" },
{ "tagb", U"" },
{ "khmr", U"" },
{ "mong", U"" },
{ "limb", U"" },
{ "tale", U"" },
{ "latn", U"Ab" },
{ "zyyy", U"😀" },
{ "", U"" }
};
Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const {
RES res = ResourceLoader::load(p_path);
Ref<DynamicFont> sampled_font;
if (res->is_class("DynamicFont")) {
Ref<Font> sampled_font;
if (res->is_class("Font")) {
sampled_font = res->duplicate();
if (sampled_font->get_outline_color() == Color(1, 1, 1, 1)) {
sampled_font->set_outline_color(Color(0, 0, 0, 1));
}
} else if (res->is_class("DynamicFontData")) {
} else if (res->is_class("FontData")) {
sampled_font.instance();
sampled_font->set_font_data(res);
sampled_font->add_data(res->duplicate());
}
sampled_font->set_size(50);
String sampled_text = "Abg";
Vector2 size = sampled_font->get_string_size(sampled_text);
String sample;
for (int j = 0; j < sampled_font->get_data_count(); j++) {
for (int i = 0; _samples[i].script != String(); i++) {
if (sampled_font->get_data(j)->is_script_supported(_samples[i].script)) {
if (sampled_font->get_data(j)->has_char(_samples[i].sample[0])) {
sample += _samples[i].sample;
}
}
}
}
Vector2 size = sampled_font->get_string_size(sample, 50);
Vector2 pos;
@ -825,7 +879,7 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path,
Ref<Font> font = sampled_font;
font->draw(canvas_item, pos, sampled_text);
font->draw_string(canvas_item, pos, sample, HALIGN_LEFT, -1.f, 50, Color(1, 1, 1));
preview_done = false;
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture