예제 #1
0
        public SKPositionedRunBuffer AllocatePositionedRun(SKPaint font, int count, int textByteCount, SKRect?bounds)
        {
            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }

            var originalEncoding = font.TextEncoding;

            try {
                font.TextEncoding = SKTextEncoding.GlyphId;

                SKRunBufferInternal runbuffer;
                if (bounds is SKRect b)
                {
                    SkiaApi.sk_textblob_builder_alloc_run_text_pos(Handle, font.GetFont().Handle, count, textByteCount, &b, &runbuffer);
                }
                else
                {
                    SkiaApi.sk_textblob_builder_alloc_run_text_pos(Handle, font.GetFont().Handle, count, textByteCount, null, &runbuffer);
                }

                return(new SKPositionedRunBuffer(runbuffer, count, textByteCount));
            } finally {
                font.TextEncoding = originalEncoding;
            }
        }
예제 #2
0
        public void DrawText(IntPtr buffer, int length, float x, float y, SKPaint paint)
        {
            if (buffer == IntPtr.Zero && length != 0)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (paint == null)
            {
                throw new ArgumentNullException(nameof(paint));
            }

            if (paint.TextAlign != SKTextAlign.Left)
            {
                var width = paint.MeasureText(buffer, length);
                if (paint.TextAlign == SKTextAlign.Center)
                {
                    width *= 0.5f;
                }
                x -= width;
            }

            using var blob = SKTextBlob.Create(buffer, length, paint.TextEncoding, paint.GetFont());
            if (blob == null)
            {
                return;
            }

            DrawText(blob, x, y, paint);
        }
예제 #3
0
        public void DrawText(byte[] text, float x, float y, SKPaint paint)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (paint == null)
            {
                throw new ArgumentNullException(nameof(paint));
            }

            if (paint.TextAlign != SKTextAlign.Left)
            {
                var width = paint.MeasureText(text);
                if (paint.TextAlign == SKTextAlign.Center)
                {
                    width *= 0.5f;
                }
                x -= width;
            }

            using var blob = SKTextBlob.Create(text, paint.TextEncoding, paint.GetFont());
            if (blob == null)
            {
                return;
            }

            DrawText(blob, x, y, paint);
        }
예제 #4
0
        public void DrawTextOnPath(string text, SKPath path, SKPoint offset, bool warpGlyphs, SKPaint paint)
        {
            if (paint == null)
            {
                throw new ArgumentNullException(nameof(paint));
            }

            DrawTextOnPath(text, path, offset, warpGlyphs, paint.GetFont(), paint);
        }
예제 #5
0
        public void DrawTextOnPath(IntPtr buffer, int length, SKPath path, float hOffset, float vOffset, SKPaint paint)
        {
            if (buffer == IntPtr.Zero && length != 0)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (paint == null)
            {
                throw new ArgumentNullException(nameof(paint));
            }

            var font = paint.GetFont();

            using var textPath = font.GetTextPathOnPath(buffer, length, paint.TextEncoding, path, paint.TextAlign, new SKPoint(hOffset, vOffset));
            DrawPath(textPath, paint);
        }
예제 #6
0
        public void DrawPositionedText(byte[] text, SKPoint[] points, SKPaint paint)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (paint == null)
            {
                throw new ArgumentNullException(nameof(paint));
            }
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            using var blob = SKTextBlob.CreatePositioned(text, paint.TextEncoding, paint.GetFont(), points);
            if (blob == null)
            {
                return;
            }

            DrawText(blob, 0, 0, paint);
        }
예제 #7
0
        public void DrawPositionedText(IntPtr buffer, int length, SKPoint[] points, SKPaint paint)
        {
            if (buffer == IntPtr.Zero && length != 0)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (paint == null)
            {
                throw new ArgumentNullException(nameof(paint));
            }
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            using var blob = SKTextBlob.CreatePositioned(buffer, length, paint.TextEncoding, paint.GetFont(), points);
            if (blob == null)
            {
                return;
            }

            DrawText(blob, 0, 0, paint);
        }
예제 #8
0
 public void DrawText(string text, float x, float y, SKPaint paint)
 {
     DrawText(text, x, y, paint.GetFont(), paint);
 }