blob: 357df596560593dba4e383069171421362bbb7c2 [file] [log] [blame]
npm660de3c2016-08-08 08:18:29 -07001// 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
Lei Zhang36865762021-06-12 01:07:37 +00007#ifndef CORE_FXGE_CFX_PATH_H_
8#define CORE_FXGE_CFX_PATH_H_
npm660de3c2016-08-08 08:18:29 -07009
Tom Sepez1e7fd162021-07-27 20:44:31 +000010#include <stdint.h>
11
Dan Sinclaire4602322017-02-15 11:07:32 -050012#include <vector>
13
dsinclaira52ab742016-09-29 13:59:29 -070014#include "core/fxcrt/fx_coordinates.h"
Lei Zhang87d20212019-06-20 22:32:10 +000015#include "core/fxcrt/retain_ptr.h"
Lei Zhang455cf862021-10-08 01:01:50 +000016#include "third_party/abseil-cpp/absl/types/optional.h"
Lei Zhang87d20212019-06-20 22:32:10 +000017
Lei Zhang36865762021-06-12 01:07:37 +000018class CFX_Path {
npm660de3c2016-08-08 08:18:29 -070019 public:
Lei Zhang92bc6922021-06-12 02:45:37 +000020 class Point {
21 public:
Lei Zhang9b4b8df2021-06-12 06:38:48 +000022 enum class Type : uint8_t { kLine, kBezier, kMove };
23
Lei Zhang92bc6922021-06-12 02:45:37 +000024 Point();
Lei Zhang9b4b8df2021-06-12 06:38:48 +000025 Point(const CFX_PointF& point, Type type, bool close);
Lei Zhang92bc6922021-06-12 02:45:37 +000026 Point(const Point& other);
27 ~Point();
28
Lei Zhang9b4b8df2021-06-12 06:38:48 +000029 bool IsTypeAndOpen(Type type) const {
Lei Zhang92bc6922021-06-12 02:45:37 +000030 return m_Type == type && !m_CloseFigure;
31 }
32
33 CFX_PointF m_Point;
Lei Zhang9b4b8df2021-06-12 06:38:48 +000034 Type m_Type;
Lei Zhang92bc6922021-06-12 02:45:37 +000035 bool m_CloseFigure;
36 };
37
Lei Zhang36865762021-06-12 01:07:37 +000038 CFX_Path();
39 CFX_Path(const CFX_Path& src);
40 CFX_Path(CFX_Path&& src) noexcept;
41 ~CFX_Path();
npm660de3c2016-08-08 08:18:29 -070042
Dan Sinclaire4602322017-02-15 11:07:32 -050043 void Clear();
npm660de3c2016-08-08 08:18:29 -070044
Tom Sepez690f3892021-12-21 01:44:08 +000045 Point::Type GetType(size_t index) const { return m_Points[index].m_Type; }
46 bool IsClosingFigure(size_t index) const {
Dan Sinclaire4602322017-02-15 11:07:32 -050047 return m_Points[index].m_CloseFigure;
48 }
Tom Sepez690f3892021-12-21 01:44:08 +000049 CFX_PointF GetPoint(size_t index) const { return m_Points[index].m_Point; }
Lei Zhang92bc6922021-06-12 02:45:37 +000050 const std::vector<Point>& GetPoints() const { return m_Points; }
51 std::vector<Point>& GetPoints() { return m_Points; }
Dan Sinclaire4602322017-02-15 11:07:32 -050052
npm660de3c2016-08-08 08:18:29 -070053 CFX_FloatRect GetBoundingBox() const;
Lei Zhangced8cbe2021-05-25 03:18:13 +000054 CFX_FloatRect GetBoundingBoxForStrokePath(float line_width,
55 float miter_limit) const;
Dan Sinclaire4602322017-02-15 11:07:32 -050056
Tom Sepez23078b52018-12-20 18:07:53 +000057 void Transform(const CFX_Matrix& matrix);
tsepez12f3e4a2016-11-02 15:17:29 -070058 bool IsRect() const;
Lei Zhang2c495302021-10-07 23:13:30 +000059 absl::optional<CFX_FloatRect> GetRect(const CFX_Matrix* matrix) const;
Dan Sinclaire4602322017-02-15 11:07:32 -050060
Lei Zhang36865762021-06-12 01:07:37 +000061 void Append(const CFX_Path& src, const CFX_Matrix* matrix);
Lei Zhang5b79f162019-09-19 13:19:05 +000062 void AppendFloatRect(const CFX_FloatRect& rect);
Dan Sinclair05df0752017-03-14 14:43:42 -040063 void AppendRect(float left, float bottom, float right, float top);
Dan Sinclair7ffb59f2017-08-10 10:16:06 -040064 void AppendLine(const CFX_PointF& pt1, const CFX_PointF& pt2);
Lei Zhang9b4b8df2021-06-12 06:38:48 +000065 void AppendPoint(const CFX_PointF& point, Point::Type type);
66 void AppendPointAndClose(const CFX_PointF& point, Point::Type type);
Dan Sinclaire4602322017-02-15 11:07:32 -050067 void ClosePath();
npm660de3c2016-08-08 08:18:29 -070068
69 private:
Lei Zhang92bc6922021-06-12 02:45:37 +000070 std::vector<Point> m_Points;
npm660de3c2016-08-08 08:18:29 -070071};
72
Lei Zhang36865762021-06-12 01:07:37 +000073class CFX_RetainablePath final : public Retainable, public CFX_Path {
Tom Sepezca4a5ff2019-01-29 00:06:20 +000074 public:
Tom Sepezb9d9b612020-06-17 20:47:22 +000075 CONSTRUCT_VIA_MAKE_RETAIN;
Tom Sepezca4a5ff2019-01-29 00:06:20 +000076
Lei Zhang36865762021-06-12 01:07:37 +000077 RetainPtr<CFX_RetainablePath> Clone() const;
Tom Sepezd26eeec2019-06-21 18:47:02 +000078
Tom Sepezca4a5ff2019-01-29 00:06:20 +000079 private:
Lei Zhang36865762021-06-12 01:07:37 +000080 CFX_RetainablePath();
81 CFX_RetainablePath(const CFX_RetainablePath& src);
82 ~CFX_RetainablePath() override;
Tom Sepezca4a5ff2019-01-29 00:06:20 +000083};
84
Lei Zhang36865762021-06-12 01:07:37 +000085#endif // CORE_FXGE_CFX_PATH_H_