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 28 namespace OHOS { 29 namespace Rosen { 30 namespace TextEngine { 31 enum class DumpType { 32 NORMAL, 33 DONT_RETURN, 34 }; 35 36 class VariantSpan { 37 public: 38 VariantSpan() noexcept(true) = default; 39 VariantSpan(const std::shared_ptr<TextSpan> &ts) noexcept(true); 40 VariantSpan(const std::shared_ptr<AnySpan> &as) noexcept(true); 41 VariantSpan(std::shared_ptr<TextSpan> &&ts) noexcept(true); 42 VariantSpan(std::shared_ptr<AnySpan> &&as) noexcept(true); 43 VariantSpan(std::nullptr_t) noexcept(true); 44 45 template<typename Type, 46 typename = std::enable_if_t<std::is_convertible_v<Type, std::shared_ptr<AnySpan>>>> VariantSpan(Type type)47 VariantSpan(Type type) noexcept(true) 48 : VariantSpan(std::static_pointer_cast<AnySpan>(type)) {} 49 50 std::shared_ptr<TextSpan> TryToTextSpan() const noexcept(false); 51 std::shared_ptr<AnySpan> TryToAnySpan() const noexcept(false); 52 53 double GetWidth() const noexcept(false); 54 double GetHeight() const noexcept(false); 55 size_t GetNumberOfCharGroup() const noexcept(false); 56 std::vector<double> GetGlyphWidths() const noexcept(false); 57 double GetVisibleWidth() const noexcept(false); 58 void Dump(const DumpType &dtype = DumpType::NORMAL) const noexcept(false); 59 60 void SetTextStyle(const TextStyle &xs) noexcept(true); 61 TextStyle &GetTextStyle() noexcept(true); 62 const TextStyle &GetTextStyle() const noexcept(true); 63 64 double GetOffsetX() const noexcept(true); 65 double GetOffsetY() const noexcept(true); 66 void AdjustOffsetX(double offset) noexcept(true); 67 void AdjustOffsetY(double offset) noexcept(true); 68 69 void Paint(TexgineCanvas &canvas, double offsetX, double offsetY) noexcept(false); 70 void PaintShadow(TexgineCanvas &canvas, double offsetX, double offsetY) noexcept(false); 71 bool IsRTL() const noexcept(false); 72 73 operator bool() const noexcept(false); 74 bool operator ==(std::nullptr_t) const noexcept(false); 75 bool operator ==(const VariantSpan &rhs) const noexcept(false); 76 bool operator !=(std::nullptr_t) const noexcept(false); 77 bool operator !=(const VariantSpan &rhs) const noexcept(false); 78 79 private: 80 void CheckPointer(bool nullable = false) const noexcept(false); 81 82 std::shared_ptr<TextSpan> ts_ = nullptr; 83 std::shared_ptr<AnySpan> as_ = nullptr; 84 85 double offsetX_ = 0; 86 double offsetY_ = 0; 87 TextStyle xs_; 88 }; 89 } // namespace TextEngine 90 } // namespace Rosen 91 } // namespace OHOS 92 93 #endif // ROSEN_MODULES_TEXGINE_SRC_VARIANT_SPAN_H 94