• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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() const29 const 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() const42 int16_t Int16::Get() const
43 {
44     if (G_ENDIAN.big != '\0') {
45         // 8 means offset
46         return ((static_cast<uint16_t>(data) & 0x0000ff00) >> 8) | ((static_cast<uint16_t>(data) & 0x000000ff) << 8);
47     } else {
48         return data;
49     }
50 }
51 
Get() const52 uint16_t Uint16::Get() const
53 {
54     if (G_ENDIAN.big != '\0') {
55         return ((static_cast<uint32_t>(data) & 0x0000ff00) >> 8) | // 8 means offset
56                ((static_cast<uint32_t>(data) & 0x000000ff) << 8); // 8 means offset
57     } else {
58         return data;
59     }
60 }
61 
Get() const62 int32_t Int32::Get() const
63 {
64     if (G_ENDIAN.big != '\0') {
65         return ((static_cast<uint32_t>(data) & 0xff000000) >> 24) |     // 24 means offset
66             ((static_cast<uint32_t>(data) & 0x00ff0000) >> 8) |         // 8 means offset
67             ((static_cast<uint32_t>(data) & 0x0000ff00) << 8) |         // 8 means offset
68             ((static_cast<uint32_t>(data) & 0x000000ff) << 24);         // 24 means offset
69     } else {
70         return data;
71     }
72 }
73 
Get() const74 uint32_t Uint32::Get() const
75 {
76     if (G_ENDIAN.big != '\0') {
77         return ((data & 0xff000000) >> 24) | ((data & 0x00ff0000) >> 8) |   // 8 & 24 means offset
78             ((data & 0x0000ff00) << 8) | ((data & 0x000000ff) << 24);
79     } else {
80         return data;
81     }
82 }
83 
Get() const84 float Fixed::Get() const
85 {
86     return data.Get() / MAX_NUM;
87 }
88 } // namespace OpenTypeBasicType
89 } // namespace TextEngine
90 } // namespace Rosen
91 } // namespace OHOS
92