1 // Copyright 2016 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FXGE_CFX_PATH_H_ 8 #define CORE_FXGE_CFX_PATH_H_ 9 10 #include <stdint.h> 11 12 #include <vector> 13 14 #include "core/fxcrt/fx_coordinates.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "third_party/abseil-cpp/absl/types/optional.h" 17 18 class CFX_Path { 19 public: 20 class Point { 21 public: 22 enum class Type : uint8_t { kLine, kBezier, kMove }; 23 24 Point(); 25 Point(const CFX_PointF& point, Type type, bool close); 26 Point(const Point& other); 27 ~Point(); 28 IsTypeAndOpen(Type type)29 bool IsTypeAndOpen(Type type) const { 30 return m_Type == type && !m_CloseFigure; 31 } 32 33 CFX_PointF m_Point; 34 Type m_Type = Type::kLine; 35 bool m_CloseFigure = false; 36 }; 37 38 CFX_Path(); 39 CFX_Path(const CFX_Path& src); 40 CFX_Path(CFX_Path&& src) noexcept; 41 ~CFX_Path(); 42 43 void Clear(); 44 GetType(size_t index)45 Point::Type GetType(size_t index) const { return m_Points[index].m_Type; } IsClosingFigure(size_t index)46 bool IsClosingFigure(size_t index) const { 47 return m_Points[index].m_CloseFigure; 48 } GetPoint(size_t index)49 CFX_PointF GetPoint(size_t index) const { return m_Points[index].m_Point; } GetPoints()50 const std::vector<Point>& GetPoints() const { return m_Points; } GetPoints()51 std::vector<Point>& GetPoints() { return m_Points; } 52 53 CFX_FloatRect GetBoundingBox() const; 54 CFX_FloatRect GetBoundingBoxForStrokePath(float line_width, 55 float miter_limit) const; 56 57 void Transform(const CFX_Matrix& matrix); 58 bool IsRect() const; 59 absl::optional<CFX_FloatRect> GetRect(const CFX_Matrix* matrix) const; 60 61 void Append(const CFX_Path& src, const CFX_Matrix* matrix); 62 void AppendFloatRect(const CFX_FloatRect& rect); 63 void AppendRect(float left, float bottom, float right, float top); 64 void AppendLine(const CFX_PointF& pt1, const CFX_PointF& pt2); 65 void AppendPoint(const CFX_PointF& point, Point::Type type); 66 void AppendPointAndClose(const CFX_PointF& point, Point::Type type); 67 void ClosePath(); 68 69 private: 70 std::vector<Point> m_Points; 71 }; 72 73 class CFX_RetainablePath final : public Retainable, public CFX_Path { 74 public: 75 CONSTRUCT_VIA_MAKE_RETAIN; 76 77 RetainPtr<CFX_RetainablePath> Clone() const; 78 79 private: 80 CFX_RetainablePath(); 81 CFX_RetainablePath(const CFX_RetainablePath& src); 82 ~CFX_RetainablePath() override; 83 }; 84 85 #endif // CORE_FXGE_CFX_PATH_H_ 86