using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using Microsoft.VisualBasic.CompilerServices;

public class SVG
{
	private string xml;

	private ArrayList gradientBlends;

	private int _iter;

	private int _width;

	private int _height;

	public SVG(int width, int height)
	{
		xml = "";
		_iter = 0;
		_width = width;
		_height = height;
		xml = "";
		gradientBlends = new ArrayList();
	}

	private int iterFilter()
	{
		checked
		{
			_iter++;
			return _iter;
		}
	}

	public string GetXml(bool scaleToFit)
	{
		checked
		{
			if (gradientBlends.Count > 0)
			{
				xml += "<defs>";
				int num = gradientBlends.Count - 1;
				for (int i = 0; i <= num; i++)
				{
					object[] array = (object[])gradientBlends[i];
					Color[] array2 = (Color[])array[0];
					float[] array3 = (float[])array[1];
					float[] array4 = (float[])array[2];
					xml = xml + "<linearGradient id=\"f" + Conversions.ToString(i) + "\"";
					if ((array4[1] == 0f) & (array4[2] == 0f))
					{
						xml += " x1=\"0%\" y1=\"0%\" x2=\"100%\" y2=\"0%\"";
					}
					else
					{
						xml += " x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\"";
					}
					xml += ">";
					int num2 = array2.Length - 1;
					for (int j = 0; j <= num2; j++)
					{
						xml = xml + "<stop offset=\"" + FormatNumber(array3[j]) + "\" stop-color=\"rgb(" + Conversions.ToString(array2[j].R) + "," + Conversions.ToString(array2[j].G) + "," + Conversions.ToString(array2[j].B) + ")\" />";
					}
					xml += "</linearGradient>";
				}
				xml += "</defs>";
			}
			xml += "</svg>";
			string text = "<?xml version=\"1.0\" standalone=\"no\"?>" + Environment.NewLine + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" + Environment.NewLine;
			text = ((!scaleToFit) ? (text + "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">" + Environment.NewLine) : (text + "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + Conversions.ToString(_width) + " " + Conversions.ToString(_height) + "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">" + Environment.NewLine));
			return text + xml;
		}
	}

	private string FormatNumber(float s)
	{
		string text = Conversions.ToString((double)checked((int)Math.Round(s * 100f)) / 100.0);
		return text.Replace(",", ".");
	}

	public void DrawRectangle(Pen p, Rectangle r)
	{
		xml = xml + "<rect x=\"" + Conversions.ToString(r.Left) + "\" y=\"" + Conversions.ToString(r.Top) + "\" width=\"" + Conversions.ToString(r.Width) + "\" height=\"" + Conversions.ToString(r.Height) + "\" style=\"fill:none;stroke-width:" + Conversions.ToString(p.Width) + ";stroke:rgb(" + Conversions.ToString(p.Color.R) + "," + Conversions.ToString(p.Color.G) + "," + Conversions.ToString(p.Color.B) + ")\" />";
	}

	public void DrawRectangleRounded(Color borderColor, Color backColor, RectangleF r)
	{
		int num = checked((!(r.Width > r.Height)) ? ((int)Math.Round((double)r.Width * 0.25)) : ((int)Math.Round((double)r.Height * 0.25)));
		xml = xml + "<rect x=\"" + Conversions.ToString(r.Left) + "\" y=\"" + Conversions.ToString(r.Top) + "\" width=\"" + Conversions.ToString(r.Width) + "\" height=\"" + Conversions.ToString(r.Height) + "\" rx=\"" + Conversions.ToString(num) + "\" ry=\"" + Conversions.ToString(num) + "\" style=\"fill:rgb(" + Conversions.ToString(backColor.R) + "," + Conversions.ToString(backColor.G) + "," + Conversions.ToString(backColor.B) + ");fill-opacity:" + FormatNumber((float)((double)(int)backColor.A / 255.0)) + ";stroke-width:1;stroke:rgb(" + Conversions.ToString(borderColor.R) + "," + Conversions.ToString(borderColor.G) + "," + Conversions.ToString(borderColor.B) + ")\"/>";
	}

	public void DrawRectangleRounded(Pen pen, LinearGradientBrush brush, RectangleF r)
	{
		checked
		{
			int num = ((!(r.Width > r.Height)) ? ((int)Math.Round((double)r.Width * 0.5)) : ((int)Math.Round((double)r.Height * 0.5)));
			xml = xml + "<rect x=\"" + Conversions.ToString((int)Math.Round(r.Left)) + "\" y=\"" + Conversions.ToString((int)Math.Round(r.Top)) + "\" width=\"" + Conversions.ToString((int)Math.Round(r.Width)) + "\" height=\"" + Conversions.ToString((int)Math.Round(r.Height)) + "\" rx=\"" + Conversions.ToString(num) + "\" ry=\"" + Conversions.ToString(num) + "\" style=\"";
			mWritePenBrushStyle(pen, brush);
			xml = xml + "\"/>" + Environment.NewLine;
		}
	}

	public void FillRectangle(Pen pen, Brush brush, Rectangle r)
	{
		xml = xml + "<rect x=\"" + Conversions.ToString(r.Left) + "\" y=\"" + Conversions.ToString(r.Top) + "\" width=\"" + Conversions.ToString(r.Width) + "\" height=\"" + Conversions.ToString(r.Height) + "\" style=\"";
		mWritePenBrushStyle(pen, brush);
		xml = xml + "\"/>" + Environment.NewLine;
	}

	public void DrawText(string text, Font font, Color c, int x, int y, StringFormat sf)
	{
		string text2 = "<text x=\"" + Conversions.ToString(x) + "\" y=\"" + Conversions.ToString(y) + "\" font-family=\"" + font.Name + "\" font-size=\"" + Conversions.ToString(font.SizeInPoints) + "\"";
		if (font.Bold)
		{
			text2 += " font-weight=\"bold\"";
		}
		if (font.Italic)
		{
			text2 += " font-style=\"italic\"";
		}
		text2 = text2 + " fill=\"rgb(" + Conversions.ToString(c.R) + "," + Conversions.ToString(c.G) + "," + Conversions.ToString(c.B) + ")\"";
		switch (sf.Alignment)
		{
		case StringAlignment.Center:
			text2 += " text-anchor=\"middle\"";
			break;
		case StringAlignment.Far:
			text2 += " text-anchor=\"end\"";
			break;
		}
		switch (sf.LineAlignment)
		{
		case StringAlignment.Center:
			text2 += " style=\"baseline-shift:-25%\"";
			break;
		case StringAlignment.Near:
			text2 += " style=\"baseline-shift:-75%\"";
			break;
		}
		if ((sf.FormatFlags & StringFormatFlags.DirectionVertical) != 0)
		{
			text2 += " glyph-orientation-vertical=\"90\"";
		}
		text2 = text2 + ">" + text + "</text>";
		xml += text2;
	}

	public void DrawPath(GraphicsPath path, Pen pen, Brush brush)
	{
		mAddPath(path, pen, brush);
	}

	public void DrawText(string text, Font font, Color c, RectangleF r, StringFormat sf)
	{
		checked
		{
			DrawText(text, font, c, sf.Alignment switch
			{
				StringAlignment.Center => (int)Math.Round(r.X + r.Width / 2f - 1f), 
				StringAlignment.Far => (int)Math.Round(r.Right - 5f), 
				_ => (int)Math.Round(r.X + 2f), 
			}, sf.LineAlignment switch
			{
				StringAlignment.Center => (int)Math.Round(r.Y + r.Height / 2f), 
				StringAlignment.Far => (int)Math.Round(r.Bottom), 
				_ => (int)Math.Round(r.Top), 
			}, sf);
		}
	}

	public void DrawText(string text, Font font, Color c, RectangleF r, int rotation)
	{
		string text2 = "<text x=\"" + Conversions.ToString(r.Left) + "\" y=\"" + Conversions.ToString(r.Top) + "\" font-family=\"" + font.Name + "\" font-size=\"" + Conversions.ToString(font.SizeInPoints) + "pt\"";
		if (font.Bold)
		{
			text2 += " font-weight=\"bold\"";
		}
		if (font.Italic)
		{
			text2 += " font-style=\"italic\"";
		}
		text2 = text2 + " stroke=\"rgb(" + Conversions.ToString(c.R) + "," + Conversions.ToString(c.G) + "," + Conversions.ToString(c.B) + ")\" rotate=\"" + Conversions.ToString(rotation) + "\"";
		text2 = text2 + ">" + text + "</text>";
		xml += text2;
	}

	public void DrawLine(Pen p, int x1, int y1, int x2, int y2)
	{
		xml = xml + "<line x1=\"" + Conversions.ToString(x1) + "\" y1=\"" + Conversions.ToString(y1) + "\" x2=\"" + Conversions.ToString(x2) + "\" y2=\"" + Conversions.ToString(y2) + "\"";
		switch (p.DashStyle)
		{
		case DashStyle.Dash:
			xml += " stroke-dasharray=\"7,4\"";
			break;
		case DashStyle.Dot:
			xml += " stroke-dasharray=\"2,2\"";
			break;
		case DashStyle.DashDot:
			xml += " stroke-dasharray=\"7,4,2,4\"";
			break;
		case DashStyle.DashDotDot:
			xml += " stroke-dasharray=\"7,4,2,4,2,4\"";
			break;
		}
		xml = xml + " style=\"stroke:rgb(" + Conversions.ToString(p.Color.R) + "," + Conversions.ToString(p.Color.G) + "," + Conversions.ToString(p.Color.B) + ");stroke-width:" + Conversions.ToString(p.Width) + "\" />";
	}

	public void DrawRectangleBlurred(Brush brush, Rectangle r)
	{
		xml = xml + "<defs><filter id=\"b" + Conversions.ToString(iterFilter()) + "\">";
		xml += "<feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"4\" />";
		xml += "</filter></defs>";
		xml = xml + "<g filter=\"url(#b" + Conversions.ToString(_iter) + ")\">";
		FillRectangle(null, brush, r);
		xml += "</g>";
	}

	public void DrawPath(Pen pen, GraphicsPath path)
	{
		mAddPath(path, pen, null);
	}

	public void DrawPolygon(Pen pen, PointF[] points)
	{
		xml = xml + "<polygon fill=\"none\" stroke=\"rgb(" + Conversions.ToString(pen.Color.R) + "," + Conversions.ToString(pen.Color.G) + "," + Conversions.ToString(pen.Color.B) + ")\" stroke-width=\"" + Conversions.ToString(pen.Width) + "\" points = \"";
		checked
		{
			int num = points.Length - 1;
			for (int i = 0; i <= num; i++)
			{
				xml = xml + Conversions.ToString(points[i].X).Replace(",", ".") + "," + Conversions.ToString(points[i].Y).Replace(",", ".") + " ";
			}
			xml += "\" />";
		}
	}

	public void FillPath(Brush brush, GraphicsPath path)
	{
		GraphicsPath graphicsPath = new GraphicsPath();
		graphicsPath.AddPath(path, connect: true);
		mAddPath(graphicsPath, null, brush);
	}

	public void FillPolygon(Color c, PointF[] points)
	{
		xml = xml + "<polygon fill=\"rgb(" + Conversions.ToString(c.R) + "," + Conversions.ToString(c.G) + "," + Conversions.ToString(c.B) + ")\" points = \"";
		checked
		{
			int num = points.Length - 1;
			for (int i = 0; i <= num; i++)
			{
				xml = xml + Conversions.ToString(points[i].X) + "," + Conversions.ToString(points[i].Y) + " ";
			}
			xml += "\" />";
		}
	}

	public void FillPolygon(Brush brush, PointF[] points)
	{
		GraphicsPath graphicsPath = new GraphicsPath();
		graphicsPath.AddPolygon(points);
		mAddPath(graphicsPath, null, brush);
	}

	public void DrawCurve(Pen pen, Point[] points)
	{
		GraphicsPath graphicsPath = new GraphicsPath();
		graphicsPath.AddCurve(points, 0.5f);
		mAddPath(graphicsPath, pen, null);
	}

	private void mAddPath(GraphicsPath path, Pen pen, Brush brush)
	{
		string text = "";
		checked
		{
			int num = path.PointCount - 1;
			for (int i = 0; i <= num; i++)
			{
				switch (path.PathTypes[i])
				{
				case 0:
					text = text + "M " + Conversions.ToString(path.PathPoints[i].X) + " " + Conversions.ToString(path.PathPoints[i].Y);
					break;
				case 129:
					text = text + " L " + Conversions.ToString(path.PathPoints[i].X) + " " + Conversions.ToString(path.PathPoints[i].Y) + "Z";
					break;
				case 1:
					text = text + " L " + Conversions.ToString(path.PathPoints[i].X) + " " + Conversions.ToString(path.PathPoints[i].Y);
					break;
				case 3:
				{
					text += " C";
					int num2 = 0;
					do
					{
						text += " ";
						text = text + Conversions.ToString(path.PathPoints[i + num2].X) + " " + Conversions.ToString(path.PathPoints[i + num2].Y);
						num2++;
					}
					while (num2 <= 2);
					if ((path.PathTypes[i + 2] & 0x80) == 128)
					{
						text += "Z";
					}
					i += 2;
					break;
				}
				case 128:
					text += "Z";
					break;
				}
			}
			xml += "<path style=\"";
			if (brush != null)
			{
				xml += "fill-rule:";
				switch (path.FillMode)
				{
				case FillMode.Alternate:
					xml += "evenodd;";
					break;
				case FillMode.Winding:
					xml += "nonzero;";
					break;
				}
			}
			mWritePenBrushStyle(pen, brush);
			xml += "\" d=\"";
			xml += text.Replace(",", ".");
			xml += "\" />";
		}
	}

	private void mWritePenBrushStyle(Pen pen, Brush brush)
	{
		if (brush == null)
		{
			xml += "fill:none;";
		}
		else if (brush is SolidBrush)
		{
			SolidBrush solidBrush = (SolidBrush)brush;
			xml = xml + "fill:rgb(" + Conversions.ToString(solidBrush.Color.R) + "," + Conversions.ToString(solidBrush.Color.G) + "," + Conversions.ToString(solidBrush.Color.B) + ");fill-opacity:" + FormatNumber((float)((double)(int)solidBrush.Color.A / 255.0)) + ";";
		}
		else if (brush is LinearGradientBrush)
		{
			LinearGradientBrush linearGradientBrush = (LinearGradientBrush)brush;
			xml = xml + "fill:url(#f" + Conversions.ToString(gradientBlends.Count) + ");";
			try
			{
				ColorBlend interpolationColors = linearGradientBrush.InterpolationColors;
				gradientBlends.Add(new object[3]
				{
					interpolationColors.Colors,
					interpolationColors.Positions,
					linearGradientBrush.Transform.Elements
				});
			}
			catch (Exception ex)
			{
				ProjectData.SetProjectError(ex);
				Exception ex2 = ex;
				if (linearGradientBrush.Blend.Positions.Length > 1)
				{
					gradientBlends.Add(new object[3]
					{
						new Color[3]
						{
							linearGradientBrush.LinearColors[0],
							linearGradientBrush.LinearColors[1],
							linearGradientBrush.LinearColors[0]
						},
						new float[3] { 0f, 0.5f, 1f },
						linearGradientBrush.Transform.Elements
					});
				}
				else
				{
					gradientBlends.Add(new object[3]
					{
						linearGradientBrush.LinearColors,
						new float[2] { 0f, 1f },
						linearGradientBrush.Transform.Elements
					});
				}
				ProjectData.ClearProjectError();
			}
		}
		else if (brush is PathGradientBrush)
		{
			PathGradientBrush pathGradientBrush = (PathGradientBrush)brush;
			xml = xml + "fill:url(#f" + Conversions.ToString(gradientBlends.Count) + ");";
			try
			{
				ColorBlend interpolationColors2 = pathGradientBrush.InterpolationColors;
				gradientBlends.Add(new object[3]
				{
					interpolationColors2.Colors,
					interpolationColors2.Positions,
					pathGradientBrush.Transform.Elements
				});
			}
			catch (Exception ex3)
			{
				ProjectData.SetProjectError(ex3);
				Exception ex4 = ex3;
				ProjectData.ClearProjectError();
			}
		}
		if (pen == null)
		{
			xml += "stroke:none;";
			return;
		}
		xml = xml + "stroke:rgb(" + Conversions.ToString(pen.Color.R) + "," + Conversions.ToString(pen.Color.G) + "," + Conversions.ToString(pen.Color.B) + ")\" stroke-width=\"" + Conversions.ToString(pen.Width) + ";";
		switch (pen.DashStyle)
		{
		case DashStyle.Dash:
			xml += "stroke-dasharray:7,4";
			break;
		case DashStyle.Dot:
			xml += "stroke-dasharray=2,2";
			break;
		case DashStyle.DashDot:
			xml += "stroke-dasharray=7,4,2,4";
			break;
		case DashStyle.DashDotDot:
			xml += "stroke-dasharray=7,4,2,4,2,4";
			break;
		}
	}

	public void FillBubble(PathGradientBrush bs, Rectangle r)
	{
		int num = r.Width / 2;
		int num2 = checked(r.Left + num);
		int num3 = r.Height / 2;
		checked
		{
			int num4 = r.Top + num3;
			int num5 = (int)Math.Round((double)num2 - (double)num * 0.4);
			int num6 = (int)Math.Round((double)num4 - (double)num3 * 0.4);
			Color centerColor = bs.CenterColor;
			Color color = bs.SurroundColors[0];
			xml = xml + "<defs><radialGradient id=\"f" + Conversions.ToString(iterFilter()) + "\" gradientUnits=\"userSpaceOnUse\" cx=\"" + Conversions.ToString(num2) + "\" cy=\"" + Conversions.ToString(num4) + "\" r=\"" + Conversions.ToString(num) + "\" fx=\"" + Conversions.ToString(num5) + "\" fy=\"" + Conversions.ToString(num6) + "\"><stop offset=\"0%\" stop-color=\"rgb(" + Conversions.ToString(centerColor.R) + "," + Conversions.ToString(centerColor.G) + "," + Conversions.ToString(centerColor.B) + ")\" /><stop offset=\"100%\" stop-color=\"rgb(" + Conversions.ToString(color.R) + "," + Conversions.ToString(color.G) + "," + Conversions.ToString(color.B) + ")\" /></radialGradient></defs>";
			xml = xml + "<ellipse fill=\"url(#f" + Conversions.ToString(_iter) + ")\" cx=\"" + Conversions.ToString(num2) + "\" cy=\"" + Conversions.ToString(num4) + "\" rx=\"" + Conversions.ToString(num) + "\" ry=\"" + Conversions.ToString(num3) + "\" />";
		}
	}

	public void FillEllipse(Color c, Rectangle r)
	{
		int num = r.Width / 2;
		int num2 = checked(r.Left + num);
		int num3 = r.Height / 2;
		int num4 = checked(r.Top + num3);
		xml = xml + "<ellipse fill=\"rgb(" + Conversions.ToString(c.R) + "," + Conversions.ToString(c.G) + "," + Conversions.ToString(c.B) + ")\" cx=\"" + Conversions.ToString(num2) + "\" cy=\"" + Conversions.ToString(num4) + "\" rx=\"" + Conversions.ToString(num) + "\" ry=\"" + Conversions.ToString(num3) + "\" />";
	}

	public void DrawEllipse(Pen pen, Rectangle r)
	{
		int num = r.Width / 2;
		int num2 = checked(r.Left + num);
		int num3 = r.Height / 2;
		int num4 = checked(r.Top + num3);
		xml = xml + "<ellipse fill=\"none\" stroke-width=\"" + Conversions.ToString(pen.Width) + "\" stroke=\"rgb(" + Conversions.ToString(pen.Color.R) + "," + Conversions.ToString(pen.Color.G) + "," + Conversions.ToString(pen.Color.B) + ")\" cx=\"" + Conversions.ToString(num2) + "\" cy=\"" + Conversions.ToString(num4) + "\" rx=\"" + Conversions.ToString(num) + "\" ry=\"" + Conversions.ToString(num3) + "\" />";
	}

	public void TransformApply(float angle, float dx, float dy)
	{
		xml += "<g transform=\"";
		if (dx != 0f || dy != 0f)
		{
			xml = xml + "translate(" + FormatNumber(dx) + "," + FormatNumber(dy) + ")";
		}
		if (angle != 0f)
		{
			xml = xml + " rotate(" + FormatNumber(angle) + ")";
		}
		xml += "\">";
	}

	public void TransformReset()
	{
		xml += "</g>";
	}

	public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle)
	{
		GraphicsPath graphicsPath = new GraphicsPath();
		graphicsPath.AddPie(rect, startAngle, sweepAngle);
		mAddPath(graphicsPath, null, new SolidBrush(((LinearGradientBrush)brush).LinearColors[0]));
	}

	public void DrawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle)
	{
		GraphicsPath graphicsPath = new GraphicsPath();
		graphicsPath.AddPie(rect, startAngle, sweepAngle);
		mAddPath(graphicsPath, pen, null);
	}
}
