예제 #1
0
        public static bool TryGetTransform(ISvgTransformable element, out Transform transform)
        {
            transform = null;

            if (element == null)
            {
                return(false);
            }

            ISvgTransformList svgTList  = element.Transform.AnimVal;
            ISvgMatrix        svgMatrix = ((SvgTransformList)element.Transform.AnimVal).TotalMatrix;
            ISvgElement       nVE       = element.NearestViewportElement;

            if (nVE != null)
            {
                SvgTransformableElement par = (element as SvgElement).ParentNode as SvgTransformableElement;
                while (par != null && par != nVE)
                {
                    svgTList  = par.Transform.AnimVal;
                    svgMatrix = svgTList.Consolidate().Matrix.Multiply(svgMatrix);
                    par       = par.ParentNode as SvgTransformableElement;
                }
            }

            if (svgMatrix.IsIdentity)
            {
                transform = Transform.Identity;
                return(false);
            }

            transform = new MatrixTransform(ToWpfMatrix(svgMatrix));
            return(true);
        }
        protected void SetTransform(GdiGraphics gr)
        {
            if (_svgElement is ISvgTransformable)
            {
                if (_transformMatrix == null)
                {
                    ISvgTransformable transElm  = (ISvgTransformable)_svgElement;
                    SvgTransformList  svgTList  = (SvgTransformList)transElm.Transform.AnimVal;
                    SvgMatrix         svgMatrix = ((SvgTransformList)transElm.Transform.AnimVal).TotalMatrix;

                    _transformMatrix = new Matrix((float)svgMatrix.A, (float)svgMatrix.B, (float)svgMatrix.C,
                                                  (float)svgMatrix.D, (float)svgMatrix.E, (float)svgMatrix.F);
                }
                gr.Transform = _transformMatrix;
            }
        }
예제 #3
0
        public static Matrix GetTransformMatrix(SvgElement element)
        {
            ISvgTransformable transElm = element as ISvgTransformable;

            if (transElm == null)
            {
                return(Matrix.Identity);
            }

            SvgTransformList svgTList     = (SvgTransformList)transElm.Transform.AnimVal;
            SvgTransform     svgTransform = (SvgTransform)svgTList.Consolidate();
            SvgMatrix        svgMatrix    = ((SvgTransformList)transElm.Transform.AnimVal).TotalMatrix;

            return(new Matrix(svgMatrix.A, svgMatrix.B, svgMatrix.C,
                              svgMatrix.D, svgMatrix.E, svgMatrix.F));
        }
예제 #4
0
        protected void Transform(GraphicsWrapper gr)
        {
            if (element is ISvgTransformable)
            {
                if (TransformMatrix == null)
                {
                    ISvgTransformable transElm = (ISvgTransformable)element;
                    SvgTransformList  svgTList = (SvgTransformList)transElm.Transform.AnimVal;
                    //SvgTransform svgTransform = (SvgTransform)svgTList.Consolidate();
                    SvgMatrix svgMatrix = ((SvgTransformList)transElm.Transform.AnimVal).TotalMatrix;

                    TransformMatrix = new Matrix(
                        (float)svgMatrix.A,
                        (float)svgMatrix.B,
                        (float)svgMatrix.C,
                        (float)svgMatrix.D,
                        (float)svgMatrix.E,
                        (float)svgMatrix.F);
                }
                gr.Transform = TransformMatrix;
            }
        }
예제 #5
0
        public static Matrix GetTransformMatrix(SvgElement element, TransformGroup transform)
        {
            ISvgTransformable transElm = element as ISvgTransformable;

            if (transElm == null)
            {
                return(Matrix.Identity);
            }

            SvgTransformList svgTList     = (SvgTransformList)transElm.Transform.AnimVal;
            SvgTransform     svgTransform = (SvgTransform)svgTList.Consolidate();
            SvgMatrix        svgMatrix    = ((SvgTransformList)transElm.Transform.AnimVal).TotalMatrix;

            var matrix = new Matrix(svgMatrix.A, svgMatrix.B, svgMatrix.C,
                                    svgMatrix.D, svgMatrix.E, svgMatrix.F);

            if (!matrix.IsIdentity)
            {
                transform.Children.Add(new MatrixTransform(matrix));
            }

            return(matrix);
        }
예제 #6
0
        protected void SetTransform(WpfDrawingContext context)
        {
            _transformMatrix = null;

            ISvgTransformable transElm = _svgElement as ISvgTransformable;

            if (transElm != null)
            {
                SvgTransformList transformList = (SvgTransformList)transElm.Transform.AnimVal;
                if (transformList.NumberOfItems > 1 && _combineTransforms == false)
                {
                    TransformGroup   transformGroup = new TransformGroup();
                    List <Transform> transforms     = new List <Transform>();

                    for (uint i = 0; i < transformList.NumberOfItems; i++)
                    {
                        ISvgTransform transform = transformList.GetItem(i);
                        double[]      values    = transform.InputValues;
                        switch (transform.TransformType)
                        {
                        case SvgTransformType.Translate:
                            if (values.Length == 1)
                            {
                                // SetTranslate(values[0], 0);
                                //transformGroup.Children.Add(new TranslateTransform(values[0], 0));
                                transforms.Add(new TranslateTransform(values[0], 0));
                            }
                            else if (values.Length == 2)
                            {
                                // SetTranslate(values[0], values[1]);
                                //transformGroup.Children.Add(new TranslateTransform(values[0], values[1]));
                                transforms.Add(new TranslateTransform(values[0], values[1]));
                            }
                            break;

                        case SvgTransformType.Rotate:
                            if (values.Length == 1)
                            {
                                // SetRotate(values[0]);
                                //transformGroup.Children.Add(new RotateTransform(values[0]));
                                transforms.Add(new RotateTransform(values[0]));
                            }
                            else if (values.Length == 3)
                            {
                                // SetRotate(values[0], values[1], values[2]);
                                //transformGroup.Children.Add(new RotateTransform(values[0], values[1], values[2]));
                                transforms.Add(new RotateTransform(values[0], values[1], values[2]));
                            }
                            break;

                        case SvgTransformType.Scale:
                            if (values.Length == 1)
                            {
                                //SetScale(values[0], values[0]);
                                transformGroup.Children.Add(new ScaleTransform(values[0], values[0]));
                            }
                            else if (values.Length == 2)
                            {
                                //SetScale(values[0], values[1]);
                                //transformGroup.Children.Add(new ScaleTransform(values[0], values[1]));
                                transforms.Add(new ScaleTransform(values[0], values[1]));
                            }
                            break;

                        case SvgTransformType.SkewX:
                            if (values.Length == 1)
                            {
                                //SetSkewX(values[0]);
                                //transformGroup.Children.Add(new SkewTransform(values[0], 0));
                                transforms.Add(new SkewTransform(values[0], 0));
                            }
                            break;

                        case SvgTransformType.SkewY:
                            if (values.Length == 1)
                            {
                                //SetSkewY(values[0]);
                                //transformGroup.Children.Add(new SkewTransform(0, values[0]));
                                transforms.Add(new SkewTransform(0, values[0]));
                            }
                            break;

                        case SvgTransformType.Matrix:
                            if (values.Length == 6)
                            {
                                //SetMatrix(new SvgMatrix(values[0], values[1], values[2], values[3], values[4], values[5]));
                                //transformGroup.Children.Add(new MatrixTransform(values[0], values[1], values[2], values[3], values[4], values[5]));
                                transforms.Add(new MatrixTransform(values[0], values[1], values[2], values[3], values[4], values[5]));
                            }
                            break;
                        }
                    }

                    transforms.Reverse();
                    transformGroup.Children = new TransformCollection(transforms);
                    _transformMatrix        = transformGroup;
                    //_transformMatrix = new MatrixTransform(transformGroup.Value);
                    return;
                }
                SvgMatrix svgMatrix = transformList.TotalMatrix;

                if (svgMatrix.IsIdentity)
                {
                    return;
                }

                _transformMatrix = new MatrixTransform(Math.Round(svgMatrix.A, 4), Math.Round(svgMatrix.B, 4),
                                                       Math.Round(svgMatrix.C, 4), Math.Round(svgMatrix.D, 4),
                                                       Math.Round(svgMatrix.E, 4), Math.Round(svgMatrix.F, 4));
            }
        }