• 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_VARIANT_SPAN_H
17 #define ROSEN_MODULES_TEXGINE_SRC_VARIANT_SPAN_H
18 
19 #include <memory>
20 #include <optional>
21 #include <vector>
22 
23 #include "texgine_canvas.h"
24 #include "texgine/font_providers.h"
25 #include "texgine/any_span.h"
26 #include "text_span.h"
27 #include "symbol_animation_config.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace TextEngine {
32 enum class DumpType {
33     NORMAL,
34     DONT_RETURN,
35 };
36 
37 class VariantSpan {
38 public:
39     VariantSpan() noexcept(true) = default;
40     VariantSpan(const std::shared_ptr<TextSpan> &ts) noexcept(true);
41     VariantSpan(const std::shared_ptr<AnySpan> &as) noexcept(true);
42     VariantSpan(std::shared_ptr<TextSpan> &&ts) noexcept(true);
43     VariantSpan(std::shared_ptr<AnySpan> &&as) noexcept(true);
44     VariantSpan(std::nullptr_t) noexcept(true);
45 
46     template<typename Type,
47              typename = std::enable_if_t<std::is_convertible_v<Type, std::shared_ptr<AnySpan>>>>
VariantSpan(Type type)48     VariantSpan(Type type) noexcept(true)
49         : VariantSpan(std::static_pointer_cast<AnySpan>(type)) {}
50 
51     std::shared_ptr<TextSpan> TryToTextSpan() const noexcept(false);
52     std::shared_ptr<AnySpan> TryToAnySpan() const noexcept(false);
53 
54     double GetWidth() const;
55     double GetHeight() const noexcept(false);
56     size_t GetNumberOfCharGroup() const noexcept(false);
57     std::vector<double> GetGlyphWidths() const noexcept(false);
58     double GetVisibleWidth() const noexcept(false);
59     size_t GetNumberOfChar() const noexcept(false);
60     void Dump(const DumpType &dtype = DumpType::NORMAL) const noexcept(false);
61 
62     void SetTextStyle(const TextStyle &xs) noexcept(true);
63     TextStyle &GetTextStyle() noexcept(true);
64     const TextStyle &GetTextStyle() const noexcept(true);
65 
66     double GetOffsetX() const noexcept(true);
67     double GetOffsetY() const noexcept(true);
68     void AdjustOffsetX(double offset) noexcept(true);
69     void AdjustOffsetY(double offset) noexcept(true);
70 
71     void Paint(TexgineCanvas &canvas, double offsetX, double offsetY) noexcept(false);
72     void PaintShadow(TexgineCanvas &canvas, double offsetX, double offsetY) noexcept(false);
73 
74     bool IsRTL() const noexcept(false);
75     bool IsHardBreak() const noexcept(false);
76 
77     double GetJustifyGap() const noexcept(true);
78     void SetJustifyGap(double justifyGap) noexcept(true);
79 
80     bool HasBackgroundRect() const;
81     RoundRectType GetRoundRectType() const noexcept(true);
82     void SetRoundRectType(RoundRectType type) noexcept(true);
83 
84     void SetTopInGroup(double top);
85     double GetTopInGroup() const;
86 
87     void SetBottomInGroup(double bottom);
88     double GetBottomInGroup() const;
89 
90     void SetMaxRoundRectRadius(double radius);
91     double GetMaxRoundRectRadius() const;
92 
93     double GetTop() const noexcept(true);
94     double GetBottom() const noexcept(true);
95 
96     operator bool() const noexcept(false);
97     bool operator ==(std::nullptr_t) const noexcept(false);
98     bool operator ==(const VariantSpan &rhs) const noexcept(false);
99     bool operator !=(std::nullptr_t) const noexcept(false);
100     bool operator !=(const VariantSpan &rhs) const noexcept(false);
SetAnimation(std::function<bool (const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig> &)> & animationFunc)101     void SetAnimation(std::function<bool(
102         const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig>&)>& animationFunc)
103     {
104         if (animationFunc != nullptr && ts_ != nullptr) {
105             ts_->SetAnimation(animationFunc);
106         }
107     }
108 
SetSymbolId(const uint64_t & id)109     void SetSymbolId(const uint64_t& id)
110     {
111         if (ts_ != nullptr) {
112             ts_->SetSymbolId(id);
113         }
114     }
115 private:
116     void CheckPointer(bool nullable = false) const;
117 
118     std::shared_ptr<TextSpan> ts_ = nullptr;
119     std::shared_ptr<AnySpan> as_ = nullptr;
120 
121     double offsetX_ = 0;
122     double offsetY_ = 0;
123     double justifyGap_ = 0;
124     TextStyle xs_;
125     RoundRectType roundRectType_ = RoundRectType::NONE;
126 };
127 } // namespace TextEngine
128 } // namespace Rosen
129 } // namespace OHOS
130 
131 #endif // ROSEN_MODULES_TEXGINE_SRC_VARIANT_SPAN_H
132