summaryrefslogtreecommitdiff
path: root/modules/text_server_fb
diff options
context:
space:
mode:
Diffstat (limited to 'modules/text_server_fb')
-rw-r--r--modules/text_server_fb/text_server_fb.cpp57
-rw-r--r--modules/text_server_fb/text_server_fb.h6
2 files changed, 30 insertions, 33 deletions
diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp
index 3d868d7be3..02acd4727c 100644
--- a/modules/text_server_fb/text_server_fb.cpp
+++ b/modules/text_server_fb/text_server_fb.cpp
@@ -111,22 +111,14 @@ bool TextServerFallback::is_locale_right_to_left(const String &p_locale) const {
return false; // No RTL support.
}
-#define OT_TAG(c1, c2, c3, c4) ((int32_t)((((uint32_t)(c1)&0xFF) << 24) | (((uint32_t)(c2)&0xFF) << 16) | (((uint32_t)(c3)&0xFF) << 8) | ((uint32_t)(c4)&0xFF)))
-
-struct FeatureInfo {
- int32_t tag;
- String name;
-};
-
-static FeatureInfo feature_set[] = {
- // Registered OpenType variation tags.
- { OT_TAG('i', 't', 'a', 'l'), "italic" },
- { OT_TAG('o', 'p', 's', 'z'), "optical_size" },
- { OT_TAG('s', 'l', 'n', 't'), "slant" },
- { OT_TAG('w', 'd', 't', 'h'), "width" },
- { OT_TAG('w', 'g', 'h', 't'), "weight" },
- { 0, String() },
-};
+void TextServerFallback::_insert_feature_sets() {
+ // Registered OpenType variation tag.
+ feature_sets.insert("italic", OT_TAG('i', 't', 'a', 'l'));
+ feature_sets.insert("optical_size", OT_TAG('o', 'p', 's', 'z'));
+ feature_sets.insert("slant", OT_TAG('s', 'l', 'n', 't'));
+ feature_sets.insert("width", OT_TAG('w', 'd', 't', 'h'));
+ feature_sets.insert("weight", OT_TAG('w', 'g', 'h', 't'));
+}
_FORCE_INLINE_ int32_t ot_tag_from_string(const char *p_str, int p_len) {
char tag[4];
@@ -150,10 +142,8 @@ _FORCE_INLINE_ int32_t ot_tag_from_string(const char *p_str, int p_len) {
}
int32_t TextServerFallback::name_to_tag(const String &p_name) const {
- for (int i = 0; feature_set[i].tag != 0; i++) {
- if (feature_set[i].name == p_name) {
- return feature_set[i].tag;
- }
+ if (feature_sets.has(p_name)) {
+ return feature_sets[p_name];
}
// No readable name, use tag string.
@@ -168,9 +158,9 @@ _FORCE_INLINE_ void ot_tag_to_string(int32_t p_tag, char *p_buf) {
}
String TextServerFallback::tag_to_name(int32_t p_tag) const {
- for (int i = 0; feature_set[i].tag != 0; i++) {
- if (feature_set[i].tag == p_tag) {
- return feature_set[i].name;
+ for (const KeyValue<StringName, int32_t> &E : feature_sets) {
+ if (E.value == p_tag) {
+ return E.key;
}
}
@@ -421,7 +411,6 @@ _FORCE_INLINE_ TextServerFallback::FontGlyph TextServerFallback::rasterize_msdf(
edgeColoringSimple(shape, 3.0); // Max. angle.
msdfgen::Bitmap<float, 4> image(w, h); // Texture size.
- //msdfgen::generateMTSDF(image, shape, p_pixel_range, 1.0, msdfgen::Vector2(-bounds.l, -bounds.b)); // Range, scale, translation.
DistancePixelConversion distancePixelConversion(p_pixel_range);
msdfgen::Projection projection(msdfgen::Vector2(1.0, 1.0), msdfgen::Vector2(-bounds.l, -bounds.b));
@@ -515,11 +504,11 @@ _FORCE_INLINE_ TextServerFallback::FontGlyph TextServerFallback::rasterize_bitma
case FT_PIXEL_MODE_MONO: {
int byte = i * bitmap.pitch + (j >> 3);
int bit = 1 << (7 - (j % 8));
- wr[ofs + 0] = 255; //grayscale as 1
+ wr[ofs + 0] = 255; // grayscale as 1
wr[ofs + 1] = (bitmap.buffer[byte] & bit) ? 255 : 0;
} break;
case FT_PIXEL_MODE_GRAY:
- wr[ofs + 0] = 255; //grayscale as 1
+ wr[ofs + 0] = 255; // grayscale as 1
wr[ofs + 1] = bitmap.buffer[i * bitmap.pitch + j];
break;
case FT_PIXEL_MODE_BGRA: {
@@ -2269,7 +2258,7 @@ bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key,
E.value.rect.position.y -= E.value.rect.size.y / 2;
} break;
case INLINE_ALIGN_TOP_TO: {
- //NOP
+ // NOP
} break;
}
full_ascent = MAX(full_ascent, -E.value.rect.position.y);
@@ -2297,7 +2286,7 @@ bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key,
E.value.rect.position.x -= E.value.rect.size.x / 2;
} break;
case INLINE_ALIGN_TOP_TO: {
- //NOP
+ // NOP
} break;
}
full_ascent = MAX(full_ascent, -E.value.rect.position.x);
@@ -2420,7 +2409,7 @@ RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_leng
E.value.rect.position.y -= E.value.rect.size.y / 2;
} break;
case INLINE_ALIGN_TOP_TO: {
- //NOP
+ // NOP
} break;
}
full_ascent = MAX(full_ascent, -E.value.rect.position.y);
@@ -2448,7 +2437,7 @@ RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_leng
E.value.rect.position.x -= E.value.rect.size.x / 2;
} break;
case INLINE_ALIGN_TOP_TO: {
- //NOP
+ // NOP
} break;
}
full_ascent = MAX(full_ascent, -E.value.rect.position.x);
@@ -2960,7 +2949,7 @@ bool TextServerFallback::shaped_text_shape(RID p_shaped) {
E.value.rect.position.y -= E.value.rect.size.y / 2;
} break;
case INLINE_ALIGN_TOP_TO: {
- //NOP
+ // NOP
} break;
}
full_ascent = MAX(full_ascent, -E.value.rect.position.y);
@@ -2988,7 +2977,7 @@ bool TextServerFallback::shaped_text_shape(RID p_shaped) {
E.value.rect.position.x -= E.value.rect.size.x / 2;
} break;
case INLINE_ALIGN_TOP_TO: {
- //NOP
+ // NOP
} break;
}
full_ascent = MAX(full_ascent, -E.value.rect.position.x);
@@ -3148,7 +3137,9 @@ float TextServerFallback::shaped_text_get_underline_thickness(RID p_shaped) cons
return sd->uthk;
}
-TextServerFallback::TextServerFallback(){};
+TextServerFallback::TextServerFallback() {
+ _insert_feature_sets();
+};
TextServerFallback::~TextServerFallback() {
if (library != nullptr) {
diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h
index 992ce5018f..fb7de8f443 100644
--- a/modules/text_server_fb/text_server_fb.h
+++ b/modules/text_server_fb/text_server_fb.h
@@ -54,6 +54,8 @@
#include FT_BBOX_H
#endif
+#define OT_TAG(c1, c2, c3, c4) ((int32_t)((((uint32_t)(c1)&0xFF) << 24) | (((uint32_t)(c2)&0xFF) << 16) | (((uint32_t)(c3)&0xFF) << 8) | ((uint32_t)(c4)&0xFF)))
+
class TextServerFallback : public TextServer {
GDCLASS(TextServerFallback, TextServer);
_THREAD_SAFE_CLASS_
@@ -61,6 +63,10 @@ class TextServerFallback : public TextServer {
static String interface_name;
static uint32_t interface_features;
+ Map<StringName, int32_t> feature_sets;
+
+ void _insert_feature_sets();
+
// Font cache data.
#ifdef MODULE_FREETYPE_ENABLED