Added path effects to the C# API

This commit is contained in:
Matthew Leibowitz 2016-07-13 21:57:42 +02:00
Родитель 990ae04023
Коммит e3e1b81d04
7 изменённых файлов: 156 добавлений и 1 удалений

Просмотреть файл

@ -16,6 +16,7 @@
<Compile Include="$(MSBuildThisFileDirectory)SKColorFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKPaint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKDocument.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKPathEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKSurface.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKCanvas.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKShader.cs" />

Просмотреть файл

@ -227,6 +227,15 @@ namespace SkiaSharp
}
}
public SKPathEffect PathEffect {
get {
return GetObject<SKPathEffect> (SkiaApi.sk_paint_get_path_effect(Handle));
}
set {
SkiaApi.sk_paint_set_path_effect (Handle, value == null ? IntPtr.Zero : value.Handle);
}
}
public float MeasureText (string text)
{
if (text == null)

Просмотреть файл

@ -0,0 +1,84 @@
//
// Bindings for SKPath
//
// Author:
// Matthew Leibowitz
//
// Copyright 2016 Xamarin Inc
//
using System;
namespace SkiaSharp
{
public enum SkPath1DPathEffectStyle
{
Translate,
Rotate,
Morph,
}
public class SKPathEffect : SKObject
{
[Preserve]
internal SKPathEffect (IntPtr handle)
: base (handle)
{
}
public static SKPathEffect CreateCompose(SKPathEffect outer, SKPathEffect inner)
{
if (outer == null)
throw new ArgumentNullException(nameof(outer));
if (inner == null)
throw new ArgumentNullException(nameof(inner));
return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_compose(outer.Handle, inner.Handle));
}
public static SKPathEffect CreateSum(SKPathEffect first, SKPathEffect second)
{
if (first == null)
throw new ArgumentNullException(nameof(first));
if (second == null)
throw new ArgumentNullException(nameof(second));
return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_sum(first.Handle, second.Handle));
}
public static SKPathEffect CreateDiscrete(float segLength, float deviation, UInt32 seedAssist = 0)
{
return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_discrete(segLength, deviation, seedAssist));
}
public static SKPathEffect CreateCorner(float radius)
{
return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_corner(radius));
}
public static SKPathEffect Create1DPath(SKPath path, float advance, float phase, SkPath1DPathEffectStyle style)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_1d_path(path.Handle, advance, phase, style));
}
public static SKPathEffect Create2DLine(float width, SKMatrix matrix)
{
return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_2d_line(width, matrix));
}
public static SKPathEffect Create2DPath(SKMatrix matrix, SKPath path)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_2d_path(matrix, path.Handle));
}
public static SKPathEffect CreateDash(float[] intervals, float phase)
{
if (intervals == null)
throw new ArgumentNullException(nameof(intervals));
return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_dash(intervals, intervals.Length, phase));
}
}
}

Просмотреть файл

@ -38,6 +38,7 @@ using sk_imagefilter_t = System.IntPtr;
using sk_colorfilter_t = System.IntPtr;
using sk_document_t = System.IntPtr;
using sk_path_iterator_t = System.IntPtr;
using sk_path_effect_t = System.IntPtr;
namespace SkiaSharp
{
@ -286,6 +287,11 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static float sk_paint_get_fontmetrics(sk_paint_t t, out SKFontMetrics fontMetrics, float scale);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_paint_get_path_effect(sk_paint_t cpaint);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_paint_set_path_effect(sk_paint_t cpaint, sk_path_effect_t effect);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_image_t sk_image_new_raster_copy(ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes);
@ -851,6 +857,24 @@ namespace SkiaSharp
public extern static bool sk_imagedecoder_decode_stream(sk_stream_streamrewindable_t cstream, sk_bitmap_t bitmap, SKColorType pref, SKImageDecoderMode mode, ref SKImageDecoderFormat format);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static int sk_matrix_try_invert(ref SKMatrix matrix, out SKMatrix result);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_path_effect_create_compose(sk_path_effect_t outer, sk_path_effect_t inner);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_path_effect_create_sum(sk_path_effect_t first, sk_path_effect_t second);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_path_effect_create_discrete(float segLength, float deviation, UInt32 seedAssist /*0*/);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_path_effect_create_corner(float radius);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_path_effect_create_1d_path(sk_path_t path, float advance, float phase, SkPath1DPathEffectStyle style);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_path_effect_create_2d_line(float width, SKMatrix matrix);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_path_effect_create_2d_path(SKMatrix matrix, sk_path_t path);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_path_effect_t sk_path_effect_create_dash(float[] intervals, int count, float phase);
}
}

Просмотреть файл

@ -31,6 +31,7 @@
#include "xamarin/sk_x_maskfilter.h"
#include "xamarin/sk_x_paint.h"
#include "xamarin/sk_x_path.h"
#include "xamarin/sk_x_patheffect.h"
#include "xamarin/sk_x_shader.h"
#include "xamarin/sk_x_stream.h"
#include "xamarin/sk_x_typeface.h"
@ -75,6 +76,7 @@ void** KeepSkiaCSymbols ()
(void*)sk_string_new_empty,
(void*)sk_document_unref,
(void*)sk_wstream_write,
(void*)sk_path_effect_create_dash,
// Xamarin
(void*)sk_managedstream_new,

Просмотреть файл

@ -948,6 +948,40 @@ namespace SkiaSharp
OpenFileDelegate?.Invoke ("document.pdf");
}
public static void PathEffects (SKCanvas canvas, int width, int height)
{
canvas.Clear (SKColors.White);
var step = height / 4;
using (var paint = new SKPaint ())
using (var effect = SKPathEffect.CreateDash (new [] { 15f, 5f }, 0)) {
paint.IsStroke = true;
paint.StrokeWidth = 4;
paint.PathEffect = effect;
canvas.DrawLine (10, step, width - 10 - 10, step, paint);
}
using (var paint = new SKPaint ())
using (var effect = SKPathEffect.CreateDiscrete (10, 10)) {
paint.IsStroke = true;
paint.StrokeWidth = 4;
paint.PathEffect = effect;
canvas.DrawLine (10, step * 2, width - 10 - 10, step * 2, paint);
}
using (var paint = new SKPaint ())
using (var dashEffect = SKPathEffect.CreateDash (new [] { 15f, 5f }, 0))
using (var discreteEffect = SKPathEffect.CreateDiscrete (10, 10))
using (var effect = SKPathEffect.CreateCompose (dashEffect, discreteEffect)) {
paint.IsStroke = true;
paint.StrokeWidth = 4;
paint.PathEffect = effect;
canvas.DrawLine (10, step * 3, width - 10 - 10, step * 3, paint);
}
}
[Flags]
public enum Platform
@ -1014,6 +1048,7 @@ namespace SkiaSharp
new Sample {Title="Chained Image Filter", Method = ChainedImageFilter, Platform = Platform.All},
new Sample {Title="Measure Text Sample", Method = MeasureTextSample, Platform = Platform.All},
new Sample {Title="Create PDF", Method = CreatePdfSample, Platform = Platform.All, TapMethod = CreatePdfSampleTapped},
new Sample {Title="Path Effects", Method = PathEffects, Platform = Platform.All},
};
}
}

2
skia

@ -1 +1 @@
Subproject commit 2e4ace6235c0515c65931e5c08b212f83e3081e4
Subproject commit e31d35bc32be52f8e2c9da9628c89ca5646ad975