Example #1
0
        private void AddShapeText(SvgDocument document, Solid solid, string strClipId)
        {
            if (solid.Label.Text.Trim() == "")
            {
                return;
            }

            Style style = new Style();

            //Add clipping to style if required
            style.ClipPathId = strClipId;

            //Set up text object
            Text text = new Text();

            text.Label           = solid.Label;
            text.LayoutRectangle = solid.InternalRectangle;

            //Get style
            string classId = null;

            classId = document.AddClass(text.GetStyle(strClipId), "");

            //Create fragment and add to document
            XmlDocumentFragment frag           = null;
            XmlNode             newElementNode = null;

            frag          = document.CreateDocumentFragment();
            frag.InnerXml = text.ExtractText(0, 0, solid.Key + "Text");
            frag.FirstChild.Attributes.GetNamedItem("class").InnerText = classId;
            newElementNode = document.ContainerNode.AppendChild(frag);
        }
Example #2
0
        public override void WriteElement(SvgDocument document, Element element)
        {
            Link line = (Link)element;

            Style style = new Style(line);

            XmlNode             newNode  = null;
            XmlDocumentFragment fragment = null;

            string classId = null;

            //Add the line
            _polyLine.Line    = line;
            fragment          = document.CreateDocumentFragment();
            fragment.InnerXml = _polyLine.ExtractPolyline();

            newNode = document.ContainerNode.AppendChild(fragment);

            //Determine style
            classId = document.AddClass(style.GetStyle(), "");
            newNode.Attributes.GetNamedItem("class").InnerText = classId;

            //Reset the key if in a container
            if (document.ContainerKey != null && document.ContainerKey != string.Empty)
            {
                newNode.Attributes.GetNamedItem("id").Value = document.ContainerKey + "," + line.Key;
            }

            //Check for start marker
            if (line.Start.Marker != null)
            {
                _marker.MarkerBase = line.Start.Marker;

                //Check for a definition or add a new one
                string defId = document.AddDefinition(_marker.ExtractMarker(-90, true));

                XmlElement newElement = (XmlElement)newNode;
                newElement.SetAttribute("marker-start", "url(#" + defId + ")");
            }

            //Check for end marker
            if (line.End.Marker != null)
            {
                _marker.MarkerBase = line.End.Marker;

                //Check for a definition or add a new one
                string defId = document.AddDefinition(_marker.ExtractMarker(90, false));

                XmlElement newElement = (XmlElement)newNode;
                newElement.SetAttribute("marker-end", "url(#" + defId + ")");
            }

            //Set the xml element
            SetNode(newNode);
        }
Example #3
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);
        }
Example #4
0
        protected virtual void WriteHeading(SvgDocument document, Table table)
        {
            //Add heading
            _definition.Path = new GraphicsPath();
            _definition.Path.AddRectangle(new RectangleF(0, 0, table.Width, table.HeadingHeight));

            //Add the definition
            string defId = document.AddDefinition(_definition.ExtractRectangle());

            //Add the class
            string gradient = Style.ExtractLinearGradient(LinearGradientMode.Horizontal, table.GradientColor, table.BackColor);
            string classId  = document.AddClass("fill:url(#none)", gradient);

            document.AddUse("Heading", defId, classId, "", 0, 0);

            //Add the rest of the background
            _definition.Path = new GraphicsPath();
            _definition.Path.AddRectangle(new RectangleF(0, 0, table.Width, table.Height - table.HeadingHeight));

            //Add the definition
            defId   = document.AddDefinition(_definition.ExtractRectangle());
            classId = document.AddClass("fill:" + Style.GetCompatibleColor(table.BackColor));

            document.AddUse("Fill", defId, classId, "", 0, table.HeadingHeight);

            Style style = new Style();
            Font  font  = null;

            //Add Heading text
            if (table.Heading.Trim() != "")
            {
                //Add clipping to style if required
                style.ClipPathId = ClipId;

                //Set up text object
                Text text = new Text();

                //Get style
                font    = Singleton.Instance.GetFont(table.FontName, table.FontSize, FontStyle.Bold);
                classId = document.AddClass(text.GetStyle(font, table.Forecolor, ClipId), "");

                //Create fragment and add to document
                XmlDocumentFragment frag           = null;
                XmlNode             newElementNode = null;

                frag          = document.CreateDocumentFragment();
                frag.InnerXml = text.ExtractText(table.Heading, font, 8, 5, table.Key + "Heading");
                frag.FirstChild.Attributes.GetNamedItem("class").InnerText = classId;
                newElementNode = document.ContainerNode.AppendChild(frag);
            }

            //Add Heading text
            if (table.SubHeading.Trim() != "")
            {
                style = new Style();

                //Add clipping to style if required
                style.ClipPathId = ClipId;

                //Set up text object
                Text text = new Text();

                //Get style
                font    = Singleton.Instance.GetFont(table.FontName, table.FontSize - 1, FontStyle.Regular);
                classId = document.AddClass(text.GetStyle(font, table.Forecolor, ClipId), "");

                //Create fragment and add to document
                XmlDocumentFragment frag           = null;
                XmlNode             newElementNode = null;

                frag          = document.CreateDocumentFragment();
                frag.InnerXml = text.ExtractText(table.SubHeading, font, 8, 20, table.Key + "Subheading");
                frag.FirstChild.Attributes.GetNamedItem("class").InnerText = classId;
                newElementNode = document.ContainerNode.AppendChild(frag);
            }
        }
Example #5
0
        protected virtual void WriteTableRow(SvgDocument document, Table table, TableRow row, ref int id, ref float height)
        {
            //Add background
            _definition.Path = new GraphicsPath();
            _definition.Path.AddRectangle(new RectangleF(0, 0, row.Indent, table.RowHeight));

            //Add the definition
            string defId = document.AddDefinition(_definition.ExtractRectangle());

            StringBuilder builder = new StringBuilder();

            builder.Append("fill:");
            builder.Append(Style.GetCompatibleColor(row.Backcolor));
            builder.Append(";fill-opacity:0.5;");

            //Add the class
            string classId = document.AddClass(builder.ToString());
            string key     = "Row" + id.ToString();

            document.AddUse(key, defId, classId, "", 0, height);

            //Add the text
            Style style = new Style();
            Font  font  = null;

            //Add row text
            if (row.Text.Trim() != "")
            {
                //Get a new clip path
                _definition.Path = new GraphicsPath();
                _definition.Path.AddRectangle(new RectangleF(0, 0, table.Width - row.Indent, table.RowHeight));

                //Add the definition
                defId = document.AddDefinition(_definition.ExtractRectangle());
                string clipId = document.AddClipPath(defId, row.Indent, height);

                //Add clipping to style if required
                style.ClipPathId = clipId;

                StringFormat format = new StringFormat();
                format.LineAlignment = StringAlignment.Center;
                format.FormatFlags   = StringFormatFlags.NoWrap;

                //Set up text object
                Text text = new Text();
                text.Format          = format;
                text.LayoutRectangle = new RectangleF(0, 0, table.Width - 20 - table.Indent - row.Indent, table.RowHeight);

                //Get style
                font    = Singleton.Instance.GetFont(table.FontName, table.FontSize, table.FontStyle);
                classId = document.AddClass(text.GetStyle(font, table.Forecolor, clipId), "");

                //Create fragment and add to document
                XmlDocumentFragment frag           = null;
                XmlNode             newElementNode = null;

                frag          = document.CreateDocumentFragment();
                frag.InnerXml = text.ExtractText(row.Text, font, row.Indent, height, key + "Text");
                frag.FirstChild.Attributes.GetNamedItem("class").InnerText = classId;
                newElementNode = document.ContainerNode.AppendChild(frag);
            }

            id++;
            height += table.RowHeight;
        }