コード例 #1
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);
		}
コード例 #2
0
		public override void Reset()
		{
			base.Reset();
			if (mDefinition == null) mDefinition = new Definition(null);
		}
コード例 #3
0
ファイル: Marker.cs プロジェクト: savagemat/arcgis-diagrammer
		private string ExtractMarkerImplementation(MarkerBase marker, float rotation, bool invert)
		{
			GraphicsPath path = marker.GetPath();

			Matrix translateMatrix = new Matrix();
			RectangleF rectF = new RectangleF();

			rectF = path.GetBounds();

			translateMatrix.Translate(-rectF.X, -rectF.Y);
			path.Transform(translateMatrix);
			translateMatrix.Dispose();

			StringBuilder def = new StringBuilder();

			def.Append("<marker id=\"\" viewbox=\"0 0 ");

			//Add viewbox data
			def.Append(XmlConvert.ToString(Math.Round(rectF.Width, 2)));
			def.Append(" ");
			def.Append(XmlConvert.ToString(Math.Round(rectF.Height, 2)));
			def.Append("\" ");
			
			//Add ref x and y
			if (!invert)
			{
				def.Append("refX=\"");
				def.Append(XmlConvert.ToString(Math.Round(rectF.Width, 2)));
				def.Append("\" ");
			}
			def.Append("refY=\"");
			def.Append(XmlConvert.ToString(Math.Round(rectF.Height/2, 2)));
			def.Append("\" ");
			
			//Units
			def.Append("markerUnits=\"strokeWidth\" ");

			//markerWidth and Height
			def.Append("markerWidth=\"");
			def.Append(XmlConvert.ToString(Math.Round(rectF.Width, 2)));
			def.Append("\" ");
			def.Append("markerHeight=\"");
			def.Append(XmlConvert.ToString(Math.Round(rectF.Height, 2)));
			def.Append("\" ");

			//Orient
			def.Append("orient=\"auto\" ");

			//Stroke-width
			def.Append("stroke=\"");
			def.Append(Style.GetCompatibleColor(marker.BorderColor));
			def.Append("\" ");

			//Stroke-width
			def.Append("stroke-width=\"");
			def.Append(XmlConvert.ToString(Math.Round(marker.BorderWidth, 2)));
			def.Append("\" ");

			//Fill
			def.Append("fill=\"");
			
			if (marker.DrawBackground)
			{
				def.Append(Style.GetCompatibleColor(marker.BackColor));
			}
			else
			{
				def.Append("white");
			}
			def.Append("\" ");
			
			def.Append(">");

			//Append path
			if (mDefinition == null)
			{
				mDefinition = new Definition(marker.GetPath());
				mDefinition.IncludeId = false;
			}
			else
			{
				mDefinition.Path = marker.GetPath();
			}

			mDefinition.Rotate(rotation);
			def.Append(mDefinition.ExtractPath());

			//Close tag
			def.Append("</marker>");

			return def.ToString();
		}
コード例 #4
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;
			}
		}
コード例 #5
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;
            }
        }