Пример #1
0
 private static bool IsFilled(SP.Paint paint)
 {
     if (paint is null)
     {
         return(false);
     }
     return(paint.Style == SP.PaintStyle.Fill || paint.Style == SP.PaintStyle.StrokeAndFill);
 }
Пример #2
0
        public static void ToSKPaint(this SP.Paint paint, SkiaCodeGenObjectCounter counter, StringBuilder sb, string indent)
        {
            var counterPaint = counter.Paint;

            sb.AppendLine($"{indent}var {counter.PaintVarName}{counterPaint} = new SKPaint();");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.Style = {paint.Style.ToSKPaintStyle()};");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.IsAntialias = {paint.IsAntialias.ToString(_ci).ToLower()};");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.StrokeWidth = {paint.StrokeWidth.ToString(_ci)}f;");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.StrokeCap = {paint.StrokeCap.ToSKStrokeCap()};");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.StrokeJoin = {paint.StrokeJoin.ToSKStrokeJoin()};");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.StrokeMiter = {paint.StrokeMiter.ToString(_ci)}f;");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.TextSize = {paint.TextSize.ToString(_ci)}f;");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.TextAlign = {paint.TextAlign.ToSKTextAlign()};");

            if (paint.Typeface != null)
            {
                // TODO: Typeface = paint.Typeface?.ToSKTypeface();
                sb.AppendLine($"{indent} // TODO: {counter.PaintVarName}{counterPaint}.Typeface");
            }

            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.LcdRenderText = {paint.LcdRenderText.ToString(_ci).ToLower()};");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.SubpixelText = {paint.SubpixelText.ToString(_ci).ToLower()};");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.TextEncoding = {paint.TextEncoding.ToSKTextEncoding()};");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.Color = {(paint.Color == null ? "SKColor.Empty" : ToSKColor(paint.Color.Value))};");

            if (paint.Shader != null)
            {
                var counterShader = ++counter.Shader;
                paint.Shader.ToSKShader(counter, sb, indent);
                sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.Shader = {counter.ShaderVarName}{counterShader};");
            }

            if (paint.ColorFilter != null)
            {
                // TODO: ColorFilter = paint.ColorFilter?.ToSKColorFilter();
                sb.AppendLine($"{indent} // TODO: {counter.PaintVarName}{counterPaint}.ColorFilter");
            }

            if (paint.ImageFilter != null)
            {
                // TODO: ImageFilter = paint.ImageFilter?.ToSKImageFilter();
                sb.AppendLine($"{indent} // TODO: {counter.PaintVarName}{counterPaint}.ImageFilter");
            }

            if (paint.PathEffect != null)
            {
                // TODO: PathEffect = paint.PathEffect?.ToSKPathEffect();
                sb.AppendLine($"{indent} // TODO: {counter.PaintVarName}{counterPaint}.PathEffect");
            }

            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.BlendMode = {paint.BlendMode.ToSKBlendMode()};");
            sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}.FilterQuality = {paint.FilterQuality.ToSKFilterQuality()};");
        }
Пример #3
0
        private static ShapeStyleViewModel ToStyle(SP.Paint paint, IFactory factory)
        {
            var style = factory.CreateShapeStyle("Style");

            if (paint is null)
            {
                return(style);
            }

            switch (paint.Shader)
            {
            case SP.ColorShader colorShader:
                style.Stroke.Color = ToArgbColor(colorShader, factory);
                style.Fill.Color   = ToArgbColor(colorShader, factory);
                break;

            case SP.LinearGradientShader linearGradientShader:
                // TODO:
                break;

            case SP.TwoPointConicalGradientShader twoPointConicalGradientShader:
                // TODO:
                break;

            case SP.PictureShader pictureShader:
                // TODO:
                break;

            default:
                break;
            }

            style.Stroke.Thickness = paint.StrokeWidth;

            style.Stroke.LineCap = ToLineCap(paint.StrokeCap);

            if (paint.PathEffect is SP.DashPathEffect dashPathEffect && dashPathEffect.Intervals is { })
Пример #4
0
        private static IShapeStyle ToStyle(SP.Paint paint, IFactory factory)
        {
            var style = factory.CreateShapeStyle("Style");

            if (paint == null)
            {
                return(style);
            }

            switch (paint.Shader)
            {
            case SP.ColorShader colorShader:
                style.Stroke = ToArgbColor(colorShader, factory);
                style.Fill   = ToArgbColor(colorShader, factory);
                break;

            case SP.LinearGradientShader linearGradientShader:
                // TODO:
                break;

            case SP.TwoPointConicalGradientShader twoPointConicalGradientShader:
                // TODO:
                break;

            case SP.PictureShader pictureShader:
                // TODO:
                break;

            default:
                break;
            }

            style.Thickness = paint.StrokeWidth;

            style.LineCap = ToLineCap(paint.StrokeCap);

            if (paint.PathEffect is SP.DashPathEffect dashPathEffect && dashPathEffect.Intervals != null)
            {
                style.Dashes     = StyleHelper.ConvertFloatArrayToDashes(dashPathEffect.Intervals);
                style.DashOffset = dashPathEffect.Phase;
            }

            if (paint.Typeface != null)
            {
                if (paint.Typeface.FamilyName != null)
                {
                    style.TextStyle.FontName = paint.Typeface.FamilyName;
                }

                style.TextStyle.FontSize = paint.TextSize;

                style.TextStyle.TextHAlignment = ToTextHAlignment(paint.TextAlign);

                if (paint.Typeface.Weight == SP.FontStyleWeight.Bold)
                {
                    style.TextStyle.FontStyle.Bold = true;
                }

                if (paint.Typeface.Style == SP.FontStyleSlant.Italic)
                {
                    style.TextStyle.FontStyle.Italic = true;
                }
            }

            return(style);
        }
Пример #5
0
 public void DrawTextOnPath(string text, Path path, float hOffset, float vOffset, Paint paint)
 {
     Commands?.Add(new DrawTextOnPathCanvasCommand(text, path, hOffset, vOffset, paint));
 }
Пример #6
0
 public void DrawText(string text, float x, float y, Paint paint)
 {
     Commands?.Add(new DrawTextCanvasCommand(text, x, y, paint));
 }
Пример #7
0
 public void DrawText(TextBlob textBlob, float x, float y, Paint paint)
 {
     Commands?.Add(new DrawTextBlobCanvasCommand(textBlob, x, y, paint));
 }
Пример #8
0
 public void DrawPath(Path path, Paint paint)
 {
     Commands?.Add(new DrawPathCanvasCommand(path, paint));
 }