Line data Source code
1 : /** 2 : Copyright (c) 2024 Stappler LLC <admin@stappler.dev> 3 : 4 : Permission is hereby granted, free of charge, to any person obtaining a copy 5 : of this software and associated documentation files (the "Software"), to deal 6 : in the Software without restriction, including without limitation the rights 7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 : copies of the Software, and to permit persons to whom the Software is 9 : furnished to do so, subject to the following conditions: 10 : 11 : The above copyright notice and this permission notice shall be included in 12 : all copies or substantial portions of the Software. 13 : 14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 : THE SOFTWARE. 21 : **/ 22 : 23 : #include "SPFont.h" 24 : 25 : namespace STAPPLER_VERSIONIZED stappler::font { 26 : 27 959707 : void CharVector::addChar(char32_t c) { 28 959707 : mem_std::emplace_ordered(chars, c); 29 959707 : } 30 : 31 0 : void CharVector::addString(const StringView &str) { 32 0 : StringViewUtf8 r(str); 33 0 : r.foreach([&] (char32_t c) { 34 0 : addChar(c); 35 0 : }); 36 0 : } 37 : 38 16953 : void CharVector::addString(const WideStringView &str) { 39 16953 : auto ptr = str.data(); 40 16953 : auto size = str.size(); 41 16953 : uint8_t offset = 0; 42 : 43 891815 : while (size > 0) { 44 874862 : auto c = unicode::utf16Decode32(ptr, offset); 45 874862 : if (c) { 46 874862 : addChar(c); 47 : } 48 874862 : ptr += offset; 49 874862 : size -= offset; 50 : } 51 16953 : } 52 : 53 0 : void CharVector::addString(const CharVector &str) { 54 0 : for (auto &c : str.chars) { 55 0 : mem_std::emplace_ordered(chars, c); 56 : } 57 0 : } 58 : 59 3063638 : uint32_t CharId::getCharId(uint16_t sourceId, char16_t ch, CharAnchor a) { 60 3063638 : uint32_t ret = ch; 61 3063638 : ret |= (toInt(a) << (sizeof(char16_t) * 8)); 62 3063381 : ret |= (sourceId << ((sizeof(char16_t) * 8) + 2)); 63 3063381 : return ret; 64 : } 65 : 66 762040 : uint32_t CharId::rebindCharId(uint32_t ret, CharAnchor a) { 67 762040 : return (ret & (~ (3 << (sizeof(char16_t) * 8)))) | (toInt(a) << (sizeof(char16_t) * 8)); 68 : } 69 : 70 0 : CharAnchor CharId::getAnchorForChar(uint32_t obj) { 71 0 : return CharAnchor((obj >> sizeof(char16_t) * 8) & 0b11); 72 : } 73 : 74 : }