1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /** @file 3 * TODO: insert short description here 4 *//* 5 * Authors: see git history 6 * 7 * Copyright (C) 2018 Authors 8 * Released under GNU GPL v2+, read the file 'COPYING' for more information. 9 */ 10 #ifndef SEEN_INKSCAPE_LIVAROT_PATH_DESCRIPTION_H 11 #define SEEN_INKSCAPE_LIVAROT_PATH_DESCRIPTION_H 12 13 #include <2geom/point.h> 14 #include "svg/stringstream.h" 15 16 // path description commands 17 /* FIXME: these should be unnecessary once the refactoring of the path 18 ** description stuff is finished. 19 */ 20 enum 21 { 22 descr_moveto = 0, // a moveto 23 descr_lineto = 1, // a (guess what) lineto 24 descr_cubicto = 2, 25 descr_bezierto = 3, // "beginning" of a quadratic bezier spline, will contain its endpoint (i know, it's bad...) 26 descr_arcto = 4, 27 descr_close = 5, 28 descr_interm_bezier = 6, // control point of the bezier spline 29 descr_forced = 7, 30 31 descr_type_mask = 15 // the command no will be stored in a "flags" field, potentially with other info, so we need 32 // a mask to AND the field and extract the command 33 }; 34 35 struct PathDescr 36 { PathDescrPathDescr37 PathDescr() : flags(0), associated(-1), tSt(0), tEn(1) {} PathDescrPathDescr38 PathDescr(int f) : flags(f), associated(-1), tSt(0), tEn(1) {} 39 virtual ~PathDescr() = default; 40 getTypePathDescr41 int getType() const { return flags & descr_type_mask; } setTypePathDescr42 void setType(int t) { 43 flags &= ~descr_type_mask; 44 flags |= t; 45 } 46 dumpSVGPathDescr47 virtual void dumpSVG(Inkscape::SVGOStringStream &/*s*/, Geom::Point const &/*last*/) const {} 48 virtual PathDescr *clone() const = 0; transformPathDescr49 virtual void transform(Geom::Affine const &/*t*/) {} dumpPathDescr50 virtual void dump(std::ostream &/*s*/) const {} 51 52 int flags; // most notably contains the path command no 53 int associated; // index in the polyline of the point that ends the path portion of this command 54 double tSt; 55 double tEn; 56 }; 57 58 struct PathDescrMoveTo : public PathDescr 59 { PathDescrMoveToPathDescrMoveTo60 PathDescrMoveTo(Geom::Point const &pp) 61 : PathDescr(descr_moveto), p(pp) {} 62 63 void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const override; 64 PathDescr *clone() const override; 65 void transform(Geom::Affine const &t) override; 66 void dump(std::ostream &s) const override; 67 68 Geom::Point p; 69 }; 70 71 struct PathDescrLineTo : public PathDescr 72 { PathDescrLineToPathDescrLineTo73 PathDescrLineTo(Geom::Point const &pp) 74 : PathDescr(descr_lineto), p(pp) {} 75 76 void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const override; 77 PathDescr *clone() const override; 78 void transform(Geom::Affine const &t) override; 79 void dump(std::ostream &s) const override; 80 81 Geom::Point p; 82 }; 83 84 // quadratic bezier curves: a set of control points, and an endpoint 85 struct PathDescrBezierTo : public PathDescr 86 { PathDescrBezierToPathDescrBezierTo87 PathDescrBezierTo(Geom::Point const &pp, int n) 88 : PathDescr(descr_bezierto), p(pp), nb(n) {} 89 90 PathDescr *clone() const override; 91 void transform(Geom::Affine const &t) override; 92 void dump(std::ostream &s) const override; 93 94 Geom::Point p; // the endpoint's coordinates 95 int nb; // number of control points, stored in the next path description commands 96 }; 97 98 /* FIXME: I don't think this should be necessary */ 99 struct PathDescrIntermBezierTo : public PathDescr 100 { PathDescrIntermBezierToPathDescrIntermBezierTo101 PathDescrIntermBezierTo() 102 : PathDescr(descr_interm_bezier) , p(0, 0) {} PathDescrIntermBezierToPathDescrIntermBezierTo103 PathDescrIntermBezierTo(Geom::Point const &pp) 104 : PathDescr(descr_interm_bezier), p(pp) {} 105 106 PathDescr *clone() const override; 107 void transform(Geom::Affine const &t) override; 108 void dump(std::ostream &s) const override; 109 110 Geom::Point p; // control point coordinates 111 }; 112 113 // cubic spline curve: 2 tangents and one endpoint 114 struct PathDescrCubicTo : public PathDescr 115 { PathDescrCubicToPathDescrCubicTo116 PathDescrCubicTo(Geom::Point const &pp, Geom::Point const &s, Geom::Point const& e) 117 : PathDescr(descr_cubicto), p(pp), start(s), end(e) {} 118 119 void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const override; 120 PathDescr *clone() const override; 121 void transform(Geom::Affine const &t) override; 122 void dump(std::ostream &s) const override; 123 124 Geom::Point p; 125 Geom::Point start; 126 Geom::Point end; 127 }; 128 129 // arc: endpoint, 2 radii and one angle, plus 2 booleans to choose the arc (svg style) 130 struct PathDescrArcTo : public PathDescr 131 { PathDescrArcToPathDescrArcTo132 PathDescrArcTo(Geom::Point const &pp, double x, double y, double a, bool l, bool c) 133 : PathDescr(descr_arcto), p(pp), rx(x), ry(y), angle(a), large(l), clockwise(c) {} 134 135 void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const override; 136 PathDescr *clone() const override; 137 void transform(Geom::Affine const &t) override; 138 void dump(std::ostream &s) const override; 139 140 Geom::Point p; 141 double rx; 142 double ry; 143 double angle; 144 bool large; 145 bool clockwise; 146 }; 147 148 struct PathDescrForced : public PathDescr 149 { PathDescrForcedPathDescrForced150 PathDescrForced() : PathDescr(descr_forced), p(0, 0) {} 151 152 PathDescr *clone() const override; 153 154 /* FIXME: not sure whether _forced should have a point associated with it; 155 ** Path::ConvertForcedToMoveTo suggests that maybe it should. 156 */ 157 Geom::Point p; 158 }; 159 160 struct PathDescrClose : public PathDescr 161 { PathDescrClosePathDescrClose162 PathDescrClose() : PathDescr(descr_close) {} 163 164 void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const override; 165 PathDescr *clone() const override; 166 167 /* FIXME: not sure whether _forced should have a point associated with it; 168 ** Path::ConvertForcedToMoveTo suggests that maybe it should. 169 */ 170 Geom::Point p; 171 }; 172 173 #endif 174 175 176 /* 177 Local Variables: 178 mode:c++ 179 c-file-style:"stroustrup" 180 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 181 indent-tabs-mode:nil 182 fill-column:99 183 End: 184 */ 185 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 186