Exemplo n.º 1
0
        /// <summary>
        /// Paint text
        /// </summary>
        private void OnPaintText(SKPaintSurfaceEventArgs e)
        {
            SKPaint textPaint = new SKPaint();

            textPaint.Color       = AnimationUtils.ColorTransform(_toggledAnimationProcess, TextColor, ToggledTextColor).ToSKColor();
            textPaint.TextSize    = (float)FontSize * DeviceScale;
            textPaint.TextAlign   = SKTextAlign.Left;
            textPaint.IsAntialias = true;

            SKFontStyleSlant  slant      = SkiaUtils.ConvertToSKFontStyle(FontStyle);
            SKFontStyleWeight fontWeight = SkiaUtils.ConvertToSKFontWeight(FontWeight);

            textPaint.Typeface = SKTypeface.FromFamilyName(FontFamily, fontWeight, SKFontStyleWidth.Normal, slant);

            SKRect skTextBounds = new SKRect();

            textPaint.MeasureText(Text, ref skTextBounds);

            float skNegativePadding = (float)EllipseDiameter * DeviceScale;

            float xText = skNegativePadding - skTextBounds.Left + (float)(TextMargin.Left * DeviceScale);
            float yText = -skTextBounds.Top + (e.Info.Height - skTextBounds.Height) / 2;

            double checkBoxWidth = _selectionViewSize.Width;

            if (_selectionViewLocation == HorizontalLocations.Left)
            {
                xText += (float)(checkBoxWidth * DeviceScale);
            }

            float lineHeight       = (float)FontSize * DeviceScale;
            float skAvailableWidth = (float)(Width - checkBoxWidth - TextMargin.HorizontalThickness) * DeviceScale;

            SkiaUtils.DrawTextArea(e.Surface.Canvas, textPaint, xText, yText, skAvailableWidth, lineHeight, IsTextWrapping, Text);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Measure total size
        /// </summary>
        protected Size MeasureTextSize(double widthConstraint, double heightConstraint)
        {
            SKPaint paint = new SKPaint();

            paint.TextSize = (float)FontSize;

            SKFontStyleSlant  slant      = SkiaUtils.ConvertToSKFontStyle(FontStyle);
            SKFontStyleWeight fontWeight = SkiaUtils.ConvertToSKFontWeight(FontWeight);

            paint.Typeface = SKTypeface.FromFamilyName(FontFamily, fontWeight, SKFontStyleWidth.Normal, slant);

            float lineHeight = (float)FontSize;

            return(SkiaUtils.MeasureText(paint, (float)widthConstraint, lineHeight, IsTextWrapping, Text));
        }