From 117336bcc334c1d380b7592f1639c1a586a28559 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Sat, 12 Jul 2008 14:45:33 +0000 Subject: [PATCH] enable writing "H/h" and "V/v" to SVG ! --- src/svg/path-string.cpp | 10 ++++++++++ src/svg/path-string.h | 20 ++++++++++++++++---- src/svg/svg-path.cpp | 7 ++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/svg/path-string.cpp b/src/svg/path-string.cpp index 39d66d74e..68fcb26d8 100644 --- a/src/svg/path-string.cpp +++ b/src/svg/path-string.cpp @@ -84,6 +84,11 @@ void Inkscape::SVG::PathString::State::append(NR::Point p, NR::Point &rp) { appendCoord(str, p[NR::Y], rp[NR::Y]); } +void Inkscape::SVG::PathString::State::append(NR::Coord v, NR::Coord& rv) { + str += ' '; + appendCoord(str, v, rv); +} + // NOTE: The following two appendRelative methods will not be exact if the total number of digits needed // to represent the difference exceeds the precision of a double. This is not very likely though, and if // it does happen the imprecise value is not likely to be chosen (because it will probably be a lot longer @@ -138,6 +143,11 @@ void Inkscape::SVG::PathString::State::appendRelative(NR::Point p, NR::Point r) appendRelativeCoord(str, p[NR::Y], r[NR::Y]); } +void Inkscape::SVG::PathString::State::appendRelative(NR::Coord v, NR::Coord r) { + str += ' '; + appendRelativeCoord(str, v, r); +} + /* Local Variables: mode:c++ diff --git a/src/svg/path-string.h b/src/svg/path-string.h index 39d6d3f07..bba4c8473 100644 --- a/src/svg/path-string.h +++ b/src/svg/path-string.h @@ -65,6 +65,18 @@ public: return *this; } + PathString &horizontalLineTo(NR::Coord x) { + _appendOp('H','h'); + _appendX(x, true); + return *this; + } + + PathString &verticalLineTo(NR::Coord y) { + _appendOp('V','v'); + _appendY(y, true); + return *this; + } + PathString &quadTo(NR::Coord cx, NR::Coord cy, NR::Coord x, NR::Coord y) { return quadTo(NR::Point(cx, cy), NR::Point(x, y)); } @@ -129,7 +141,7 @@ private: _abs_state.append(p); _rel_state.append(p); } -/* + void _appendX(NR::Coord x, bool sc) { double rx; _abs_state.append(x, rx); @@ -142,7 +154,7 @@ private: _abs_state.append(y, ry); _rel_state.appendRelative(ry, _current_point[NR::Y]); if (sc) _current_point[NR::Y] = ry; - }*/ + } void _appendPoint(NR::Point p, bool sc) { NR::Point rp; @@ -167,9 +179,9 @@ private: void append(NR::Coord v); void append(NR::Point v); - //void append(NR::Coord v, NR::Coord& rv); + void append(NR::Coord v, NR::Coord& rv); void append(NR::Point p, NR::Point& rp); - //void appendRelative(NR::Coord v, NR::Coord r); + void appendRelative(NR::Coord v, NR::Coord r); void appendRelative(NR::Point p, NR::Point r); bool operator<=(const State& s) const { diff --git a/src/svg/svg-path.cpp b/src/svg/svg-path.cpp index 3deb6105c..a57b9248c 100644 --- a/src/svg/svg-path.cpp +++ b/src/svg/svg-path.cpp @@ -762,11 +762,12 @@ static void sp_svg_write_curve(Inkscape::SVG::PathString & str, Geom::Curve cons svg_elliptical_arc->rotation_angle(), svg_elliptical_arc->large_arc_flag(), svg_elliptical_arc->sweep_flag(), svg_elliptical_arc->finalPoint() ); -/* else if(Geom::HLineSegment const *hline_segment = dynamic_cast(c)) { - str.horizontalLineTo( ... ); + } + else if(Geom::HLineSegment const *hline_segment = dynamic_cast(c)) { + str.horizontalLineTo( hline_segment->finalPoint()[0] ); } else if(Geom::VLineSegment const *vline_segment = dynamic_cast(c)) { - str.verticalLineTo( ... ); */ + str.verticalLineTo( vline_segment->finalPoint()[1] ); } else { //this case handles sbasis as well as all other curve types Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c->toSBasis(), 0.1); -- 2.30.2