/// <summary> /// Parse an SVG shape and return a GraphicPathGeometry /// </summary> public static GraphicPathGeometry Parse(XElement shape, Matrix currentTransformationMatrix) { GraphicPathGeometry geometry = null; switch (shape.Name.LocalName) { case "path": geometry = ParsePath(shape); break; case "polygon": geometry = ParsePolygon(shape); break; case "circle": geometry = ParseCircle(shape); break; case "ellipse": geometry = ParseEllipse(shape); break; case "rect": geometry = ParseRect(shape); break; case "line": geometry = ParseLine(shape); break; case "polyline": geometry = ParsePolyline(shape); break; } if (geometry != null) { //Matrix currentPathTransformationMatrix = currentTransformationMatrix; //var attrs = shape.Attribute("transform"); //if (attrs != null) //{ // var transformMatrix = TransformMatrixParser.GetTransformMatrix(attrs.Value); // currentPathTransformationMatrix = transformMatrix * currentPathTransformationMatrix; //} var trans = new TransformVisual(); geometry = trans.Transform(geometry, currentTransformationMatrix); } return(geometry); }
/// <summary> /// Parse an SVG shape and return a GraphicPathGeometry /// </summary> public GraphicPathGeometry Parse(XElement shape, Matrix currentTransformationMatrix) { GraphicPathGeometry geometry = null; switch (shape.Name.LocalName) { case "path": geometry = ParsePath(shape); break; case "polygon": geometry = ParsePolygon(shape); break; case "circle": geometry = ParseCircle(shape); break; case "ellipse": geometry = ParseEllipse(shape); break; case "rect": geometry = ParseRect(shape); break; case "line": geometry = ParseLine(shape); break; case "polyline": geometry = ParsePolyline(shape); break; } if (geometry != null) { var trans = new TransformVisual(); geometry = trans.Transform(geometry, currentTransformationMatrix); } return(geometry); }
public static void CreateArc(EpsInterpreter interpreter, bool sweepDirection) { var operandStack = interpreter.OperandStack; GraphicsState graphicState = interpreter.GraphicState; var angle2 = operandStack.PopRealValue(); var angle1 = operandStack.PopRealValue(); var r = operandStack.PopRealValue(); var y = operandStack.PopRealValue(); var x = operandStack.PopRealValue(); // be aware the segment converter returns coordinates in user space var(segments, startPoint, currentPoint) = ArcToPathSegmentConverter.ArcToPathSegments(new Point(x, y), r, angle1, angle2, sweepDirection); if (graphicState.CurrentGeometry == null) { graphicState.CurrentGeometry = new GraphicPathGeometry(); var point = MatrixUtilities.TransformPoint(startPoint, graphicState.CurrentTransformationMatrix); var move = new GraphicMoveSegment { StartPoint = point }; graphicState.CurrentGeometry.Segments.Add(move); graphicState.LastMove = move; } else { var point = MatrixUtilities.TransformPoint(startPoint, graphicState.CurrentTransformationMatrix); var lineSegment = new GraphicLineSegment { To = point }; graphicState.CurrentGeometry.Segments.Add(lineSegment); } var transformVisual = new TransformVisual(); var transformedSegments = transformVisual.TransformSegments(segments, graphicState.CurrentTransformationMatrix); graphicState.CurrentGeometry.Segments.AddRange(transformedSegments); graphicState.CurrentPoint = currentPoint; }