Exemplo n.º 1
0
        private void AddShapeImage(SvgDocument document, Solid solid, string definitionId, string clipId)
        {
            ImageRef image = new ImageRef();

            XmlDocumentFragment frag       = null;
            XmlElement          newElement = null;

            string classId = null;
            string id      = null;

            image.SolidElement = solid;

            //Set up clipping if required
            if (solid.Clip)
            {
                System.Text.StringBuilder objBuilder = new System.Text.StringBuilder();

                objBuilder.Append("clip-path:url(\"#");
                objBuilder.Append(clipId);
                objBuilder.Append("\");");

                classId = document.AddClass(objBuilder.ToString(), "");
            }

            //Extract image
            image.Image = solid.Image;

            frag          = document.CreateDocumentFragment();
            frag.InnerXml = image.ExtractImage();

            //Create image element
            newElement = document.CreateElement("image");

            newElement.SetAttribute("href", "http://www.w3.org/1999/xlink", frag.FirstChild.Attributes.GetNamedItem("href").InnerXml);
            newElement.SetAttribute("x", frag.FirstChild.Attributes.GetNamedItem("x").InnerText);
            newElement.SetAttribute("y", frag.FirstChild.Attributes.GetNamedItem("y").InnerText);
            newElement.SetAttribute("width", frag.FirstChild.Attributes.GetNamedItem("width").InnerText);
            newElement.SetAttribute("height", frag.FirstChild.Attributes.GetNamedItem("height").InnerText);

            id = frag.FirstChild.Attributes.GetNamedItem("id").InnerText;
            newElement.SetAttribute("id", id);

            if (solid.Clip)
            {
                newElement.SetAttribute("class", classId);
            }

            //Append image to the current container
            document.ContainerNode.AppendChild(newElement);
        }
Exemplo n.º 2
0
        public override void WriteElement(SvgDocument document, Element element)
        {
            base.WriteElement(document, element);

            XmlNode node = Node;

            ComplexShape complex = (ComplexShape)element;

            //Add a group for the complex shape
            XmlElement newElement = null;

            StringBuilder builder = new StringBuilder();

            builder.Append("translate(");
            builder.Append(XmlConvert.ToString(complex.X));
            builder.Append(",");
            builder.Append(XmlConvert.ToString(complex.Y));
            builder.Append(")");

            newElement = document.CreateElement("g");
            newElement.SetAttribute("id", complex.Key + "Children");
            newElement.SetAttribute("transform", builder.ToString());

            document.ContainerNode.AppendChild(newElement);

            //Set the element as the temporary container node
            XmlNode temp    = document.ContainerNode;
            string  tempKey = document.ContainerKey;

            document.ContainerNode = newElement;
            document.ContainerKey  = complex.Key;

            //Add each child as an element
            foreach (Solid solid in complex.Children.Values)
            {
                document.AddElement(solid);
            }

            document.ContainerNode = temp;
            document.ContainerKey  = tempKey;

            //Write the ports

            //Restore the XmlElement
            SetNode(node);

            //Set the xml element for the group
            _groupElement = newElement;
        }
Exemplo n.º 3
0
        public override void WriteElement(SvgDocument document, Element element)
        {
            Table table = (Table)element;

            //Get definition
            Definition definition = new Definition(table.GetPath());

            DefinitionId = document.AddDefinition(definition.ExtractDefinition(), "");

            //Add the shadow use only if background is drawn, layer has shadows, and is a subclass of solid
            if (table.DrawBackground && table.Layer.DrawShadows)
            {
                StringBuilder stringBuilder = new StringBuilder();
                double        opacity       = Math.Round(Convert.ToDouble(table.Opacity / 1000F), 2);

                stringBuilder.Append("fill:");
                stringBuilder.Append(ColorTranslator.ToHtml(table.Layer.ShadowColor));
                stringBuilder.Append(";fill-opacity:");
                stringBuilder.Append(opacity.ToString());
                stringBuilder.Append(";");

                ClassId = document.AddClass(stringBuilder.ToString(), "");

                document.AddUse(table.Key.ToString() + "Shadow", DefinitionId, ClassId, "", table.X + element.Layer.ShadowOffset.X, table.Y + element.Layer.ShadowOffset.Y);
            }

            //Set up the clip
            ClipId = document.AddClipPath(DefinitionId, 0, 0);

            //Add a group for the table shape
            XmlElement newElement = null;

            StringBuilder builder = new StringBuilder();

            builder.Append("translate(");
            builder.Append(XmlConvert.ToString(table.X));
            builder.Append(",");
            builder.Append(XmlConvert.ToString(table.Y));
            builder.Append(")");

            newElement = document.CreateElement("g");
            newElement.SetAttribute("id", table.Key + "Table");
            newElement.SetAttribute("transform", builder.ToString());

            builder = new StringBuilder();

            builder.Append("url(#");
            builder.Append(ClipId);
            builder.Append(")");

            newElement.SetAttribute("clip-path", builder.ToString());

            document.ContainerNode.AppendChild(newElement);

            //Set the element as the temporary container node
            XmlNode temp    = document.ContainerNode;
            string  tempKey = document.ContainerKey;

            document.ContainerNode = newElement;
            document.ContainerKey  = table.Key;

            //Add each child as an element
            WriteHeading(document, table);

            if (table.Expanded)
            {
                int   groupId = 1;
                int   rowId   = 1;
                float height  = table.HeadingHeight + 1;

                foreach (TableRow row in table.Rows)
                {
                    WriteTableRow(document, table, row, ref rowId, ref height);
                }

                foreach (TableGroup group in table.Groups)
                {
                    WriteTableGroup(document, table, group, ref groupId, ref rowId, ref height);
                }
            }

            document.ContainerNode = temp;
            document.ContainerKey  = tempKey;

            StringBuilder style       = new StringBuilder();
            string        colorString = Style.GetCompatibleColor(table.BorderColor);

            style.Append("stroke:");
            style.Append(colorString);
            style.Append(";");
            style.Append("stroke-width:");
            style.Append(table.BorderWidth);
            style.Append(";");
            style.Append(Style.GetDashStyle(table.BorderStyle, table.BorderWidth));
            style.Append("fill:none");
            style.Append(";");

            //Determine style
            ClassId = document.AddClass(style.ToString());

            //Add the use
            document.AddUse(table.Key.ToString(), DefinitionId, ClassId, "", table.X, table.Y);

            //Set the xml element
            SetNode(newElement);
        }
Exemplo n.º 4
0
        public override void WriteElement(SvgDocument document, Element element)
        {
            Solid solid = (Solid)element;

            Definition definition = new Definition(solid.GetPath());
            Style      style      = null;

            //Add the definition
            //Determine definition
            DefinitionId = document.AddDefinition(definition.ExtractDefinition(), "");

            //Get style, no clipping path as this time
            style = new Style(solid);

            //Add the shadow use only if background is drawn, layer has shadows, and is a subclass of solid
            if (solid.DrawBackground && solid.Layer.DrawShadows && solid.GetType() != typeof(Solid) && solid.GetType() != typeof(Port))
            {
                StringBuilder stringBuilder = new System.Text.StringBuilder();
                double        opacity       = Math.Round(Convert.ToDouble(solid.Opacity / 1000F), 2);

                stringBuilder.Append("fill:");
                stringBuilder.Append(ColorTranslator.ToHtml(solid.Layer.ShadowColor));
                stringBuilder.Append(";fill-opacity:");
                stringBuilder.Append(opacity.ToString());
                stringBuilder.Append(";");

                ClassId = document.AddClass(stringBuilder.ToString(), "");

                document.AddUse(solid.Key.ToString() + "Shadow", DefinitionId, ClassId, "", solid.X + element.Layer.ShadowOffset.X, solid.Y + element.Layer.ShadowOffset.Y);
            }

            //Determine style
            ClassId = document.AddClass(style.GetStyle(), style.LinearGradient);

            //Add the use
            document.AddUse(solid.Key.ToString(), DefinitionId, ClassId, "", solid.X, solid.Y);

            SetNode(document.Node);

            if (solid.Image != null || solid.Label != null)
            {
                ClipId = document.AddClipPath(DefinitionId, 0, 0);

                //Add a group for the complex shape
                XmlElement newElement = null;

                StringBuilder builder = new StringBuilder();
                builder.Append("translate(");
                builder.Append(XmlConvert.ToString(solid.X));
                builder.Append(",");
                builder.Append(XmlConvert.ToString(solid.Y));
                builder.Append(")");

                newElement = document.CreateElement("g");
                newElement.SetAttribute("id", solid.Key + "Container");
                newElement.SetAttribute("transform", builder.ToString());

                document.ContainerNode.AppendChild(newElement);

                //Set the element as the temporary container node
                XmlNode temp = document.ContainerNode;
                document.ContainerNode = newElement;

                //Add images
                if (solid.Image != null)
                {
                    AddShapeImage(document, solid, DefinitionId, ClipId);
                }

                //Add text with a clipping path
                if (solid.Label != null)
                {
                    AddShapeText(document, solid, ClipId);
                }

                document.ContainerNode = temp;
            }
        }