1 /*
2  * Copyright (c) 2020-2022 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_DRAW_LABEL_H
17 #define GRAPHIC_LITE_DRAW_LABEL_H
18 
19 #include "common/typed_text.h"
20 #include "draw/draw_utils.h"
21 #include "gfx_utils/geometry2d.h"
22 #include "gfx_utils/heap_base.h"
23 #include "gfx_utils/style.h"
24 
25 namespace OHOS {
26 class DrawLabel : public HeapBase {
27 public:
28     static uint16_t DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInfo& labelLine,
29                                     uint16_t& letterIndex);
30 
31     static void DrawArcText(BufferInfo& gfxDstBuffer, const Rect& mask, const char* text, const Point& arcCenter,
32                             uint16_t fontId, uint8_t fontSize, const ArcTextInfo arcTextInfo, const float changeAngle,
33                             TextOrientation orientation, const Style& style, uint8_t opaScale, bool compatibilityMode);
34 
35     static bool CalculateAngle(uint16_t letterWidth,
36                                uint16_t letterHeight,
37                                int16_t letterSpace,
38                                const ArcTextInfo arcTextInfo,
39                                bool xorFlag,
40                                uint32_t index,
41                                TextOrientation orientation,
42                                float& posX,
43                                float& posY,
44                                float& rotateAngle,
45                                float& angle,
46                                const Point& arcCenter,
47                                bool compatibilityMode);
48 
49     static void DrawLetterWithRotate(BufferInfo& gfxDstBuffer,
50                                      const Rect& mask,
51                                      const ArcLetterInfo& letterInfo,
52                                      float posX,
53                                      float posY);
54 
55     static uint8_t GetLineMaxLetterSize(const char* text, uint16_t lineLength, uint16_t fontId, uint8_t fontSize,
56                                         uint16_t letterIndex, SpannableString* spannableString);
57     static void GetLineBackgroundColor(uint16_t letterIndex, List<LineBackgroundColor>* linebackgroundColor,
58                                        bool& havelinebackground, ColorType& linebgColor);
59     static void GetBackgroundColor(uint16_t letterIndex, List<BackgroundColor>* backgroundColor,
60                                    bool& havebackground, ColorType& bgColor);
61     static void GetForegroundColor(uint16_t letterIndex, List<ForegroundColor>* foregroundColor, ColorType& fgColor);
62     static void DrawLineBackgroundColor(BufferInfo& gfxDstBuffer, uint16_t letterIndex,
63                                         const LabelLineInfo& labelLine);
64 
65 private:
66     static bool CalculatedTransformDataInfo(uint8_t** buffer, TransformDataInfo& letterTranDataInfo,
67         const ArcLetterInfo& letterInfo);
68 
69     static bool CalculatedClipAngle(const ArcLetterInfo& letterInfo, float& angle);
70 
71     static void CalculatedBeginAndCopySize(const ArcLetterInfo& letterInfo, const uint16_t sizePerPx,
72         const uint16_t cols, const int16_t offsetX, uint16_t& begin, uint16_t& copyCols, TextInRange& range);
73 
74     static void OnCalculatedClockwise(const ArcLetterInfo& letterInfo, const uint16_t sizePerPx,
75         const uint16_t cols, const int16_t offsetX, uint16_t& begin, uint16_t& copyCols, TextInRange& range);
76 
77     static void OnCalculatedAnticlockwise(const ArcLetterInfo& letterInfo, const uint16_t sizePerPx,
78         const uint16_t cols, const int16_t offsetX, uint16_t& begin, uint16_t& copyCols, TextInRange& range);
79 };
80 } // namespace OHOS
81 #endif // GRAPHIC_LITE_DRAW_LABEL_H
82