1 // Copyright 2016 PDFium Authors. All rights reserved. 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_PATHDATA_H_ 8 #define CORE_FXGE_CFX_PATHDATA_H_ 9 10 #include <vector> 11 12 #include "core/fxcrt/fx_coordinates.h" 13 #include "core/fxcrt/fx_system.h" 14 #include "core/fxcrt/retain_ptr.h" 15 16 enum class FXPT_TYPE : uint8_t { LineTo, BezierTo, MoveTo }; 17 18 class FX_PATHPOINT { 19 public: 20 FX_PATHPOINT(); 21 FX_PATHPOINT(const CFX_PointF& point, FXPT_TYPE type, bool close); 22 FX_PATHPOINT(const FX_PATHPOINT& other); 23 ~FX_PATHPOINT(); 24 IsTypeAndOpen(FXPT_TYPE type)25 bool IsTypeAndOpen(FXPT_TYPE type) const { 26 return m_Type == type && !m_CloseFigure; 27 } 28 29 CFX_PointF m_Point; 30 FXPT_TYPE m_Type; 31 bool m_CloseFigure; 32 }; 33 34 class CFX_PathData { 35 public: 36 CFX_PathData(); 37 CFX_PathData(const CFX_PathData& src); 38 CFX_PathData(CFX_PathData&& src); 39 ~CFX_PathData(); 40 41 void Clear(); 42 GetType(int index)43 FXPT_TYPE GetType(int index) const { return m_Points[index].m_Type; } IsClosingFigure(int index)44 bool IsClosingFigure(int index) const { 45 return m_Points[index].m_CloseFigure; 46 } 47 GetPoint(int index)48 CFX_PointF GetPoint(int index) const { return m_Points[index].m_Point; } GetPoints()49 const std::vector<FX_PATHPOINT>& GetPoints() const { return m_Points; } GetPoints()50 std::vector<FX_PATHPOINT>& GetPoints() { return m_Points; } 51 52 CFX_FloatRect GetBoundingBox() const; 53 CFX_FloatRect GetBoundingBox(float line_width, float miter_limit) const; 54 55 void Transform(const CFX_Matrix& matrix); 56 bool IsRect() const; 57 bool GetZeroAreaPath(const CFX_Matrix* pMatrix, 58 bool bAdjust, 59 CFX_PathData* NewPath, 60 bool* bThin, 61 bool* setIdentity) const; 62 bool IsRect(const CFX_Matrix* pMatrix, CFX_FloatRect* rect) const; 63 64 void Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix); 65 void AppendFloatRect(const CFX_FloatRect& rect); 66 void AppendRect(float left, float bottom, float right, float top); 67 void AppendLine(const CFX_PointF& pt1, const CFX_PointF& pt2); 68 void AppendPoint(const CFX_PointF& point, FXPT_TYPE type, bool closeFigure); 69 void ClosePath(); 70 71 private: 72 std::vector<FX_PATHPOINT> m_Points; 73 }; 74 75 class CFX_RetainablePathData final : public Retainable, public CFX_PathData { 76 public: 77 template <typename T, typename... Args> 78 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 79 80 RetainPtr<CFX_RetainablePathData> Clone() const; 81 82 private: 83 CFX_RetainablePathData(); 84 CFX_RetainablePathData(const CFX_RetainablePathData& src); 85 ~CFX_RetainablePathData() override; 86 }; 87 88 #endif // CORE_FXGE_CFX_PATHDATA_H_ 89