using System;
using System.Drawing;
using System.Drawing.Drawing2D;

public class CustomGraphics
{
	private bool _svgMode;

	private Graphics _g;

	private SVG _svg;

	private bool _transform;

	private float _angle;

	private float _dx;

	private float _dy;

	public Graphics Graphics
	{
		get
		{
			return _g;
		}
		set
		{
			_g = value;
		}
	}

	public bool svgMode
	{
		get
		{
			return _svgMode;
		}
		set
		{
			_svgMode = value;
		}
	}

	public string svgText => _svg.GetXml(scaleToFit);

	public Graphics g => _g;

	public CustomGraphics()
	{
		_svgMode = false;
		_transform = false;
	}

	public void Prepare(Graphics g, int width, int height)
	{
		_g = g;
		_svg = new SVG(width, height);
		_transform = false;
		_angle = 0f;
		_dx = 0f;
		_dy = 0f;
	}

	public void FillRectangle(Brush brush, RectangleF r)
	{
		FillRectangle(brush, checked(Rectangle.FromLTRB((int)Math.Round(r.Left), (int)Math.Round(r.Top), (int)Math.Round(r.Right), (int)Math.Round(r.Bottom))));
	}

	public void FillRectangle(Brush brush, Rectangle r)
	{
		if (_svgMode)
		{
			_svg.FillRectangle(null, brush, r);
		}
		_g.FillRectangle(brush, r);
	}

	public void DrawString(string text, Font font, SolidBrush brush, int x, int y)
	{
		DrawString(text, font, brush, x, y, new StringFormat());
	}

	public void DrawString(string text, Font font, SolidBrush brush, RectangleF rf, StringFormat sf)
	{
		if (_svgMode)
		{
			if (_transform)
			{
				_svg.TransformApply(_angle, _dx, _dy);
				_svg.DrawText(text, font, brush.Color, rf, sf);
				_svg.TransformReset();
			}
			else
			{
				_svg.DrawText(text, font, brush.Color, rf, sf);
			}
		}
		_g.DrawString(text, font, brush, rf, sf);
	}

	public void DrawString(string text, Font font, SolidBrush brush, int x, int y, StringFormat sf)
	{
		if (_svgMode)
		{
			if (_transform)
			{
				_svg.TransformApply(_angle, _dx, _dy);
				_svg.DrawText(text, font, brush.Color, x, y, sf);
				_svg.TransformReset();
			}
			else
			{
				_svg.DrawText(text, font, brush.Color, x, y, sf);
			}
		}
		_g.DrawString(text, font, brush, x, y, sf);
	}

	public void DrawLine(Pen pen, float x1, float y1, float x2, float y2)
	{
		checked
		{
			if (_svgMode)
			{
				_svg.DrawLine(pen, (int)Math.Round(x1), (int)Math.Round(y1), (int)Math.Round(x2), (int)Math.Round(y2));
			}
			_g.DrawLine(pen, x1, y1, x2, y2);
		}
	}

	public void DrawLine(Pen pen, PointF p1, PointF p2)
	{
		checked
		{
			if (_svgMode)
			{
				_svg.DrawLine(pen, (int)Math.Round(p1.X), (int)Math.Round(p1.Y), (int)Math.Round(p2.X), (int)Math.Round(p2.Y));
			}
			_g.DrawLine(pen, p1, p2);
		}
	}

	public void DrawRectangle(Pen pen, Rectangle r)
	{
		if (_svgMode)
		{
			_svg.DrawRectangle(pen, r);
		}
		_g.DrawRectangle(pen, r);
	}

	public void FillBlurredPath(PathGradientBrush brush, GraphicsPath path)
	{
		if (_svgMode)
		{
			RectangleF bounds = path.GetBounds();
			_svg.DrawRectangleBlurred(brush, checked(Rectangle.FromLTRB((int)Math.Round(bounds.Left), (int)Math.Round(bounds.Top), (int)Math.Round(bounds.Right), (int)Math.Round(bounds.Bottom))));
		}
		_g.FillPath(brush, path);
	}

	public void DrawPath(Pen pen, GraphicsPath path)
	{
		if (_svgMode)
		{
			_svg.DrawPath(pen, path);
		}
		_g.DrawPath(pen, path);
	}

	public void FillPath(Brush brush, GraphicsPath path)
	{
		if (_svgMode)
		{
			_svg.FillPath(brush, path);
		}
		_g.FillPath(brush, path);
	}

	public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle)
	{
		if (_svgMode)
		{
			_svg.FillPie(brush, rect, startAngle, sweepAngle);
		}
		_g.FillPie(brush, rect, startAngle, sweepAngle);
	}

	public void FillPolygon(Brush brush, PointF[] points)
	{
		if (_svgMode)
		{
			_svg.FillPolygon(brush, points);
		}
		_g.FillPolygon(brush, points);
	}

	public void DrawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle)
	{
		if (_svgMode)
		{
			_svg.DrawPie(pen, rect, startAngle, sweepAngle);
		}
		_g.DrawPie(pen, rect, startAngle, sweepAngle);
	}

	public void DrawPolygon(Pen pen, PointF[] points)
	{
		if (_svgMode)
		{
			_svg.DrawPolygon(pen, points);
		}
		_g.DrawPolygon(pen, points);
	}

	public void RotateTransform(float angle)
	{
		if (_svgMode)
		{
			_angle = angle;
			_transform = true;
		}
		_g.RotateTransform(angle);
	}

	public void TranslateTransform(float dx, float dy, MatrixOrder order)
	{
		if (_svgMode)
		{
			_dx = dx;
			_dy = dy;
			_transform = true;
		}
		_g.TranslateTransform(dx, dy, order);
	}

	public void TranslateTransform(float dx, float dy)
	{
		if (_svgMode)
		{
			_dx = dx;
			_dy = dy;
			_transform = true;
		}
		_g.TranslateTransform(dx, dy);
	}

	public void ResetTransform()
	{
		_transform = false;
		_g.ResetTransform();
	}

	public void DrawCurve(Pen pen, Point[] points)
	{
		if (_svgMode)
		{
			_svg.DrawCurve(pen, points);
		}
		_g.DrawCurve(pen, points);
	}

	public SizeF MeasureString(string text, Font font)
	{
		return _g.MeasureString(text, font);
	}

	public SizeF MeasureString(string text, Font font, SizeF sizef, StringFormat sf)
	{
		return _g.MeasureString(text, font, sizef, sf);
	}

	public void FillBubble(Brush bs, Rectangle r)
	{
		if (_svgMode)
		{
			_svg.FillBubble((PathGradientBrush)bs, r);
		}
		_g.FillEllipse(bs, r);
	}

	public void FillEllipse(SolidBrush bs, Rectangle r)
	{
		if (_svgMode)
		{
			_svg.FillEllipse(bs.Color, r);
		}
		_g.FillEllipse(bs, r);
	}

	public void FillEllipse(SolidBrush bs, int left, int top, int width, int height)
	{
		FillEllipse(bs, checked(Rectangle.FromLTRB(left, top, left + width, top + height)));
	}

	public void FillEllipse(PathGradientBrush bs, RectangleF r)
	{
		if (_svgMode)
		{
			_svg.FillEllipse(bs.CenterColor, checked(Rectangle.FromLTRB((int)Math.Round(r.Left), (int)Math.Round(r.Top), (int)Math.Round(r.Right), (int)Math.Round(r.Bottom))));
		}
		_g.FillEllipse(bs, r);
	}

	public void DrawEllipse(Pen pen, Rectangle r)
	{
		if (_svgMode)
		{
			_svg.DrawEllipse(pen, r);
		}
		_g.DrawEllipse(pen, r);
	}

	public void FillRoundedRectangle(Color borderColor, Color backColor, GraphicsPath p)
	{
		if (_svgMode)
		{
			_svg.DrawRectangleRounded(borderColor, backColor, p.GetBounds());
		}
		_g.FillPath(new SolidBrush(backColor), p);
		_g.DrawPath(new Pen(borderColor), p);
	}

	public void FillHorizontalRoundedRectangle(Pen pen, LinearGradientBrush brush, GraphicsPath p)
	{
		if (_svgMode)
		{
			_svg.DrawRectangleRounded(pen, brush, p.GetBounds());
		}
		_g.FillPath(brush, p);
		_g.DrawPath(pen, p);
	}

	public void Clear(Color color)
	{
		_g.Clear(color);
	}
}
