2016-05-18 03:47:02 +03:00
|
|
|
|
//
|
|
|
|
|
// 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)
|
2016-05-18 03:47:02 +03:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SKString ()
|
2016-06-17 23:54:08 +03:00
|
|
|
|
: base (SkiaApi.sk_string_new_empty (), true)
|
2016-05-18 03:47:02 +03:00
|
|
|
|
{
|
|
|
|
|
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)
|
2016-05-18 03:47:02 +03:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 03:47:02 +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);
|
2016-05-18 03:47:02 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2016-05-18 03:47:02 +03:00
|
|
|
|
|
|
|
|
|
protected override void Dispose (bool disposing)
|
|
|
|
|
{
|
2016-06-17 23:54:08 +03:00
|
|
|
|
if (Handle != IntPtr.Zero && OwnsHandle) {
|
2016-05-18 03:47:02 +03:00
|
|
|
|
SkiaApi.sk_string_destructor (Handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.Dispose (disposing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|