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