• 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 #ifndef ROSEN_MODULES_TEXGINE_SRC_TEXT_SPAN_H
17 #define ROSEN_MODULES_TEXGINE_SRC_TEXT_SPAN_H
18 
19 #include <any>
20 
21 #include "char_groups.h"
22 #include "texgine_canvas.h"
23 #include "texgine_font_metrics.h"
24 #include "texgine_text_blob.h"
25 #include "texgine/typography.h"
26 #include "texgine/typography_style.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 namespace TextEngine {
31 class TextSpan : public std::enable_shared_from_this<TextSpan> {
32 public:
33     static std::shared_ptr<TextSpan> MakeEmpty();
34     static std::shared_ptr<TextSpan> MakeFromText(std::string const &text);
35     static std::shared_ptr<TextSpan> MakeFromText(std::u16string const &text);
36     static std::shared_ptr<TextSpan> MakeFromText(std::u32string const &text);
37     static std::shared_ptr<TextSpan> MakeFromText(std::vector<uint16_t> const &text);
38     static std::shared_ptr<TextSpan> MakeFromText(std::vector<uint32_t> const &text);
39     static std::shared_ptr<TextSpan> MakeFromCharGroups(const CharGroups &cgs);
40 
41     TextSpan() = default;
42     virtual ~TextSpan() = default;
43     void AddUTF16Text(std::vector<uint16_t> const &text);
44 
45     double GetWidth() const;
46     double GetHeight() const;
47     double GetPostBreak() const;
48     double GetPreBreak() const;
49     bool IsRTL() const;
50     void Paint(TexgineCanvas &canvas, double offsetX, double offsetY, const TextStyle &xs);
51     void PaintShadow(TexgineCanvas &canvas, double offsetX, double offsetY, const std::vector<TextShadow> &shadows);
52     std::shared_ptr<TextSpan> CloneWithCharGroups(CharGroups const &cgs);
53 
54     void operator+=(TextSpan const &textSpan)
55     {
56         u16vect_.insert(u16vect_.end(), textSpan.u16vect_.begin(), textSpan.u16vect_.end());
57     }
58 
59     TexgineFontMetrics tmetrics_;
60     bool rtl_ = false;
61     std::shared_ptr<Typeface> typeface_ = nullptr;
62 
63     std::vector<uint16_t> u16vect_;
64     std::shared_ptr<TexgineTextBlob> textBlob_ = nullptr;
65     std::vector<double> glyphWidths_;
66 
67     CharGroups cgs_;
68 
69     double preBreak_ = 0.0;
70     double postBreak_ = 0.0;
71     double width_ = 0.0;
72 
73 private:
74     friend class TextBreaker;
75     friend class BidiProcesser;
76     friend class ControllerForTest;
77     friend class TextMerger;
78     friend class LineBreaker;
79     friend class TypographyImpl;
80     friend class VariantSpan;
81     friend class TextShaper;
82     friend class TextReverser;
83     friend void ReportMemoryUsage(std::string const &member, TextSpan const &that, bool needThis);
84 
85     void PaintDecoration(TexgineCanvas &canvas, double offsetX, double offsetY, const TextStyle &xs);
86     void PaintDecorationStyle(TexgineCanvas &canvas, double left, double right, double y, const TextStyle &xs);
87 };
88 } // namespace TextEngine
89 } // namespace Rosen
90 } // namespace OHOS
91 
92 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXT_SPAN_H
93