[12762] | 1 | using System;
|
---|
| 2 | using System.Text;
|
---|
| 3 | using System.Windows;
|
---|
| 4 | using System.Windows.Media;
|
---|
| 5 | using System.Collections.Generic;
|
---|
| 6 |
|
---|
| 7 | using SharpVectors.Dom.Css;
|
---|
| 8 | using SharpVectors.Dom.Svg;
|
---|
| 9 |
|
---|
| 10 | namespace SharpVectors.Renderers.Utils
|
---|
| 11 | {
|
---|
| 12 | public static class WpfConvert
|
---|
| 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 null;
|
---|
| 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 null;
|
---|
| 31 | }
|
---|
| 32 | if (Double.IsNaN(dGreen) || Double.IsInfinity(dGreen))
|
---|
| 33 | {
|
---|
| 34 | return null;
|
---|
| 35 | }
|
---|
| 36 | if (Double.IsNaN(dBlue) || Double.IsInfinity(dBlue))
|
---|
| 37 | {
|
---|
| 38 | return null;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | return Color.FromRgb(Convert.ToByte(dRed), Convert.ToByte(dGreen), Convert.ToByte(dBlue));
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public static Rect ToRect(ICssRect rect)
|
---|
| 45 | {
|
---|
| 46 | if (rect == null)
|
---|
| 47 | {
|
---|
| 48 | return Rect.Empty;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | double x = rect.Left.GetFloatValue(CssPrimitiveType.Px);
|
---|
| 52 | double y = rect.Top.GetFloatValue(CssPrimitiveType.Px);
|
---|
| 53 | double width = rect.Right.GetFloatValue(CssPrimitiveType.Px) - x;
|
---|
| 54 | double height = rect.Bottom.GetFloatValue(CssPrimitiveType.Px) - y;
|
---|
| 55 |
|
---|
| 56 | return new Rect(x, y, width, height);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | /// <summary>
|
---|
| 61 | /// This converts the specified <see cref="Rect"/> structure to a
|
---|
| 62 | /// <see cref="SvgRectF"/> structure.
|
---|
| 63 | /// </summary>
|
---|
| 64 | /// <param name="rect">The <see cref="Rect"/> structure to convert.</param>
|
---|
| 65 | /// <returns>
|
---|
| 66 | /// The <see cref="SvgRectF"/> structure that is converted from the
|
---|
| 67 | /// specified <see cref="Rect"/> structure.
|
---|
| 68 | /// </returns>
|
---|
| 69 | public static Rect ToRect(SvgRectF rect)
|
---|
| 70 | {
|
---|
| 71 | return new Rect(rect.X, rect.Y, rect.Width, rect.Height);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public static Rect ToRect(ISvgRect rect)
|
---|
| 75 | {
|
---|
| 76 | if (rect == null)
|
---|
| 77 | {
|
---|
| 78 | return Rect.Empty;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | return new Rect(rect.X, rect.Y, rect.Width, rect.Height);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | public static GradientSpreadMethod ToSpreadMethod(SvgSpreadMethod sm)
|
---|
| 85 | {
|
---|
| 86 | switch (sm)
|
---|
| 87 | {
|
---|
| 88 | case SvgSpreadMethod.Pad:
|
---|
| 89 | return GradientSpreadMethod.Pad;
|
---|
| 90 | case SvgSpreadMethod.Reflect:
|
---|
| 91 | return GradientSpreadMethod.Reflect;
|
---|
| 92 | case SvgSpreadMethod.Repeat:
|
---|
| 93 | return GradientSpreadMethod.Repeat;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | return GradientSpreadMethod.Pad;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | }
|
---|