# Path Class

> A path in a PDF file defines shapes.

- Product: Adobe PDF Library 21
- Language: Modern C++
- Version: 21.4.0
- HTML page: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Path
- Version index: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/llms.txt

```cpp
class Path : Element
```

**Namespace:** `datalogics_interface`

**Inherits from:** [`Element`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Element.md)

## Description

A path in a PDF file defines shapes.

Paths in PDF files are used to draw lines, define filled areas, and define boundaries for clipping graphics. A path is composed of straight and curved line segments.

**Referenced by:** [`Path`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Path.md)

**Uses types:** [`Clip`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Clip.md), [`ElementCloneFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementCloneFlags.md), [`ElementType`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementType.md), [`GraphicState`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md), [`Matrix`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md), [`Path`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Path.md), [`PathPaintOp`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/PathPaintOp.md), [`Rect`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md)

## Constructors

### Path

```cpp
datalogics_interface::Path::Path()
```

*constructor*

Create a path.

### Path

```cpp
datalogics_interface::Path::Path(GraphicState gs)
```

*constructor*

**Parameters**

- `gs` ([`GraphicState`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md))

Create a path.

### Path

```cpp
datalogics_interface::Path::Path(Path &&) noexcept
```

*constructor*

**Parameters**

- (unnamed) ([`Path &&`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Path.md))

### ~Path

```cpp
datalogics_interface::Path::~Path() override
```

*destructor*

## Methods

### add_curve

```cpp
void datalogics_interface::Path::add_curve(const Point &p1, const Point &p2, const Point &p3)
```

**Parameters**

- `p1` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - first Bezier control point
- `p2` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - second Bezier control point
- `p3` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - the ending Point of the Bezier curve which will also be the current point of the current path.

**Returns:** `void`

Adds a Bezier curve from the current path using the first two points specified as Bezier control points ending at the third point. The new current point is then set to the third point.

### add_curve_v

```cpp
void datalogics_interface::Path::add_curve_v(const Point &p1, const Point &p2)
```

**Parameters**

- `p1` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - first Bezier control point
- `p2` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - the ending Point of the Bezier curve which will also be the new current point of the path.

**Returns:** `void`

Adds a Bezier curve from the current path. This extends from the current path to the point Point2 using the current point and the first point specified as Bezier control points ending at the second point. The new current point is then set to the second point.

### add_curve_y

```cpp
void datalogics_interface::Path::add_curve_y(const Point &p1, const Point &p2)
```

**Parameters**

- `p1` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - first Bezier control point
- `p2` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - second Bezier control point and the ending Point of the Bezier curve which will also be the new current point of the path.

**Returns:** `void`

Adds a Bezier curve from the current path. This extends from the current path to the point Point2 using the two points specified as Bezier control points ending at the second point. The new current point is then set to the second point.

### add_line

```cpp
void datalogics_interface::Path::add_line(const Point &pt)
```

**Parameters**

- `pt` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - the coordinates of the endpoint of the new line.

**Returns:** `void`

Adds a line to the current path from the current path position. The given point becomes the new current position.

### add_rect

```cpp
void datalogics_interface::Path::add_rect(const Point &pt, double width, double height)
```

**Parameters**

- `pt` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - the coordinates of the lower left corner of the new rectangle.
- `width` (`double`): - the width of the new rectangle.
- `height` (`double`): - the height of the new rectangle.

**Returns:** `void`

Adds a rectangle to the current path with the lower left corner at the give point, and with the width and height specified.

### clear_graphic_state

```cpp
void datalogics_interface::Path::clear_graphic_state()
```

**Returns:** `void`

Removes the graphic state from this path.

### clone

```cpp
std::unique_ptr< Path > datalogics_interface::Path::clone() const
```

**Returns:** [`std::unique_ptr< Path >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Path.md)

The copied path.

Makes a copy of the path.

Make a copy of an path to obtain a new path that has a distinct set of attributes.

### clone

```cpp
std::unique_ptr< Path > datalogics_interface::Path::clone(ElementCloneFlags flags) const
```

**Parameters**

- `flags` ([`ElementCloneFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementCloneFlags.md))

**Returns:** [`std::unique_ptr< Path >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Path.md)

The copied path.

Makes a copy of the path.

Make a copy of an path to obtain a new path that has a distinct set of attributes.

### close_path

```cpp
void datalogics_interface::Path::close_path()
```

**Returns:** `void`

Closes the current subpath.

### get_bounding_box

```cpp
Rect datalogics_interface::Element::get_bounding_box() const
```

**Returns:** [`Rect`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md)

The bounding box for this element. The coordinates of the bounding box are specified in user space coordinates, relative to the element's Content. Note that user space coordinates correspond to unrotated pages; any rotation specified in the page dictionary is not taken into account.

The bounding box for this element.

The bounding box is a rectangle that is guaranteed to encompass the element, but it is not guaranteed to be the smallest box that could contain the element. For example, if the element is a Path that contains an arc, the bounding box encompasses the bezier control points, and not just the curve itself.

### get_clip

```cpp
std::unique_ptr< Clip > datalogics_interface::Element::get_clip()
```

**Returns:** [`std::unique_ptr< Clip >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Clip.md)

The current Clip for this Element, or NULL if no clip is set.

Gets the current Clip for an Element.

### get_element_type

```cpp
ElementType datalogics_interface::Element::get_element_type() const
```

**Returns:** [`ElementType`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementType.md)

Returns the runtime type of this element.

### get_graphic_state

```cpp
std::unique_ptr< GraphicState > datalogics_interface::Path::get_graphic_state()
```

**Returns:** [`std::unique_ptr< GraphicState >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md)

The graphic state, or nullptr if none is set.

Get the graphic state of the current path.

May return null if this element does not have a GraphicState.

### get_matrix

```cpp
Matrix datalogics_interface::Element::get_matrix() const
```

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md)

The current transformation matrix applied to this element.

The transformation matrix for the element.

### get_paint_op

```cpp
PathPaintOp datalogics_interface::Path::get_paint_op() const
```

**Returns:** [`PathPaintOp`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/PathPaintOp.md)

the PathPaintOpFlags flags describing the fill and stroke attributes.

Gets the fill and stroke attributes of a path.

### get_segments

```cpp
std::vector< std::shared_ptr< Segment > > datalogics_interface::Path::get_segments() const
```

**Returns:** [`std::vector< std::shared_ptr< Segment > >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Segment.md)

Get the segments of the path.

Returns a list of Segment objects, one for each segment in the path.

### move_to

```cpp
void datalogics_interface::Path::move_to(const Point &pt)
```

**Parameters**

- `pt` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): - the coordinates of the new current point.

**Returns:** `void`

Moves the current point of the path to the given point.

### operator=

```cpp
Path & datalogics_interface::Path::operator=(Path &&) noexcept
```

**Parameters**

- (unnamed) ([`Path &&`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Path.md))

**Returns:** [`Path &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Path.md)

### rotate

```cpp
void datalogics_interface::Element::rotate(double theta)
```

**Parameters**

- `theta` (`double`): The rotation angle in degrees.

**Returns:** `void`

Rotate an element by theta degrees counterclockwise using the matrix [ cos T sin T -sin T cos T 0 0 ].

### scale

```cpp
void datalogics_interface::Element::scale(double sx, double sy)
```

**Parameters**

- `sx` (`double`): The horizontal scale factor.
- `sy` (`double`): The vertical scale factor.

**Returns:** `void`

Scale an element by (sx,sy) units using the matrix [ sx 0 0 sy 0 0 ].

### set_clip

```cpp
void datalogics_interface::Element::set_clip(Clip &clip)
```

**Parameters**

- `clip` ([`Clip &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Clip.md)): The clip to set as the current clip for this element, or NULL to remove clipping.

**Returns:** `void`

Sets the current Clip for an Element.

### set_graphic_state

```cpp
void datalogics_interface::Path::set_graphic_state(const GraphicState &gs)
```

**Parameters**

- `gs` ([`const GraphicState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md)): - the new/updated Graphic State for the path.

**Returns:** `void`

Set the Graphic State of the current path.

**Note:** The Path copies the graphic state internally.

### set_matrix

```cpp
void datalogics_interface::Element::set_matrix(const Matrix &matrix)
```

**Parameters**

- `matrix` ([`const Matrix &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md)): The transformation matrix for the element.

**Returns:** `void`

Set the transformation matrix for the element.

### set_paint_op

```cpp
void datalogics_interface::Path::set_paint_op(PathPaintOp op)
```

**Parameters**

- `op` ([`PathPaintOp`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/PathPaintOp.md)): - the flags describing the fill and stroke attributes.

**Returns:** `void`

Sets the fill and stroke attributes of a path.

### translate

```cpp
void datalogics_interface::Element::translate(double tx, double ty)
```

**Parameters**

- `tx` (`double`): The horizontal translation distance in user space units.
- `ty` (`double`): The vertical translation distance in user space units.

**Returns:** `void`

Translate an element by (tx,ty) units using the matrix [ 1 0 0 1 tx ty ].

### try_as

```cpp
T * datalogics_interface::Element::try_as()
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `T *`

Attempt to downcast this element to a derived type. Returns a pointer to the derived type, or nullptr if the type doesn't match.

### try_as

```cpp
const T * datalogics_interface::Element::try_as() const
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `const T *`

Const overload of try_as(). Returns a const pointer, or nullptr.
