From 92a0c347170827cbad4a90b9b845716c4326438e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Thu, 29 Jul 2021 05:13:50 +0000 Subject: [PATCH] Add new line static field --- SvgToXaml/SvgConverter.cs | 85 ++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/SvgToXaml/SvgConverter.cs b/SvgToXaml/SvgConverter.cs index 8b23000..ee6d069 100644 --- a/SvgToXaml/SvgConverter.cs +++ b/SvgToXaml/SvgConverter.cs @@ -8,6 +8,8 @@ namespace SvgToXaml { public static class SvgConverter { + public static char[] NewLine = { '\r', '\n' }; + public static string ToString(double value) { return value.ToString(CultureInfo.InvariantCulture); @@ -52,7 +54,7 @@ namespace SvgToXaml brush += $"{indent}\r\n"; + brush += $"/>{NewLine}"; return brush; } @@ -74,8 +76,8 @@ namespace SvgToXaml brush += $"{indent}\r\n"; - brush += $"{indent} \r\n"; + brush += $" SpreadMethod=\"{ToGradientSpreadMethod(linearGradientShader.Mode)}\">{NewLine}"; + brush += $"{indent} {NewLine}"; if (linearGradientShader.Colors is { } && linearGradientShader.ColorPos is { }) { @@ -83,12 +85,12 @@ namespace SvgToXaml { var color = ToHexColor(linearGradientShader.Colors[i]); var offset = ToString(linearGradientShader.ColorPos[i]); - brush += $"{indent} \r\n"; + brush += $"{indent} {NewLine}"; } } - brush += $"{indent} \r\n"; - brush += $"{indent}\r\n"; + brush += $"{indent} {NewLine}"; + brush += $"{indent}{NewLine}"; return brush; } @@ -123,8 +125,8 @@ namespace SvgToXaml brush += $" Center=\"{ToPoint(center)}\""; brush += $" GradientOrigin=\"{ToPoint(gradientOrigin)}\""; brush += $" Radius=\"{ToString(endRadius)}\""; - brush += $" SpreadMethod=\"{ToGradientSpreadMethod(twoPointConicalGradientShader.Mode)}\">\r\n"; - brush += $"{indent} \r\n"; + brush += $" SpreadMethod=\"{ToGradientSpreadMethod(twoPointConicalGradientShader.Mode)}\">{NewLine}"; + brush += $"{indent} {NewLine}"; if (twoPointConicalGradientShader.Colors is { } && twoPointConicalGradientShader.ColorPos is { }) { @@ -132,12 +134,12 @@ namespace SvgToXaml { var color = ToHexColor(twoPointConicalGradientShader.Colors[i]); var offset = ToString(twoPointConicalGradientShader.ColorPos[i]); - brush += $"{indent} \r\n"; + brush += $"{indent} {NewLine}"; } } - brush += $"{indent} \r\n"; - brush += $"{indent}\r\n"; + brush += $"{indent} {NewLine}"; + brush += $"{indent}{NewLine}"; return brush; } @@ -217,11 +219,11 @@ namespace SvgToXaml if (skPaint.Shader is not ColorShader || (skPaint.PathEffect is DashPathEffect { Intervals: { } })) { - pen += $">\r\n"; + pen += $">{NewLine}"; } else { - pen += $"/>\r\n"; + pen += $"/>{NewLine}"; } if (skPaint.PathEffect is DashPathEffect dashPathEffect && dashPathEffect.Intervals is { }) @@ -235,21 +237,21 @@ namespace SvgToXaml var offset = dashPathEffect.Phase / skPaint.StrokeWidth; - pen += $"{indent} \r\n"; - pen += $"{indent} \r\n"; - pen += $"{indent} \r\n"; + pen += $"{indent} {NewLine}"; + pen += $"{indent} {NewLine}"; + pen += $"{indent} {NewLine}"; } if (skPaint.Shader is not ColorShader) { - pen += $"{indent} \r\n"; + pen += $"{indent} {NewLine}"; pen += ToBrush(skPaint.Shader, skBounds, indent + " "); - pen += $"{indent} \r\n"; + pen += $"{indent} {NewLine}"; } if (skPaint.Shader is not ColorShader || (skPaint.PathEffect is DashPathEffect { Intervals: { } })) { - pen += $"{indent}\r\n"; + pen += $"{indent}{NewLine}"; } return pen; @@ -290,11 +292,9 @@ namespace SvgToXaml { var sb = new StringBuilder(); - sb.Append($"\r\n"); - sb.Append($" \r\n"); - sb.Append($" \r\n"); - - var indent = " "; + sb.Append($"{NewLine}"); + sb.Append($" {NewLine}"); + sb.Append($" {NewLine}"); if (skPicture?.Commands is { }) { @@ -401,26 +401,27 @@ namespace SvgToXaml } } - bool isDrawingGroup = !totalMatrix.IsIdentity || clipPath is not null; + var isDrawingGroup = !totalMatrix.IsIdentity || clipPath is not null; + var indent = " "; if (isDrawingGroup) { - sb.Append($"{indent}\r\n"); + sb.Append($"{indent}{NewLine}"); } if (isDrawingGroup && !totalMatrix.IsIdentity) { - sb.Append($"{indent} \r\n"); - sb.Append($"{indent} \r\n"); - sb.Append($"{indent} \r\n"); + sb.Append($"{indent} {NewLine}"); + sb.Append($"{indent} {NewLine}"); + sb.Append($"{indent} {NewLine}"); } if (isDrawingGroup && clipPath is not null) { var clipGeometry = ToSvgPathData(clipPath); - sb.Append($"{indent} \r\n"); - sb.Append($"{indent} {clipGeometry}\r\n"); - sb.Append($"{indent} \r\n"); + sb.Append($"{indent} {NewLine}"); + sb.Append($"{indent} {clipGeometry}{NewLine}"); + sb.Append($"{indent} {NewLine}"); } var drawingIndent = isDrawingGroup ? $"{indent} " : indent; @@ -458,35 +459,35 @@ namespace SvgToXaml if (brush is not null || pen is not null) { - sb.Append($">\r\n"); + sb.Append($">{NewLine}"); } else { - sb.Append($"/>\r\n"); + sb.Append($"/>{NewLine}"); } if (brush is { }) { - sb.Append($"{drawingIndent} \r\n"); + sb.Append($"{drawingIndent} {NewLine}"); sb.Append($"{brush}"); - sb.Append($"{drawingIndent} \r\n"); + sb.Append($"{drawingIndent} {NewLine}"); } if (pen is { }) { - sb.Append($"{drawingIndent} \r\n"); + sb.Append($"{drawingIndent} {NewLine}"); sb.Append($"{pen}"); - sb.Append($"{drawingIndent} \r\n"); + sb.Append($"{drawingIndent} {NewLine}"); } if (brush is not null || pen is not null) { - sb.Append($"{drawingIndent}\r\n"); + sb.Append($"{drawingIndent}{NewLine}"); } if (isDrawingGroup) { - sb.Append($"{indent}\r\n"); + sb.Append($"{indent}{NewLine}"); } break; @@ -513,8 +514,8 @@ namespace SvgToXaml } } - sb.Append($" \r\n"); - sb.Append($" \r\n"); + sb.Append($" {NewLine}"); + sb.Append($" {NewLine}"); sb.Append($""); return sb.ToString();