Commit 44800cf6 authored by RazrFalcon's avatar RazrFalcon

Fixed SmoothCurveTo and SmoothQuadratic conversion.

parent 64a5fabb
......@@ -28,6 +28,7 @@ This changelog also contains important changes in dependencies.
- (usvg) Groups regrouping. Caused an incorrect rendering of `clipPath`
that had `filter` on a child.
- (usvg) Style attributes resolving on the root `svg` element.
- (usvg) `SmoothCurveTo` and `SmoothQuadratic` conversion.
- (qt-backend) Stroking of LineTo specified as CurveTo.
- (svgdom) `stroke-miterlimit` attribute parsing.
- (svgdom) `length` and `number` attribute types parsing.
......
e-filter-061.svg
e-filter-062.svg
e-mask-016.svg
e-pattern-024.svg
e-path-044.svg
e-path-045.svg
e-filter-061.svg
e-filter-062.svg
e-mask-016.svg
e-pattern-024.svg
e-path-044.svg
e-path-045.svg
......@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Coordinates resolving when units are `userSpaceOnUse`.
- Groups regrouping.
- Style attributes resolving on the root `svg` element.
- `SmoothCurveTo` and `SmoothQuadratic` conversion.
### Removed
- `Rect::transform`.
......
......@@ -74,10 +74,10 @@ fn convert_path(mut path: svgdom::Path) -> Vec<tree::PathSegment> {
let mut py = 0.0;
// Previous SmoothQuadratic coordinates.
let mut ptx = None;
let mut pty = None;
let mut ptx = 0.0;
let mut pty = 0.0;
for seg in path.iter() {
for (idx, seg) in path.iter().enumerate() {
match *seg {
svgdom::PathSegment::MoveTo { x, y, .. } => {
new_path.push(tree::PathSegment::MoveTo { x, y });
......@@ -100,28 +100,21 @@ fn convert_path(mut path: svgdom::Path) -> Vec<tree::PathSegment> {
// (If there is no previous command or if the previous command
// was not an C, c, S or s, assume the first control point is
// coincident with the current point.)'
let new_x1;
let new_y1;
if let Some(seg) = new_path.last().cloned() {
match seg {
tree::PathSegment::CurveTo { x2, y2, x, y, .. } => {
new_x1 = x * 2.0 - x2;
new_y1 = y * 2.0 - y2;
if let Some(prev_seg) = path.get(idx - 1).cloned() {
let (x1, y1) = match prev_seg {
svgdom::PathSegment::CurveTo { x2, y2, x, y, .. } |
svgdom::PathSegment::SmoothCurveTo { x2, y2, x, y, .. } => {
(x * 2.0 - x2, y * 2.0 - y2)
}
_ => {
new_x1 = px;
new_y1 = py;
(px, py)
}
}
};
new_path.push(tree::PathSegment::CurveTo { x1: new_x1, y1: new_y1, x2, y2, x, y });
new_path.push(tree::PathSegment::CurveTo { x1, y1, x2, y2, x, y });
}
}
svgdom::PathSegment::Quadratic { x1, y1, x, y, .. } => {
// Remember last control point.
ptx = Some(x * 2.0 - x1);
pty = Some(y * 2.0 - y1);
new_path.push(quad_to_curve(px, py, x1, y1, x, y));
}
svgdom::PathSegment::SmoothQuadratic { x, y, .. } => {
......@@ -130,21 +123,24 @@ fn convert_path(mut path: svgdom::Path) -> Vec<tree::PathSegment> {
// the current point. (If there is no previous command or
// if the previous command was not a Q, q, T or t, assume
// the control point is coincident with the current point.)'
let new_x1;
let new_y1;
if let (Some(tx), Some(ty)) = (ptx, pty) {
new_x1 = tx;
new_y1 = ty;
// Reset control point.
ptx = Some(x * 2.0 - tx);
pty = Some(y * 2.0 - ty);
} else {
new_x1 = px;
new_y1 = py;
}
if let Some(prev_seg) = path.get(idx - 1).cloned() {
let (x1, y1) = match prev_seg {
svgdom::PathSegment::Quadratic { x1, y1, x, y, .. } => {
(x * 2.0 - x1, y * 2.0 - y1)
}
svgdom::PathSegment::SmoothQuadratic { x, y, .. } => {
(x * 2.0 - ptx, y * 2.0 - pty)
}
_ => {
(px, py)
}
};
new_path.push(quad_to_curve(px, py, new_x1, new_y1, x, y));
ptx = x1;
pty = y1;
new_path.push(quad_to_curve(px, py, x1, y1, x, y));
}
}
svgdom::PathSegment::EllipticalArc { rx, ry, x_axis_rotation, large_arc, sweep, x, y, .. } => {
let arc = lyon_geom::SvgArc {
......
......@@ -556,7 +556,7 @@ e-path-040,c4a572e2
e-path-041,c4a572e2
e-path-042,9aae2dae
e-path-043,9aae2dae
e-path-044,22e89c3a
e-path-044,0d323be5
e-pattern-001,dc4acacd
e-pattern-002,705a53fe
e-pattern-003,dc4acacd
......@@ -951,3 +951,5 @@ e-clipPath-042,108b66ef
e-filter-060,7fbfbc22
e-filter-061,d6667c63
e-filter-062,32cc3451
e-path-045,47fe0aec
e-path-046,d5800e26
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment