Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
path-util.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors:
6 * see git history
7 * Created by fred on Fri Dec 05 2003.
8 * tweaked endlessly by bulia byak <buliabyak@users.sf.net>
9 *
10 * Copyright (C) 2018 Authors
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
14#include "path-util.h"
15#include "path/path-boolop.h"
16#include "text-editing.h"
17#include "livarot/Path.h"
18#include "display/curve.h"
19
20#include "object/sp-flowtext.h"
21#include "object/sp-image.h"
22#include "object/sp-path.h"
23#include "object/sp-text.h"
24
25std::unique_ptr<Path> Path_for_pathvector(Geom::PathVector const &pathv)
26{
27 auto dest = std::make_unique<Path>();
28 dest->LoadPathVector(pathv);
29 return dest;
30}
31
32std::unique_ptr<Path> Path_for_item(SPItem *item, bool doTransformation, bool transformFull)
33{
35
36 if (!curve) {
37 return nullptr;
38 }
39
40 auto pathv = pathvector_for_curve(item, *curve, doTransformation, transformFull);
41
42 return Path_for_pathvector(pathv);
43}
44
45std::unique_ptr<Path> Path_for_item_before_LPE(SPItem *item, bool doTransformation, bool transformFull)
46{
48
49 if (!curve) {
50 return nullptr;
51 }
52
53 auto pathv = pathvector_for_curve(item, *curve, doTransformation, transformFull);
54
55 return Path_for_pathvector(pathv);
56}
57
58Geom::PathVector pathvector_for_curve(SPItem *item, Geom::PathVector const &curve, bool doTransformation, bool transformFull)
59{
60 auto result = curve;
61
62 if (doTransformation) {
63 if (transformFull) {
65 } else {
67 }
68 }
69
70 return result;
71}
72
73std::optional<Geom::PathVector> curve_for_item(SPItem *item)
74{
75 if (!item) {
76 return {};
77 }
78
79 if (auto path = cast<SPPath>(item)) {
80 return ptr_to_opt(path->curveForEdit());
81 } else if (auto shape = cast<SPShape>(item)) {
82 return ptr_to_opt(shape->curve());
83 } else if (is<SPText>(item) || is<SPFlowtext>(item)) {
84 return te_get_layout(item)->convertToCurves();
85 } else if (auto image = cast<SPImage>(item)) {
86 return ptr_to_opt(image->get_curve());
87 }
88
89 return {};
90}
91
92std::optional<Geom::PathVector> curve_for_item_before_LPE(SPItem *item)
93{
94 if (!item) {
95 return {};
96 }
97
98 if (auto shape = cast<SPShape>(item)) {
99 return ptr_to_opt(shape->curveForEdit());
100 } else if (is<SPText>(item) || is<SPFlowtext>(item)) {
101 return te_get_layout(item)->convertToCurves();
102 } else if (auto image = cast<SPImage>(item)) {
103 return ptr_to_opt(image->get_curve());
104 }
105
106 return {};
107}
108
109std::optional<Path::cut_position> get_nearest_position_on_Path(Path *path, Geom::Point p, unsigned seg)
110{
111 if (!path) {
112 return {};
113 }
114 // Get nearest position on path.
115 return path->PointToCurvilignPosition(p, seg);
116}
117
118Geom::Point get_point_on_Path(Path *path, int piece, double t)
119{
120 Geom::Point p;
121 path->PointAt(piece, t, p);
122 return p;
123}
124
125std::optional<Geom::PathVector> intersect_clips(std::optional<Geom::PathVector> &&a, std::optional<Geom::PathVector> &&b)
126{
127 if (!a) return std::move(b);
128 if (!b) return std::move(a);
129 if (a->empty()) return std::move(a);
130 if (b->empty()) return std::move(b);
132}
133
134/*
135 Local Variables:
136 mode:c++
137 c-file-style:"stroustrup"
138 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
139 indent-tabs-mode:nil
140 fill-column:99
141 End:
142*/
143// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
@ fill_nonZero
Definition LivarotDefs.h:70
@ bool_op_inters
Definition LivarotDefs.h:79
TODO: insert short description here.
Sequence of subpaths.
Definition pathvector.h:122
Two-dimensional point that doubles as a vector.
Definition point.h:66
Path and its polyline approximation.
Definition Path.h:93
cut_position PointToCurvilignPosition(Geom::Point const &pos, unsigned seg=0) const
void PointAt(int piece, double at, Geom::Point &pos)
Definition Path.cpp:328
Base class for visual SVG elements.
Definition sp-item.h:109
Geom::Affine transform
Definition sp-item.h:138
Geom::Affine i2doc_affine() const
Returns the accumulated transformation of the item and all its ancestors, including root's viewport.
Definition sp-item.cpp:1824
Css & result
auto ptr_to_opt(T const &p)
Create a std::optional<T> from a (generalised) pointer to T.
Definition curve.h:90
std::unique_ptr< Magick::Image > image
SPItem * item
Geom::PathVector sp_pathvector_boolop(Geom::PathVector const &pathva, Geom::PathVector const &pathvb, BooleanOp bop, FillRule fra, FillRule frb)
Perform a boolean operation on two pathvectors.
Boolean operations.
Geom::Point get_point_on_Path(Path *path, int piece, double t)
Gets the point at a particular time in a particular piece in a path description.
std::optional< Geom::PathVector > curve_for_item(SPItem *item)
Gets an SPCurve from the SPItem.
Definition path-util.cpp:73
std::optional< Path::cut_position > get_nearest_position_on_Path(Path *path, Geom::Point p, unsigned seg)
Get the nearest position given a Livarot Path and a point.
std::unique_ptr< Path > Path_for_pathvector(Geom::PathVector const &pathv)
Creates a Livarot Path object from the Geom::PathVector.
Definition path-util.cpp:25
std::unique_ptr< Path > Path_for_item_before_LPE(SPItem *item, bool doTransformation, bool transformFull)
Creates a Livarot Path object from the SPItem.
Definition path-util.cpp:45
std::optional< Geom::PathVector > intersect_clips(std::optional< Geom::PathVector > &&a, std::optional< Geom::PathVector > &&b)
Intersect two clips, treating empty optionals as no clip.
std::optional< Geom::PathVector > curve_for_item_before_LPE(SPItem *item)
Gets an SPCurve from the SPItem before any LPE.
Definition path-util.cpp:92
Geom::PathVector pathvector_for_curve(SPItem *item, Geom::PathVector const &curve, bool doTransformation, bool transformFull)
Gets a Geom::PathVector from the SPCurve object.
Definition path-util.cpp:58
std::unique_ptr< Path > Path_for_item(SPItem *item, bool doTransformation, bool transformFull)
Creates a Livarot Path object from an SPItem.
Definition path-util.cpp:32
Path utilities.
TODO: insert short description here.
SVG <image> implementation.
Definition curve.h:24
Text::Layout const * te_get_layout(SPItem const *item)