Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion IconResources/IconResources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IconResources</RootNamespace>
<AssemblyName>IconResources</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
3 changes: 1 addition & 2 deletions IconResources/Images/Icons.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using System.Windows;

namespace IconResources.Images
Expand Down
42 changes: 22 additions & 20 deletions SvgConverter/ConverterLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public static ConvertedSvgData ConvertSvg(string filepath, ResultMode resultMode
//var obj = ConvertSvgToObject(filepath, resultMode, null, out name) as DependencyObject;
//var xaml = SvgObjectToXaml(obj, false, name);
//var svg = File.ReadAllText(filepath);

return new ConvertedSvgData { Filepath = filepath
//, ConvertedObj = obj, Svg = svg, Xaml = xaml

return new ConvertedSvgData
{
Filepath = filepath
//, ConvertedObj = obj, Svg = svg, Xaml = xaml
};
}

Expand Down Expand Up @@ -163,21 +165,21 @@ private static void ReplaceBrushesInDrawingGroupsOld(XElement rootElement, ResKe
.Distinct(StringComparer.InvariantCultureIgnoreCase) //same Color only once
.Select((s, i) => new
{
ResKey1 = BuildColorName(i+1, resKeyInfo),
ResKey2 = BuildColorBrushName(i + 1, resKeyInfo),
ResKey1 = BuildColorName(i + 1, resKeyInfo),
ResKey2 = BuildColorBrushName(i + 1, resKeyInfo),
Color = s
}) //add numbers
.ToList();

//building global Elements like: <SolidColorBrush x:Key="ImagesColorBrush1" Color="{DynamicResource ImagesColor1}" />
rootElement.AddFirst(allBrushes
.Select(brush => new XElement(NsDef + "SolidColorBrush",
.Select(brush => new XElement(NsDef + "SolidColorBrush",
new XAttribute(Nsx + "Key", brush.ResKey2),
new XAttribute("Color", $"{{DynamicResource {brush.ResKey1}}}"))));

//building global Elements like: <Color x:Key="ImagesColor1">#FF000000</Color>
rootElement.AddFirst(allBrushes
.Select(brush => new XElement(NsDef + "Color",
.Select(brush => new XElement(NsDef + "Color",
new XAttribute(Nsx + "Key", brush.ResKey1),
brush.Color)));

Expand All @@ -191,24 +193,24 @@ private static void ReplaceBrushesInDrawingGroupsOld(XElement rootElement, ResKe
var keyDg = node.Attribute(Nsx + "Key").Value;
var elemName = GetElemNameFromResKey(keyDg, resKeyInfo);
var elemBaseName = elemName.Replace("DrawingGroup", "");

var brushAttributes = CollectBrushAttributesWithColor(node).ToList();

foreach (var brushAttribute in brushAttributes)
{
var color = brushAttribute.Value;
string resKeyColor;
if (colorKeys.TryGetValue(color, out resKeyColor))
{ //global color found

//build resourcename
var nameBrush = brushAttributes.Count > 1
? $"{elemBaseName}Color{brushAttributes.IndexOf(brushAttribute) + 1}Brush"
: $"{elemBaseName}ColorBrush"; //dont add number if only one color
var resKeyBrush = BuildResKey(nameBrush, resKeyInfo);
node.AddBeforeSelf(new XElement(NsDef + "SolidColorBrush",
new XAttribute(Nsx + "Key", resKeyBrush),
new XAttribute("Color", $"{{Binding Color, Source={BuildResKeyReference(resKeyColor, false)}}}") ));
node.AddBeforeSelf(new XElement(NsDef + "SolidColorBrush",
new XAttribute(Nsx + "Key", resKeyBrush),
new XAttribute("Color", $"{{Binding Color, Source={BuildResKeyReference(resKeyColor, false)}}}")));
//set brush value as Reference
// <GeometryDrawing Brush="{DynamicResource {x:Static nsname:Test.cloud-3-iconBrushColor}}" ... />
brushAttribute.Value = BuildResKeyReference(resKeyBrush, true);
Expand All @@ -224,7 +226,7 @@ private static void ReplaceBrushesInDrawingGroups(XElement rootElement, ResKeyIn
foreach (var node in drawingGroups)
{
var brushAttributes = CollectBrushAttributesWithColor(node).ToList();

foreach (var brushAttribute in brushAttributes)
{
var color = brushAttribute.Value;
Expand Down Expand Up @@ -386,8 +388,8 @@ private static bool IsSvgz(string filepath)
private static void FixIds(XElement root)
{
var idAttributesStartingWithDigit = root.DescendantsAndSelf()
.SelectMany(d=>d.Attributes())
.Where(a=>string.Equals(a.Name.LocalName, "Id", StringComparison.InvariantCultureIgnoreCase));
.SelectMany(d => d.Attributes())
.Where(a => string.Equals(a.Name.LocalName, "Id", StringComparison.InvariantCultureIgnoreCase));
foreach (var attr in idAttributesStartingWithDigit)
{
if (char.IsDigit(attr.Value.FirstOrDefault()))
Expand All @@ -407,7 +409,7 @@ internal static DrawingImage DrawingToImage(Drawing drawing)

internal static string WpfObjToXaml(object wpfObject, bool includeRuntime)
{
XmlXamlWriter writer = new XmlXamlWriter(new WpfDrawingSettings { IncludeRuntime = includeRuntime});
XmlXamlWriter writer = new XmlXamlWriter(new WpfDrawingSettings { IncludeRuntime = includeRuntime });
var xaml = writer.Save(wpfObject);
return xaml;
}
Expand Down Expand Up @@ -545,7 +547,7 @@ private static void ExtractGeometries(XElement drawingGroupElement, ResKeyInfo r
: (int?)null;
var localName = BuildGeometryName(name, no, resKeyInfo);
//Add this: <Geometry x:Key="cloud_3_iconGeometry">F1 M512,512z M0,0z M409.338,216.254C398.922,351.523z</Geometry>
drawingGroupElement.AddBeforeSelf(new XElement(NsDef+"Geometry",
drawingGroupElement.AddBeforeSelf(new XElement(NsDef + "Geometry",
new XAttribute(Nsx + "Key", localName),
geo.Value));
geo.Value = BuildResKeyReference(localName, false);
Expand Down Expand Up @@ -575,12 +577,12 @@ public static void RemoveObjectNames(DrawingGroup drawingGroup)

internal static string BuildDrawingGroupName(string elementName, ResKeyInfo resKeyInfo)
{
var rawName = elementName + "DrawingGroup";
var rawName = ValidateName(elementName).Trim('_') + "_DrawingGroup";
return BuildResKey(rawName, resKeyInfo);
}
internal static string BuildDrawingImageName(string elementName, ResKeyInfo resKeyInfo)
{
var rawName = elementName + "DrawingImage";
var rawName = ValidateName(elementName).Trim('_') + "_DrawingImage";
return BuildResKey(rawName, resKeyInfo);
}

Expand Down
2 changes: 1 addition & 1 deletion SvgConverter/SvgConverter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SvgConverter</RootNamespace>
<AssemblyName>SvgConverter</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion SvgConverter/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
2 changes: 1 addition & 1 deletion SvgConverterTest/SvgConverterTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SvgConverterTest</RootNamespace>
<AssemblyName>SvgConverterTest</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand Down
2 changes: 1 addition & 1 deletion SvgConverterTest/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
124 changes: 84 additions & 40 deletions SvgToXaml/DetailWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,77 +1,121 @@
<Window x:Class="SvgToXaml.DetailWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewModels="clr-namespace:SvgToXaml.ViewModels"
xmlns:textViewer="clr-namespace:SvgToXaml.TextViewer"
mc:Ignorable="d"
Title="{Binding Filename}" Height="375" Width="300"
d:DataContext="{x:Static viewModels:SvgImageViewModel.DesignInstance}">
<Window
x:Class="SvgToXaml.DetailWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:textViewer="clr-namespace:SvgToXaml.TextViewer"
xmlns:viewModels="clr-namespace:SvgToXaml.ViewModels"
xmlns:appproperties="clr-namespace:SvgToXaml.Properties"
Title="{Binding Filename}"
Width="300"
Height="375"
d:DataContext="{x:Static viewModels:SvgImageViewModel.DesignInstance}"
mc:Ignorable="d">
<Grid>
<TabControl TabStripPlacement="Bottom">
<TabItem Header="View Image">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderThickness="1" BorderBrush="#FF00008A" Margin="2">
<Image x:Name="Image" Source="{Binding PreviewSource}" Stretch="Uniform">
<Border
Grid.Row="0"
Margin="2"
Background="{Binding Source={x:Static appproperties:Settings.Default},Path=LastBackgroundBrush}"
BorderBrush="#FF00008A"
BorderThickness="1">
<Image
x:Name="Image"
Source="{Binding PreviewSource}"
Stretch="Uniform">
<Image.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding OpenDetailCommand}" />
<MouseBinding Command="{Binding OpenDetailCommand}" Gesture="LeftDoubleClick" />
</Image.InputBindings>
</Image>
</Border>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Grid HorizontalAlignment="Center" Width="80">
<Grid Width="80" HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Designed" TextAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" TextAlignment="Center" VerticalAlignment="Center" Text="{Binding SvgDesignInfo}"/>
<TextBlock
VerticalAlignment="Center"
Text="Designed"
TextAlignment="Center" />
<TextBlock
Grid.Row="1"
VerticalAlignment="Center"
Text="{Binding SvgDesignInfo}"
TextAlignment="Center" />
</Grid>
<Grid HorizontalAlignment="Center" Width="80">
<Grid Width="80" HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Actual Size" TextAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" TextAlignment="Center" VerticalAlignment="Center">
<Run Text="{Binding ElementName=Image,Path=ActualWidth,Mode=OneWay,StringFormat={}{0:0.0}}"/>
<Run Text="x"/>
<Run Text="{Binding ElementName=Image,Path=ActualHeight,Mode=OneWay,StringFormat={}{0:0.0}}"/>
<TextBlock
VerticalAlignment="Center"
Text="Actual Size"
TextAlignment="Center" />
<TextBlock
Grid.Row="1"
VerticalAlignment="Center"
TextAlignment="Center">
<Run Text="{Binding ElementName=Image, Path=ActualWidth, Mode=OneWay, StringFormat={}{0:0.0}}" />
<Run Text="x" />
<Run Text="{Binding ElementName=Image, Path=ActualHeight, Mode=OneWay, StringFormat={}{0:0.0}}" />
</TextBlock>
</Grid>
<Grid HorizontalAlignment="Center" Width="80">
<Grid Width="80" HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Stretch" Foreground="Blue" TextDecorations="Underline" TextAlignment="Center" VerticalAlignment="Center" MouseLeftButtonDown="ToggleStretchClicked"/>
<TextBlock Grid.Row="1" TextAlignment="Center" VerticalAlignment="Center" Text="{Binding ElementName=Image, Path=Stretch}"/>
<TextBlock
VerticalAlignment="Center"
Foreground="Blue"
MouseLeftButtonDown="ToggleStretchClicked"
Text="Stretch"
TextAlignment="Center"
TextDecorations="Underline" />
<TextBlock
Grid.Row="1"
VerticalAlignment="Center"
Text="{Binding ElementName=Image, Path=Stretch}"
TextAlignment="Center" />
</Grid>
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="Xaml" Visibility="{Binding HasXaml, Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="25"/>
<RowDefinition Height="*" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<textViewer:XmlViewer Grid.Row="0" x:Name="XmlViewer" FontFamily="Consolas" FontSize="10pt" Text="{Binding Xaml}">

</textViewer:XmlViewer>
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
<textViewer:XmlViewer
x:Name="XmlViewer"
Grid.Row="0"
FontFamily="Consolas"
FontSize="10pt"
Text="{Binding Xaml}" />
<StackPanel
Grid.Row="1"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button Click="CopyToClipboardClick">Copy to Clipboard</Button>
</StackPanel>

</Grid>
</TabItem>
<TabItem Header="Svg" Visibility="{Binding HasSvg, Converter={StaticResource BooleanToVisibilityConverter}}">
<textViewer:XmlViewer FontFamily="Consolas" FontSize="10pt" Text="{Binding Svg}"/>
<textViewer:XmlViewer
FontFamily="Consolas"
FontSize="10pt"
Text="{Binding Svg}" />
</TabItem>
</TabControl>
</Grid>
Expand Down
10 changes: 9 additions & 1 deletion SvgToXaml/DetailWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Input;
Expand All @@ -18,7 +19,14 @@ public DetailWindow()

private void CopyToClipboardClick(object sender, RoutedEventArgs e)
{
Clipboard.SetText(XmlViewer.Text);
try
{
Clipboard.SetText(XmlViewer.Text);
}
catch (Exception ex)
{
Trace.TraceError(ex.Message);
}
}

private void ToggleStretchClicked(object sender, MouseButtonEventArgs e)
Expand Down
Loading