Move static feature set and number system StringNames to the singleton.
Remove `hb_` prefix from the custom bitmap font functions to avoid potential conflicts with the HarfBuzz. Cleanup commented debug code. Update numbering system data to CLDR 39.
This commit is contained in:
parent
0a8b35b7c9
commit
8e98e71997
4 changed files with 269 additions and 157 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue