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_EXPORT_TEXGINE_ANY_SPAN_H 17 #define ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_ANY_SPAN_H 18 19 #include "texgine_canvas.h" 20 #include "texgine/text_style.h" 21 #include "texgine/typography_types.h" 22 #include "texgine/utils/memory_object.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 namespace TextEngine { 27 #define MAXRGB 255 28 #define MAXALPHA 255 29 30 /* 31 * @brief AnySpanAlignment is the alignment of the AnySpan in a Typography. 32 */ 33 enum class AnySpanAlignment { 34 OFFSET_AT_BASELINE, // The bottom edge of the AnySpan is aligned with 35 // the offset position below the baseline. 36 ABOVE_BASELINE, // The bottom edge of the AnySpan is aligned with baseline. 37 BELOW_BASELINE, // The top edge of the AnySpan is aligned with baseline. 38 TOP_OF_ROW_BOX, // The top edge of the AnySpan is aligned with the 39 // top edge of the row box. 40 BOTTOM_OF_ROW_BOX, // The bottom edge of the AnySpan is aligned with the 41 // bottom edge of the row box. 42 CENTER_OF_ROW_BOX, // The vertical centerline of the AnySpan is aligned with the 43 // vertical centerline of the row box. 44 }; 45 46 /* 47 * @brief AnySpan is a span that can be any width, height and draw any content. 48 */ 49 class AnySpan : public MemoryObject { 50 public: 51 virtual ~AnySpan() = default; 52 53 /* 54 * @brief Returns the width of the span. 55 */ 56 virtual double GetWidth() const = 0; 57 58 /* 59 * @brief Returns the height of the span. 60 */ 61 virtual double GetHeight() const = 0; 62 63 /* 64 * @brief Returns the alignment of the span. 65 */ 66 virtual AnySpanAlignment GetAlignment() const = 0; 67 68 /* 69 * @brief Returns the baseline of the span. 70 */ 71 virtual TextBaseline GetBaseline() const = 0; 72 73 /* 74 * @brief Returns the offset of the span. 75 */ 76 virtual double GetLineOffset() const = 0; 77 78 /* 79 * @brief This method will be called when the Typography is drawn. 80 * @param canvas Canvas to be drawn. 81 * @param offsetx The Offset in x-asix of the starting point for drawing the AnySpan 82 * @param offsety The Offset in y-asix of the starting point for drawing the AnySpan 83 */ 84 virtual void Paint(TexgineCanvas& canvas, double offsetx, double offsety) = 0; 85 SetTextStyle(const TextStyle & style)86 void SetTextStyle(const TextStyle& style) 87 { 88 xs_ = style; 89 } 90 SetRoundRectType(const RoundRectType type)91 void SetRoundRectType(const RoundRectType type) 92 { 93 roundRectType_ = type; 94 } 95 SetTopInGroup(const double top)96 void SetTopInGroup(const double top) 97 { 98 topInGroup_ = top; 99 } 100 GetTopInGroup()101 double GetTopInGroup() const 102 { 103 return topInGroup_; 104 } 105 SetBottomInGroup(const double bottom)106 void SetBottomInGroup(const double bottom) 107 { 108 bottomInGroup_ = bottom; 109 } 110 GetBottomInGroup()111 double GetBottomInGroup() const 112 { 113 return bottomInGroup_; 114 } 115 SetMaxRoundRectRadius(const double radius)116 void SetMaxRoundRectRadius(const double radius) 117 { 118 maxRoundRectRadius_ = radius; 119 } 120 GetMaxRoundRectRadius()121 double GetMaxRoundRectRadius() const 122 { 123 return maxRoundRectRadius_; 124 } 125 126 private: 127 friend void ReportMemoryUsage(const std::string& member, const AnySpan& that, const bool needThis); 128 void ReportMemoryUsage(const std::string& member, const bool needThis) const override; 129 130 double topInGroup_ = 0.0; 131 double bottomInGroup_ = 0.0; 132 double maxRoundRectRadius_ = 0.0; 133 TextStyle xs_; 134 RoundRectType roundRectType_ = RoundRectType::NONE; 135 }; 136 } // namespace TextEngine 137 } // namespace Rosen 138 } // namespace OHOS 139 140 #endif // ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_ANY_SPAN_H 141