1 /*
2  * Copyright (c) 2024 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 "text_line_base.h"
17 
18 #include "convert.h"
19 #include "run_impl.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 namespace AdapterTxt {
TextLineBaseImpl(std::unique_ptr<SPText::TextLineBase> textlinebase)24 TextLineBaseImpl::TextLineBaseImpl(std::unique_ptr<SPText::TextLineBase> textlinebase)
25     : textlinebase_(std::move(textlinebase))
26 {
27 }
28 
GetGlyphCount() const29 size_t TextLineBaseImpl::GetGlyphCount() const
30 {
31     if (!textlinebase_) {
32         return 0;
33     }
34     return textlinebase_->GetGlyphCount();
35 }
36 
GetGlyphRuns() const37 std::vector<std::unique_ptr<Run>> TextLineBaseImpl::GetGlyphRuns() const
38 {
39     if (!textlinebase_) {
40         return {};
41     }
42 
43     std::vector<std::unique_ptr<SPText::Run>> textRuns = textlinebase_->GetGlyphRuns();
44     std::vector<std::unique_ptr<Run>> runs;
45 
46     for (std::unique_ptr<SPText::Run>& textRun : textRuns) {
47         std::unique_ptr<RunImpl> runPtr = std::make_unique<RunImpl>(std::move(textRun));
48         runs.emplace_back(std::move(runPtr));
49     }
50     return runs;
51 }
52 
GetTextRange() const53 Boundary TextLineBaseImpl::GetTextRange() const
54 {
55     if (!textlinebase_) {
56         Boundary boundary(0, 0);
57         return boundary;
58     }
59 
60     return Convert(textlinebase_->GetTextRange());
61 }
62 
Paint(Drawing::Canvas * canvas,double x,double y)63 void TextLineBaseImpl::Paint(Drawing::Canvas *canvas, double x, double y)
64 {
65     if (!textlinebase_) {
66         return;
67     }
68     return textlinebase_->Paint(canvas, x, y);
69 }
70 } // namespace AdapterTxt
71 } // namespace Rosen
72 } // namespace OHOS
73