コード例 #1
0
        public SKRect Draw(SKCanvas canvas, SKRect rect, TextShaper textShaper = null, FlowDirection flowDirection = FlowDirection.LeftToRight)
        {
            LoadMeasures(textShaper);

            var y = rect.Top + FontHeight + MarginY;

            if (LineBreakMode == LineBreakMode.MiddleTruncation)
            {
                var spans = GetSpans(rect.Width);
                if (flowDirection == FlowDirection.LeftToRight)
                {
                    var x = rect.Left;
                    if (spans.Count > 0)
                    {
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, spans[0]);
                        x += spans[0].width;
                    }
                    if (spans.Count > 1)
                    {
                        canvas.DrawGlyphSpan(EllipsisGlyphSpan, x, y, Color, spans[1]);
                        x += spans[1].width;
                    }
                    if (spans.Count > 2)
                    {
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, spans[2]);
                    }
                }
                else
                {
                    var x = rect.Right;
                    if (spans.Count > 0)
                    {
                        x -= spans[0].width;
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, spans[0]);
                    }
                    if (spans.Count > 1)
                    {
                        x -= spans[1].width;
                        canvas.DrawGlyphSpan(EllipsisGlyphSpan, x, y, Color, spans[1]);
                    }
                    if (spans.Count > 2)
                    {
                        x -= spans[2].width;
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, spans[2]);
                    }
                }
                y += LineHeight;
            }
            else
            {
                var lines = GetLines(rect.Width);
                var i     = 0;
                foreach (var line in lines)
                {
                    if (GetLineColor != null)
                    {
                        Color = GetLineColor(i++, lines.Count);
                    }
                    if (LineBreakMode == LineBreakMode.WordWrap)
                    {
                        float x;
                        if (flowDirection == FlowDirection.LeftToRight)
                        {
                            x = rect.Left;
                        }
                        else
                        {
                            x = rect.Right - line.width;
                        }
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, line, GlyphAnimation);
                    }
                    else if (LineBreakMode == LineBreakMode.Center)
                    {
                        var x = rect.Left + (rect.Width - line.width) / 2;
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, line, GlyphAnimation);
                    }
                    y += LineHeight;
                }
            }

            var paintrect = new SKRect(rect.Left, rect.Top, rect.Right, y - LineHeight + MarginY);

#if DEBUGCONTAINER
            if (canvas != null)
            {
                using (var borderpaint = new SKPaint()
                {
                    Color = SKColors.Red.WithAlpha(64), IsStroke = true
                })
                    canvas.DrawRect(paintrect, borderpaint);
            }
#endif

            return(paintrect);
        }