• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "run_impl.h"
17 
18 #include "convert.h"
19 #include "impl/run_impl.h"
20 #include "typography_types.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace AdapterTxt {
RunImpl(std::unique_ptr<SPText::Run> run)25 RunImpl::RunImpl(std::unique_ptr<SPText::Run> run): run_(std::move(run))
26 {
27 }
28 
GetFont() const29 Drawing::Font RunImpl::GetFont() const
30 {
31     if (!run_) {
32         return {};
33     }
34     return run_->GetFont();
35 }
36 
GetGlyphCount() const37 size_t RunImpl::GetGlyphCount() const
38 {
39     if (!run_) {
40         return 0;
41     }
42     return run_->GetGlyphCount();
43 }
44 
GetGlyphs() const45 std::vector<uint16_t> RunImpl::GetGlyphs() const
46 {
47     if (!run_) {
48         return {};
49     }
50     return run_->GetGlyphs();
51 }
52 
GetPositions()53 std::vector<Drawing::Point> RunImpl::GetPositions()
54 {
55     if (!run_) {
56         return {};
57     }
58     return run_->GetPositions();
59 }
60 
GetOffsets()61 std::vector<Drawing::Point> RunImpl::GetOffsets()
62 {
63     if (!run_) {
64         return {};
65     }
66     return run_->GetOffsets();
67 }
68 
Paint(Drawing::Canvas * canvas,double x,double y)69 void RunImpl::Paint(Drawing::Canvas *canvas, double x, double y)
70 {
71     if (!run_) {
72         return;
73     }
74     return run_->Paint(canvas, x, y);
75 }
76 
GetGlyphs(int64_t start,int64_t length) const77 std::vector<uint16_t> RunImpl::GetGlyphs(int64_t start, int64_t length) const
78 {
79     if (run_ == nullptr || start < 0 || length < 0) {
80         return {};
81     }
82     return run_->GetGlyphs(start, length);
83 }
84 
GetPositions(int64_t start,int64_t length) const85 std::vector<Drawing::Point> RunImpl::GetPositions(int64_t start, int64_t length) const
86 {
87     if (run_ == nullptr || start < 0 || length < 0) {
88         return {};
89     }
90     return run_->GetPositions(start, length);
91 }
92 
GetAdvances(uint32_t start,uint32_t length) const93 std::vector<Drawing::Point> RunImpl::GetAdvances(uint32_t start, uint32_t length) const
94 {
95     if (run_ == nullptr) {
96         return {};
97     }
98     return run_->GetAdvances(start, length);
99 }
100 
GetTextDirection() const101 TextDirection RunImpl::GetTextDirection() const
102 {
103     if (run_ == nullptr) {
104         return TextDirection::LTR;
105     }
106     if (run_->GetTextDirection() == SPText::TextDirection::RTL) {
107         return TextDirection::RTL;
108     } else {
109         return TextDirection::LTR;
110     }
111 }
112 
GetStringRange(uint64_t * location,uint64_t * length) const113 void RunImpl::GetStringRange(uint64_t* location, uint64_t* length) const
114 {
115     if (location == nullptr || length == nullptr) {
116         return;
117     } else if (run_ == nullptr) {
118         *location = 0;
119         *length = 0;
120         return;
121     }
122     run_->GetStringRange(location, length);
123 }
124 
GetStringIndices(int64_t start,int64_t length) const125 std::vector<uint64_t> RunImpl::GetStringIndices(int64_t start, int64_t length) const
126 {
127     if (run_ == nullptr || start < 0 || length < 0) {
128         return {};
129     }
130     return run_->GetStringIndices(start, length);
131 }
132 
GetImageBounds() const133 Drawing::Rect RunImpl::GetImageBounds() const
134 {
135     if (run_ == nullptr) {
136         return {};
137     }
138     return run_->GetImageBounds();
139 }
140 
GetTypographicBounds(float * ascent,float * descent,float * leading) const141 float RunImpl::GetTypographicBounds(float* ascent, float* descent, float* leading) const
142 {
143     if (ascent == nullptr || descent == nullptr || leading == nullptr) {
144         return 0.0;
145     } else if (run_ == nullptr) {
146         *ascent = 0.0;
147         *descent = 0.0;
148         *leading = 0.0;
149         return 0.0;
150     }
151     return run_->GetTypographicBounds(ascent, descent, leading);
152 }
153 } // namespace AdapterTxt
154 } // namespace Rosen
155 } // namespace OHOS
156