• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/components_ng/test/pattern/text/mock/mock_txt_paragraph.h"
17 
18 #include "core/components_ng/render/adapter/txt_font_collection.h"
19 #include "core/components_ng/render/adapter/txt_paragraph.h"
20 
21 namespace OHOS::Ace::NG {
22 namespace LayoutWidth {
23 float layoutWidth = 0.0f;
24 }
25 namespace {
26 bool textParapraphCanConstruct = true;
27 std::vector<bool> textParapraphDidExceedMaxLines;
28 } // namespace
29 
SetCanConstruct(bool canConstruct)30 void MockTxtParagraph::SetCanConstruct(bool canConstruct)
31 {
32     textParapraphCanConstruct = canConstruct;
33 }
34 
SetDidExceedMaxLines(const std::vector<bool> & didExceedMaxLines)35 void MockTxtParagraph::SetDidExceedMaxLines(const std::vector<bool>& didExceedMaxLines)
36 {
37     textParapraphDidExceedMaxLines = didExceedMaxLines;
38 }
39 
Create(const ParagraphStyle & paraStyle,const RefPtr<FontCollection> & fontCollection)40 RefPtr<Paragraph> Paragraph::Create(const ParagraphStyle& paraStyle, const RefPtr<FontCollection>& fontCollection)
41 {
42     if (!textParapraphCanConstruct) {
43         return nullptr;
44     }
45     auto txtFontCollection = DynamicCast<TxtFontCollection>(fontCollection);
46     CHECK_NULL_RETURN(txtFontCollection, nullptr);
47     auto sharedFontCollection = txtFontCollection->GetRawFontCollection();
48     return AceType::MakeRefPtr<TxtParagraph>(paraStyle, sharedFontCollection);
49 }
50 
IsValid()51 bool TxtParagraph::IsValid()
52 {
53     return paragraph_ != nullptr;
54 }
55 
CreateBuilder()56 void TxtParagraph::CreateBuilder() {}
57 
PushStyle(const TextStyle & style)58 void TxtParagraph::PushStyle(const TextStyle& style) {}
59 
PopStyle()60 void TxtParagraph::PopStyle() {}
61 
AddText(const std::u16string & text)62 void TxtParagraph::AddText(const std::u16string& text) {}
63 
Build()64 void TxtParagraph::Build() {}
65 
Reset()66 void TxtParagraph::Reset() {}
67 
Layout(float width)68 void TxtParagraph::Layout(float width)
69 {
70     LayoutWidth::layoutWidth = width;
71 }
72 
GetHeight()73 float TxtParagraph::GetHeight()
74 {
75     return 50.0f;
76 }
77 
GetTextWidth()78 float TxtParagraph::GetTextWidth()
79 {
80     return 150.0f;
81 }
82 
GetMaxIntrinsicWidth()83 float TxtParagraph::GetMaxIntrinsicWidth()
84 {
85     return 150.0f;
86 }
87 
DidExceedMaxLines()88 bool TxtParagraph::DidExceedMaxLines()
89 {
90     if (textParapraphDidExceedMaxLines.empty()) {
91         return true;
92     }
93     bool result = *textParapraphDidExceedMaxLines.begin();
94     textParapraphDidExceedMaxLines.erase(textParapraphDidExceedMaxLines.begin());
95     return result;
96 }
97 
GetLongestLine()98 float TxtParagraph::GetLongestLine()
99 {
100     return 100.0f;
101 }
102 
GetMaxWidth()103 float TxtParagraph::GetMaxWidth()
104 {
105     return LayoutWidth::layoutWidth;
106 }
107 
GetAlphabeticBaseline()108 float TxtParagraph::GetAlphabeticBaseline()
109 {
110     return 0.0f;
111 }
112 
GetLineCount()113 size_t TxtParagraph::GetLineCount()
114 {
115     return 1;
116 }
117 
Paint(const RSCanvas & canvas,float x,float y)118 void TxtParagraph::Paint(const RSCanvas& canvas, float x, float y) {}
119 
Paint(SkCanvas * skCanvas,float x,float y)120 void TxtParagraph::Paint(SkCanvas* skCanvas, float x, float y) {}
121 
GetHandlePositionForClick(const Offset & offset)122 int32_t TxtParagraph::GetHandlePositionForClick(const Offset& offset)
123 {
124     return 0;
125 }
126 
GetRectsForRange(int32_t start,int32_t end,std::vector<Rect> & selectedRects)127 void TxtParagraph::GetRectsForRange(int32_t start, int32_t end, std::vector<Rect>& selectedRects)
128 {
129     selectedRects = { Rect(start, start, end - start, end - start) };
130 }
131 
ComputeOffsetForCaretDownstream(int32_t extent,CaretMetrics & result)132 bool TxtParagraph::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetrics& result)
133 {
134     return true;
135 }
ComputeOffsetForCaretUpstream(int32_t extent,CaretMetrics & result)136 bool TxtParagraph::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics& result)
137 {
138     return true;
139 }
140 
AddPlaceholder(const PlaceholderRun & span)141 int32_t TxtParagraph::AddPlaceholder(const PlaceholderRun& span)
142 {
143     placeHolderIndex_ = -1;
144     return -1;
145 }
146 
GetRectsForPlaceholders(std::vector<Rect> & selectedRects)147 void TxtParagraph::GetRectsForPlaceholders(std::vector<Rect>& selectedRects) {}
148 
SetIndents(const std::vector<float> & indents)149 void TxtParagraph::SetIndents(const std::vector<float>& indents) {}
GetWordBoundary(int32_t offset,int32_t & start,int32_t & end)150 bool TxtParagraph::GetWordBoundary(int32_t offset, int32_t& start, int32_t& end)
151 {
152     return false;
153 }
154 } // namespace OHOS::Ace::NG
155