|
|
@ -1,8 +1,8 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
using Avalonia.Media; |
|
|
using Avalonia.Media; |
|
|
using Avalonia.Platform; |
|
|
|
|
|
using Avalonia.Media.Imaging; |
|
|
using Avalonia.Media.Imaging; |
|
|
|
|
|
using Avalonia.Platform; |
|
|
using SkiaSharp; |
|
|
using SkiaSharp; |
|
|
|
|
|
|
|
|
namespace Avalonia.Skia |
|
|
namespace Avalonia.Skia |
|
|
@ -67,7 +67,7 @@ namespace Avalonia.Skia |
|
|
{ |
|
|
{ |
|
|
return new SKPoint((float)p.X, (float)p.Y); |
|
|
return new SKPoint((float)p.X, (float)p.Y); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static SKPoint ToSKPoint(this Vector p) |
|
|
public static SKPoint ToSKPoint(this Vector p) |
|
|
{ |
|
|
{ |
|
|
return new SKPoint((float)p.X, (float)p.Y); |
|
|
return new SKPoint((float)p.X, (float)p.Y); |
|
|
@ -77,17 +77,17 @@ namespace Avalonia.Skia |
|
|
{ |
|
|
{ |
|
|
return new SKRect((float)r.X, (float)r.Y, (float)r.Right, (float)r.Bottom); |
|
|
return new SKRect((float)r.X, (float)r.Y, (float)r.Right, (float)r.Bottom); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal static SKRect ToSKRect(this LtrbRect r) |
|
|
internal static SKRect ToSKRect(this LtrbRect r) |
|
|
{ |
|
|
{ |
|
|
return new SKRect((float)r.Left, (float)r.Right, (float)r.Right, (float)r.Bottom); |
|
|
return new SKRect((float)r.Left, (float)r.Right, (float)r.Right, (float)r.Bottom); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static SKRectI ToSKRectI(this PixelRect r) |
|
|
public static SKRectI ToSKRectI(this PixelRect r) |
|
|
{ |
|
|
{ |
|
|
return new SKRectI(r.X, r.Y, r.Right, r.Bottom); |
|
|
return new SKRectI(r.X, r.Y, r.Right, r.Bottom); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal static SKRectI ToSKRectI(this LtrbPixelRect r) |
|
|
internal static SKRectI ToSKRectI(this LtrbPixelRect r) |
|
|
{ |
|
|
{ |
|
|
return new SKRectI(r.Left, r.Top, r.Right, r.Bottom); |
|
|
return new SKRectI(r.Left, r.Top, r.Right, r.Bottom); |
|
|
@ -103,7 +103,7 @@ namespace Avalonia.Skia |
|
|
{ |
|
|
{ |
|
|
r.RadiiTopLeft.ToSKPoint(), r.RadiiTopRight.ToSKPoint(), |
|
|
r.RadiiTopLeft.ToSKPoint(), r.RadiiTopRight.ToSKPoint(), |
|
|
r.RadiiBottomRight.ToSKPoint(), r.RadiiBottomLeft.ToSKPoint(), |
|
|
r.RadiiBottomRight.ToSKPoint(), r.RadiiBottomLeft.ToSKPoint(), |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
@ -112,17 +112,17 @@ namespace Avalonia.Skia |
|
|
{ |
|
|
{ |
|
|
return new Rect(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top); |
|
|
return new Rect(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal static LtrbRect ToAvaloniaLtrbRect(this SKRect r) |
|
|
internal static LtrbRect ToAvaloniaLtrbRect(this SKRect r) |
|
|
{ |
|
|
{ |
|
|
return new LtrbRect(r.Left, r.Top, r.Right, r.Bottom); |
|
|
return new LtrbRect(r.Left, r.Top, r.Right, r.Bottom); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static PixelRect ToAvaloniaPixelRect(this SKRectI r) |
|
|
public static PixelRect ToAvaloniaPixelRect(this SKRectI r) |
|
|
{ |
|
|
{ |
|
|
return new PixelRect(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top); |
|
|
return new PixelRect(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal static LtrbPixelRect ToAvaloniaLtrbPixelRect(this SKRectI r) |
|
|
internal static LtrbPixelRect ToAvaloniaLtrbPixelRect(this SKRectI r) |
|
|
{ |
|
|
{ |
|
|
return new LtrbPixelRect(r.Left, r.Top, r.Right, r.Bottom); |
|
|
return new LtrbPixelRect(r.Left, r.Top, r.Right, r.Bottom); |
|
|
@ -220,9 +220,12 @@ namespace Avalonia.Skia |
|
|
switch (m) |
|
|
switch (m) |
|
|
{ |
|
|
{ |
|
|
default: |
|
|
default: |
|
|
case GradientSpreadMethod.Pad: return SKShaderTileMode.Clamp; |
|
|
case GradientSpreadMethod.Pad: |
|
|
case GradientSpreadMethod.Reflect: return SKShaderTileMode.Mirror; |
|
|
return SKShaderTileMode.Clamp; |
|
|
case GradientSpreadMethod.Repeat: return SKShaderTileMode.Repeat; |
|
|
case GradientSpreadMethod.Reflect: |
|
|
|
|
|
return SKShaderTileMode.Mirror; |
|
|
|
|
|
case GradientSpreadMethod.Repeat: |
|
|
|
|
|
return SKShaderTileMode.Repeat; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -231,9 +234,12 @@ namespace Avalonia.Skia |
|
|
switch (a) |
|
|
switch (a) |
|
|
{ |
|
|
{ |
|
|
default: |
|
|
default: |
|
|
case TextAlignment.Left: return SKTextAlign.Left; |
|
|
case TextAlignment.Left: |
|
|
case TextAlignment.Center: return SKTextAlign.Center; |
|
|
return SKTextAlign.Left; |
|
|
case TextAlignment.Right: return SKTextAlign.Right; |
|
|
case TextAlignment.Center: |
|
|
|
|
|
return SKTextAlign.Center; |
|
|
|
|
|
case TextAlignment.Right: |
|
|
|
|
|
return SKTextAlign.Right; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -262,9 +268,12 @@ namespace Avalonia.Skia |
|
|
switch (a) |
|
|
switch (a) |
|
|
{ |
|
|
{ |
|
|
default: |
|
|
default: |
|
|
case SKTextAlign.Left: return TextAlignment.Left; |
|
|
case SKTextAlign.Left: |
|
|
case SKTextAlign.Center: return TextAlignment.Center; |
|
|
return TextAlignment.Left; |
|
|
case SKTextAlign.Right: return TextAlignment.Right; |
|
|
case SKTextAlign.Center: |
|
|
|
|
|
return TextAlignment.Center; |
|
|
|
|
|
case SKTextAlign.Right: |
|
|
|
|
|
return TextAlignment.Right; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -275,7 +284,18 @@ namespace Avalonia.Skia |
|
|
SKFontStyleSlant.Upright => FontStyle.Normal, |
|
|
SKFontStyleSlant.Upright => FontStyle.Normal, |
|
|
SKFontStyleSlant.Italic => FontStyle.Italic, |
|
|
SKFontStyleSlant.Italic => FontStyle.Italic, |
|
|
SKFontStyleSlant.Oblique => FontStyle.Oblique, |
|
|
SKFontStyleSlant.Oblique => FontStyle.Oblique, |
|
|
_ => throw new ArgumentOutOfRangeException(nameof (slant), slant, null) |
|
|
_ => throw new ArgumentOutOfRangeException(nameof(slant), slant, null) |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static SKFontStyleSlant ToSkia(this FontStyle style) |
|
|
|
|
|
{ |
|
|
|
|
|
return style switch |
|
|
|
|
|
{ |
|
|
|
|
|
FontStyle.Normal => SKFontStyleSlant.Upright, |
|
|
|
|
|
FontStyle.Italic => SKFontStyleSlant.Italic, |
|
|
|
|
|
FontStyle.Oblique => SKFontStyleSlant.Oblique, |
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(style), style, null) |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|