public static SKTextBlob CreateHorizontal(ReadOnlySpan <byte> text, SKTextEncoding encoding, SKFont font, ReadOnlySpan <float> positions, float y) { fixed(void *t = text) { return(CreateHorizontal(t, text.Length, encoding, font, positions, y)); } }
public static SKTextBlob Create(ReadOnlySpan <byte> text, SKTextEncoding encoding, SKFont font, SKPoint origin = default) { fixed(void *t = text) { return(Create(t, text.Length, encoding, font, origin)); } }
public static SKTextBlob CreatePathPositioned(ReadOnlySpan <byte> text, SKTextEncoding encoding, SKFont font, SKPath path, SKTextAlign textAlign = SKTextAlign.Left, SKPoint origin = default) { fixed(void *t = text) { return(CreatePathPositioned(t, text.Length, encoding, font, path, textAlign, origin)); } }
internal static SKTextBlob CreatePathPositioned(void *text, int length, SKTextEncoding encoding, SKFont font, SKPath path, SKTextAlign textAlign = SKTextAlign.Left, SKPoint origin = default) { if (font == null) { throw new ArgumentNullException(nameof(font)); } var count = font.CountGlyphs(text, length, encoding); if (count <= 0) { return(null); } // we use temporary arrays because we might only use part of the text using var glyphs = Utils.RentArray <ushort> (count); using var glyphWidths = Utils.RentArray <float> (glyphs.Length); using var glyphOffsets = Utils.RentArray <SKPoint> (glyphs.Length); font.GetGlyphs(text, length, encoding, glyphs); font.GetGlyphWidths(glyphs, glyphWidths, Span <SKRect> .Empty); font.GetGlyphPositions(glyphs, glyphOffsets, origin); using var builder = new SKTextBlobBuilder(); builder.AddPathPositionedRun(glyphs, font, glyphWidths, glyphOffsets, path, textAlign); return(builder.Build()); }
public static SKTextBlob CreatePositioned(ReadOnlySpan <byte> text, SKTextEncoding encoding, SKFont font, ReadOnlySpan <SKPoint> positions) { fixed(void *t = text) { return(CreatePositioned(t, text.Length, encoding, font, positions)); } }
public static SKTextBlob CreateRotationScale(ReadOnlySpan <byte> text, SKTextEncoding encoding, SKFont font, ReadOnlySpan <SKRotationScaleMatrix> positions) { fixed(void *t = text) { return(CreateRotationScale(t, text.Length, encoding, font, positions)); } }
public ushort[] GetGlyphs(ReadOnlySpan <byte> text, SKTextEncoding encoding) { fixed(void *t = text) { return(GetGlyphs((IntPtr)t, text.Length, encoding)); } }
public int CountGlyphs(ReadOnlySpan <byte> str, SKTextEncoding encoding) { fixed(byte *p = str) { return(CountGlyphs((IntPtr)p, str.Length, encoding)); } }
public void BreakTextReturnsTheCorrectNumberOfBytes(SKTextEncoding encoding, string text, int extectedRead) { var paint = new SKPaint(); paint.TextEncoding = encoding; // get bytes var bytes = encoding == SKTextEncoding.GlyphId ? GetGlyphBytes(text) : StringUtilities.GetEncodedText(text, encoding); var read = paint.BreakText(bytes, 50.0f, out var measured); Assert.Equal(extectedRead, read); Assert.True(measured > 0); byte[] GetGlyphBytes(string text) { var glyphs = paint.GetGlyphs(text); var bytes = new byte[Buffer.ByteLength(glyphs)]; Buffer.BlockCopy(glyphs, 0, bytes, 0, bytes.Length); return(bytes); } }
public int CountGlyphs(IntPtr str, int strLen, SKTextEncoding encoding) { if (str == IntPtr.Zero && strLen != 0) { throw new ArgumentNullException(nameof(str)); } return(SkiaApi.sk_typeface_chars_to_glyphs(Handle, (byte *)str, encoding.ToEncoding(), null, strLen)); }
public void CountGlyphsReturnsTheCorrectNumberOfGlyphsForUnicode(SKTextEncoding encoding) { using var font = new SKFont(); var bytes = StringUtilities.GetEncodedText("ä", encoding); var count = font.CountGlyphs(bytes, encoding); Assert.Equal(1, count); }
public static int GetUnicodeCharacterCode(string character, SKTextEncoding encoding) { if (GetUnicodeStringLength(encoding) != character.Length) { throw new ArgumentException(nameof(character), $"Only a single character can be specified."); } var bytes = GetEncodedText(character, encoding); return(BitConverter.ToInt32(bytes, 0)); }
public static string GetString(IntPtr data, int dataLength, SKTextEncoding encoding) { if (data == IntPtr.Zero || dataLength <= 0) { return(""); } byte[] result = new byte[dataLength]; Marshal.Copy(data, result, 0, dataLength); return(GetString(result, encoding)); }
public static byte[] GetEncodedText(string text, SKTextEncoding encoding) { switch (encoding) { case SKTextEncoding.Utf8: return Encoding.UTF8.GetBytes(text); case SKTextEncoding.Utf16: return Encoding.Unicode.GetBytes(text); case SKTextEncoding.Utf32: return Encoding.UTF32.GetBytes(text); default: throw new ArgumentException($"Encoding {encoding} is not supported"); } }
private static int GetUnicodeStringLength(SKTextEncoding encoding) { switch (encoding) { case SKTextEncoding.Utf8: case SKTextEncoding.Utf16: return(1); case SKTextEncoding.Utf32: return(2); default: throw new ArgumentOutOfRangeException(nameof(encoding), $"Encoding {encoding} is not supported."); } }
public static string GetString(byte[] data, SKTextEncoding encoding) { switch (encoding) { case SKTextEncoding.Utf8: return(Encoding.UTF8.GetString(data)); case SKTextEncoding.Utf16: return(Encoding.Unicode.GetString(data)); case SKTextEncoding.Utf32: return(Encoding.UTF32.GetString(data)); default: throw new ArgumentOutOfRangeException(nameof(encoding), $"Encoding {encoding} is not supported."); } }
public static byte[] GetEncodedText(string text, SKTextEncoding encoding) { switch (encoding) { case SKTextEncoding.Utf8: return(Encoding.UTF8.GetBytes(text)); case SKTextEncoding.Utf16: return(Encoding.Unicode.GetBytes(text)); case SKTextEncoding.Utf32: return(Encoding.UTF32.GetBytes(text)); default: throw new ArgumentException($"Encoding {encoding} is not supported"); } }
public static string GetString(IntPtr data, int dataLength, SKTextEncoding encoding) { if (data == IntPtr.Zero || dataLength <= 0) return ""; byte[] result = new byte[dataLength]; Marshal.Copy(data, result, 0, dataLength); switch (encoding) { case SKTextEncoding.Utf8: return Encoding.UTF8.GetString(result); case SKTextEncoding.Utf16: return Encoding.Unicode.GetString(result); case SKTextEncoding.Utf32: return Encoding.UTF32.GetString(result); default: throw new ArgumentException($"Encoding {encoding} is not supported"); } }
internal static SKTextBlob Create(void *text, int length, SKTextEncoding encoding, SKFont font, SKPoint origin) { if (font == null) { throw new ArgumentNullException(nameof(font)); } var count = font.CountGlyphs(text, length, encoding); if (count <= 0) { return(null); } using var builder = new SKTextBlobBuilder(); var buffer = builder.AllocatePositionedRun(font, count); font.GetGlyphs(text, length, encoding, buffer.GetGlyphSpan()); font.GetGlyphPositions(buffer.GetGlyphSpan(), buffer.GetPositionSpan(), origin); return(builder.Build()); }
internal static SKTextBlob CreateHorizontal(void *text, int length, SKTextEncoding encoding, SKFont font, ReadOnlySpan <float> positions, float y) { if (font == null) { throw new ArgumentNullException(nameof(font)); } var count = font.CountGlyphs(text, length, encoding); if (count <= 0) { return(null); } using var builder = new SKTextBlobBuilder(); var buffer = builder.AllocateHorizontalRun(font, count, y); font.GetGlyphs(text, length, encoding, buffer.GetGlyphSpan()); positions.CopyTo(buffer.GetPositionSpan()); return(builder.Build()); }
public static byte[] GetEncodedText(string text, SKTextEncoding encoding) { if (text == null) { throw new ArgumentNullException(nameof(text)); } switch (encoding) { case SKTextEncoding.Utf8: return(Encoding.UTF8.GetBytes(text)); case SKTextEncoding.Utf16: return(Encoding.Unicode.GetBytes(text)); case SKTextEncoding.Utf32: return(Encoding.UTF32.GetBytes(text)); default: throw new ArgumentOutOfRangeException(nameof(encoding), $"Encoding {encoding} is not supported."); } }
public ushort[] GetGlyphs(IntPtr text, int length, SKTextEncoding encoding) { if (text == IntPtr.Zero && length != 0) { throw new ArgumentNullException(nameof(text)); } var n = SkiaApi.sk_typeface_chars_to_glyphs(Handle, (void *)text, encoding.ToEncoding(), null, length); if (n <= 0) { return(new ushort[0]); } var glyphs = new ushort[n]; fixed(ushort *gp = glyphs) { SkiaApi.sk_typeface_chars_to_glyphs(Handle, (void *)text, encoding.ToEncoding(), gp, n); } return(glyphs); }
public static string GetString(IntPtr data, int dataLength, SKTextEncoding encoding) { if (data == IntPtr.Zero || dataLength <= 0) { return(""); } byte[] result = new byte[dataLength]; Marshal.Copy(data, result, 0, dataLength); switch (encoding) { case SKTextEncoding.Utf8: return(Encoding.UTF8.GetString(result)); case SKTextEncoding.Utf16: return(Encoding.Unicode.GetString(result)); case SKTextEncoding.Utf32: return(Encoding.UTF32.GetString(result)); default: throw new ArgumentOutOfRangeException(nameof(encoding), $"Encoding {encoding} is not supported."); } }
public extern static void sk_paint_set_text_encoding(sk_paint_t t, SKTextEncoding encoding);
public int CountGlyphs(ReadOnlySpan <byte> str, SKTextEncoding encoding) => GetFont().CountGlyphs(str, encoding);
public int CountGlyphs(IntPtr str, int strLen, SKTextEncoding encoding) => GetFont().CountGlyphs(str, strLen, encoding);
public ushort[] GetGlyphs(ReadOnlySpan <byte> text, SKTextEncoding encoding) { using var font = ToFont(); return(font.GetGlyphs(text, encoding)); }
public ushort[] GetGlyphs(IntPtr text, int length, SKTextEncoding encoding) { using var font = ToFont(); return(font.GetGlyphs(text, length, encoding)); }
public SKTextRun(byte[] text, SKTextEncoding encoding) { Text = text; TextEncoding = encoding; }
public SKTextRun(string text, SKTextEncoding encoding) { Text = StringUtilities.GetEncodedText(text, encoding); TextEncoding = encoding; }
public bool ContainsGlyphs(IntPtr text, int length, SKTextEncoding encoding) => GetFont().ContainsGlyphs(text, length, encoding);
public bool ContainsGlyphs(ReadOnlySpan <byte> text, SKTextEncoding encoding) => GetFont().ContainsGlyphs(text, encoding);