Skip to content

Commit

Permalink
Fixed issue (sometimes other elements not drawn correctly), reusing e…
Browse files Browse the repository at this point in the history
…xisiting paint
  • Loading branch information
daniel-luberda committed Jun 9, 2018
1 parent c572fa9 commit 9cf03c4
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,29 @@ private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fi
var endPoint = gradient.GetEndPoint(x, y, elementSize.Width, elementSize.Height);

using (var gradientShader = SKShader.CreateLinearGradient(startPoint, endPoint, gradient.Colors, gradient.Positions, gradient.TileMode))
using (var gradientPaint = new SKPaint() { Shader = gradientShader, IsAntialias = true, BlendMode = SKBlendMode.SrcOver })
{
canvas.DrawPath(elementPath, gradientPaint);
var oldColor = fill.Color;
var oldShader = fill.Shader;
fill.Color = SKColors.Black;
fill.Shader = gradientShader;
canvas.DrawPath(elementPath, fill);
fill.Color = oldColor;
fill.Shader = oldShader;
}
break;
case SKRadialGradient gradient:
var centerPoint = gradient.GetCenterPoint(x, y, elementSize.Width, elementSize.Height);
var radius = gradient.GetRadius(elementSize.Width, elementSize.Height);

using (var gradientShader = SKShader.CreateRadialGradient(centerPoint, radius, gradient.Colors, gradient.Positions, gradient.TileMode))
using (var gradientPaint = new SKPaint() { Shader = gradientShader, IsAntialias = true })
{
canvas.DrawPath(elementPath, gradientPaint);
var oldColor = fill.Color;
var oldShader = fill.Shader;
fill.Color = SKColors.Black;
fill.Shader = gradientShader;
canvas.DrawPath(elementPath, fill);
fill.Color = oldColor;
fill.Shader = oldShader;
}
break;
default:
Expand Down Expand Up @@ -876,7 +886,7 @@ private void ReadPaints(Dictionary<string, string> style, ref SKPaint strokePain
if (ColorHelper.TryParse(stroke, out SKColor color))
{
// preserve alpha
if (color.Alpha == 255)
if (color.Alpha == 255 && fillPaint.Color.Alpha > 0)
strokePaint.Color = color.WithAlpha(strokePaint.Color.Alpha);
else
strokePaint.Color = color;
Expand Down Expand Up @@ -1017,7 +1027,7 @@ private void ReadPaints(Dictionary<string, string> style, ref SKPaint strokePain
if (ColorHelper.TryParse(fill, out SKColor color))
{
// preserve alpha
if (color.Alpha == 255)
if (color.Alpha == 255 && fillPaint.Color.Alpha > 0)
fillPaint.Color = color.WithAlpha(fillPaint.Color.Alpha);
else
fillPaint.Color = color;
Expand Down

0 comments on commit 9cf03c4

Please sign in to comment.