Exemple #1
0
        private void drawText(SSText text, SKCanvas canvas)
        {
            var        lineNum    = 0;
            float      textheight = getTextHeight(text);
            SSPosition startPoint = PositionHelper.getPosition(text.alignX, text.alignY, 0, textheight, canvasSize);
            SSPosition position   = startPoint;

            foreach (SSLine line in text.lines)
            {
                LineProps lineProps = calculateLineProps(line);
                if (text.alignX.style == AlignKeys.Center)
                {
                    position.x -= (lineProps.width / 2);
                }
                else if (text.alignX.style == AlignKeys.Right)
                {
                    position.x -= lineProps.width;
                }
                position.y += lineProps.maxHeight;
                if (lineNum > 0)
                {
                    position.y += text.extraLineSpacing;
                }
                drawLine(line, position, canvas);
                lineNum++;
                position.x = startPoint.x;
            }
        }
Exemple #2
0
        private LineProps calculateLineProps(SSLine line)
        {
            LineProps lineProps = new LineProps(0, 0);

            foreach (SSLabel label in line.labels)
            {
                using (SKPaint paint = new SKPaint()) {
                    paint.TextSize    = label.fontSize;
                    paint.IsAntialias = true;
                    paint.Typeface    = getFont(label);
                    lineProps.width  += paint.MeasureText(label.text);
                    if (label.fontSize > lineProps.maxHeight)
                    {
                        lineProps.maxHeight = label.fontSize;
                    }
                }
            }
            return(lineProps);
        }