// "Therefore those skilled at the unorthodox // are infinite as heaven and earth, // inexhaustible as the great rivers. // When they come to an end, // they begin again, // like the days and months; // they die and are reborn, // like the four seasons." // // - Sun Tsu, // "The Art of War" using System; using System.Drawing; using TheArtOfDev.HtmlRenderer.Adapters.Entities; namespace TheArtOfDev.HtmlRenderer.WinForms.Utilities { /// /// Utilities for converting WinForms entities to HtmlRenderer core entities. /// internal static class Utils { /// /// Convert from WinForms point to core point. /// public static RPoint Convert(PointF p) { return new RPoint(p.X, p.Y); } /// /// Convert from WinForms point to core point. /// public static PointF[] Convert(RPoint[] points) { PointF[] myPoints = new PointF[points.Length]; for (int i = 0; i < points.Length; i++) myPoints[i] = Convert(points[i]); return myPoints; } /// /// Convert from core point to WinForms point. /// public static PointF Convert(RPoint p) { return new PointF((float)p.X, (float)p.Y); } /// /// Convert from core point to WinForms point. /// public static Point ConvertRound(RPoint p) { return new Point((int)Math.Round(p.X), (int)Math.Round(p.Y)); } /// /// Convert from WinForms size to core size. /// public static RSize Convert(SizeF s) { return new RSize(s.Width, s.Height); } /// /// Convert from core size to WinForms size. /// public static SizeF Convert(RSize s) { return new SizeF((float)s.Width, (float)s.Height); } /// /// Convert from core size to WinForms size. /// public static Size ConvertRound(RSize s) { return new Size((int)Math.Round(s.Width), (int)Math.Round(s.Height)); } /// /// Convert from WinForms rectangle to core rectangle. /// public static RRect Convert(RectangleF r) { return new RRect(r.X, r.Y, r.Width, r.Height); } /// /// Convert from core rectangle to WinForms rectangle. /// public static RectangleF Convert(RRect r) { return new RectangleF((float)r.X, (float)r.Y, (float)r.Width, (float)r.Height); } /// /// Convert from core rectangle to WinForms rectangle. /// public static Rectangle ConvertRound(RRect r) { return new Rectangle((int)Math.Round(r.X), (int)Math.Round(r.Y), (int)Math.Round(r.Width), (int)Math.Round(r.Height)); } /// /// Convert from WinForms color to core color. /// public static RColor Convert(Color c) { return RColor.FromArgb(c.A, c.R, c.G, c.B); } /// /// Convert from core color to WinForms color. /// public static Color Convert(RColor c) { return Color.FromArgb(c.A, c.R, c.G, c.B); } } }