public static void Translate(this ICanvas canvas, Point translation) { canvas.Transform(Transform.Translate(translation)); }
Transform ReadTransform(string raw) { if (string.IsNullOrWhiteSpace(raw)) { return(Transform.Identity); } var s = raw.Trim(); var calls = s.Split(new[] { ')' }, StringSplitOptions.RemoveEmptyEntries); var t = Transform.Identity; foreach (var c in calls) { var args = c.Split(new[] { '(', ',', ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); var nt = Transform.Identity; switch (args [0]) { case "matrix": if (args.Length == 7) { nt = new Transform( ReadNumber(args[1]), ReadNumber(args[2]), ReadNumber(args[3]), ReadNumber(args[4]), ReadNumber(args[5]), ReadNumber(args[6])); } else { throw new NotSupportedException("Matrices are expected to have 6 elements, this one has " + (args.Length - 1)); } break; case "translate": if (args.Length >= 3) { nt = Transform.Translate(new Size(ReadNumber(args [1]), ReadNumber(args [2]))); } else if (args.Length >= 2) { nt = Transform.Translate(new Size(ReadNumber(args[1]), 0)); } break; case "scale": if (args.Length >= 3) { nt = Transform.Scale(new Size(ReadNumber(args[1]), ReadNumber(args[2]))); } else if (args.Length >= 2) { var sx = ReadNumber(args [1]); nt = Transform.Scale(new Size(sx, sx)); } break; case "rotate": var a = ReadNumber(args [1]); if (args.Length >= 4) { var x = ReadNumber(args [2]); var y = ReadNumber(args [3]); var t1 = Transform.Translate(new Size(x, y)); var t2 = Transform.Rotate(a); var t3 = Transform.Translate(new Size(-x, -y)); nt = t1 * t2 * t3; } else { nt = Transform.Rotate(a); } break; default: throw new NotSupportedException("Can't transform " + args[0]); } t = t * nt; } return(t); }
public static void Translate(this ICanvas canvas, double dx, double dy) { canvas.Transform(Transform.Translate(dx, dy)); }