Exemple #1
0
 public static void Scale(this ICanvas canvas, Size scale)
 {
     if (scale.Width != 1 || scale.Height != 1)
     {
         canvas.Transform(Transform.Scale(scale));
     }
 }
Exemple #2
0
 public static void Scale(this ICanvas canvas, double scale)
 {
     if (scale != 1)
     {
         canvas.Transform(Transform.Scale(scale, scale));
     }
 }
Exemple #3
0
 public static void Scale(this ICanvas canvas, double sx, double sy)
 {
     if (sx != 1 || sy != 1)
     {
         canvas.Transform(Transform.Scale(sx, sy));
     }
 }
Exemple #4
0
        public static Transform StretchFillRect(Rect sourceRect, Rect destRect)
        {
            var t1 = Transform.Translate(-sourceRect.TopLeft);
            var s  = Transform.Scale(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);
            var t2 = Transform.Translate(destRect.TopLeft);

            return(t2 * s * t1);
        }
Exemple #5
0
        public static Transform AspectFillRect(Rect sourceRect, Rect destRect)
        {
            var scalex = destRect.Width / sourceRect.Width;
            var scaley = destRect.Height / sourceRect.Height;
            var scale  = Math.Min(scalex, scaley);

            var t1 = Transform.Translate(-sourceRect.TopLeft);
            var s  = Transform.Scale(scale);
            var t2 = Transform.Translate(destRect.TopLeft);
            var t3 = Transform.Translate(
                (destRect.Width - scale * sourceRect.Width) / 2,
                (destRect.Height - scale * sourceRect.Height) / 2);

            return(t3 * t2 * s * t1);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
 public static Transform ScaleAt(double sx, double sy, double x, double y)
 {
     return(Transform.Translate(x, y) * Transform.Scale(sx, sy) * Transform.Translate(-x, -y));
 }