• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 #ifndef GRAPHIC_LITE_TYPE_TEXT_H
17 #define GRAPHIC_LITE_TYPE_TEXT_H
18 #include "common/text.h"
19 #include "graphic_config.h"
20 #ifndef _FONT_TOOL
21 #include "components/ui_arc_label.h"
22 #include "font/ui_font_header.h"
23 #include "gfx_utils/geometry2d.h"
24 #endif
25 
26 namespace OHOS {
27 #ifndef _FONT_TOOL
28 class TypedText : public HeapBase {
29 public:
30     static constexpr uint32_t MAX_UINT16_LOW_SCOPE = 0xFFFF;
31     static constexpr uint32_t MAX_UINT16_HIGH_SCOPE = 0xEFFFF;
32     static constexpr uint32_t UTF16_LOW_MASK = 0x03FF;
33     static constexpr uint32_t UTF16_LOW_PARAM = 56320;
34     static constexpr uint32_t UTF16_HIGH_PARAM1 = 55296;
35     static constexpr uint8_t UTF16_HIGH_PARAM2 = 64;
36     static constexpr uint8_t UTF16_HIGH_SHIFT = 10;
37     static constexpr uint8_t UTF8_TO_UNICODE_SHIFT1 = 6;
38     static constexpr uint8_t UTF8_TO_UNICODE_SHIFT2 = 12;
39     static constexpr uint8_t UTF8_TO_UNICODE_SHIFT3 = 18;
40 
41     static Point GetTextSize(const char* text,
42                              int16_t letterSpace,
43                              int16_t lineHeight,
44                              int16_t maxWidth,
45                              int8_t lineSpace = 0);
46 
47     static uint32_t GetNextLine(const char* text,
48                                 int16_t letterSpace,
49                                 int16_t maxWidth);
50 
51     static int16_t GetTextWidth(const char* text,
52                                 uint16_t length,
53                                 int16_t letterSpace);
54 
55     static Rect GetArcTextRect(const char* text,
56                                const Point& arcCenter,
57                                int16_t letterSpace,
58                                UIArcLabel::TextOrientation orientation,
59                                const UIArcLabel::ArcTextInfo& arcTextInfo);
60 
61     static float GetAngleForArcLen(float len,
62                                    uint16_t height,
63                                    uint16_t radius,
64                                    UITextLanguageDirect direct,
65                                    UIArcLabel::TextOrientation orientation);
66 
67     static void GetArcLetterPos(const Point& arcCenter, uint16_t radius, float angle, float& posX, float& posY);
68 
69 #else  // _FONT_TOOL
70 class TypedText {
71 public:
72 #endif // _FONT_TOOL
73     static uint32_t GetUTF8Next(const char* text, uint32_t i, uint32_t& j);
74     static uint8_t GetUTF8OneCharacterSize(const char* str);
75     static uint32_t GetByteIndexFromUTF8Id(const char* text, uint32_t utf8Id);
76     static uint32_t GetUTF8CharacterSize(const char* text, uint32_t byteIndex = UINT32_MAX);
77     static void Utf8ToUtf16(const char* utf8Str, uint16_t* utf16Str, uint32_t len);
78     static uint32_t GetUtf16Cnt(const char* utf8Str);
79 
80 private:
81     static bool GetWrapPoint(const char* text, uint32_t& breakPoint);
82 };
83 } // namespace OHOS
84 #endif // GRAPHIC_LITE_TYPE_TEXT_H
85