Added bindings for canvas annotations

This commit is contained in:
Matthew Leibowitz 2017-01-17 02:49:40 +02:00
Родитель 1b4902a6b1
Коммит 93a5c9436c
4 изменённых файлов: 64 добавлений и 2 удалений

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

@ -462,6 +462,47 @@ namespace SkiaSharp
SkiaApi.sk_canvas_flush (Handle);
}
public void DrawAnnotation (SKRect rect, string key, SKData value)
{
SkiaApi.sk_canvas_draw_annotation (Handle, ref rect, Util.GetEncodedText (key, SKTextEncoding.Utf8), value == null ? IntPtr.Zero : value.Handle);
}
public void DrawUrlAnnotation (SKRect rect, SKData value)
{
SkiaApi.sk_canvas_draw_url_annotation (Handle, ref rect, value == null ? IntPtr.Zero : value.Handle);
}
public SKData DrawUrlAnnotation (SKRect rect, string value)
{
var data = SKData.FromCString (value);
DrawUrlAnnotation (rect, data);
return data;
}
public void DrawNamedDestinationAnnotation (SKPoint point, SKData value)
{
SkiaApi.sk_canvas_draw_named_destination_annotation (Handle, ref point, value == null ? IntPtr.Zero : value.Handle);
}
public SKData DrawNamedDestinationAnnotation (SKPoint point, string value)
{
var data = SKData.FromCString (value);
DrawNamedDestinationAnnotation (point, data);
return data;
}
public void DrawLinkDestinationAnnotation (SKRect rect, SKData value)
{
SkiaApi.sk_canvas_draw_link_destination_annotation (Handle, ref rect, value == null ? IntPtr.Zero : value.Handle);
}
public SKData DrawLinkDestinationAnnotation (SKRect rect, string value)
{
var data = SKData.FromCString (value);
DrawLinkDestinationAnnotation (rect, data);
return data;
}
public void DrawBitmapNinePatch (SKBitmap bitmap, SKRectI center, SKRect dst, SKPaint paint = null)
{
if (bitmap == null)

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

@ -10,6 +10,7 @@
using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
namespace SkiaSharp
{
@ -52,7 +53,12 @@ namespace SkiaSharp
}
public SKData (byte[] bytes)
: this (SkiaApi.sk_data_new_with_copy (bytes, (IntPtr) bytes.Length), true)
: this (bytes, (ulong) bytes.Length)
{
}
public SKData (byte[] bytes, ulong length)
: this (SkiaApi.sk_data_new_with_copy (bytes, (IntPtr) length), true)
{
if (Handle == IntPtr.Zero) {
throw new InvalidOperationException ("Unable to copy the SKData instance.");
@ -66,6 +72,12 @@ namespace SkiaSharp
return GetObject<SKData> (SkiaApi.sk_data_new_from_malloc (bytes, (IntPtr) length));
}
internal static SKData FromCString (string str)
{
var bytes = Encoding.ASCII.GetBytes (str ?? string.Empty);
return new SKData (bytes, (ulong)(bytes.Length + 1)); // + 1 for the terminating char
}
public SKData Subset (ulong offset, ulong length)
{
if (Marshal.SizeOf (typeof(IntPtr)) == 4) {

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

@ -202,6 +202,15 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_canvas_get_total_matrix(sk_canvas_t canvas, ref SKMatrix matrix);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_canvas_draw_annotation(sk_canvas_t t, ref SKRect rect, byte[] key, sk_data_t value);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_canvas_draw_url_annotation(sk_canvas_t t, ref SKRect rect, sk_data_t value);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_canvas_draw_named_destination_annotation(sk_canvas_t t, ref SKPoint point, sk_data_t value);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_canvas_draw_link_destination_annotation(sk_canvas_t t, ref SKRect rect, sk_data_t value);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_canvas_clip_rect_with_operation(sk_canvas_t t, ref SKRect crect, SKClipOperation op, bool doAA);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]

2
externals/skia поставляемый

@ -1 +1 @@
Subproject commit 706b362df172f4c2538e9f6848f9957a4ea9dc87
Subproject commit a100ca604629d377d0ba1acbb3c41001561483fe