[12762] | 1 | using System;
|
---|
| 2 | using System.Text;
|
---|
| 3 | using System.Drawing;
|
---|
| 4 | using System.Collections.Generic;
|
---|
| 5 |
|
---|
| 6 | using SharpVectors.Dom.Css;
|
---|
| 7 | using SharpVectors.Dom.Svg;
|
---|
| 8 |
|
---|
| 9 | namespace SharpVectors.Renderers
|
---|
| 10 | {
|
---|
| 11 | public static class GdiConverter
|
---|
| 12 | {
|
---|
| 13 |
|
---|
| 14 | /// <summary>
|
---|
| 15 | /// A GDI Color representation of the RgbColor
|
---|
| 16 | /// </summary>
|
---|
| 17 | public static Color ToColor(ICssColor color)
|
---|
| 18 | {
|
---|
| 19 | if (color == null)
|
---|
| 20 | {
|
---|
| 21 | return Color.Empty;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | double dRed = color.Red.GetFloatValue(CssPrimitiveType.Number);
|
---|
| 25 | double dGreen = color.Green.GetFloatValue(CssPrimitiveType.Number);
|
---|
| 26 | double dBlue = color.Blue.GetFloatValue(CssPrimitiveType.Number);
|
---|
| 27 |
|
---|
| 28 | if (Double.IsNaN(dRed) || Double.IsInfinity(dRed))
|
---|
| 29 | {
|
---|
| 30 | return Color.Empty;
|
---|
| 31 | }
|
---|
| 32 | if (Double.IsNaN(dGreen) || Double.IsInfinity(dGreen))
|
---|
| 33 | {
|
---|
| 34 | return Color.Empty;
|
---|
| 35 | }
|
---|
| 36 | if (Double.IsNaN(dBlue) || Double.IsInfinity(dBlue))
|
---|
| 37 | {
|
---|
| 38 | return Color.Empty;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | return Color.FromArgb(Convert.ToInt32(dRed), Convert.ToInt32(dGreen), Convert.ToInt32(dBlue));
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public static RectangleF ToRectangle(ICssRect rect)
|
---|
| 45 | {
|
---|
| 46 | if (rect == null)
|
---|
| 47 | {
|
---|
| 48 | return RectangleF.Empty;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | float x = (float)rect.Left.GetFloatValue(CssPrimitiveType.Px);
|
---|
| 52 | float y = (float)rect.Top.GetFloatValue(CssPrimitiveType.Px);
|
---|
| 53 | float width = (float)rect.Right.GetFloatValue(CssPrimitiveType.Px) - x;
|
---|
| 54 | float height = (float)rect.Bottom.GetFloatValue(CssPrimitiveType.Px) - y;
|
---|
| 55 |
|
---|
| 56 | return new RectangleF(x, y, width, height);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | /// <summary>
|
---|
| 61 | /// This converts the specified <see cref="RectangleF"/> structure to a
|
---|
| 62 | /// <see cref="SvgRectF"/> structure.
|
---|
| 63 | /// </summary>
|
---|
| 64 | /// <param name="rect">The <see cref="RectangleF"/> structure to convert.</param>
|
---|
| 65 | /// <returns>
|
---|
| 66 | /// The <see cref="SvgRectF"/> structure that is converted from the
|
---|
| 67 | /// specified <see cref="RectangleF"/> structure.
|
---|
| 68 | /// </returns>
|
---|
| 69 | public static RectangleF ToRectangle(SvgRectF rect)
|
---|
| 70 | {
|
---|
| 71 | return new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public static RectangleF ToRectangle(SvgRect rect)
|
---|
| 75 | {
|
---|
| 76 | if (rect == null)
|
---|
| 77 | {
|
---|
| 78 | return RectangleF.Empty;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | return new RectangleF((float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | }
|
---|
| 85 | }
|
---|