• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "texgine_path.h"
17 
18 namespace OHOS {
19 namespace Rosen {
20 namespace TextEngine {
21 #ifndef USE_ROSEN_DRAWING
GetPath() const22 std::shared_ptr<SkPath> TexginePath::GetPath() const
23 #else
24 std::shared_ptr<RSPath> TexginePath::GetPath() const
25 #endif
26 {
27     return path_;
28 }
29 
30 #ifndef USE_ROSEN_DRAWING
SetPath(const std::shared_ptr<SkPath> path)31 void TexginePath::SetPath(const std::shared_ptr<SkPath> path)
32 #else
33 void TexginePath::SetPath(const std::shared_ptr<RSPath> path)
34 #endif
35 {
36     path_ = path;
37 }
38 
AddOval(const TexgineRect & oval,TexginePathDirection dir)39 TexginePath &TexginePath::AddOval(const TexgineRect &oval, TexginePathDirection dir)
40 {
41     if (path_ != nullptr && oval.GetRect() != nullptr) {
42 #ifndef USE_ROSEN_DRAWING
43         path_->addOval(*oval.GetRect(), static_cast<SkPathDirection>(dir));
44 #else
45         path_->AddOval(*oval.GetRect(), static_cast<Drawing::PathDirection>(dir));
46 #endif
47     }
48     return *this;
49 }
50 
MoveTo(const TexginePoint & p)51 TexginePath &TexginePath::MoveTo(const TexginePoint &p)
52 {
53 #ifndef USE_ROSEN_DRAWING
54     if (path_ != nullptr) {
55         path_->moveTo(SkPoint { p.fX, p.fY });
56     }
57 #else
58     if (path_ != nullptr) {
59         path_->MoveTo(p.fX, p.fY);
60     }
61 #endif
62     return *this;
63 }
64 
QuadTo(const TexginePoint & p1,const TexginePoint & p2)65 TexginePath &TexginePath::QuadTo(const TexginePoint &p1, const TexginePoint &p2)
66 {
67 #ifndef USE_ROSEN_DRAWING
68     SkPoint point1({p1.fX, p1.fY});
69     SkPoint point2({p2.fX, p2.fY});
70     if (path_ != nullptr) {
71         path_->quadTo(point1, point2);
72     }
73 #else
74     RSPoint pointL(p1.fX, p1.fY);
75     RSPoint pointR(p2.fX, p2.fY);
76     if (path_ != nullptr) {
77         path_->QuadTo(pointL, pointR);
78     }
79 #endif
80     return *this;
81 }
82 
LineTo(const TexginePoint & p)83 TexginePath &TexginePath::LineTo(const TexginePoint &p)
84 {
85 #ifndef USE_ROSEN_DRAWING
86     if (path_ != nullptr) {
87         path_->lineTo(SkPoint { p.fX, p.fY });
88     }
89 #else
90     if (path_ != nullptr) {
91         path_->LineTo(p.fX, p.fY);
92     }
93 #endif
94     return *this;
95 }
96 } // namespace TextEngine
97 } // namespace Rosen
98 } // namespace OHOS
99