[TextServer, GDExtension] Fix building text servers as GDExtension, expose new/changed low-level methods to GDExtension API.
This commit is contained in:
@ -56,8 +56,8 @@ if env["thorvg_enabled"] and env["freetype_enabled"]:
|
||||
thirdparty_tvg_dir = "../../../thirdparty/thorvg/"
|
||||
thirdparty_tvg_sources = [
|
||||
# common
|
||||
"src/common/tvgBezier.cpp",
|
||||
"src/common/tvgCompressor.cpp",
|
||||
"src/common/tvgLines.cpp",
|
||||
"src/common/tvgMath.cpp",
|
||||
"src/common/tvgStr.cpp",
|
||||
# SVG parser
|
||||
@ -68,6 +68,7 @@ if env["thorvg_enabled"] and env["freetype_enabled"]:
|
||||
"src/loaders/svg/tvgSvgUtil.cpp",
|
||||
"src/loaders/svg/tvgXmlParser.cpp",
|
||||
"src/loaders/raw/tvgRawLoader.cpp",
|
||||
# image loaders
|
||||
"src/loaders/external_png/tvgPngLoader.cpp",
|
||||
"src/loaders/jpg/tvgJpgd.cpp",
|
||||
"src/loaders/jpg/tvgJpgLoader.cpp",
|
||||
@ -112,6 +113,7 @@ if env["thorvg_enabled"] and env["freetype_enabled"]:
|
||||
"../../../thirdparty/thorvg/src/loaders/raw",
|
||||
"../../../thirdparty/thorvg/src/loaders/external_png",
|
||||
"../../../thirdparty/thorvg/src/loaders/jpg",
|
||||
"../../../thirdparty/libpng",
|
||||
]
|
||||
)
|
||||
|
||||
@ -146,8 +148,6 @@ if env["msdfgen_enabled"] and env["freetype_enabled"]:
|
||||
"core/Projection.cpp",
|
||||
"core/Scanline.cpp",
|
||||
"core/Shape.cpp",
|
||||
"core/SignedDistance.cpp",
|
||||
"core/Vector2.cpp",
|
||||
"core/contour-combiners.cpp",
|
||||
"core/edge-coloring.cpp",
|
||||
"core/edge-segments.cpp",
|
||||
|
||||
@ -62,8 +62,8 @@ using namespace godot;
|
||||
|
||||
extern "C" {
|
||||
|
||||
GDExtensionBool GDE_EXPORT textserver_fallback_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
|
||||
GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
|
||||
GDExtensionBool GDE_EXPORT textserver_fallback_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
|
||||
GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
|
||||
|
||||
init_obj.register_initializer(&initialize_text_server_fb_module);
|
||||
init_obj.register_terminator(&uninitialize_text_server_fb_module);
|
||||
|
||||
@ -40,6 +40,8 @@
|
||||
#include <godot_cpp/classes/translation_server.hpp>
|
||||
#include <godot_cpp/core/error_macros.hpp>
|
||||
|
||||
#define OT_TAG(m_c1, m_c2, m_c3, m_c4) ((int32_t)((((uint32_t)(m_c1) & 0xff) << 24) | (((uint32_t)(m_c2) & 0xff) << 16) | (((uint32_t)(m_c3) & 0xff) << 8) | ((uint32_t)(m_c4) & 0xff)))
|
||||
|
||||
using namespace godot;
|
||||
|
||||
#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get_setting_with_override(m_var)
|
||||
@ -287,7 +289,7 @@ _FORCE_INLINE_ TextServerFallback::FontTexturePosition TextServerFallback::find_
|
||||
{
|
||||
// Zero texture.
|
||||
uint8_t *w = tex.image->ptrw();
|
||||
ERR_FAIL_COND_V(texsize * texsize * p_color_size > tex.image->data_size(), ret);
|
||||
ERR_FAIL_COND_V(texsize * texsize * p_color_size > tex.image->get_data_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) {
|
||||
@ -475,7 +477,7 @@ _FORCE_INLINE_ TextServerFallback::FontGlyph TextServerFallback::rasterize_msdf(
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
int ofs = ((i + tex_pos.y + p_rect_margin * 2) * tex.texture_w + j + tex_pos.x + p_rect_margin * 2) * 4;
|
||||
ERR_FAIL_COND_V(ofs >= tex.image->data_size(), FontGlyph());
|
||||
ERR_FAIL_COND_V(ofs >= tex.image->get_data_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));
|
||||
@ -552,7 +554,7 @@ _FORCE_INLINE_ TextServerFallback::FontGlyph TextServerFallback::rasterize_bitma
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
int ofs = ((i + tex_pos.y + p_rect_margin * 2) * tex.texture_w + j + tex_pos.x + p_rect_margin * 2) * color_size;
|
||||
ERR_FAIL_COND_V(ofs >= tex.image->data_size(), FontGlyph());
|
||||
ERR_FAIL_COND_V(ofs >= tex.image->get_data_size(), FontGlyph());
|
||||
switch (p_bitmap.pixel_mode) {
|
||||
case FT_PIXEL_MODE_MONO: {
|
||||
int byte = i * p_bitmap.pitch + (j >> 3);
|
||||
@ -1474,7 +1476,7 @@ int64_t TextServerFallback::_font_get_spacing(const RID &p_font_rid, SpacingType
|
||||
}
|
||||
}
|
||||
|
||||
void TextServerFallback::_font_set_baseline_offset(const RID &p_font_rid, float p_baseline_offset) {
|
||||
void TextServerFallback::_font_set_baseline_offset(const RID &p_font_rid, double p_baseline_offset) {
|
||||
FontFallbackLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid);
|
||||
if (fdv) {
|
||||
if (fdv->baseline_offset != p_baseline_offset) {
|
||||
@ -1492,7 +1494,7 @@ void TextServerFallback::_font_set_baseline_offset(const RID &p_font_rid, float
|
||||
}
|
||||
}
|
||||
|
||||
float TextServerFallback::_font_get_baseline_offset(const RID &p_font_rid) const {
|
||||
double TextServerFallback::_font_get_baseline_offset(const RID &p_font_rid) const {
|
||||
FontFallbackLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid);
|
||||
if (fdv) {
|
||||
return fdv->baseline_offset;
|
||||
@ -4465,7 +4467,11 @@ PackedInt32Array TextServerFallback::_shaped_text_get_character_breaks(const RID
|
||||
if (size > 0) {
|
||||
ret.resize(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
#ifdef GDEXTENSION
|
||||
ret[i] = i + 1 + sd->start;
|
||||
#else
|
||||
ret.write[i] = i + 1 + sd->start;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
@ -247,7 +247,7 @@ class TextServerFallback : public TextServerExtension {
|
||||
struct FontFallbackLinkedVariation {
|
||||
RID base_font;
|
||||
int extra_spacing[4] = { 0, 0, 0, 0 };
|
||||
float baseline_offset = 0.0;
|
||||
double baseline_offset = 0.0;
|
||||
};
|
||||
|
||||
struct FontFallback {
|
||||
@ -276,7 +276,7 @@ class TextServerFallback : public TextServerExtension {
|
||||
int weight = 400;
|
||||
int stretch = 100;
|
||||
int extra_spacing[4] = { 0, 0, 0, 0 };
|
||||
float baseline_offset = 0.0;
|
||||
double baseline_offset = 0.0;
|
||||
|
||||
HashMap<Vector2i, FontForSizeFallback *, VariantHasher, VariantComparator> cache;
|
||||
|
||||
@ -494,7 +494,7 @@ class TextServerFallback : public TextServerExtension {
|
||||
double embolden = 0.0;
|
||||
Transform2D transform;
|
||||
int extra_spacing[4] = { 0, 0, 0, 0 };
|
||||
float baseline_offset = 0.0;
|
||||
double baseline_offset = 0.0;
|
||||
|
||||
bool operator==(const SystemFontKey &p_b) const {
|
||||
return (font_name == p_b.font_name) && (antialiasing == p_b.antialiasing) && (italic == p_b.italic) && (disable_embedded_bitmaps == p_b.disable_embedded_bitmaps) && (mipmaps == p_b.mipmaps) && (msdf == p_b.msdf) && (force_autohinter == p_b.force_autohinter) && (weight == p_b.weight) && (stretch == p_b.stretch) && (msdf_range == p_b.msdf_range) && (msdf_source_size == p_b.msdf_source_size) && (fixed_size == p_b.fixed_size) && (hinting == p_b.hinting) && (subpixel_positioning == p_b.subpixel_positioning) && (variation_coordinates == p_b.variation_coordinates) && (oversampling == p_b.oversampling) && (embolden == p_b.embolden) && (transform == p_b.transform) && (extra_spacing[SPACING_TOP] == p_b.extra_spacing[SPACING_TOP]) && (extra_spacing[SPACING_BOTTOM] == p_b.extra_spacing[SPACING_BOTTOM]) && (extra_spacing[SPACING_SPACE] == p_b.extra_spacing[SPACING_SPACE]) && (extra_spacing[SPACING_GLYPH] == p_b.extra_spacing[SPACING_GLYPH]) && (baseline_offset == p_b.baseline_offset);
|
||||
@ -659,8 +659,8 @@ public:
|
||||
MODBIND3(font_set_spacing, const RID &, SpacingType, int64_t);
|
||||
MODBIND2RC(int64_t, font_get_spacing, const RID &, SpacingType);
|
||||
|
||||
MODBIND2(font_set_baseline_offset, const RID &, float);
|
||||
MODBIND1RC(float, font_get_baseline_offset, const RID &);
|
||||
MODBIND2(font_set_baseline_offset, const RID &, double);
|
||||
MODBIND1RC(double, font_get_baseline_offset, const RID &);
|
||||
|
||||
MODBIND2(font_set_transform, const RID &, const Transform2D &);
|
||||
MODBIND1RC(Transform2D, font_get_transform, const RID &);
|
||||
|
||||
Reference in New Issue
Block a user