private void AddSegmentText(SvgDocument document, int index, ComplexLine line,Segment segment, PointF targetPoint, PointF referencePoint)
        {
            //Get midpoint of segment
            PointF location = new PointF(targetPoint.X + ((referencePoint.X - targetPoint.X) / 2), targetPoint.Y + ((referencePoint.Y - targetPoint.Y) / 2));

            if (segment.Label.Text.Trim() == "") return;

            Style style = new Style();

            //Set up text object
            location = OffsetPoint(location, segment.Label.Offset);
            //location = OffsetPoint(location, line.Rectangle.Location);

            Double rotation = Geometry.DegreesFromRadians(Geometry.GetAngle(targetPoint.X, targetPoint.Y, referencePoint.X, referencePoint.Y));

            Text text = new Text();
            text.Label = segment.Label;
            text.LayoutRectangle = new RectangleF(location, new SizeF());

            //Get style
            string classId = null;
            classId = document.AddClass(text.GetStyle());

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

            frag = document.CreateDocumentFragment();
            frag.InnerXml = text.ExtractText(0, 0, line.Key + index.ToString() + "Text", "rotate(" + rotation.ToString() + "," + location.X.ToString() + "," + location.Y.ToString() + ")");
            //frag.InnerXml = text.ExtractText(0, 0, line.Key + index.ToString() + "Text");
            frag.FirstChild.Attributes.GetNamedItem("class").InnerText = classId;
            newElementNode = document.ContainerNode.AppendChild(frag);
        }
Пример #2
0
		public override void WriteElement(SvgDocument document, Element element)
		{
			base.WriteElement(document, element);
			
			XmlNode node = Node;

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

			document.ContainerKey = shape.Key + "Ports";

			//Add each child as an element
			foreach (Port port in shape.Ports.Values)
			{
				if (port.Visible) document.AddElement(port);
			}

			document.ContainerKey = tempKey;

			//Restore shape element
			SetNode(node);
		}
Пример #3
0
        private void AddLinkText(SvgDocument document, Link link)
        {
            if (link.Label.Text.Trim() == "") return;

            Style style = new Style();

            //Set up text object
            PointF location = link.GetLabelLocation();
            location = OffsetPoint(location, link.Label.Offset);
            location = OffsetPoint(location, link.Rectangle.Location);

            Text text = new Text();
            text.Label = link.Label;
            text.LayoutRectangle = new RectangleF(location, new SizeF());

            //Get style
            string classId = null;
            classId = document.AddClass(text.GetStyle());

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

            frag = document.CreateDocumentFragment();
            frag.InnerXml = text.ExtractText(0, 0, link.Key + "Text");
            frag.FirstChild.Attributes.GetNamedItem("class").InnerText = classId;
            newElementNode = document.ContainerNode.AppendChild(frag);
        }
Пример #4
0
		public override void WriteElement(SvgDocument document, Element element)
		{
            base.WriteElement(document, element);

			Link link = (Link) element;

            //Add link text
            if (link.Label != null) AddLinkText(document, link);
		}
Пример #5
0
		public override void WriteElement(SvgDocument document, Element element)
		{
			Line line = (Line) element;
			
			Style style = new Style(line);

			XmlNode newNode = null;
			XmlDocumentFragment fragment = null;

			string classId = null;

			//Add the line
			mPolyLine.Line = line;
			fragment = document.CreateDocumentFragment();
			fragment.InnerXml = mPolyLine.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)
			{
				mMarker.MarkerBase = line.Start.Marker;

				//Check for a definition or add a new one
				string defId = document.AddDefinition(mMarker.ExtractMarker(-90, true));
				
				XmlElement newElement = (XmlElement) newNode;
				newElement.SetAttribute("marker-start","url(#" + defId + ")");
			}

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

				//Check for a definition or add a new one
				string defId = document.AddDefinition(mMarker.ExtractMarker(90, false));
				
				XmlElement newElement = (XmlElement) newNode;
				newElement.SetAttribute("marker-end","url(#" + defId + ")");
			}

			//Set the xml element
			SetNode(newNode);
		}
Пример #6
0
		public override void WriteElement(SvgDocument document, Element element)
		{
			base.WriteElement(document, element);

			//Reset the transform to the port transform
			XmlElement xmlelement = (XmlElement) Node;
			Port port = element as Port;

			xmlelement.SetAttribute("x", (port.X + port.Offset.X).ToString());
			xmlelement.SetAttribute("y", (port.Y + port.Offset.Y).ToString());
		}
		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 (SolidElement 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
			mGroupElement = newElement;
		}
		public override void WriteElement(SvgDocument document, Element element)
		{
            base.WriteElement(document, element);

			ComplexLine line = (ComplexLine) element;

            //Add text
            //Render the segment items
            for (int i = 0; i < line.Points.Count - 1; i++)
            {
                Segment segment = line.Segments[i];
                PointF location = (PointF) line.Points[i];
                PointF reference = (PointF) line.Points[i + 1];

                if (segment.Label != null) AddSegmentText(document, i, line, segment, location, reference);
            }            
		}
Пример #9
0
		protected virtual void WriteHeading(SvgDocument document, Table table)
		{
			//Add heading
			mDefinition.Path = new GraphicsPath();
			mDefinition.Path.AddRectangle(new RectangleF(0,0,table.Width, table.HeadingHeight));

			//Add the definition
			string defId = document.AddDefinition(mDefinition.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
			mDefinition.Path = new GraphicsPath();
			mDefinition.Path.AddRectangle(new RectangleF(0, 0, table.Width, table.Height - table.HeadingHeight));

			//Add the definition
			defId = document.AddDefinition(mDefinition.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 = Component.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 = Component.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);
			}
		}
Пример #10
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);
		}
Пример #11
0
		protected virtual void WriteTableRow(SvgDocument document, Table table, TableRow row, ref int id, ref float height)
		{
			//Add background
			mDefinition.Path = new GraphicsPath();
			mDefinition.Path.AddRectangle(new RectangleF(0, 0, row.Indent, table.RowHeight));

			//Add the definition
			string defId = document.AddDefinition(mDefinition.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
				mDefinition.Path = new GraphicsPath();
				mDefinition.Path.AddRectangle(new RectangleF(0, 0, table.Width - row.Indent, table.RowHeight));

				//Add the definition
				defId = document.AddDefinition(mDefinition.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 = Component.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;
		}
Пример #12
0
		public override void WriteElement(SvgDocument document, Element element)
		{
			SolidElement solid = (SolidElement) 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(SolidElement) && 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;
			}
		}
Пример #13
0
		private void AddShapeImage(SvgDocument document, SolidElement 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);

		}
Пример #14
0
		public abstract void WriteElement(SvgDocument document, Element element);
Пример #15
0
		//Save the diagram to disk or to a stream
		protected virtual void ExportToSvg(Stream stream)
		{
			SvgDocument svg = new SvgDocument();
			svg.AddDiagram(this);
			svg.Save(stream);
		}
Пример #16
0
		private void AddShapeText(SvgDocument document, SolidElement 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);
		}
Пример #17
0
        public override void WriteElement(SvgDocument document, Element element)
        {
            SolidElement solid = (SolidElement)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(SolidElement) && 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;
            }
        }