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
21 namespace OHOS {
22 namespace Rosen {
23 namespace AdapterTxt {
RunImpl(std::unique_ptr<SPText::Run> run)24 RunImpl::RunImpl(std::unique_ptr<SPText::Run> run): run_(std::move(run))
25 {
26 }
27
GetFont() const28 Drawing::Font RunImpl::GetFont() const
29 {
30 if (!run_) {
31 return {};
32 }
33 return run_->GetFont();
34 }
35
GetGlyphCount() const36 size_t RunImpl::GetGlyphCount() const
37 {
38 if (!run_) {
39 return 0;
40 }
41 return run_->GetGlyphCount();
42 }
43
GetGlyphs() const44 std::vector<uint16_t> RunImpl::GetGlyphs() const
45 {
46 if (!run_) {
47 return {};
48 }
49 return run_->GetGlyphs();
50 }
51
GetPositions()52 std::vector<Drawing::Point> RunImpl::GetPositions()
53 {
54 if (!run_) {
55 return {};
56 }
57 return run_->GetPositions();
58 }
59
GetOffsets()60 std::vector<Drawing::Point> RunImpl::GetOffsets()
61 {
62 if (!run_) {
63 return {};
64 }
65 return run_->GetOffsets();
66 }
67
Paint(Drawing::Canvas * canvas,double x,double y)68 void RunImpl::Paint(Drawing::Canvas *canvas, double x, double y)
69 {
70 if (!run_) {
71 return;
72 }
73 return run_->Paint(canvas, x, y);
74 }
75
GetGlyphs(int64_t start,int64_t length) const76 std::vector<uint16_t> RunImpl::GetGlyphs(int64_t start, int64_t length) const
77 {
78 if (run_ == nullptr || start < 0 || length < 0) {
79 return {};
80 }
81 return run_->GetGlyphs(start, length);
82 }
83
GetPositions(int64_t start,int64_t length) const84 std::vector<Drawing::Point> RunImpl::GetPositions(int64_t start, int64_t length) const
85 {
86 if (run_ == nullptr || start < 0 || length < 0) {
87 return {};
88 }
89 return run_->GetPositions(start, length);
90 }
91
GetStringRange(uint64_t * location,uint64_t * length) const92 void RunImpl::GetStringRange(uint64_t* location, uint64_t* length) const
93 {
94 if (location == nullptr || length == nullptr) {
95 return;
96 } else if (run_ == nullptr) {
97 *location = 0;
98 *length = 0;
99 return;
100 }
101 run_->GetStringRange(location, length);
102 }
103
GetStringIndices(int64_t start,int64_t length) const104 std::vector<uint64_t> RunImpl::GetStringIndices(int64_t start, int64_t length) const
105 {
106 if (run_ == nullptr || start < 0 || length < 0) {
107 return {};
108 }
109 return run_->GetStringIndices(start, length);
110 }
111
GetImageBounds() const112 Drawing::Rect RunImpl::GetImageBounds() const
113 {
114 if (run_ == nullptr) {
115 return {};
116 }
117 return run_->GetImageBounds();
118 }
119
GetTypographicBounds(float * ascent,float * descent,float * leading) const120 float RunImpl::GetTypographicBounds(float* ascent, float* descent, float* leading) const
121 {
122 if (ascent == nullptr || descent == nullptr || leading == nullptr) {
123 return 0.0;
124 } else if (run_ == nullptr) {
125 *ascent = 0.0;
126 *descent = 0.0;
127 *leading = 0.0;
128 return 0.0;
129 }
130 return run_->GetTypographicBounds(ascent, descent, leading);
131 }
132 } // namespace AdapterTxt
133 } // namespace Rosen
134 } // namespace OHOS
135