• 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 #ifndef ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_PATH_H
17 #define ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_PATH_H
18 
19 #include <memory>
20 
21 #ifndef USE_ROSEN_DRAWING
22 #include <include/core/SkPath.h>
23 #else
24 #include "drawing.h"
25 #endif
26 
27 #include "texgine_rect.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace TextEngine {
32 enum class TexginePathDirection {
33     K_CW,  // clockwise direction for adding closed contours
34     K_CCW, // counter-clockwise direction for adding closed contours
35 };
36 
37 struct TexginePoint {
38     float fX;
39     float fY;
40 };
41 
42 class TexginePath {
43 public:
44     /*
45      * @brief Returns the SkPath that user sets to TexginePath or TexginePath`s own SkPath
46      */
47 #ifndef USE_ROSEN_DRAWING
48     std::shared_ptr<SkPath> GetPath() const;
49 #else
50     std::shared_ptr<RSPath> GetPath() const;
51 #endif
52 
53     /*
54      * @brief Sets SkPath to TexginePath
55      */
56 #ifndef USE_ROSEN_DRAWING
57     void SetPath(const std::shared_ptr<SkPath> path);
58 #else
59     void SetPath(const std::shared_ptr<RSPath> path);
60 #endif
61 
62     /*
63      * @brief Adds oval to path, Oval is upright ellipse bounded by SkRect oval with
64      *        radii equal to half oval width and half oval height
65      * @param oval The boundary of the added ellipse
66      * @param dir TexginePathDirection to wind ellipse
67      * @return reference to SkPath
68      */
69     TexginePath &AddOval(const TexgineRect &oval, TexginePathDirection dir = TexginePathDirection::K_CW);
70 
71     /*
72      * @brief Add contour start point at SkPoint p
73      * @param p contour start
74      * @return reference to SkPath
75      */
76     TexginePath &MoveTo(const TexginePoint &p);
77 
78     /*
79      * @brief Add a quadrilateral from the last point to SkPoint p1 to SkPoint p2
80      * @param p1 Control the SkPoint of added quadrilaterals
81      * @param p2 The end of SkPoint added quad
82      */
83     TexginePath &QuadTo(const TexginePoint &p1, const TexginePoint &p2);
84 
85     /*
86      * @brief Adds line from last point to SkPoint p
87      * @param  end SkPoint of added line
88      */
89     TexginePath &LineTo(const TexginePoint &p);
90 
91 private:
92 #ifndef USE_ROSEN_DRAWING
93     std::shared_ptr<SkPath> path_ = std::make_shared<SkPath>();
94 #else
95     std::shared_ptr<RSPath> path_ = std::make_shared<RSPath>();
96 #endif
97 };
98 } // namespace TextEngine
99 } // namespace Rosen
100 } // namespace OHOS
101 
102 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_PATH_H
103