1 /* 2 * Copyright (c) 2022-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_RENDER_PAPAGRAPH_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_PAPAGRAPH_H 18 19 #ifdef USE_ROSEN_DRAWING 20 #include "include/core/SkCanvas.h" 21 #endif 22 23 #include "base/memory/ace_type.h" 24 #include "core/components/common/layout/constants.h" 25 #include "core/components/common/properties/text_style.h" 26 #include "core/components_ng/render/drawing_forward.h" 27 #include "core/components_ng/render/font_collection.h" 28 #include "core/pipeline_ng/pipeline_context.h" 29 30 namespace OHOS::Ace::NG { 31 32 struct ParagraphStyle { 33 TextDirection direction = TextDirection::AUTO; 34 TextAlign align = TextAlign::LEFT; 35 uint32_t maxLines = 1; 36 std::string fontLocale; 37 WordBreak wordBreak = WordBreak::NORMAL; 38 TextOverflow textOverflow = TextOverflow::CLIP; 39 }; 40 41 // Paragraph is interface for drawing text and text paragraph. 42 class Paragraph : public virtual AceType { 43 DECLARE_ACE_TYPE(NG::Paragraph, AceType) 44 45 public: 46 static RefPtr<Paragraph> Create(const ParagraphStyle& paraStyle, const RefPtr<FontCollection>& fontCollection); 47 48 // whether the paragraph has been build 49 virtual bool IsValid() = 0; 50 51 // interfaces for build text paragraph 52 virtual void PushStyle(const TextStyle& style) = 0; 53 virtual void PopStyle() = 0; 54 virtual void AddText(const std::u16string& text) = 0; 55 virtual int32_t AddPlaceholder(const PlaceholderRun& span) = 0; 56 virtual void Build() = 0; 57 virtual void Reset() = 0; 58 59 // interfaces for layout 60 virtual void Layout(float width) = 0; 61 virtual float GetHeight() = 0; 62 virtual float GetTextWidth() = 0; 63 virtual size_t GetLineCount() = 0; 64 virtual float GetMaxIntrinsicWidth() = 0; 65 virtual bool DidExceedMaxLines() = 0; 66 virtual float GetLongestLine() = 0; 67 virtual float GetMaxWidth() = 0; 68 virtual float GetAlphabeticBaseline() = 0; 69 virtual int32_t GetHandlePositionForClick(const Offset& offset) = 0; 70 virtual void GetRectsForRange(int32_t start, int32_t end, std::vector<Rect>& selectedRects) = 0; 71 virtual void GetRectsForPlaceholders(std::vector<Rect>& selectedRects) = 0; 72 virtual bool ComputeOffsetForCaretDownstream(int32_t extent, CaretMetrics& result) = 0; 73 virtual bool ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics& result) = 0; 74 virtual void SetIndents(const std::vector<float>& indents) = 0; 75 virtual bool GetWordBoundary(int32_t offset, int32_t& start, int32_t& end) = 0; 76 77 // interfaces for painting 78 virtual void Paint(const RSCanvas& canvas, float x, float y) = 0; 79 virtual void Paint(SkCanvas* skCanvas, float x, float y) = 0; 80 }; 81 82 } // namespace OHOS::Ace::NG 83 84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_PAPAGRAPH_H 85