Exemplo n.º 1
0
        public SvgElement AddElement(ISvgElement mypath)
        {
//			AttributeFunc.SetAttributeValue((XmlElement)mypath,"layer",SvgDocument.currentLayer);
            XmlNode node1   = OwnerDocument.RootElement;
            XmlNode newNode = null;

            Matrix matrix1 = new Matrix();
//				if (node1 is IGraph)
//				{
//					matrix1 = ((IGraph) node1).GraphTransform.Matrix.Clone();
//					Matrix matrix2 = this.coordTransform.Clone();
//					matrix2.Invert();
//					matrix1.Multiply(matrix2, MatrixOrder.Append);
//				}
//				matrix1.Invert();
//				matrix1 = TransformFunc.RoundMatrix(matrix1, 2);
            bool flag1 = OwnerDocument.AcceptChanges;

            //				OwnerDocument.AcceptChanges = false;
            OwnerDocument.AcceptChanges = true;
            if (mypath is IGraphPath)
            {
                ISvgBrush brush1 = ((IGraphPath)mypath).GraphBrush;
                if ((brush1 is ITransformBrush) && (((SvgElement)brush1).ParentNode == null))
                {
                    bool flag2 = OwnerDocument.AcceptChanges;
                    OwnerDocument.AcceptChanges = true;
                    OwnerDocument.NumberOfUndoOperations++;
                    XmlNode node2 = OwnerDocument.AddDefsElement((SvgElement)brush1);
                    OwnerDocument.AcceptChanges = false;
                    if (node2 is ITransformBrush)
                    {
                        string text1 = ((SvgElement)node2).ID;
                        AttributeFunc.SetAttributeValue((SvgElement)mypath, "fill", "url(#" + text1 + ")");
                    }
                    OwnerDocument.AcceptChanges = flag2;
                }
                brush1 = ((IGraphPath)mypath).GraphStroke.Brush;
                if ((brush1 is ITransformBrush) && (((SvgElement)brush1).ParentNode == null))
                {
                    bool flag3 = OwnerDocument.AcceptChanges;
                    OwnerDocument.AcceptChanges = true;
                    OwnerDocument.NumberOfUndoOperations++;
                    XmlNode node3 = OwnerDocument.AddDefsElement((SvgElement)brush1);
                    OwnerDocument.AcceptChanges = false;
                    if (node3 is ITransformBrush)
                    {
                        string text2 = ((SvgElement)node3).ID;
                        AttributeFunc.SetAttributeValue((SvgElement)mypath, "stroke", "url(#" + text2 + ")");
                    }
                    OwnerDocument.AcceptChanges = flag3;
                }
            }
            if (!matrix1.IsIdentity && (mypath is IGraph))
            {
                bool flag4 = OwnerDocument.AcceptChanges;
                OwnerDocument.AcceptChanges = false;
                Matrix matrix3 = ((IGraph)mypath).Transform.Matrix.Clone();
                matrix1.Multiply(matrix3);
                Transf transf1 = new Transf();
                transf1.setMatrix(matrix1);
                AttributeFunc.SetAttributeValue((SvgElement)mypath, "transform", transf1.ToString());
                OwnerDocument.AcceptChanges = flag4;
            }
            if (((SvgElement)mypath).ParentNode != node1)
            {
                if (((ContainerElement)node1).IsValidChild((SvgElement)mypath))
                {
                    //						node1.AppendChild((SvgElement) mypath);
                    SvgElement element1 = (SvgElement)mypath;                            //(SvgElement)OwnerDocument.ImportNode((SvgElement) mypath,true);
                    newNode = node1.AppendChild(element1);
                    OwnerDocument.Render(element1);
                }
            }
            OwnerDocument.AcceptChanges = flag1;

            return(newNode != null?newNode as SvgElement:null);
        }