Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }