Makes FontData importable resource.
Adds multi-channel SDF font texture generation and rendering support. Adds per-font oversampling support. Adds FontData import plugins (for dynamic fonts, BMFonts and monospaced image fonts), font texture cache pre-generation and loading. Adds BMFont binary format and outline support.
This commit is contained in:
parent
00268e37a0
commit
4c3f7d1290
130 changed files with 17847 additions and 6893 deletions
|
|
@ -38,7 +38,8 @@ def make_icu_data(target, source, env):
|
|||
# Thirdparty source files
|
||||
|
||||
thirdparty_obj = []
|
||||
freetype_enabled = env.module_check_dependencies("text_server_adv", ["freetype"])
|
||||
freetype_enabled = env.module_check_dependencies("text_server_adv", ["freetype"], True)
|
||||
msdngen_enabled = env.module_check_dependencies("text_server_adv", ["msdfgen"], True)
|
||||
|
||||
if env["builtin_harfbuzz"]:
|
||||
env_harfbuzz = env_modules.Clone()
|
||||
|
|
@ -509,6 +510,13 @@ env_text_server_adv.Append(
|
|||
]
|
||||
)
|
||||
|
||||
if msdngen_enabled:
|
||||
env_text_server_adv.Append(
|
||||
CPPPATH=[
|
||||
"#thirdparty/msdfgen",
|
||||
]
|
||||
)
|
||||
|
||||
if freetype_enabled:
|
||||
env_text_server_adv.Append(
|
||||
CPPPATH=[
|
||||
|
|
|
|||
|
|
@ -1,585 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* bitmap_font_adv.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "bitmap_font_adv.h"
|
||||
|
||||
/*************************************************************************/
|
||||
/* hb_bmp_font_t HarfBuzz Bitmap font interface */
|
||||
/*************************************************************************/
|
||||
|
||||
struct hb_bmp_font_t {
|
||||
BitmapFontDataAdvanced *face = nullptr;
|
||||
float font_size = 0.0;
|
||||
bool unref = false; /* Whether to destroy bm_face when done. */
|
||||
};
|
||||
|
||||
static hb_bmp_font_t *_hb_bmp_font_create(BitmapFontDataAdvanced *p_face, float p_font_size, bool p_unref) {
|
||||
hb_bmp_font_t *bm_font = reinterpret_cast<hb_bmp_font_t *>(calloc(1, sizeof(hb_bmp_font_t)));
|
||||
|
||||
if (!bm_font) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bm_font->face = p_face;
|
||||
bm_font->font_size = p_font_size;
|
||||
bm_font->unref = p_unref;
|
||||
|
||||
return bm_font;
|
||||
}
|
||||
|
||||
static void _hb_bmp_font_destroy(void *data) {
|
||||
hb_bmp_font_t *bm_font = reinterpret_cast<hb_bmp_font_t *>(data);
|
||||
free(bm_font);
|
||||
}
|
||||
|
||||
static hb_bool_t hb_bmp_get_nominal_glyph(hb_font_t *font, void *font_data, hb_codepoint_t unicode, hb_codepoint_t *glyph, void *user_data) {
|
||||
const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
|
||||
|
||||
if (!bm_font->face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bm_font->face->has_char(unicode)) {
|
||||
if (bm_font->face->has_char(0xF000u + unicode)) {
|
||||
*glyph = 0xF000u + unicode;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
*glyph = unicode;
|
||||
return true;
|
||||
}
|
||||
|
||||
static hb_position_t hb_bmp_get_glyph_h_advance(hb_font_t *font, void *font_data, hb_codepoint_t glyph, void *user_data) {
|
||||
const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
|
||||
|
||||
if (!bm_font->face) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!bm_font->face->has_char(glyph)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bm_font->face->get_advance(glyph, bm_font->font_size).x * 64;
|
||||
}
|
||||
|
||||
static hb_position_t hb_bmp_get_glyph_v_advance(hb_font_t *font, void *font_data, hb_codepoint_t glyph, void *user_data) {
|
||||
const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
|
||||
|
||||
if (!bm_font->face) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!bm_font->face->has_char(glyph)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -bm_font->face->get_advance(glyph, bm_font->font_size).y * 64;
|
||||
}
|
||||
|
||||
static hb_position_t hb_bmp_get_glyph_h_kerning(hb_font_t *font, void *font_data, hb_codepoint_t left_glyph, hb_codepoint_t right_glyph, void *user_data) {
|
||||
const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
|
||||
|
||||
if (!bm_font->face) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!bm_font->face->has_char(left_glyph)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!bm_font->face->has_char(right_glyph)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bm_font->face->get_kerning(left_glyph, right_glyph, bm_font->font_size).x * 64;
|
||||
}
|
||||
|
||||
static hb_bool_t hb_bmp_get_glyph_v_origin(hb_font_t *font, void *font_data, hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y, void *user_data) {
|
||||
const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
|
||||
|
||||
if (!bm_font->face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bm_font->face->has_char(glyph)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*x = bm_font->face->get_advance(glyph, bm_font->font_size).x * 32;
|
||||
*y = bm_font->face->get_ascent(bm_font->font_size) * 64;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static hb_bool_t hb_bmp_get_glyph_extents(hb_font_t *font, void *font_data, hb_codepoint_t glyph, hb_glyph_extents_t *extents, void *user_data) {
|
||||
const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
|
||||
|
||||
if (!bm_font->face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bm_font->face->has_char(glyph)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
extents->x_bearing = 0;
|
||||
extents->y_bearing = 0;
|
||||
extents->width = bm_font->face->get_size(glyph, bm_font->font_size).x * 64;
|
||||
extents->height = bm_font->face->get_size(glyph, bm_font->font_size).y * 64;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static hb_bool_t hb_bmp_get_font_h_extents(hb_font_t *font, void *font_data, hb_font_extents_t *metrics, void *user_data) {
|
||||
const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
|
||||
|
||||
if (!bm_font->face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
metrics->ascender = bm_font->face->get_ascent(bm_font->font_size);
|
||||
metrics->descender = bm_font->face->get_descent(bm_font->font_size);
|
||||
metrics->line_gap = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static hb_font_funcs_t *funcs = nullptr;
|
||||
void hb_bmp_create_font_funcs() {
|
||||
funcs = hb_font_funcs_create();
|
||||
|
||||
hb_font_funcs_set_font_h_extents_func(funcs, hb_bmp_get_font_h_extents, nullptr, nullptr);
|
||||
//hb_font_funcs_set_font_v_extents_func (funcs, hb_bmp_get_font_v_extents, nullptr, nullptr);
|
||||
hb_font_funcs_set_nominal_glyph_func(funcs, hb_bmp_get_nominal_glyph, nullptr, nullptr);
|
||||
//hb_font_funcs_set_variation_glyph_func (funcs, hb_bmp_get_variation_glyph, nullptr, nullptr);
|
||||
hb_font_funcs_set_glyph_h_advance_func(funcs, hb_bmp_get_glyph_h_advance, nullptr, nullptr);
|
||||
hb_font_funcs_set_glyph_v_advance_func(funcs, hb_bmp_get_glyph_v_advance, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_h_origin_func(funcs, hb_bmp_get_glyph_h_origin, nullptr, nullptr);
|
||||
hb_font_funcs_set_glyph_v_origin_func(funcs, hb_bmp_get_glyph_v_origin, nullptr, nullptr);
|
||||
hb_font_funcs_set_glyph_h_kerning_func(funcs, hb_bmp_get_glyph_h_kerning, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_bmp_get_glyph_v_kerning, nullptr, nullptr);
|
||||
hb_font_funcs_set_glyph_extents_func(funcs, hb_bmp_get_glyph_extents, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_contour_point_func (funcs, hb_bmp_get_glyph_contour_point, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_name_func (funcs, hb_bmp_get_glyph_name, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_from_name_func (funcs, hb_bmp_get_glyph_from_name, nullptr, nullptr);
|
||||
|
||||
hb_font_funcs_make_immutable(funcs);
|
||||
}
|
||||
|
||||
void hb_bmp_free_font_funcs() {
|
||||
if (funcs != nullptr) {
|
||||
hb_font_funcs_destroy(funcs);
|
||||
funcs = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void _hb_bmp_font_set_funcs(hb_font_t *p_font, BitmapFontDataAdvanced *p_face, int p_size, bool p_unref) {
|
||||
hb_font_set_funcs(p_font, funcs, _hb_bmp_font_create(p_face, p_size, p_unref), _hb_bmp_font_destroy);
|
||||
}
|
||||
|
||||
hb_font_t *hb_bmp_font_create(BitmapFontDataAdvanced *p_face, int p_size, hb_destroy_func_t p_destroy) {
|
||||
hb_font_t *font;
|
||||
hb_face_t *face = hb_face_create(nullptr, 0);
|
||||
|
||||
font = hb_font_create(face);
|
||||
hb_face_destroy(face);
|
||||
_hb_bmp_font_set_funcs(font, p_face, p_size, false);
|
||||
return font;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/* BitmapFontDataAdvanced */
|
||||
/*************************************************************************/
|
||||
|
||||
Error BitmapFontDataAdvanced::load_from_file(const String &p_filename, int p_base_size) {
|
||||
_THREAD_SAFE_METHOD_
|
||||
//fnt format used by angelcode bmfont
|
||||
//https://www.angelcode.com/products/bmfont/
|
||||
|
||||
FileAccess *f = FileAccess::open(p_filename, FileAccess::READ);
|
||||
ERR_FAIL_COND_V_MSG(!f, ERR_FILE_NOT_FOUND, "Can't open font: " + p_filename + ".");
|
||||
|
||||
while (true) {
|
||||
String line = f->get_line();
|
||||
|
||||
int delimiter = line.find(" ");
|
||||
String type = line.substr(0, delimiter);
|
||||
int pos = delimiter + 1;
|
||||
Map<String, String> keys;
|
||||
|
||||
while (pos < line.size() && line[pos] == ' ') {
|
||||
pos++;
|
||||
}
|
||||
|
||||
while (pos < line.size()) {
|
||||
int eq = line.find("=", pos);
|
||||
if (eq == -1) {
|
||||
break;
|
||||
}
|
||||
String key = line.substr(pos, eq - pos);
|
||||
int end = -1;
|
||||
String value;
|
||||
if (line[eq + 1] == '"') {
|
||||
end = line.find("\"", eq + 2);
|
||||
if (end == -1) {
|
||||
break;
|
||||
}
|
||||
value = line.substr(eq + 2, end - 1 - eq - 1);
|
||||
pos = end + 1;
|
||||
} else {
|
||||
end = line.find(" ", eq + 1);
|
||||
if (end == -1) {
|
||||
end = line.size();
|
||||
}
|
||||
value = line.substr(eq + 1, end - eq);
|
||||
pos = end;
|
||||
}
|
||||
|
||||
while (pos < line.size() && line[pos] == ' ') {
|
||||
pos++;
|
||||
}
|
||||
|
||||
keys[key] = value;
|
||||
}
|
||||
|
||||
if (type == "info") {
|
||||
if (keys.has("size")) {
|
||||
base_size = keys["size"].to_int();
|
||||
}
|
||||
} else if (type == "common") {
|
||||
if (keys.has("lineHeight")) {
|
||||
height = keys["lineHeight"].to_int();
|
||||
}
|
||||
if (keys.has("base")) {
|
||||
ascent = keys["base"].to_int();
|
||||
}
|
||||
} else if (type == "page") {
|
||||
if (keys.has("file")) {
|
||||
String base_dir = p_filename.get_base_dir();
|
||||
String file = base_dir.plus_file(keys["file"]);
|
||||
if (RenderingServer::get_singleton() != nullptr) {
|
||||
Ref<Texture2D> tex = ResourceLoader::load(file);
|
||||
if (tex.is_null()) {
|
||||
ERR_PRINT("Can't load font texture!");
|
||||
} else {
|
||||
ERR_FAIL_COND_V_MSG(tex.is_null(), ERR_FILE_CANT_READ, "It's not a reference to a valid Texture object.");
|
||||
textures.push_back(tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (type == "char") {
|
||||
Character c;
|
||||
char32_t idx = 0;
|
||||
if (keys.has("id")) {
|
||||
idx = keys["id"].to_int();
|
||||
}
|
||||
if (keys.has("x")) {
|
||||
c.rect.position.x = keys["x"].to_int();
|
||||
}
|
||||
if (keys.has("y")) {
|
||||
c.rect.position.y = keys["y"].to_int();
|
||||
}
|
||||
if (keys.has("width")) {
|
||||
c.rect.size.width = keys["width"].to_int();
|
||||
}
|
||||
if (keys.has("height")) {
|
||||
c.rect.size.height = keys["height"].to_int();
|
||||
}
|
||||
if (keys.has("xoffset")) {
|
||||
c.align.x = keys["xoffset"].to_int();
|
||||
}
|
||||
if (keys.has("yoffset")) {
|
||||
c.align.y = keys["yoffset"].to_int();
|
||||
}
|
||||
if (keys.has("page")) {
|
||||
c.texture_idx = keys["page"].to_int();
|
||||
}
|
||||
if (keys.has("xadvance")) {
|
||||
c.advance.x = keys["xadvance"].to_int();
|
||||
}
|
||||
if (keys.has("yadvance")) {
|
||||
c.advance.x = keys["yadvance"].to_int();
|
||||
}
|
||||
if (c.advance.x < 0) {
|
||||
c.advance.x = c.rect.size.width + 1;
|
||||
}
|
||||
if (c.advance.y < 0) {
|
||||
c.advance.y = c.rect.size.height + 1;
|
||||
}
|
||||
char_map[idx] = c;
|
||||
} else if (type == "kerning") {
|
||||
KerningPairKey kpk;
|
||||
float k = 0.0;
|
||||
if (keys.has("first")) {
|
||||
kpk.A = keys["first"].to_int();
|
||||
}
|
||||
if (keys.has("second")) {
|
||||
kpk.B = keys["second"].to_int();
|
||||
}
|
||||
if (keys.has("amount")) {
|
||||
k = keys["amount"].to_int();
|
||||
}
|
||||
kerning_map[kpk] = k;
|
||||
}
|
||||
|
||||
if (f->eof_reached()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (base_size == 0) {
|
||||
base_size = height;
|
||||
}
|
||||
|
||||
if (hb_handle) {
|
||||
hb_font_destroy(hb_handle);
|
||||
}
|
||||
hb_handle = hb_bmp_font_create(this, base_size, nullptr);
|
||||
valid = true;
|
||||
|
||||
memdelete(f);
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error BitmapFontDataAdvanced::bitmap_new(float p_height, float p_ascent, int p_base_size) {
|
||||
height = p_height;
|
||||
ascent = p_ascent;
|
||||
|
||||
base_size = p_base_size;
|
||||
if (base_size == 0) {
|
||||
base_size = height;
|
||||
}
|
||||
|
||||
char_map.clear();
|
||||
textures.clear();
|
||||
kerning_map.clear();
|
||||
if (hb_handle) {
|
||||
hb_font_destroy(hb_handle);
|
||||
}
|
||||
hb_handle = hb_bmp_font_create(this, base_size, nullptr);
|
||||
valid = true;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void BitmapFontDataAdvanced::bitmap_add_texture(const Ref<Texture> &p_texture) {
|
||||
ERR_FAIL_COND(!valid);
|
||||
ERR_FAIL_COND_MSG(p_texture.is_null(), "It's not a reference to a valid Texture object.");
|
||||
|
||||
textures.push_back(p_texture);
|
||||
}
|
||||
|
||||
void BitmapFontDataAdvanced::bitmap_add_char(char32_t p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) {
|
||||
ERR_FAIL_COND(!valid);
|
||||
|
||||
Character chr;
|
||||
chr.rect = p_rect;
|
||||
chr.texture_idx = p_texture_idx;
|
||||
if (p_advance < 0) {
|
||||
chr.advance.x = chr.rect.size.x;
|
||||
} else {
|
||||
chr.advance.x = p_advance;
|
||||
}
|
||||
chr.align = p_align;
|
||||
char_map[p_char] = chr;
|
||||
}
|
||||
|
||||
void BitmapFontDataAdvanced::bitmap_add_kerning_pair(char32_t p_A, char32_t p_B, int p_kerning) {
|
||||
ERR_FAIL_COND(!valid);
|
||||
|
||||
KerningPairKey kpk;
|
||||
kpk.A = p_A;
|
||||
kpk.B = p_B;
|
||||
|
||||
if (p_kerning == 0 && kerning_map.has(kpk)) {
|
||||
kerning_map.erase(kpk);
|
||||
} else {
|
||||
kerning_map[kpk] = p_kerning;
|
||||
}
|
||||
}
|
||||
|
||||
float BitmapFontDataAdvanced::get_height(int p_size) const {
|
||||
ERR_FAIL_COND_V(!valid, 0.f);
|
||||
return height * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
float BitmapFontDataAdvanced::get_ascent(int p_size) const {
|
||||
ERR_FAIL_COND_V(!valid, 0.f);
|
||||
return ascent * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
float BitmapFontDataAdvanced::get_descent(int p_size) const {
|
||||
ERR_FAIL_COND_V(!valid, 0.f);
|
||||
return (height - ascent) * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
float BitmapFontDataAdvanced::get_underline_position(int p_size) const {
|
||||
ERR_FAIL_COND_V(!valid, 0.f);
|
||||
return 2 * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
float BitmapFontDataAdvanced::get_underline_thickness(int p_size) const {
|
||||
ERR_FAIL_COND_V(!valid, 0.f);
|
||||
return 1 * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
void BitmapFontDataAdvanced::set_distance_field_hint(bool p_distance_field) {
|
||||
distance_field_hint = p_distance_field;
|
||||
}
|
||||
|
||||
bool BitmapFontDataAdvanced::get_distance_field_hint() const {
|
||||
return distance_field_hint;
|
||||
}
|
||||
|
||||
float BitmapFontDataAdvanced::get_base_size() const {
|
||||
return base_size;
|
||||
}
|
||||
|
||||
hb_font_t *BitmapFontDataAdvanced::get_hb_handle(int p_size) {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V(!valid, nullptr);
|
||||
return hb_handle;
|
||||
}
|
||||
|
||||
bool BitmapFontDataAdvanced::has_char(char32_t p_char) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V(!valid, false);
|
||||
return char_map.has(p_char);
|
||||
}
|
||||
|
||||
String BitmapFontDataAdvanced::get_supported_chars() const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V(!valid, String());
|
||||
String chars;
|
||||
const uint32_t *k = nullptr;
|
||||
while ((k = char_map.next(k))) {
|
||||
chars += char32_t(*k);
|
||||
}
|
||||
return chars;
|
||||
}
|
||||
|
||||
Vector2 BitmapFontDataAdvanced::get_advance(uint32_t p_char, int p_size) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V(!valid, Vector2());
|
||||
const Character *c = char_map.getptr(p_char);
|
||||
ERR_FAIL_COND_V(c == nullptr, Vector2());
|
||||
|
||||
return c->advance * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
Vector2 BitmapFontDataAdvanced::get_align(uint32_t p_char, int p_size) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V(!valid, Vector2());
|
||||
const Character *c = char_map.getptr(p_char);
|
||||
ERR_FAIL_COND_V(c == nullptr, Vector2());
|
||||
|
||||
return c->align * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
Vector2 BitmapFontDataAdvanced::get_size(uint32_t p_char, int p_size) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V(!valid, Vector2());
|
||||
const Character *c = char_map.getptr(p_char);
|
||||
ERR_FAIL_COND_V(c == nullptr, Vector2());
|
||||
|
||||
return c->rect.size * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
float BitmapFontDataAdvanced::get_font_scale(int p_size) const {
|
||||
return float(p_size) / float(base_size);
|
||||
}
|
||||
|
||||
Vector2 BitmapFontDataAdvanced::get_kerning(uint32_t p_char, uint32_t p_next, int p_size) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V(!valid, Vector2());
|
||||
KerningPairKey kpk;
|
||||
kpk.A = p_char;
|
||||
kpk.B = p_next;
|
||||
|
||||
const Map<KerningPairKey, int>::Element *E = kerning_map.find(kpk);
|
||||
if (E) {
|
||||
return Vector2(-E->get() * (float(p_size) / float(base_size)), 0.f);
|
||||
} else {
|
||||
return Vector2();
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 BitmapFontDataAdvanced::draw_glyph(RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
if (p_index == 0) {
|
||||
return Vector2();
|
||||
}
|
||||
ERR_FAIL_COND_V(!valid, Vector2());
|
||||
const Character *c = char_map.getptr(p_index);
|
||||
|
||||
ERR_FAIL_COND_V(c == nullptr, Vector2());
|
||||
ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), Vector2());
|
||||
if (c->texture_idx != -1) {
|
||||
Point2i cpos = p_pos;
|
||||
cpos += (c->align + Vector2(0, -ascent)) * (float(p_size) / float(base_size));
|
||||
Size2i csize = c->rect.size * (float(p_size) / float(base_size));
|
||||
if (RenderingServer::get_singleton() != nullptr) {
|
||||
//if (distance_field_hint) { // Not implemented.
|
||||
// RenderingServer::get_singleton()->canvas_item_set_distance_field_mode(p_canvas, true);
|
||||
//}
|
||||
RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), textures[c->texture_idx]->get_rid(), c->rect, p_color, false, false);
|
||||
//if (distance_field_hint) {
|
||||
// RenderingServer::get_singleton()->canvas_item_set_distance_field_mode(p_canvas, false);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
return c->advance * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
Vector2 BitmapFontDataAdvanced::draw_glyph_outline(RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
if (p_index == 0) {
|
||||
return Vector2();
|
||||
}
|
||||
ERR_FAIL_COND_V(!valid, Vector2());
|
||||
const Character *c = char_map.getptr(p_index);
|
||||
|
||||
ERR_FAIL_COND_V(c == nullptr, Vector2());
|
||||
ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), Vector2());
|
||||
|
||||
// Not supported, return advance for compatibility.
|
||||
|
||||
return c->advance * (float(p_size) / float(base_size));
|
||||
}
|
||||
|
||||
BitmapFontDataAdvanced::~BitmapFontDataAdvanced() {
|
||||
if (hb_handle) {
|
||||
hb_font_destroy(hb_handle);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* bitmap_font_adv.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef BITMAP_FONT_ADV_H
|
||||
#define BITMAP_FONT_ADV_H
|
||||
|
||||
#include "font_adv.h"
|
||||
|
||||
void hb_bmp_create_font_funcs();
|
||||
void hb_bmp_free_font_funcs();
|
||||
|
||||
struct BitmapFontDataAdvanced : public FontDataAdvanced {
|
||||
_THREAD_SAFE_CLASS_
|
||||
|
||||
private:
|
||||
Vector<Ref<Texture2D>> textures;
|
||||
|
||||
struct Character {
|
||||
int texture_idx = 0;
|
||||
Rect2 rect;
|
||||
Vector2 align;
|
||||
Vector2 advance = Vector2(-1, -1);
|
||||
};
|
||||
|
||||
struct KerningPairKey {
|
||||
union {
|
||||
struct {
|
||||
uint32_t A, B;
|
||||
};
|
||||
|
||||
uint64_t pair = 0;
|
||||
};
|
||||
|
||||
_FORCE_INLINE_ bool operator<(const KerningPairKey &p_r) const { return pair < p_r.pair; }
|
||||
};
|
||||
|
||||
HashMap<uint32_t, Character> char_map;
|
||||
Map<KerningPairKey, int> kerning_map;
|
||||
hb_font_t *hb_handle = nullptr;
|
||||
|
||||
float height = 0.f;
|
||||
float ascent = 0.f;
|
||||
int base_size = 0;
|
||||
bool distance_field_hint = false;
|
||||
|
||||
public:
|
||||
virtual void clear_cache() override{};
|
||||
|
||||
virtual Error load_from_file(const String &p_filename, int p_base_size) override;
|
||||
virtual Error bitmap_new(float p_height, float p_ascent, int p_base_size) override;
|
||||
|
||||
virtual void bitmap_add_texture(const Ref<Texture> &p_texture) override;
|
||||
virtual void bitmap_add_char(char32_t p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) override;
|
||||
virtual void bitmap_add_kerning_pair(char32_t p_A, char32_t p_B, int p_kerning) override;
|
||||
|
||||
virtual float get_height(int p_size) const override;
|
||||
virtual float get_ascent(int p_size) const override;
|
||||
virtual float get_descent(int p_size) const override;
|
||||
|
||||
virtual float get_underline_position(int p_size) const override;
|
||||
virtual float get_underline_thickness(int p_size) const override;
|
||||
|
||||
virtual void set_antialiased(bool p_antialiased) override{};
|
||||
virtual bool get_antialiased() const override { return false; };
|
||||
|
||||
virtual void set_hinting(TextServer::Hinting p_hinting) override{};
|
||||
virtual TextServer::Hinting get_hinting() const override { return TextServer::HINTING_NONE; };
|
||||
|
||||
virtual void set_distance_field_hint(bool p_distance_field) override;
|
||||
virtual bool get_distance_field_hint() const override;
|
||||
|
||||
virtual void set_force_autohinter(bool p_enabeld) override{};
|
||||
virtual bool get_force_autohinter() const override { return false; };
|
||||
|
||||
virtual bool has_outline() const override { return false; };
|
||||
virtual float get_base_size() const override;
|
||||
virtual float get_font_scale(int p_size) const override;
|
||||
|
||||
virtual hb_font_t *get_hb_handle(int p_size) override;
|
||||
|
||||
virtual bool has_char(char32_t p_char) const override;
|
||||
virtual String get_supported_chars() const override;
|
||||
|
||||
virtual Vector2 get_advance(uint32_t p_char, int p_size) const override;
|
||||
Vector2 get_align(uint32_t p_char, int p_size) const;
|
||||
Vector2 get_size(uint32_t p_char, int p_size) const;
|
||||
virtual Vector2 get_kerning(uint32_t p_char, uint32_t p_next, int p_size) const override;
|
||||
virtual uint32_t get_glyph_index(char32_t p_char, char32_t p_variation_selector) const override { return (uint32_t)p_char; };
|
||||
|
||||
virtual Vector2 draw_glyph(RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const override;
|
||||
virtual Vector2 draw_glyph_outline(RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const override;
|
||||
|
||||
virtual ~BitmapFontDataAdvanced();
|
||||
};
|
||||
|
||||
#endif // BITMAP_FONT_ADV_H
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,195 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* dynamic_font_adv.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef DYNAMIC_FONT_ADV_H
|
||||
#define DYNAMIC_FONT_ADV_H
|
||||
|
||||
#include "font_adv.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h"
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_TRUETYPE_TABLES_H
|
||||
|
||||
#include <hb-ft.h>
|
||||
#include <hb-ot.h>
|
||||
|
||||
struct DynamicFontDataAdvanced : public FontDataAdvanced {
|
||||
_THREAD_SAFE_CLASS_
|
||||
|
||||
private:
|
||||
struct CharTexture {
|
||||
Vector<uint8_t> imgdata;
|
||||
int texture_size = 0;
|
||||
Vector<int> offsets;
|
||||
Ref<ImageTexture> texture;
|
||||
};
|
||||
|
||||
struct Character {
|
||||
bool found = false;
|
||||
int texture_idx = 0;
|
||||
Rect2 rect;
|
||||
Rect2 rect_uv;
|
||||
Vector2 align;
|
||||
Vector2 advance = Vector2(-1, -1);
|
||||
|
||||
static Character not_found();
|
||||
};
|
||||
|
||||
struct TexturePosition {
|
||||
int index = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
};
|
||||
|
||||
struct CacheID {
|
||||
union {
|
||||
struct {
|
||||
uint32_t size : 16;
|
||||
uint32_t outline_size : 16;
|
||||
};
|
||||
uint32_t key = 0;
|
||||
};
|
||||
bool operator<(CacheID right) const {
|
||||
return key < right.key;
|
||||
}
|
||||
};
|
||||
|
||||
struct DataAtSize {
|
||||
FT_Face face = nullptr;
|
||||
TT_OS2 *os2 = nullptr;
|
||||
FT_StreamRec stream;
|
||||
|
||||
int size = 0;
|
||||
float scale_color_font = 1.f;
|
||||
float ascent = 0.0;
|
||||
float descent = 0.0;
|
||||
float underline_position = 0.0;
|
||||
float underline_thickness = 0.0;
|
||||
|
||||
Vector<CharTexture> textures;
|
||||
HashMap<uint32_t, Character> glyph_map;
|
||||
|
||||
hb_font_t *hb_handle = nullptr;
|
||||
~DataAtSize() {
|
||||
if (hb_handle != nullptr) {
|
||||
hb_font_destroy(hb_handle);
|
||||
}
|
||||
if (face != nullptr) {
|
||||
FT_Done_Face(face);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FT_Library library = nullptr;
|
||||
|
||||
// Source data.
|
||||
const uint8_t *font_mem = nullptr;
|
||||
int font_mem_size = 0;
|
||||
String font_path;
|
||||
Vector<uint8_t> font_mem_cache;
|
||||
|
||||
Map<int32_t, double> variations;
|
||||
|
||||
float rect_margin = 1.f;
|
||||
int base_size = 16;
|
||||
float oversampling = 1.f;
|
||||
bool antialiased = true;
|
||||
bool force_autohinter = false;
|
||||
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
|
||||
|
||||
Map<CacheID, DataAtSize *> size_cache;
|
||||
Map<CacheID, DataAtSize *> size_cache_outline;
|
||||
|
||||
DataAtSize *get_data_for_size(int p_size, int p_outline_size = 0);
|
||||
|
||||
TexturePosition find_texture_pos_for_glyph(DataAtSize *p_data, int p_color_size, Image::Format p_image_format, int p_width, int p_height);
|
||||
Character bitmap_to_character(DataAtSize *p_data, FT_Bitmap bitmap, int yofs, int xofs, const Vector2 &advance);
|
||||
_FORCE_INLINE_ void update_glyph(int p_size, uint32_t p_index);
|
||||
_FORCE_INLINE_ void update_glyph_outline(int p_size, int p_outline_size, uint32_t p_index);
|
||||
|
||||
public:
|
||||
virtual void clear_cache() override;
|
||||
|
||||
virtual Error load_from_file(const String &p_filename, int p_base_size) override;
|
||||
virtual Error load_from_memory(const uint8_t *p_data, size_t p_size, int p_base_size) override;
|
||||
|
||||
virtual float get_height(int p_size) const override;
|
||||
virtual float get_ascent(int p_size) const override;
|
||||
virtual float get_descent(int p_size) const override;
|
||||
|
||||
virtual Dictionary get_feature_list() const override;
|
||||
virtual Dictionary get_variation_list() const override;
|
||||
|
||||
virtual void set_variation(const String &p_name, double p_value) override;
|
||||
virtual double get_variation(const String &p_name) const override;
|
||||
|
||||
virtual float get_underline_position(int p_size) const override;
|
||||
virtual float get_underline_thickness(int p_size) const override;
|
||||
|
||||
virtual void set_antialiased(bool p_antialiased) override;
|
||||
virtual bool get_antialiased() const override;
|
||||
|
||||
virtual void set_hinting(TextServer::Hinting p_hinting) override;
|
||||
virtual TextServer::Hinting get_hinting() const override;
|
||||
|
||||
virtual void set_force_autohinter(bool p_enabled) override;
|
||||
virtual bool get_force_autohinter() const override;
|
||||
|
||||
virtual void set_distance_field_hint(bool p_distance_field) override{};
|
||||
virtual bool get_distance_field_hint() const override { return false; };
|
||||
|
||||
virtual bool has_outline() const override;
|
||||
virtual float get_base_size() const override;
|
||||
|
||||
virtual bool is_script_supported(uint32_t p_script) const override;
|
||||
|
||||
virtual bool has_char(char32_t p_char) const override;
|
||||
virtual String get_supported_chars() const override;
|
||||
virtual float get_font_scale(int p_size) const override;
|
||||
|
||||
virtual hb_font_t *get_hb_handle(int p_size) override;
|
||||
virtual uint32_t get_glyph_index(char32_t p_char, char32_t p_variation_selector) const override;
|
||||
virtual Vector2 get_advance(uint32_t p_index, int p_size) const override;
|
||||
virtual Vector2 get_kerning(uint32_t p_char, uint32_t p_next, int p_size) const override;
|
||||
|
||||
virtual Vector2 draw_glyph(RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const override;
|
||||
virtual Vector2 draw_glyph_outline(RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const override;
|
||||
|
||||
virtual bool get_glyph_contours(int p_size, uint32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const override;
|
||||
|
||||
virtual ~DynamicFontDataAdvanced() override;
|
||||
};
|
||||
|
||||
#endif // MODULE_FREETYPE_ENABLED
|
||||
|
||||
#endif // DYNAMIC_FONT_ADV_H
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* font_adv.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef FONT_ADV_H
|
||||
#define FONT_ADV_H
|
||||
|
||||
#include "servers/text_server.h"
|
||||
|
||||
#include <hb.h>
|
||||
|
||||
struct FontDataAdvanced {
|
||||
Map<String, bool> lang_support_overrides;
|
||||
Map<String, bool> script_support_overrides;
|
||||
bool valid = false;
|
||||
int spacing_space = 0;
|
||||
int spacing_glyph = 0;
|
||||
|
||||
virtual void clear_cache() = 0;
|
||||
|
||||
virtual Error load_from_file(const String &p_filename, int p_base_size) { return ERR_CANT_CREATE; };
|
||||
virtual Error load_from_memory(const uint8_t *p_data, size_t p_size, int p_base_size) { return ERR_CANT_CREATE; };
|
||||
virtual Error bitmap_new(float p_height, float p_ascent, int p_base_size) { return ERR_CANT_CREATE; };
|
||||
|
||||
virtual void bitmap_add_texture(const Ref<Texture> &p_texture) { ERR_FAIL_MSG("Not supported."); };
|
||||
virtual void bitmap_add_char(char32_t p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) { ERR_FAIL_MSG("Not supported."); };
|
||||
virtual void bitmap_add_kerning_pair(char32_t p_A, char32_t p_B, int p_kerning) { ERR_FAIL_MSG("Not supported."); };
|
||||
|
||||
virtual float get_height(int p_size) const = 0;
|
||||
virtual float get_ascent(int p_size) const = 0;
|
||||
virtual float get_descent(int p_size) const = 0;
|
||||
|
||||
virtual Dictionary get_feature_list() const { return Dictionary(); };
|
||||
virtual Dictionary get_variation_list() const { return Dictionary(); };
|
||||
|
||||
virtual void set_variation(const String &p_name, double p_value){};
|
||||
virtual double get_variation(const String &p_name) const { return 0; };
|
||||
|
||||
virtual float get_underline_position(int p_size) const = 0;
|
||||
virtual float get_underline_thickness(int p_size) const = 0;
|
||||
|
||||
virtual int get_spacing_space() const { return spacing_space; };
|
||||
virtual void set_spacing_space(int p_value) {
|
||||
spacing_space = p_value;
|
||||
clear_cache();
|
||||
};
|
||||
|
||||
virtual int get_spacing_glyph() const { return spacing_glyph; };
|
||||
virtual void set_spacing_glyph(int p_value) {
|
||||
spacing_glyph = p_value;
|
||||
clear_cache();
|
||||
};
|
||||
|
||||
virtual void set_antialiased(bool p_antialiased) = 0;
|
||||
virtual bool get_antialiased() const = 0;
|
||||
|
||||
virtual void set_hinting(TextServer::Hinting p_hinting) = 0;
|
||||
virtual TextServer::Hinting get_hinting() const = 0;
|
||||
|
||||
virtual void set_distance_field_hint(bool p_distance_field) = 0;
|
||||
virtual bool get_distance_field_hint() const = 0;
|
||||
|
||||
virtual void set_force_autohinter(bool p_enabeld) = 0;
|
||||
virtual bool get_force_autohinter() const = 0;
|
||||
|
||||
virtual bool has_outline() const = 0;
|
||||
virtual float get_base_size() const = 0;
|
||||
|
||||
virtual bool is_lang_supported(const String &p_lang) const { return true; };
|
||||
virtual bool is_script_supported(uint32_t p_script) const { return true; };
|
||||
|
||||
virtual bool has_char(char32_t p_char) const = 0;
|
||||
virtual String get_supported_chars() const = 0;
|
||||
virtual float get_font_scale(int p_size) const { return 1.0f; };
|
||||
|
||||
virtual hb_font_t *get_hb_handle(int p_size) = 0;
|
||||
virtual uint32_t get_glyph_index(char32_t p_char, char32_t p_variation_selector) const = 0;
|
||||
virtual Vector2 get_advance(uint32_t p_char, int p_size) const = 0;
|
||||
virtual Vector2 get_kerning(uint32_t p_char, uint32_t p_next, int p_size) const = 0;
|
||||
|
||||
virtual Vector2 draw_glyph(RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const = 0;
|
||||
virtual Vector2 draw_glyph_outline(RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const = 0;
|
||||
|
||||
virtual bool get_glyph_contours(int p_size, uint32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { return false; };
|
||||
|
||||
virtual ~FontDataAdvanced(){};
|
||||
};
|
||||
|
||||
#endif // FONT_ADV_H
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -39,6 +39,7 @@
|
|||
#include "servers/text_server.h"
|
||||
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "core/templates/thread_work_pool.h"
|
||||
#include "scene/resources/texture.h"
|
||||
#include "script_iterator.h"
|
||||
|
||||
|
|
@ -53,11 +54,24 @@
|
|||
#include <unicode/ustring.h>
|
||||
#include <unicode/utypes.h>
|
||||
|
||||
#include "modules/modules_enabled.gen.h"
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_TRUETYPE_TABLES_H
|
||||
#include FT_STROKER_H
|
||||
#include FT_ADVANCES_H
|
||||
#include FT_MULTIPLE_MASTERS_H
|
||||
#include FT_BBOX_H
|
||||
|
||||
#include <hb-ft.h>
|
||||
#include <hb-ot.h>
|
||||
#endif
|
||||
|
||||
#include <hb-icu.h>
|
||||
#include <hb.h>
|
||||
|
||||
#include "font_adv.h"
|
||||
|
||||
class TextServerAdvanced : public TextServer {
|
||||
GDCLASS(TextServerAdvanced, TextServer);
|
||||
_THREAD_SAFE_CLASS_
|
||||
|
|
@ -65,8 +79,149 @@ class TextServerAdvanced : public TextServer {
|
|||
static String interface_name;
|
||||
static uint32_t interface_features;
|
||||
|
||||
// ICU support data.
|
||||
|
||||
uint8_t *icu_data = nullptr;
|
||||
|
||||
// Font cache data.
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
mutable FT_Library library = nullptr;
|
||||
#endif
|
||||
|
||||
const int rect_range = 2;
|
||||
|
||||
struct FontTexture {
|
||||
Image::Format format;
|
||||
PackedByteArray imgdata;
|
||||
int texture_w = 0;
|
||||
int texture_h = 0;
|
||||
PackedInt32Array offsets;
|
||||
Ref<ImageTexture> texture;
|
||||
};
|
||||
|
||||
struct FontTexturePosition {
|
||||
int index = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
};
|
||||
|
||||
struct FontGlyph {
|
||||
bool found = false;
|
||||
int texture_idx = -1;
|
||||
Rect2 rect;
|
||||
Rect2 uv_rect;
|
||||
Vector2 advance;
|
||||
};
|
||||
|
||||
struct FontDataForSizeAdvanced {
|
||||
real_t ascent = 0.f;
|
||||
real_t descent = 0.f;
|
||||
real_t underline_position = 0.f;
|
||||
real_t underline_thickness = 0.f;
|
||||
real_t scale = 1.f;
|
||||
real_t oversampling = 1.f;
|
||||
|
||||
int spacing_glyph = 0;
|
||||
int spacing_space = 0;
|
||||
|
||||
Vector2i size;
|
||||
|
||||
Vector<FontTexture> textures;
|
||||
HashMap<int32_t, FontGlyph> glyph_map;
|
||||
Map<Vector2i, Vector2> kerning_map;
|
||||
|
||||
hb_font_t *hb_handle = nullptr;
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
FT_Face face = nullptr;
|
||||
FT_StreamRec stream;
|
||||
#endif
|
||||
|
||||
~FontDataForSizeAdvanced() {
|
||||
if (hb_handle != nullptr) {
|
||||
hb_font_destroy(hb_handle);
|
||||
}
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (face != nullptr) {
|
||||
FT_Done_Face(face);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
struct FontDataAdvanced {
|
||||
Mutex mutex;
|
||||
|
||||
bool antialiased = true;
|
||||
bool msdf = false;
|
||||
int msdf_range = 14;
|
||||
int msdf_source_size = 48;
|
||||
int fixed_size = 0;
|
||||
bool force_autohinter = false;
|
||||
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
|
||||
Dictionary variation_coordinates;
|
||||
real_t oversampling = 0.f;
|
||||
|
||||
Map<Vector2i, FontDataForSizeAdvanced *> cache;
|
||||
|
||||
bool face_init = false;
|
||||
Set<uint32_t> supported_scripts;
|
||||
Dictionary supported_features;
|
||||
Dictionary supported_varaitions;
|
||||
|
||||
// Language/script support override.
|
||||
Map<String, bool> language_support_overrides;
|
||||
Map<String, bool> script_support_overrides;
|
||||
|
||||
PackedByteArray data;
|
||||
const uint8_t *data_ptr;
|
||||
size_t data_size;
|
||||
mutable ThreadWorkPool work_pool;
|
||||
|
||||
~FontDataAdvanced() {
|
||||
work_pool.finish();
|
||||
for (const Map<Vector2i, FontDataForSizeAdvanced *>::Element *E = cache.front(); E; E = E->next()) {
|
||||
memdelete(E->get());
|
||||
}
|
||||
cache.clear();
|
||||
}
|
||||
};
|
||||
|
||||
_FORCE_INLINE_ FontTexturePosition find_texture_pos_for_glyph(FontDataForSizeAdvanced *p_data, int p_color_size, Image::Format p_image_format, int p_width, int p_height) const;
|
||||
#ifdef MODULE_MSDFGEN_ENABLED
|
||||
_FORCE_INLINE_ FontGlyph rasterize_msdf(FontDataAdvanced *p_font_data, FontDataForSizeAdvanced *p_data, int p_pixel_range, int p_rect_margin, FT_Outline *outline, const Vector2 &advance) const;
|
||||
#endif
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
_FORCE_INLINE_ FontGlyph rasterize_bitmap(FontDataForSizeAdvanced *p_data, int p_rect_margin, FT_Bitmap bitmap, int yofs, int xofs, const Vector2 &advance) const;
|
||||
#endif
|
||||
_FORCE_INLINE_ bool _ensure_glyph(FontDataAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph) const;
|
||||
_FORCE_INLINE_ bool _ensure_cache_for_size(FontDataAdvanced *p_font_data, const Vector2i &p_size) const;
|
||||
_FORCE_INLINE_ void _font_clear_cache(FontDataAdvanced *p_font_data);
|
||||
void _generateMTSDF_threaded(uint32_t y, void *p_td) const;
|
||||
|
||||
_FORCE_INLINE_ Vector2i _get_size(const FontDataAdvanced *p_font_data, int p_size) const {
|
||||
if (p_font_data->msdf) {
|
||||
return Vector2i(p_font_data->msdf_source_size, 0);
|
||||
} else if (p_font_data->fixed_size > 0) {
|
||||
return Vector2i(p_font_data->fixed_size, 0);
|
||||
} else {
|
||||
return Vector2i(p_size, 0);
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Vector2i _get_size_outline(const FontDataAdvanced *p_font_data, const Vector2i &p_size) const {
|
||||
if (p_font_data->msdf) {
|
||||
return Vector2i(p_font_data->msdf_source_size, 0);
|
||||
} else if (p_font_data->fixed_size > 0) {
|
||||
return Vector2i(p_font_data->fixed_size, MIN(p_size.y, 1));
|
||||
} else {
|
||||
return p_size;
|
||||
}
|
||||
}
|
||||
|
||||
// Shaped text cache data.
|
||||
|
||||
struct ShapedTextDataAdvanced : public ShapedTextData {
|
||||
/* Intermediate data */
|
||||
Char16String utf16;
|
||||
|
|
@ -88,7 +243,9 @@ class TextServerAdvanced : public TextServer {
|
|||
}
|
||||
};
|
||||
|
||||
float oversampling = 1.f;
|
||||
// Common data.
|
||||
|
||||
real_t oversampling = 1.f;
|
||||
mutable RID_PtrOwner<FontDataAdvanced> font_owner;
|
||||
mutable RID_PtrOwner<ShapedTextDataAdvanced> shaped_owner;
|
||||
|
||||
|
|
@ -97,6 +254,30 @@ class TextServerAdvanced : public TextServer {
|
|||
void _shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_start, int32_t p_end, hb_script_t p_script, hb_direction_t p_direction, Vector<RID> p_fonts, int p_span, int p_fb_index);
|
||||
TextServer::Glyph _shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size);
|
||||
|
||||
// HarfBuzz bitmap font interface.
|
||||
|
||||
static hb_font_funcs_t *funcs;
|
||||
|
||||
struct hb_bmp_font_t {
|
||||
TextServerAdvanced::FontDataForSizeAdvanced *face = nullptr;
|
||||
bool unref = false; /* Whether to destroy bm_face when done. */
|
||||
};
|
||||
|
||||
static hb_bmp_font_t *_hb_bmp_font_create(TextServerAdvanced::FontDataForSizeAdvanced *p_face, bool p_unref);
|
||||
static void _hb_bmp_font_destroy(void *p_data);
|
||||
static hb_bool_t hb_bmp_get_nominal_glyph(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_unicode, hb_codepoint_t *r_glyph, void *p_user_data);
|
||||
static hb_position_t hb_bmp_get_glyph_h_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data);
|
||||
static hb_position_t hb_bmp_get_glyph_v_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data);
|
||||
static hb_position_t hb_bmp_get_glyph_h_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data);
|
||||
static hb_position_t hb_bmp_get_glyph_v_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data);
|
||||
static hb_bool_t hb_bmp_get_glyph_v_origin(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_position_t *r_x, hb_position_t *r_y, void *p_user_data);
|
||||
static hb_bool_t hb_bmp_get_glyph_extents(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_glyph_extents_t *r_extents, void *p_user_data);
|
||||
static hb_bool_t hb_bmp_get_font_h_extents(hb_font_t *p_font, void *p_font_data, hb_font_extents_t *r_metrics, void *p_user_data);
|
||||
static void hb_bmp_create_font_funcs();
|
||||
static void hb_bmp_free_font_funcs();
|
||||
static void _hb_bmp_font_set_funcs(hb_font_t *p_font, TextServerAdvanced::FontDataForSizeAdvanced *p_face, bool p_unref);
|
||||
static hb_font_t *hb_bmp_font_create(TextServerAdvanced::FontDataForSizeAdvanced *p_face, hb_destroy_func_t p_destroy);
|
||||
|
||||
protected:
|
||||
static void _bind_methods(){};
|
||||
|
||||
|
|
@ -119,81 +300,132 @@ public:
|
|||
|
||||
virtual bool is_locale_right_to_left(const String &p_locale) override;
|
||||
|
||||
virtual int32_t name_to_tag(const String &p_name) override;
|
||||
virtual String tag_to_name(int32_t p_tag) override;
|
||||
virtual int32_t name_to_tag(const String &p_name) const override;
|
||||
virtual String tag_to_name(int32_t p_tag) const override;
|
||||
|
||||
/* Font interface */
|
||||
virtual RID create_font_system(const String &p_name, int p_base_size = 16) override;
|
||||
virtual RID create_font_resource(const String &p_filename, int p_base_size = 16) override;
|
||||
virtual RID create_font_memory(const uint8_t *p_data, size_t p_size, const String &p_type, int p_base_size = 16) override;
|
||||
virtual RID create_font_bitmap(float p_height, float p_ascent, int p_base_size = 16) override;
|
||||
virtual RID create_font() override;
|
||||
|
||||
virtual void font_bitmap_add_texture(RID p_font, const Ref<Texture> &p_texture) override;
|
||||
virtual void font_bitmap_add_char(RID p_font, char32_t p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) override;
|
||||
virtual void font_bitmap_add_kerning_pair(RID p_font, char32_t p_A, char32_t p_B, int p_kerning) override;
|
||||
virtual void font_set_data(RID p_font_rid, const PackedByteArray &p_data) override;
|
||||
virtual void font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) override;
|
||||
|
||||
virtual float font_get_height(RID p_font, int p_size) const override;
|
||||
virtual float font_get_ascent(RID p_font, int p_size) const override;
|
||||
virtual float font_get_descent(RID p_font, int p_size) const override;
|
||||
virtual void font_set_antialiased(RID p_font_rid, bool p_antialiased) override;
|
||||
virtual bool font_is_antialiased(RID p_font_rid) const override;
|
||||
|
||||
virtual float font_get_underline_position(RID p_font, int p_size) const override;
|
||||
virtual float font_get_underline_thickness(RID p_font, int p_size) const override;
|
||||
virtual void font_set_multichannel_signed_distance_field(RID p_font_rid, bool p_msdf) override;
|
||||
virtual bool font_is_multichannel_signed_distance_field(RID p_font_rid) const override;
|
||||
|
||||
virtual int font_get_spacing_space(RID p_font) const override;
|
||||
virtual void font_set_spacing_space(RID p_font, int p_value) override;
|
||||
virtual void font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pixel_range) override;
|
||||
virtual int font_get_msdf_pixel_range(RID p_font_rid) const override;
|
||||
|
||||
virtual int font_get_spacing_glyph(RID p_font) const override;
|
||||
virtual void font_set_spacing_glyph(RID p_font, int p_value) override;
|
||||
virtual void font_set_msdf_size(RID p_font_rid, int p_msdf_size) override;
|
||||
virtual int font_get_msdf_size(RID p_font_rid) const override;
|
||||
|
||||
virtual void font_set_antialiased(RID p_font, bool p_antialiased) override;
|
||||
virtual bool font_get_antialiased(RID p_font) const override;
|
||||
virtual void font_set_fixed_size(RID p_font_rid, int p_fixed_size) override;
|
||||
virtual int font_get_fixed_size(RID p_font_rid) const override;
|
||||
|
||||
virtual Dictionary font_get_feature_list(RID p_font) const override;
|
||||
virtual Dictionary font_get_variation_list(RID p_font) const override;
|
||||
virtual void font_set_force_autohinter(RID p_font_rid, bool p_force_autohinter) override;
|
||||
virtual bool font_is_force_autohinter(RID p_font_rid) const override;
|
||||
|
||||
virtual void font_set_variation(RID p_font, const String &p_name, double p_value) override;
|
||||
virtual double font_get_variation(RID p_font, const String &p_name) const override;
|
||||
virtual void font_set_hinting(RID p_font_rid, TextServer::Hinting p_hinting) override;
|
||||
virtual TextServer::Hinting font_get_hinting(RID p_font_rid) const override;
|
||||
|
||||
virtual void font_set_hinting(RID p_font, Hinting p_hinting) override;
|
||||
virtual Hinting font_get_hinting(RID p_font) const override;
|
||||
virtual void font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) override;
|
||||
virtual Dictionary font_get_variation_coordinates(RID p_font_rid) const override;
|
||||
|
||||
virtual void font_set_distance_field_hint(RID p_font, bool p_distance_field) override;
|
||||
virtual bool font_get_distance_field_hint(RID p_font) const override;
|
||||
virtual void font_set_oversampling(RID p_font_rid, real_t p_oversampling) override;
|
||||
virtual real_t font_get_oversampling(RID p_font_rid) const override;
|
||||
|
||||
virtual void font_set_force_autohinter(RID p_font, bool p_enabeld) override;
|
||||
virtual bool font_get_force_autohinter(RID p_font) const override;
|
||||
virtual Array font_get_size_cache_list(RID p_font_rid) const override;
|
||||
virtual void font_clear_size_cache(RID p_font_rid) override;
|
||||
virtual void font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) override;
|
||||
|
||||
virtual bool font_has_char(RID p_font, char32_t p_char) const override;
|
||||
virtual String font_get_supported_chars(RID p_font) const override;
|
||||
hb_font_t *_font_get_hb_handle(RID p_font, int p_font_size) const;
|
||||
|
||||
virtual bool font_has_outline(RID p_font) const override;
|
||||
virtual float font_get_base_size(RID p_font) const override;
|
||||
virtual void font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) override;
|
||||
virtual real_t font_get_ascent(RID p_font_rid, int p_size) const override;
|
||||
|
||||
virtual bool font_is_language_supported(RID p_font, const String &p_language) const override;
|
||||
virtual void font_set_language_support_override(RID p_font, const String &p_language, bool p_supported) override;
|
||||
virtual bool font_get_language_support_override(RID p_font, const String &p_language) override;
|
||||
virtual void font_remove_language_support_override(RID p_font, const String &p_language) override;
|
||||
Vector<String> font_get_language_support_overrides(RID p_font) override;
|
||||
virtual void font_set_descent(RID p_font_rid, int p_size, real_t p_descent) override;
|
||||
virtual real_t font_get_descent(RID p_font_rid, int p_size) const override;
|
||||
|
||||
virtual bool font_is_script_supported(RID p_font, const String &p_script) const override;
|
||||
virtual void font_set_script_support_override(RID p_font, const String &p_script, bool p_supported) override;
|
||||
virtual bool font_get_script_support_override(RID p_font, const String &p_script) override;
|
||||
virtual void font_remove_script_support_override(RID p_font, const String &p_script) override;
|
||||
Vector<String> font_get_script_support_overrides(RID p_font) override;
|
||||
virtual void font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) override;
|
||||
virtual real_t font_get_underline_position(RID p_font_rid, int p_size) const override;
|
||||
|
||||
virtual uint32_t font_get_glyph_index(RID p_font, char32_t p_char, char32_t p_variation_selector = 0x0000) const override;
|
||||
virtual Vector2 font_get_glyph_advance(RID p_font, uint32_t p_index, int p_size) const override;
|
||||
virtual Vector2 font_get_glyph_kerning(RID p_font, uint32_t p_index_a, uint32_t p_index_b, int p_size) const override;
|
||||
virtual void font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) override;
|
||||
virtual real_t font_get_underline_thickness(RID p_font_rid, int p_size) const override;
|
||||
|
||||
virtual Vector2 font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color = Color(1, 1, 1)) const override;
|
||||
virtual Vector2 font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color = Color(1, 1, 1)) const override;
|
||||
virtual void font_set_scale(RID p_font_rid, int p_size, real_t p_scale) override;
|
||||
virtual real_t font_get_scale(RID p_font_rid, int p_size) const override;
|
||||
|
||||
virtual bool font_get_glyph_contours(RID p_font, int p_size, uint32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const override;
|
||||
virtual void font_set_spacing(RID p_font_rid, int p_size, SpacingType p_spacing, int p_value) override;
|
||||
virtual int font_get_spacing(RID p_font_rid, int p_size, SpacingType p_spacing) const override;
|
||||
|
||||
virtual float font_get_oversampling() const override;
|
||||
virtual void font_set_oversampling(float p_oversampling) override;
|
||||
virtual int font_get_texture_count(RID p_font_rid, const Vector2i &p_size) const override;
|
||||
virtual void font_clear_textures(RID p_font_rid, const Vector2i &p_size) override;
|
||||
virtual void font_remove_texture(RID p_font_rid, const Vector2i &p_size, int p_texture_index) override;
|
||||
|
||||
virtual Vector<String> get_system_fonts() const override;
|
||||
virtual void font_set_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image) override;
|
||||
virtual Ref<Image> font_get_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const override;
|
||||
|
||||
virtual void font_set_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset) override;
|
||||
virtual PackedInt32Array font_get_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const override;
|
||||
|
||||
virtual Array font_get_glyph_list(RID p_font_rid, const Vector2i &p_size) const override;
|
||||
virtual void font_clear_glyphs(RID p_font_rid, const Vector2i &p_size) override;
|
||||
virtual void font_remove_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) override;
|
||||
|
||||
virtual Vector2 font_get_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph) const override;
|
||||
virtual void font_set_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph, const Vector2 &p_advance) override;
|
||||
|
||||
virtual Vector2 font_get_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override;
|
||||
virtual void font_set_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset) override;
|
||||
|
||||
virtual Vector2 font_get_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override;
|
||||
virtual void font_set_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size) override;
|
||||
|
||||
virtual Rect2 font_get_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override;
|
||||
virtual void font_set_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect) override;
|
||||
|
||||
virtual int font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override;
|
||||
virtual void font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) override;
|
||||
|
||||
virtual bool font_get_glyph_contours(RID p_font, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const override;
|
||||
|
||||
virtual Array font_get_kerning_list(RID p_font_rid, int p_size) const override;
|
||||
virtual void font_clear_kerning_map(RID p_font_rid, int p_size) override;
|
||||
virtual void font_remove_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) override;
|
||||
|
||||
virtual void font_set_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) override;
|
||||
virtual Vector2 font_get_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) const override;
|
||||
|
||||
virtual int32_t font_get_glyph_index(RID p_font_rid, int p_size, char32_t p_char, char32_t p_variation_selector = 0) const override;
|
||||
|
||||
virtual bool font_has_char(RID p_font_rid, char32_t p_char) const override;
|
||||
virtual String font_get_supported_chars(RID p_font_rid) const override;
|
||||
|
||||
virtual void font_render_range(RID p_font, const Vector2i &p_size, char32_t p_start, char32_t p_end) override;
|
||||
virtual void font_render_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_index) override;
|
||||
|
||||
virtual void font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color = Color(1, 1, 1)) const override;
|
||||
virtual void font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color = Color(1, 1, 1)) const override;
|
||||
|
||||
virtual bool font_is_language_supported(RID p_font_rid, const String &p_language) const override;
|
||||
virtual void font_set_language_support_override(RID p_font_rid, const String &p_language, bool p_supported) override;
|
||||
virtual bool font_get_language_support_override(RID p_font_rid, const String &p_language) override;
|
||||
virtual void font_remove_language_support_override(RID p_font_rid, const String &p_language) override;
|
||||
virtual Vector<String> font_get_language_support_overrides(RID p_font_rid) override;
|
||||
|
||||
virtual bool font_is_script_supported(RID p_font_rid, const String &p_script) const override;
|
||||
virtual void font_set_script_support_override(RID p_font_rid, const String &p_script, bool p_supported) override;
|
||||
virtual bool font_get_script_support_override(RID p_font_rid, const String &p_script) override;
|
||||
virtual void font_remove_script_support_override(RID p_font_rid, const String &p_script) override;
|
||||
virtual Vector<String> font_get_script_support_overrides(RID p_font_rid) override;
|
||||
|
||||
virtual Dictionary font_supported_feature_list(RID p_font_rid) const override;
|
||||
virtual Dictionary font_supported_variation_list(RID p_font_rid) const override;
|
||||
|
||||
virtual real_t font_get_global_oversampling() const override;
|
||||
virtual void font_set_global_oversampling(real_t p_oversampling) override;
|
||||
|
||||
/* Shaped text buffer interface */
|
||||
|
||||
|
|
@ -222,14 +454,14 @@ public:
|
|||
virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override;
|
||||
virtual RID shaped_text_get_parent(RID p_shaped) const override;
|
||||
|
||||
virtual float shaped_text_fit_to_width(RID p_shaped, float p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override;
|
||||
virtual float shaped_text_tab_align(RID p_shaped, const Vector<float> &p_tab_stops) override;
|
||||
virtual real_t shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override;
|
||||
virtual real_t shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) override;
|
||||
|
||||
virtual bool shaped_text_shape(RID p_shaped) override;
|
||||
virtual bool shaped_text_update_breaks(RID p_shaped) override;
|
||||
virtual bool shaped_text_update_justification_ops(RID p_shaped) override;
|
||||
|
||||
virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint8_t p_trim_flags) override;
|
||||
virtual void shaped_text_overrun_trim_to_width(RID p_shaped, real_t p_width, uint8_t p_trim_flags) override;
|
||||
virtual TrimData shaped_text_get_trim_data(RID p_shaped) const override;
|
||||
|
||||
virtual bool shaped_text_is_ready(RID p_shaped) const override;
|
||||
|
|
@ -244,11 +476,11 @@ public:
|
|||
virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override;
|
||||
|
||||
virtual Size2 shaped_text_get_size(RID p_shaped) const override;
|
||||
virtual float shaped_text_get_ascent(RID p_shaped) const override;
|
||||
virtual float shaped_text_get_descent(RID p_shaped) const override;
|
||||
virtual float shaped_text_get_width(RID p_shaped) const override;
|
||||
virtual float shaped_text_get_underline_position(RID p_shaped) const override;
|
||||
virtual float shaped_text_get_underline_thickness(RID p_shaped) const override;
|
||||
virtual real_t shaped_text_get_ascent(RID p_shaped) const override;
|
||||
virtual real_t shaped_text_get_descent(RID p_shaped) const override;
|
||||
virtual real_t shaped_text_get_width(RID p_shaped) const override;
|
||||
virtual real_t shaped_text_get_underline_position(RID p_shaped) const override;
|
||||
virtual real_t shaped_text_get_underline_thickness(RID p_shaped) const override;
|
||||
|
||||
virtual String format_number(const String &p_string, const String &p_language = "") const override;
|
||||
virtual String parse_number(const String &p_string, const String &p_language = "") const override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue