Beispiel #1
0
        private void AddCurveImplementation(Curve curve)
        {
            if (curve == null)
            {
                return;
            }

            Curvedline curved = new Curvedline(curve);
            Style      style  = new Style(curve);

            XmlNode             newNode  = null;
            XmlDocumentFragment fragment = null;

            string classId = null;

            //Add the line
            fragment          = base.CreateDocumentFragment();
            fragment.InnerXml = curved.ExtractCurve();

            newNode = ContainerNode.AppendChild(fragment);

            //Determine style
            classId = AddClassImplementation(style.GetStyle(), "");
            newNode.Attributes.GetNamedItem("class").InnerText = classId;
        }
		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);
		}
Beispiel #3
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);
        }
		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;
			}
		}
		private void AddCurveImplementation(Curve curve)
		{
			if (curve == null) return;

			Curvedline curved = new Curvedline(curve);
			Style style = new Style(curve);

			XmlNode newNode = null;
			XmlDocumentFragment fragment = null;

			string classId = null;

			//Add the line
			fragment = base.CreateDocumentFragment();
			fragment.InnerXml = curved.ExtractCurve();

			newNode = ContainerNode.AppendChild(fragment);

			//Determine style
			classId = AddClassImplementation(style.GetStyle(), "");
			newNode.Attributes.GetNamedItem("class").InnerText = classId;
		}
Beispiel #6
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;
            }
        }