SkiaSharp/binding/Binding/SKString.cs

79 строки
1.6 KiB
C#
Исходник Постоянная ссылка Обычный вид История

//
// Bindings for SKTypeface
//
// Author:
// Matthew Leibowitz
//
// Copyright 2016 Xamarin Inc
//
using System;
using System.Runtime.InteropServices;
namespace SkiaSharp
{
internal class SKString : SKObject
{
[Preserve]
2016-06-17 23:54:08 +03:00
internal SKString (IntPtr handle, bool owns)
: base (handle, owns)
{
}
public SKString ()
2016-06-17 23:54:08 +03:00
: base (SkiaApi.sk_string_new_empty (), true)
{
if (Handle == IntPtr.Zero) {
throw new InvalidOperationException ("Unable to create a new SKString instance.");
}
}
public SKString (byte [] src, long length)
2016-06-17 23:54:08 +03:00
: base (SkiaApi.sk_string_new_with_copy (src, (IntPtr)length), true)
{
if (Handle == IntPtr.Zero) {
throw new InvalidOperationException ("Unable to copy the SKString instance.");
}
}
2017-01-17 22:30:45 +03:00
public SKString (byte [] src)
: this (src, src.Length)
{
}
public SKString (string str)
2017-02-04 15:12:55 +03:00
: this (StringUtilities.GetEncodedText (str, SKTextEncoding.Utf8))
2017-01-17 22:30:45 +03:00
{
}
public override string ToString ()
{
var cstr = SkiaApi.sk_string_get_c_str (Handle);
var clen = SkiaApi.sk_string_get_size (Handle);
2017-02-04 15:12:55 +03:00
return StringUtilities.GetString (cstr, (int)clen, SKTextEncoding.Utf8);
}
public static explicit operator string (SKString skString)
{
return skString.ToString ();
}
2017-01-17 22:30:45 +03:00
internal static SKString Create (string str)
{
if (str == null) {
return null;
}
return new SKString (str);
}
protected override void Dispose (bool disposing)
{
2016-06-17 23:54:08 +03:00
if (Handle != IntPtr.Zero && OwnsHandle) {
SkiaApi.sk_string_destructor (Handle);
}
base.Dispose (disposing);
}
}
}