示例#1
0
 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));
     }
 }
示例#2
0
 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));
     }
 }
示例#3
0
 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));
     }
 }
示例#4
0
        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());
        }
示例#5
0
 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));
     }
 }
示例#6
0
 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));
     }
 }
示例#7
0
 public ushort[] GetGlyphs(ReadOnlySpan <byte> text, SKTextEncoding encoding)
 {
     fixed(void *t = text)
     {
         return(GetGlyphs((IntPtr)t, text.Length, encoding));
     }
 }
示例#8
0
 public int CountGlyphs(ReadOnlySpan <byte> str, SKTextEncoding encoding)
 {
     fixed(byte *p = str)
     {
         return(CountGlyphs((IntPtr)p, str.Length, encoding));
     }
 }
示例#9
0
        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);
            }
        }
示例#10
0
        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));
        }
示例#11
0
        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);
        }
示例#12
0
        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));
        }
示例#13
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));
        }
示例#14
0
文件: Util.cs 项目: Core2D/SkiaSharp
 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");
     }
 }
示例#15
0
        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.");
            }
        }
示例#16
0
        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.");
            }
        }
示例#17
0
        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");
            }
        }
示例#18
0
文件: Util.cs 项目: Core2D/SkiaSharp
 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");
     }
 }
示例#19
0
        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());
        }
示例#20
0
        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());
        }
示例#21
0
        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.");
            }
        }
示例#22
0
        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);
        }
示例#23
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);
            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.");
            }
        }
示例#24
0
		public extern static void sk_paint_set_text_encoding(sk_paint_t t, SKTextEncoding encoding);
示例#25
0
 public int CountGlyphs(ReadOnlySpan <byte> str, SKTextEncoding encoding) =>
 GetFont().CountGlyphs(str, encoding);
示例#26
0
 public int CountGlyphs(IntPtr str, int strLen, SKTextEncoding encoding) =>
 GetFont().CountGlyphs(str, strLen, encoding);
示例#27
0
 public ushort[] GetGlyphs(ReadOnlySpan <byte> text, SKTextEncoding encoding)
 {
     using var font = ToFont();
     return(font.GetGlyphs(text, encoding));
 }
示例#28
0
 public ushort[] GetGlyphs(IntPtr text, int length, SKTextEncoding encoding)
 {
     using var font = ToFont();
     return(font.GetGlyphs(text, length, encoding));
 }
示例#29
0
 public SKTextRun(byte[] text, SKTextEncoding encoding)
 {
     Text         = text;
     TextEncoding = encoding;
 }
示例#30
0
 public SKTextRun(string text, SKTextEncoding encoding)
 {
     Text         = StringUtilities.GetEncodedText(text, encoding);
     TextEncoding = encoding;
 }
示例#31
0
 public extern static void sk_paint_set_text_encoding(sk_paint_t t, SKTextEncoding encoding);
示例#32
0
 public bool ContainsGlyphs(IntPtr text, int length, SKTextEncoding encoding) =>
 GetFont().ContainsGlyphs(text, length, encoding);
示例#33
0
 public bool ContainsGlyphs(ReadOnlySpan <byte> text, SKTextEncoding encoding) =>
 GetFont().ContainsGlyphs(text, encoding);