• 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RICH_EDITOR_RICH_EDITOR_LAYOUT_ALGORITHM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RICH_EDITOR_RICH_EDITOR_LAYOUT_ALGORITHM_H
18 
19 #include "core/components_ng/pattern/rich_editor/paragraph_manager.h"
20 #include "core/components_ng/pattern/text/text_layout_algorithm.h"
21 
22 namespace OHOS::Ace::NG {
23 class ACE_EXPORT RichEditorLayoutAlgorithm : public TextLayoutAlgorithm {
24     DECLARE_ACE_TYPE(RichEditorLayoutAlgorithm, TextLayoutAlgorithm);
25 
26 public:
27     RichEditorLayoutAlgorithm() = delete;
28     RichEditorLayoutAlgorithm(std::list<RefPtr<SpanItem>> spans, ParagraphManager* paragraphs);
29     ~RichEditorLayoutAlgorithm() override = default;
30 
GetParentGlobalOffset()31     const OffsetF& GetParentGlobalOffset() const
32     {
33         return parentGlobalOffset_;
34     }
35     std::optional<SizeF> MeasureContent(
36         const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override;
37 
38     void Layout(LayoutWrapper* layoutWrapper) override;
39 
40     void Measure(LayoutWrapper* layoutWrapper) override;
41 
GetTextRect()42     const RectF& GetTextRect()
43     {
44         return richTextRect_;
45     }
46 
47 protected:
48     OffsetF GetContentOffset(LayoutWrapper* layoutWrapper) override;
49 
50 private:
51     void GetPlaceholderRects(std::vector<RectF>& rectF) override;
52     RefPtr<SpanItem> GetFirstTextSpanItem() const;
53     int32_t GetPreviousLength() const override;
54     ParagraphStyle GetParagraphStyle(
55         const TextStyle& textStyle, const std::string& content, LayoutWrapper* layoutWrapper) const override;
56 
ApplyIndent(const TextStyle & textStyle,double width)57     void ApplyIndent(const TextStyle& textStyle, double width) override
58     { // do nothing
59     }
60 
61     float GetShadowOffset(const std::list<RefPtr<SpanItem>>& group);
62 
SpansToString()63     std::string SpansToString()
64     {
65         std::stringstream ss;
66         for (auto& list : spans_) {
67             ss << "[";
68             for_each(list.begin(), list.end(), [&ss](RefPtr<SpanItem>& item) {
69                 ss << "[" << StringUtils::RestoreEscape(item->content) << "], "; });
70             ss << "], ";
71         }
72         return ss.str();
73     }
74 
75     std::vector<std::list<RefPtr<SpanItem>>> spans_;
76     ParagraphManager* pManager_;
77     OffsetF parentGlobalOffset_;
78     RectF richTextRect_;
79     ACE_DISALLOW_COPY_AND_MOVE(RichEditorLayoutAlgorithm);
80 };
81 } // namespace OHOS::Ace::NG
82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RICH_EDITOR_RICH_EDITOR_LAYOUT_ALGORITHM_H
83