예제 #1
0
        /// <summary>
        /// Populates text measures. If you use a shared textShaper, call this before GetSpans, or GetLines.
        /// </summary>
        public void LoadMeasures(TextShaper textShaper = null)
        {
            if (textShaper == null)
            {
                textShaper = new TextShaper(false);
            }

            if (GlyphSpan == null)
            {
                GlyphSpan = textShaper.GetGlyphSpan(Font, Text);

                var fontMetrics = GlyphSpan.Paints[0].FontMetrics;
                FontHeight = fontMetrics.CapHeight;
                if (Font.LineHeight.HasValue)
                {
                    LineHeight = Font.LineHeight.Value;
                }
                else
                {
                    LineHeight = (fontMetrics.Descent - fontMetrics.Ascent + fontMetrics.Leading) * LineSpacing;
                }
                MarginY = (LineHeight - FontHeight) / 2;
            }

            if (LineBreakMode == LineBreakMode.MiddleTruncation)
            {
                if (EllipsisGlyphSpan == null)
                {
                    EllipsisGlyphSpan = textShaper.GetGlyphSpan(Font, " … ");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Draw a measuredspan (ie a substring) of the glyphspan
        /// </summary>
        /// <param name="x">Left coordinate</param>
        /// <param name="y">Bottom coordinate of the text baseline</param>
        /// <param name="measuredSpan"></param>
        public static void DrawGlyphSpan(this SKCanvas canvas, GlyphSpan glyphSpan, float x, float y, SKColor color, MeasuredSpan measuredSpan, GlyphAnimation glyphAnimation = null)
        {
            if (canvas == null)
            {
                return;
            }

            if (color.Alpha == 0)
            {
                return;
            }

            if (measuredSpan.glyphstart < 0)
            {
                return;
            }

            if (measuredSpan.glyphend < 0)
            {
                return;
            }

            // paint the "substring" blocks
            if (glyphAnimation == null)
            {
                glyphSpan.PaintBlocks(canvas, measuredSpan.glyphstart, measuredSpan.glyphend, x, y, color);
            }
            else
            {
                glyphSpan.PaintBlocks(canvas, measuredSpan.glyphstart, measuredSpan.glyphend, x, y, color, glyphAnimation);
            }
        }