1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "opentype_basic_type.h" 17 18 namespace OHOS { 19 namespace Rosen { 20 namespace TextEngine { 21 namespace OpenTypeBasicType { 22 #define MAX_NUM 65536.0 23 24 constexpr union { 25 unsigned int i; 26 unsigned char big; 27 } G_ENDIAN{1}; 28 Get() const29const std::string Tag::Get() const 30 { 31 // 5 is the size of open type table tags length 32 int size = 5; 33 char tagsWithZero[size]; 34 tagsWithZero[0] = tags[0]; // 0 means array subscripts 35 tagsWithZero[1] = tags[1]; // 1 means array subscripts 36 tagsWithZero[2] = tags[2]; // 2 means array subscripts 37 tagsWithZero[3] = tags[3]; // 3 means array subscripts 38 tagsWithZero[4] = 0; // 4 means array subscripts 39 return tagsWithZero; 40 } 41 Get() const42int16_t Int16::Get() const 43 { 44 if (G_ENDIAN.big != '\0') { 45 return ((data & 0x0000ff00) >> 8) | ((data & 0x000000ff) << 8); // 8 means offset 46 } else { 47 return data; 48 } 49 } 50 Get() const51uint16_t Uint16::Get() const 52 { 53 if (G_ENDIAN.big != '\0') { 54 return ((static_cast<uint32_t>(data) & 0x0000ff00) >> 8) | // 8 means offset 55 ((static_cast<uint32_t>(data) & 0x000000ff) << 8); // 8 means offset 56 } else { 57 return data; 58 } 59 } 60 Get() const61int32_t Int32::Get() const 62 { 63 if (G_ENDIAN.big != '\0') { 64 return ((static_cast<uint32_t>(data) & 0xff000000) >> 24) | // 24 means offset 65 ((static_cast<uint32_t>(data) & 0x00ff0000) >> 8) | // 8 means offset 66 ((static_cast<uint32_t>(data) & 0x0000ff00) << 8) | // 8 means offset 67 ((static_cast<uint32_t>(data) & 0x000000ff) << 24); // 24 means offset 68 } else { 69 return data; 70 } 71 } 72 Get() const73uint32_t Uint32::Get() const 74 { 75 if (G_ENDIAN.big != '\0') { 76 return ((data & 0xff000000) >> 24) | ((data & 0x00ff0000) >> 8) | // 8 & 24 means offset 77 ((data & 0x0000ff00) << 8) | ((data & 0x000000ff) << 24); 78 } else { 79 return data; 80 } 81 } 82 Get() const83float Fixed::Get() const 84 { 85 return data.Get() / MAX_NUM; 86 } 87 } // namespace OpenTypeBasicType 88 } // namespace TextEngine 89 } // namespace Rosen 90 } // namespace OHOS 91