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_PATTERNS_RICH_EDITOR_PARAGRAPH_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_PARAGRAPH_MANAGER_H 18 #include <list> 19 #include <optional> 20 21 #include "base/geometry/offset.h" 22 #include "base/memory/ace_type.h" 23 #include "core/components_ng/render/paragraph.h" 24 namespace OHOS::Ace::NG { 25 class ParagraphManager : public virtual AceType { 26 DECLARE_ACE_TYPE(ParagraphManager, AceType); 27 28 public: 29 struct ParagraphInfo { 30 RefPtr<Paragraph> paragraph; 31 int32_t start = 0; 32 int32_t end = 0; 33 34 std::string ToString() const; 35 }; 36 std::optional<double> minParagraphFontSize = std::nullopt; 37 38 int32_t GetIndex(Offset offset, bool clamp = false) const; 39 float GetHeight() const; 40 GetParagraphs()41 const std::list<ParagraphInfo>& GetParagraphs() const 42 { 43 return paragraphs_; 44 } 45 void Reset(); 46 47 std::vector<RectF> GetRects(int32_t start, int32_t end) const; 48 std::vector<RectF> GetPlaceholderRects() const; 49 OffsetF ComputeCursorOffset(int32_t index, float& selectLineHeight, bool downStreamFirst = false, 50 bool needLineHighest = true) const; 51 OffsetF ComputeCursorInfoByClick(int32_t index, float& selectLineHeight, const OffsetF& lastTouchOffset) const; 52 bool IsSelectLineHeadAndUseLeadingMargin(int32_t start) const; 53 AddParagraph(ParagraphInfo && info)54 void AddParagraph(ParagraphInfo&& info) 55 { 56 paragraphs_.emplace_back(std::move(info)); 57 } 58 59 private: 60 std::list<ParagraphInfo> paragraphs_; 61 }; 62 } // namespace OHOS::Ace::NG 63 #endif 64