[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,6 +37,7 @@
#include "scene/2d/sprite_2d.h"
#include "scene/3d/sprite_3d.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/text_line.h"
#include "servers/audio/audio_stream.h"
/// BOOL ///
@ -80,12 +81,14 @@ void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x,
int AnimationTrackEditColor::get_key_height() const {
Ref<Font> font = get_theme_font("font", "Label");
return font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
return font->get_height(font_size) * 0.8;
}
Rect2 AnimationTrackEditColor::get_key_rect(int p_index, float p_pixels_sec) {
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 0.8;
return Rect2(-fh / 2, 0, fh, get_size().height);
}
@ -95,7 +98,8 @@ bool AnimationTrackEditColor::is_key_selectable_by_distance() const {
void AnimationTrackEditColor::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) {
Ref<Font> font = get_theme_font("font", "Label");
int fh = (font->get_height() * 0.8);
int font_size = get_theme_font_size("font_size", "Label");
int fh = (font->get_height(font_size) * 0.8);
int x_from = p_x + fh / 2 - 1;
int x_to = p_next_x - fh / 2 + 1;
@ -144,7 +148,8 @@ void AnimationTrackEditColor::draw_key(int p_index, float p_pixels_sec, int p_x,
Color color = get_animation()->track_get_key_value(get_track(), p_index);
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 0.8;
Rect2 rect(Vector2(p_x - fh / 2, int(get_size().height - fh) / 2), Size2(fh, fh));
@ -182,7 +187,8 @@ int AnimationTrackEditAudio::get_key_height() const {
}
Ref<Font> font = get_theme_font("font", "Label");
return int(font->get_height() * 1.5);
int font_size = get_theme_font_size("font_size", "Label");
return int(font->get_height(font_size) * 1.5);
}
Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) {
@ -214,7 +220,8 @@ Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) {
return Rect2(0, 0, len * p_pixels_sec, get_size().height);
} else {
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 0.8;
return Rect2(0, 0, fh, get_size().height);
}
}
@ -277,7 +284,8 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x,
}
Ref<Font> font = get_theme_font("font", "Label");
float fh = int(font->get_height() * 1.5);
int font_size = get_theme_font_size("font_size", "Label");
float fh = int(font->get_height(font_size) * 1.5);
Rect2 rect = Rect2(from_x, (get_size().height - fh) / 2, to_x - from_x, fh);
draw_rect(rect, Color(0.25, 0.25, 0.25));
@ -307,7 +315,8 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x,
}
} else {
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 0.8;
Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh));
Color color = get_theme_color("font_color", "Label");
@ -339,7 +348,8 @@ int AnimationTrackEditSpriteFrame::get_key_height() const {
}
Ref<Font> font = get_theme_font("font", "Label");
return int(font->get_height() * 2);
int font_size = get_theme_font_size("font_size", "Label");
return int(font->get_height(font_size) * 2);
}
Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_sec) {
@ -406,7 +416,8 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se
size = size.floor();
Ref<Font> font = get_theme_font("font", "Label");
int height = int(font->get_height() * 2);
int font_size = get_theme_font_size("font_size", "Label");
int height = int(font->get_height(font_size) * 2);
int width = height * size.width / size.height;
return Rect2(0, 0, width, get_size().height);
@ -496,7 +507,8 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
}
Ref<Font> font = get_theme_font("font", "Label");
int height = int(font->get_height() * 2);
int font_size = get_theme_font_size("font_size", "Label");
int height = int(font->get_height(font_size) * 2);
int width = height * region.size.width / region.size.height;
@ -539,7 +551,8 @@ int AnimationTrackEditSubAnim::get_key_height() const {
}
Ref<Font> font = get_theme_font("font", "Label");
return int(font->get_height() * 1.5);
int font_size = get_theme_font_size("font_size", "Label");
return int(font->get_height(font_size) * 1.5);
}
Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float p_pixels_sec) {
@ -567,7 +580,8 @@ Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float p_pixels_sec) {
return Rect2(0, 0, len * p_pixels_sec, get_size().height);
} else {
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 0.8;
return Rect2(0, 0, fh, get_size().height);
}
}
@ -621,7 +635,8 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
}
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 1.5;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 1.5;
Rect2 rect(from_x, int(get_size().height - fh) / 2, to_x - from_x, fh);
@ -664,7 +679,7 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
int limit = to_x - from_x - 4;
if (limit > 0) {
draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height()) / 2 + font->get_ascent()), anim, color);
draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), anim, HALIGN_LEFT, -1, font_size, color);
}
if (p_selected) {
@ -673,7 +688,8 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
}
} else {
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 0.8;
Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh));
Color color = get_theme_color("font_color", "Label");
@ -771,7 +787,8 @@ void AnimationTrackEditTypeAudio::_preview_changed(ObjectID p_which) {
int AnimationTrackEditTypeAudio::get_key_height() const {
Ref<Font> font = get_theme_font("font", "Label");
return int(font->get_height() * 1.5);
int font_size = get_theme_font_size("font_size", "Label");
return int(font->get_height(font_size) * 1.5);
}
Rect2 AnimationTrackEditTypeAudio::get_key_rect(int p_index, float p_pixels_sec) {
@ -835,7 +852,8 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int
}
Ref<Font> font = get_theme_font("font", "Label");
float fh = int(font->get_height() * 1.5);
int font_size = get_theme_font_size("font_size", "Label");
float fh = int(font->get_height(font_size) * 1.5);
float len = stream->get_length();
@ -1104,7 +1122,8 @@ int AnimationTrackEditTypeAnimation::get_key_height() const {
}
Ref<Font> font = get_theme_font("font", "Label");
return int(font->get_height() * 1.5);
int font_size = get_theme_font_size("font_size", "Label");
return int(font->get_height(font_size) * 1.5);
}
Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_sec) {
@ -1132,7 +1151,8 @@ Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_
return Rect2(0, 0, len * p_pixels_sec, get_size().height);
} else {
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 0.8;
return Rect2(0, 0, fh, get_size().height);
}
}
@ -1186,7 +1206,8 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
}
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 1.5;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 1.5;
Rect2 rect(from_x, int(get_size().height - fh) / 2, to_x - from_x, fh);
@ -1229,7 +1250,7 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
int limit = to_x - from_x - 4;
if (limit > 0) {
draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height()) / 2 + font->get_ascent()), anim, color);
draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), anim, HALIGN_LEFT, -1, font_size, color);
}
if (p_selected) {
@ -1238,7 +1259,8 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
}
} else {
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
int font_size = get_theme_font_size("font_size", "Label");
int fh = font->get_height(font_size) * 0.8;
Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh));
Color color = get_theme_color("font_color", "Label");