diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-08-05 09:25:28 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-11-26 13:55:26 +0200 |
commit | 493da99269b3a111cf58e0352495e25ee49c5f84 (patch) | |
tree | bc34af12b8f3697ee6da79c1c44e2cfcd8d4b90c /core | |
parent | a8c2cc9028535aa6f474e93b71b09b5b7402c79d (diff) |
[Complex Text Layouts] Implement TextServer interface. Implement Fallback TextServer.
Diffstat (limited to 'core')
-rw-r--r-- | core/os/main_loop.cpp | 1 | ||||
-rw-r--r-- | core/os/main_loop.h | 1 | ||||
-rw-r--r-- | core/string/ustring.cpp | 5 | ||||
-rw-r--r-- | core/string/ustring.h | 7 | ||||
-rw-r--r-- | core/templates/lru.h | 126 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 4 |
6 files changed, 136 insertions, 8 deletions
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index d29bcd011f..9252ba0840 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -47,6 +47,7 @@ void MainLoop::_bind_methods() { BIND_CONSTANT(NOTIFICATION_APPLICATION_PAUSED); BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_IN); BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_OUT); + BIND_CONSTANT(NOTIFICATION_TEXT_SERVER_CHANGED); ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted"))); }; diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 8c46ad9b6a..7bc91fbb83 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -56,6 +56,7 @@ public: NOTIFICATION_APPLICATION_PAUSED = 2015, NOTIFICATION_APPLICATION_FOCUS_IN = 2016, NOTIFICATION_APPLICATION_FOCUS_OUT = 2017, + NOTIFICATION_TEXT_SERVER_CHANGED = 2018, }; virtual void init(); diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 213578485e..d630e987ea 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -209,7 +209,6 @@ void CharString::copy_from(const char *p_cstr) { /* String */ /*************************************************************************/ -//TODO: move to TextServer //kind of poor should be rewritten properly String String::word_wrap(int p_chars_per_line) const { int from = 0; @@ -4796,7 +4795,7 @@ Vector<uint8_t> String::to_utf16_buffer() const { Char16String charstr = s->utf16(); Vector<uint8_t> retval; - size_t len = charstr.length() * 2; + size_t len = charstr.length() * sizeof(char16_t); retval.resize(len); uint8_t *w = retval.ptrw(); copymem(w, (const void *)charstr.ptr(), len); @@ -4811,7 +4810,7 @@ Vector<uint8_t> String::to_utf32_buffer() const { } Vector<uint8_t> retval; - size_t len = s->length() * 4; + size_t len = s->length() * sizeof(char32_t); retval.resize(len); uint8_t *w = retval.ptrw(); copymem(w, (const void *)s->ptr(), len); diff --git a/core/string/ustring.h b/core/string/ustring.h index bfae16fe64..7ff78b2d86 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -28,8 +28,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef USTRING_H -#define USTRING_H +#ifndef USTRING_GODOT_H +#define USTRING_GODOT_H +// Note: Renamed to avoid conflict with ICU header with the same name. #include "core/templates/cowdata.h" #include "core/templates/vector.h" @@ -555,4 +556,4 @@ _FORCE_INLINE_ Vector<String> sarray(P... p_args) { return arr; } -#endif // USTRING_H +#endif // USTRING_GODOT_H diff --git a/core/templates/lru.h b/core/templates/lru.h new file mode 100644 index 0000000000..d02c4337d1 --- /dev/null +++ b/core/templates/lru.h @@ -0,0 +1,126 @@ +/*************************************************************************/ +/* lru.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef LRU_H +#define LRU_H + +#include "core/math/math_funcs.h" +#include "hash_map.h" +#include "list.h" + +template <class TKey, class TData> +class LRUCache { +private: + struct Pair { + TKey key; + TData data; + + Pair() {} + Pair(const TKey &p_key, const TData &p_data) : + key(p_key), + data(p_data) { + } + }; + + typedef typename List<Pair>::Element *Element; + + List<Pair> _list; + HashMap<TKey, Element> _map; + size_t capacity; + +public: + const TData *insert(const TKey &p_key, const TData &p_value) { + Element *e = _map.getptr(p_key); + Element n = _list.push_front(Pair(p_key, p_value)); + + if (e) { + _list.erase(*e); + _map.erase(p_key); + } + _map[p_key] = _list.front(); + + while (_map.size() > capacity) { + Element d = _list.back(); + _map.erase(d->get().key); + _list.pop_back(); + } + + return &n->get().data; + } + + void clear() { + _map.clear(); + _list.clear(); + } + + bool has(const TKey &p_key) const { + return _map.getptr(p_key); + } + + const TData &get(const TKey &p_key) { + Element *e = _map.getptr(p_key); + CRASH_COND(!e); + _list.move_to_front(*e); + return (*e)->get().data; + }; + + const TData *getptr(const TKey &p_key) { + Element *e = _map.getptr(p_key); + if (!e) { + return nullptr; + } else { + _list.move_to_front(*e); + return &(*e)->get().data; + } + } + + _FORCE_INLINE_ size_t get_capacity() const { return capacity; } + + void set_capacity(size_t p_capacity) { + if (capacity > 0) { + capacity = p_capacity; + while (_map.size() > capacity) { + Element d = _list.back(); + _map.erase(d->get().key); + _list.pop_back(); + } + } + } + + LRUCache() { + capacity = 64; + } + + LRUCache(int p_capacity) { + capacity = p_capacity; + } +}; + +#endif diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 13514b7b9f..214c424013 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -418,7 +418,7 @@ struct _VariantCall { String s; if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); - s.parse_utf16((const char16_t *)r, p_instance->size() / 2); + s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t))); } return s; } @@ -427,7 +427,7 @@ struct _VariantCall { String s; if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); - s = String((const char32_t *)r, p_instance->size() / 4); + s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t))); } return s; } |