• 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_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 /*
28  * @brief AnySpanAlignment is the alignment of the AnySpan in a Typography.
29  */
30 enum class AnySpanAlignment {
31     OFFSET_AT_BASELINE,  // The bottom edge of the AnySpan is aligned with
32                          // the offset position below the baseline.
33     ABOVE_BASELINE,      // The bottom edge of the AnySpan is aligned with baseline.
34     BELOW_BASELINE,      // The top edge of the AnySpan is aligned with baseline.
35     TOP_OF_ROW_BOX,      // The top edge of the AnySpan is aligned with the
36                          // top edge of the row box.
37     BOTTOM_OF_ROW_BOX,   // The bottom edge of the AnySpan is aligned with the
38                          // bottom edge of the row box.
39     CENTER_OF_ROW_BOX,   // The vertical centerline of the AnySpan is aligned with the
40                          // vertical centerline of the row box.
41 };
42 
43 /*
44  * @brief AnySpan is a span that can be any width, height and draw any content.
45  */
46 class AnySpan : public MemoryObject {
47 public:
48     virtual ~AnySpan() = default;
49 
50     /*
51      * @brief Returns the width of the span.
52      */
53     virtual double GetWidth() const = 0;
54 
55     /*
56      * @brief Returns the height of the span.
57      */
58     virtual double GetHeight() const = 0;
59 
60     /*
61      * @brief Returns the alignment of the span.
62      */
63     virtual AnySpanAlignment GetAlignment() const = 0;
64 
65     /*
66      * @brief Returns the baseline of the span.
67      */
68     virtual TextBaseline GetBaseline() const = 0;
69 
70     /*
71      * @brief Returns the offset of the span.
72      */
73     virtual double GetLineOffset() const = 0;
74 
75     /*
76      * @brief This method will be called when the Typography is drawn.
77      * @param canvas  Canvas to be drawn.
78      * @param offsetx The Offset in x-asix of the starting point for drawing the AnySpan
79      * @param offsety The Offset in y-asix of the starting point for drawing the AnySpan
80      */
81     virtual void Paint(TexgineCanvas& canvas, double offsetx, double offsety) = 0;
82 
83 private:
84     friend void ReportMemoryUsage(const std::string& member, const AnySpan& that, const bool needThis);
85     void ReportMemoryUsage(const std::string& member, const bool needThis) const override;
86 };
87 } // namespace TextEngine
88 } // namespace Rosen
89 } // namespace OHOS
90 
91 #endif // ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_ANY_SPAN_H
92