diff options
| author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2022-11-09 14:45:21 +0200 |
|---|---|---|
| committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2022-11-10 10:43:15 +0200 |
| commit | 35528b800cf9dacce62f9664a7f4e56fcae491a3 (patch) | |
| tree | 91b9a4139b056e4337a779c348f1a319db24419b /core/string/optimized_translation.cpp | |
| parent | dca5cb8e40fd2a348a59ea73c597eb742c14c980 (diff) | |
| download | redot-engine-35528b800cf9dacce62f9664a7f4e56fcae491a3.tar.gz | |
[Font] Add an import option to pre-render all glyphs required for the translation.
Diffstat (limited to 'core/string/optimized_translation.cpp')
| -rw-r--r-- | core/string/optimized_translation.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/string/optimized_translation.cpp b/core/string/optimized_translation.cpp index b130c2fc79..2fb3b54e27 100644 --- a/core/string/optimized_translation.cpp +++ b/core/string/optimized_translation.cpp @@ -267,6 +267,39 @@ StringName OptimizedTranslation::get_message(const StringName &p_src_text, const } } +Vector<String> OptimizedTranslation::get_translated_message_list() const { + Vector<String> msgs; + + const int *htr = hash_table.ptr(); + const uint32_t *htptr = (const uint32_t *)&htr[0]; + const int *btr = bucket_table.ptr(); + const uint32_t *btptr = (const uint32_t *)&btr[0]; + const uint8_t *sr = strings.ptr(); + const char *sptr = (const char *)&sr[0]; + + for (int i = 0; i < hash_table.size(); i++) { + uint32_t p = htptr[i]; + if (p != 0xFFFFFFFF) { + const Bucket &bucket = *(const Bucket *)&btptr[p]; + for (int j = 0; j < bucket.size; j++) { + if (bucket.elem[j].comp_size == bucket.elem[j].uncomp_size) { + String rstr; + rstr.parse_utf8(&sptr[bucket.elem[j].str_offset], bucket.elem[j].uncomp_size); + msgs.push_back(rstr); + } else { + CharString uncomp; + uncomp.resize(bucket.elem[j].uncomp_size + 1); + smaz_decompress(&sptr[bucket.elem[j].str_offset], bucket.elem[j].comp_size, uncomp.ptrw(), bucket.elem[j].uncomp_size); + String rstr; + rstr.parse_utf8(uncomp.get_data()); + msgs.push_back(rstr); + } + } + } + } + return msgs; +} + StringName OptimizedTranslation::get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context) const { // The use of plurals translation is not yet supported in OptimizedTranslation. return get_message(p_src_text, p_context); |
