This commit is contained in:
Wiesław Šoltés 2022-08-21 22:18:26 +02:00
Родитель 8d6cc8e4a3
Коммит deb383c050
8 изменённых файлов: 21 добавлений и 217 удалений

Просмотреть файл

@ -96,12 +96,6 @@ public class MainWindowViewModel : ViewModelBase
await Reload();
});
// ReSharper disable once AsyncVoidLambda
this.WhenAnyValue(x => x.Project.Settings.UseBrushTransform).Subscribe(async _ =>
{
await Reload();
});
// ReSharper disable once AsyncVoidLambda
this.WhenAnyValue(x => x.Project.Settings.IgnoreOpacity).Subscribe(async _ =>
{
@ -410,7 +404,6 @@ public class MainWindowViewModel : ViewModelBase
var converter = new SvgToXamlConverter.SvgToXamlConverter()
{
UseCompatMode = Project.Settings.UseCompatMode,
UseBrushTransform = Project.Settings.UseBrushTransform,
ReuseExistingResources = Project.Settings.ReuseExistingResources,
Resources = Project.Settings.UseResources ? new ResourceDictionary() : null
};
@ -423,7 +416,6 @@ public class MainWindowViewModel : ViewModelBase
var converter = new SvgToXamlConverter.SvgToXamlConverter()
{
UseCompatMode = Project.Settings.UseCompatMode,
UseBrushTransform = Project.Settings.UseBrushTransform,
ReuseExistingResources = Project.Settings.ReuseExistingResources,
Resources = Project.Settings.UseResources ? new ResourceDictionary() : null
};
@ -497,7 +489,6 @@ public class MainWindowViewModel : ViewModelBase
var converter = new SvgToXamlConverter.SvgToXamlConverter()
{
UseCompatMode = Project.Settings.UseCompatMode,
UseBrushTransform = Project.Settings.UseBrushTransform,
AddTransparentBackground = Project.Settings.AddTransparentBackground,
ReuseExistingResources = Project.Settings.ReuseExistingResources,
Resources = Project.Settings.UseResources ? new ResourceDictionary() : null
@ -511,7 +502,6 @@ public class MainWindowViewModel : ViewModelBase
var converter = new SvgToXamlConverter.SvgToXamlConverter()
{
UseCompatMode = Project.Settings.UseCompatMode,
UseBrushTransform = Project.Settings.UseBrushTransform,
AddTransparentBackground = Project.Settings.AddTransparentBackground,
ReuseExistingResources = Project.Settings.ReuseExistingResources,
Resources = Project.Settings.UseResources ? new ResourceDictionary() : null
@ -533,7 +523,6 @@ public class MainWindowViewModel : ViewModelBase
var converter = new SvgToXamlConverter.SvgToXamlConverter()
{
UseCompatMode = Project.Settings.UseCompatMode,
UseBrushTransform = Project.Settings.UseBrushTransform,
ReuseExistingResources = Project.Settings.ReuseExistingResources,
Resources = Project.Settings.UseResources ? new ResourceDictionary() : null
};
@ -592,7 +581,6 @@ public class MainWindowViewModel : ViewModelBase
var converter = new SvgToXamlConverter.SvgToXamlConverter()
{
UseCompatMode = Project.Settings.UseCompatMode,
UseBrushTransform = Project.Settings.UseBrushTransform,
ReuseExistingResources = Project.Settings.ReuseExistingResources,
Resources = Project.Settings.UseResources ? new ResourceDictionary() : null
};

Просмотреть файл

@ -44,7 +44,6 @@ public class ProjectViewModel : ViewModelBase
UseResources = true,
ReuseExistingResources = true,
UseCompatMode = false,
UseBrushTransform = false,
AddTransparentBackground = true,
IgnoreOpacity = false,
IgnoreFilter = false,

Просмотреть файл

@ -10,7 +10,6 @@ public class SettingsViewModel : ViewModelBase
private bool _useResources;
private bool _reuseExistingResources;
private bool _useCompatMode;
private bool _useBrushTransform;
private bool _addTransparentBackground;
private bool _ignoreOpacity;
private bool _ignoreFilter;
@ -52,13 +51,6 @@ public class SettingsViewModel : ViewModelBase
set => this.RaiseAndSetIfChanged(ref _useCompatMode, value);
}
[JsonInclude]
public bool UseBrushTransform
{
get => _useBrushTransform;
set => this.RaiseAndSetIfChanged(ref _useBrushTransform, value);
}
[JsonInclude]
public bool AddTransparentBackground
{

Просмотреть файл

@ -355,12 +355,6 @@
HorizontalContentAlignment="Stretch"
Margin="0"
Padding="6"/>
<CheckBox IsChecked="{Binding UseBrushTransform}"
Content="Use Brush Transform"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Margin="0"
Padding="6"/>
<Separator Background="{DynamicResource SystemChromeAltLowColor}" Opacity="0.3" Height="0.55"/>
<CheckBox IsChecked="{Binding AddTransparentBackground}"
Content="Add Transparent Background"

Просмотреть файл

@ -8,8 +8,6 @@ public record GeneratorContext
public bool UseCompatMode { get; init; } = false;
public bool UseBrushTransform { get; init; } = false;
public bool AddTransparentBackground { get; init; } = false;
public bool ReuseExistingResources { get; init; } = false;

Просмотреть файл

@ -172,39 +172,6 @@ public class XamlGenerator : GeneratorBase
var start = linearGradientBrush.Start;
var end = linearGradientBrush.End;
if (!context.UseBrushTransform)
{
if (linearGradientBrush.LocalMatrix is { })
{
var localMatrix = linearGradientBrush.LocalMatrix.Value;
localMatrix.TransX = Math.Max(0f, localMatrix.TransX - linearGradientBrush.Bounds.Location.X);
localMatrix.TransY = Math.Max(0f, localMatrix.TransY - linearGradientBrush.Bounds.Location.Y);
start = localMatrix.MapPoint(start);
end = localMatrix.MapPoint(end);
}
else
{
start.X = Math.Max(0f, start.X - linearGradientBrush.Bounds.Location.X);
start.Y = Math.Max(0f, start.Y - linearGradientBrush.Bounds.Location.Y);
end.X = Math.Max(0f, end.X - linearGradientBrush.Bounds.Location.X);
end.Y = Math.Max(0f, end.Y - linearGradientBrush.Bounds.Location.Y);
}
}
else
{
if (!context.UseCompatMode)
{
if (linearGradientBrush.LocalMatrix is null)
{
start.X = Math.Max(0f, start.X - linearGradientBrush.Bounds.Location.X);
start.Y = Math.Max(0f, start.Y - linearGradientBrush.Bounds.Location.Y);
end.X = Math.Max(0f, end.X - linearGradientBrush.Bounds.Location.X);
end.Y = Math.Max(0f, end.Y - linearGradientBrush.Bounds.Location.Y);
}
}
}
sb.Append($"<LinearGradientBrush{ToKey(linearGradientBrush.Key)}");
sb.Append($" StartPoint=\"{ToPoint(start)}\"");
@ -222,22 +189,13 @@ public class XamlGenerator : GeneratorBase
sb.Append($">{context.NewLine}");
if (context.UseBrushTransform)
if (linearGradientBrush.LocalMatrix is { })
{
if (linearGradientBrush.LocalMatrix is { })
{
// TODO: Missing Transform property on LinearGradientBrush
var localMatrix = linearGradientBrush.LocalMatrix.Value;
var localMatrix = linearGradientBrush.LocalMatrix.Value;
if (!context.UseCompatMode)
{
localMatrix = linearGradientBrush.WithTransXY(localMatrix, linearGradientBrush.Bounds.Location.X, linearGradientBrush.Bounds.Location.Y);
}
sb.Append($" <LinearGradientBrush.Transform>{context.NewLine}");
sb.Append($" <MatrixTransform Matrix=\"{ToMatrix(localMatrix)}\"/>{context.NewLine}");
sb.Append($" </LinearGradientBrush.Transform>{context.NewLine}");
}
sb.Append($" <LinearGradientBrush.Transform>{context.NewLine}");
sb.Append($" <MatrixTransform Matrix=\"{ToMatrix(localMatrix)}\"/>{context.NewLine}");
sb.Append($" </LinearGradientBrush.Transform>{context.NewLine}");
}
if (linearGradientBrush.GradientStops.Count > 0)
@ -268,43 +226,6 @@ public class XamlGenerator : GeneratorBase
var center = radialGradientBrush.Center;
var gradientOrigin = radialGradientBrush.Center;
if (!context.UseBrushTransform)
{
if (radialGradientBrush.LocalMatrix is { })
{
var localMatrix = radialGradientBrush.LocalMatrix.Value;
localMatrix.TransX = Math.Max(0f, localMatrix.TransX - radialGradientBrush.Bounds.Location.X);
localMatrix.TransY = Math.Max(0f, localMatrix.TransY - radialGradientBrush.Bounds.Location.Y);
center = localMatrix.MapPoint(center);
gradientOrigin = localMatrix.MapPoint(gradientOrigin);
var radiusMapped = localMatrix.MapVector(new SkiaSharp.SKPoint(radius, 0));
radius = radiusMapped.X;
}
else
{
center.X = Math.Max(0f, center.X - radialGradientBrush.Bounds.Location.X);
center.Y = Math.Max(0f, center.Y - radialGradientBrush.Bounds.Location.Y);
gradientOrigin.X = Math.Max(0f, gradientOrigin.X - radialGradientBrush.Bounds.Location.X);
gradientOrigin.Y = Math.Max(0f, gradientOrigin.Y - radialGradientBrush.Bounds.Location.Y);
}
}
else
{
if (!context.UseCompatMode)
{
if (radialGradientBrush.LocalMatrix is null)
{
center.X = Math.Max(0f, center.X - radialGradientBrush.Bounds.Location.X);
center.Y = Math.Max(0f, center.Y - radialGradientBrush.Bounds.Location.Y);
gradientOrigin.X = Math.Max(0f, gradientOrigin.X - radialGradientBrush.Bounds.Location.X);
gradientOrigin.Y = Math.Max(0f, gradientOrigin.Y - radialGradientBrush.Bounds.Location.Y);
}
}
}
if (!context.UseCompatMode)
{
radius = radius / radialGradientBrush.Bounds.Width;
@ -337,22 +258,13 @@ public class XamlGenerator : GeneratorBase
sb.Append($">{context.NewLine}");
if (context.UseBrushTransform)
if (radialGradientBrush.LocalMatrix is { })
{
if (radialGradientBrush.LocalMatrix is { })
{
// TODO: Missing Transform property on RadialGradientBrush
var localMatrix = radialGradientBrush.LocalMatrix.Value;
var localMatrix = radialGradientBrush.LocalMatrix.Value;
if (!context.UseCompatMode)
{
localMatrix = radialGradientBrush.WithTransXY(localMatrix, radialGradientBrush.Bounds.Location.X, radialGradientBrush.Bounds.Location.Y);
}
sb.Append($" <RadialGradientBrush.Transform>{context.NewLine}");
sb.Append($" <MatrixTransform Matrix=\"{ToMatrix(localMatrix)}\"/>{context.NewLine}");
sb.Append($" </RadialGradientBrush.Transform>{context.NewLine}");
}
sb.Append($" <RadialGradientBrush.Transform>{context.NewLine}");
sb.Append($" <MatrixTransform Matrix=\"{ToMatrix(localMatrix)}\"/>{context.NewLine}");
sb.Append($" </RadialGradientBrush.Transform>{context.NewLine}");
}
if (radialGradientBrush.GradientStops.Count > 0)
@ -389,43 +301,6 @@ public class XamlGenerator : GeneratorBase
var center = twoPointConicalGradientBrush.End;
var gradientOrigin = twoPointConicalGradientBrush.Start;
if (!context.UseBrushTransform)
{
if (twoPointConicalGradientBrush.LocalMatrix is { })
{
var localMatrix = twoPointConicalGradientBrush.LocalMatrix.Value;
localMatrix.TransX = Math.Max(0f, localMatrix.TransX - twoPointConicalGradientBrush.Bounds.Location.X);
localMatrix.TransY = Math.Max(0f, localMatrix.TransY - twoPointConicalGradientBrush.Bounds.Location.Y);
center = localMatrix.MapPoint(center);
gradientOrigin = localMatrix.MapPoint(gradientOrigin);
var radiusMapped = localMatrix.MapVector(new SkiaSharp.SKPoint(endRadius, 0));
endRadius = radiusMapped.X;
}
else
{
center.X = Math.Max(0f, center.X - twoPointConicalGradientBrush.Bounds.Location.X);
center.Y = Math.Max(0f, center.Y - twoPointConicalGradientBrush.Bounds.Location.Y);
gradientOrigin.X = Math.Max(0f, gradientOrigin.X - twoPointConicalGradientBrush.Bounds.Location.X);
gradientOrigin.Y = Math.Max(0f, gradientOrigin.Y - twoPointConicalGradientBrush.Bounds.Location.Y);
}
}
else
{
if (!context.UseCompatMode)
{
if (twoPointConicalGradientBrush.LocalMatrix is null)
{
center.X = Math.Max(0f, center.X - twoPointConicalGradientBrush.Bounds.Location.X);
center.Y = Math.Max(0f, center.Y - twoPointConicalGradientBrush.Bounds.Location.Y);
gradientOrigin.X = Math.Max(0f, gradientOrigin.X - twoPointConicalGradientBrush.Bounds.Location.X);
gradientOrigin.Y = Math.Max(0f, gradientOrigin.Y - twoPointConicalGradientBrush.Bounds.Location.Y);
}
}
}
if (!context.UseCompatMode)
{
endRadius = endRadius / twoPointConicalGradientBrush.Bounds.Width;
@ -458,22 +333,13 @@ public class XamlGenerator : GeneratorBase
sb.Append($">{context.NewLine}");
if (context.UseBrushTransform)
if (twoPointConicalGradientBrush.LocalMatrix is { })
{
if (twoPointConicalGradientBrush.LocalMatrix is { })
{
// TODO: Missing Transform property on RadialGradientBrush
var localMatrix = twoPointConicalGradientBrush.LocalMatrix.Value;
var localMatrix = twoPointConicalGradientBrush.LocalMatrix.Value;
if (!context.UseCompatMode)
{
localMatrix = twoPointConicalGradientBrush.WithTransXY(localMatrix, twoPointConicalGradientBrush.Bounds.Location.X, twoPointConicalGradientBrush.Bounds.Location.Y);
}
sb.Append($" <RadialGradientBrush.Transform>{context.NewLine}");
sb.Append($" <MatrixTransform Matrix=\"{ToMatrix(localMatrix)}\"/>{context.NewLine}");
sb.Append($" </RadialGradientBrush.Transform>{context.NewLine}");
}
sb.Append($" <RadialGradientBrush.Transform>{context.NewLine}");
sb.Append($" <MatrixTransform Matrix=\"{ToMatrix(localMatrix)}\"/>{context.NewLine}");
sb.Append($" </RadialGradientBrush.Transform>{context.NewLine}");
}
if (twoPointConicalGradientBrush.GradientStops.Count > 0)
@ -504,23 +370,6 @@ public class XamlGenerator : GeneratorBase
var sb = new StringBuilder();
if (!context.UseBrushTransform)
{
if (pictureBrush.LocalMatrix is { })
{
var localMatrix = pictureBrush.LocalMatrix.Value;
if (!localMatrix.IsIdentity)
{
// TODO: LocalMatrix
}
}
else
{
// TODO: Adjust using Bounds.Location ?
}
}
var sourceRect = pictureBrush.CullRect;
var destinationRect = pictureBrush.Tile;
@ -559,22 +408,13 @@ public class XamlGenerator : GeneratorBase
sb.Append($">{context.NewLine}");
if (context.UseBrushTransform)
if (pictureBrush.LocalMatrix is { })
{
if (pictureBrush.LocalMatrix is { })
{
// TODO: Missing Transform property on VisualBrush
var localMatrix = pictureBrush.LocalMatrix.Value;
var localMatrix = pictureBrush.LocalMatrix.Value;
if (!context.UseCompatMode)
{
localMatrix = pictureBrush.WithTransXY(localMatrix, pictureBrush.Bounds.Location.X, pictureBrush.Bounds.Location.Y);
}
sb.Append($" <VisualBrush.Transform>{context.NewLine}");
sb.Append($" <MatrixTransform Matrix=\"{ToMatrix(localMatrix)}\"/>{context.NewLine}");
sb.Append($" </VisualBrush.Transform>{context.NewLine}");
}
sb.Append($" <VisualBrush.Transform>{context.NewLine}");
sb.Append($" <MatrixTransform Matrix=\"{ToMatrix(localMatrix)}\"/>{context.NewLine}");
sb.Append($" </VisualBrush.Transform>{context.NewLine}");
}
if (pictureBrush.Picture is not null)

Просмотреть файл

@ -17,8 +17,6 @@ public class SvgToXamlConverter
public bool UseCompatMode { get; set; }
public bool UseBrushTransform { get; set; }
public bool AddTransparentBackground { get; set; }
public bool ReuseExistingResources { get; set; }
@ -33,7 +31,6 @@ public class SvgToXamlConverter
{
NewLine = NewLine,
UseCompatMode = UseCompatMode,
UseBrushTransform = UseBrushTransform,
AddTransparentBackground = AddTransparentBackground,
ReuseExistingResources = ReuseExistingResources,
WriteResources = false,
@ -53,7 +50,6 @@ public class SvgToXamlConverter
{
NewLine = NewLine,
UseCompatMode = UseCompatMode,
UseBrushTransform = UseBrushTransform,
AddTransparentBackground = AddTransparentBackground,
ReuseExistingResources = ReuseExistingResources,
WriteResources = true,
@ -105,7 +101,6 @@ public class SvgToXamlConverter
{
NewLine = NewLine,
UseCompatMode = UseCompatMode,
UseBrushTransform = UseBrushTransform,
AddTransparentBackground = AddTransparentBackground,
ReuseExistingResources = ReuseExistingResources,
WriteResources = false,

Просмотреть файл

@ -58,7 +58,6 @@ class Program
var converter = new SvgToXamlConverter.SvgToXamlConverter()
{
UseCompatMode = false,
UseBrushTransform = false,
ReuseExistingResources = false,
Resources = null
};
@ -82,7 +81,6 @@ class Program
var converter = new SvgToXamlConverter.SvgToXamlConverter()
{
UseCompatMode = false,
UseBrushTransform = false,
ReuseExistingResources = false,
Resources = null
};