mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
[TextServer, GDExtension] Fix building text servers as GDExtension, expose new/changed low-level methods to GDExtension API.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user