void Add()

in FigmaSharp.Views/FigmaSharp.Views.Cocoa/Graphics/SvgFile.cs [141:204]


        void Add (CALayer layer)
        {
            shapeLayer.AddSublayer(layer);

            if (layer is CAShapeLayer sh && sh.Path != null)
            {
                var bounds = sh.Path.BoundingBox;
               
                if (Scaling == PathScaling.AspectFit)
                {
                    nfloat factorX = Frame.Width / bounds.Width;
                    nfloat factorY = Frame.Height / bounds.Height;
                    nfloat factor = (nfloat) Math.Min(factorX, factorY);

                    nfloat width = bounds.Width * factor;
                    nfloat height = bounds.Height * factor;
                    nfloat translateX = (Frame.Width - width) / 2f;
                    nfloat translateY = (Frame.Height - height) / 2f;

                    var transform = CGAffineTransform.MakeTranslation(-bounds.X, -bounds.Y);
                    transform.Translate(translateX, translateY);
                    transform.Scale (factor, factor);
                    sh.AffineTransform = transform;
                }
                else if (Scaling == PathScaling.AspectFill)
                {
                    nfloat factorX = Frame.Width / bounds.Width;
                    nfloat factorY = Frame.Height / bounds.Height;
                    nfloat factor = (nfloat) Math.Max(factorX, factorY);

                    nfloat width = bounds.Width * factor;
                    nfloat height = bounds.Height * factor;
                    nfloat translateX = (Frame.Width - width) / 2f;
                    nfloat translateY = (Frame.Height - height) / 2f;

                    var transform = CGAffineTransform.MakeTranslation (-bounds.X, -bounds.Y);
                    transform.Translate(translateX, translateY, 0);
                    transform.Scale(factor, factor, 0);
                    sh.AffineTransform = transform;
                }
                else if (Scaling == PathScaling.Fill)
                {
                    var factorX = Frame.Width / bounds.Width;
                    var factorY = Frame.Height / bounds.Height;
                    var transform = CGAffineTransform.MakeScale (factorX, factorY);

                    var translateX = bounds.X * factorX;
                    var translateY = bounds.Y * factorY;
                    transform.Translate(translateX, translateY);
                    sh.AffineTransform = transform;
                }
                else
                {
                    var width = bounds.Width;
                    var height = bounds.Height;
                    var translateX = (Frame.Width - width) / 2;
                    var translateY = (Frame.Height - height) / 2;

                    var transform = CGAffineTransform.MakeTranslation (-bounds.X, -bounds.Y);
                    transform.Translate(translateX, translateY);
                    sh.AffineTransform = transform;
                }
            }
        }