Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #88

Merged
merged 11 commits into from
Dec 19, 2023
2 changes: 1 addition & 1 deletion .github/workflows/dotnetpull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: .NET

on:
pull_request:
branches: [ master ]
branches: [ master, develop ]

defaults:
run:
Expand Down
8 changes: 7 additions & 1 deletion Docs/articles/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ The control only has a couple of properties, `SizeType` and `ImageSource`.

For `None` and `ContentToSizeNoStretch`, the Horizontal/VerticalContentAlignment properties can be used to position the image within the control.

* `ImageSource` - This property is the same as `SetImage(drawing)`, and is exposed to allow for the source to be set through binding.
* `ImageSource` - This property is the same as `SetImage(drawing)`, and is exposed to allow for the source to be set through binding.

The colors of an `SVGImage` can be overridden at run-time through some additional properties of the `SVGImage`:

* `OverrideFillColor` - This property overrides all fill colors of an SVG image
* `OverrideStrokeColor` - Overrides all stroke colors of an SVG image
* `OverrideColor` - Overrides all colors of an SVG image. `OverrideFillColor` and `OverrideStrokeColor` take precedence over the `OverrideColor` property.
10 changes: 5 additions & 5 deletions Docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ The respository includes
* **Samples:** For sample applications
* **Docs:** For the documentations (in markdown format).

The command lines installation options are: For the version `5.0.118`
* **.NET CLI:** dotnet add package DotNetProjects.SVGImage --version 5.0.118
* **Package Manager:** NuGet\Install-Package DotNetProjects.SVGImage -Version 5.0.118
The command lines installation options are: For the version `5.1.0`
* **.NET CLI:** dotnet add package DotNetProjects.SVGImage --version 5.1.0
* **Package Manager:** NuGet\Install-Package DotNetProjects.SVGImage -Version 5.1.0

For reference in projects use: For the version `5.0.118`
For reference in projects use: For the version `5.1.0`
```xml
<PackageReference Include="DotNetProjects.SVGImage" Version="5.0.118" />
<PackageReference Include="DotNetProjects.SVGImage" Version="5.1.0" />
```

## How to build
Expand Down
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
next-version: 5.0.118
next-version: 5.1.0
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ The respository includes
* **Samples:** For sample applications
* **Docs:** For the documentations (in markdown format).

The command lines installation options are: For the version `5.0.118`
* **.NET CLI:** dotnet add package DotNetProjects.SVGImage --version 5.0.118
* **Package Manager:** NuGet\Install-Package DotNetProjects.SVGImage -Version 5.0.118
The command lines installation options are: For the version `5.1.0`
* **.NET CLI:** dotnet add package DotNetProjects.SVGImage --version 5.1.0
* **Package Manager:** NuGet\Install-Package DotNetProjects.SVGImage -Version 5.1.0

For reference in projects use: For the version `5.0.118`
For reference in projects use: For the version `5.1.0`
```xml
<PackageReference Include="DotNetProjects.SVGImage" Version="5.0.118" />
<PackageReference Include="DotNetProjects.SVGImage" Version="5.1.0" />
```

## How to build
Expand Down
2 changes: 1 addition & 1 deletion Samples/Example/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<svg1:SVGImage Source="/Example;component/Images/example radgrad01.svg" RenderTransformOrigin="0.848,0.125" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" />
<svg1:SVGImage Source="/Example;component/Images/tiger.svg" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" />
<svg1:SVGImage Source="/Example;component/Images/1.svg" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" />
<svg1:SVGImage Source="/Example;component/Images/2.svg" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" />
<svg1:SVGImage Source="/Example;component/Images/2.svg" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" OverrideFillColor="DarkGreen" OverrideStrokeColor="DarkSalmon" x:Name="OverrideSeparateColorTest" MouseDoubleClick="SVGImage_MouseDoubleClickSeparateOverride" />
<svg1:SVGImage Source="/Example;component/Images/3.svg" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" />
<svg1:SVGImage Source="/Example;component/Images/4.svg" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" />
<svg1:SVGImage Source="/Example;component/Images/5.svg" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" />
Expand Down
20 changes: 19 additions & 1 deletion Samples/Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;

using System.Windows;

namespace Example
Expand Down Expand Up @@ -149,5 +148,24 @@ private void SVGImage_MouseDoubleClick(object sender, System.Windows.Input.Mouse
rnd == 1 ? System.Windows.Media.Colors.Magenta :
System.Windows.Media.Colors.Black;
}

private void SVGImage_MouseDoubleClickSeparateOverride(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
System.Windows.Media.Color[] colors =
{
System.Windows.Media.Colors.White,
System.Windows.Media.Colors.Magenta,
System.Windows.Media.Colors.DarkGreen,
System.Windows.Media.Colors.DarkSalmon,
System.Windows.Media.Colors.DarkBlue,
System.Windows.Media.Colors.Black,
};
var ran = new Random();
var rndFill = ran.Next(0, colors.Length);
OverrideSeparateColorTest.OverrideFillColor = colors[rndFill];

var rndStroke = ran.Next(0, colors.Length);
OverrideSeparateColorTest.OverrideStrokeColor = colors[rndStroke];
}
}
}
3 changes: 1 addition & 2 deletions Samples/IconConverterSample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Net;
using System.IO;
using System.Reflection;
using System.IO.Compression;
using System.Windows;

Expand All @@ -24,7 +23,7 @@ private void OnWindowLoaded(object sender, RoutedEventArgs e)
InitializeProtocol(); //For the web access

// ICons credit: https://github.com/icons8/flat-color-icons
string workingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string workingDir = Path.GetFullPath(PageMultiple.SamplesDir);

string iconsPath = Path.Combine(workingDir, PageMultiple.IconZipFile);
if (!File.Exists(iconsPath))
Expand Down
12 changes: 7 additions & 5 deletions Samples/IconConverterSample/PageMultiple.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.IO.Compression;

namespace IconConverterSample
{
Expand Down Expand Up @@ -43,8 +44,9 @@ public Uri ImageUri
/// </summary>
public partial class PageMultiple : Page
{
public const string IconZipFile = @"..\svg-icons.zip";
public const string IconFolder = @"Svg-Icons";
public const string SamplesDir = @"..\..\..\..\Tests";
public const string IconZipFile = "svg-icons.zip";
public const string IconFolder = "Svg-Icons";

public PageMultiple()
{
Expand All @@ -56,15 +58,15 @@ public PageMultiple()

private void OnPageLoaded(object sender, RoutedEventArgs e)
{
string workingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string workingDir = Path.GetFullPath(SamplesDir);

string iconsPath = Path.Combine(workingDir, PageMultiple.IconZipFile);
string iconsPath = Path.Combine(workingDir, IconZipFile);
if (!File.Exists(iconsPath))
{
return;
}

var iconsDir = new DirectoryInfo(Path.Combine(workingDir, PageMultiple.IconFolder));
var iconsDir = new DirectoryInfo(Path.Combine(workingDir, IconFolder));
if (!iconsDir.Exists)
{
return;
Expand Down
5 changes: 2 additions & 3 deletions Samples/IconConverterSample/PageSingle.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace IconConverterSample
/// </summary>
public partial class PageSingle : Page
{
//private const string SvgFileName = @"..\Asian_Openbill.svg";
private const string SvgFileName = @"..\Sf_er_nkm.svg";
private const string SvgFileName = @"..\..\Resources\Hypocolius.svg";

public static readonly DependencyProperty LocalFileNameProperty = DependencyProperty.Register("LocalFileName",
typeof(string), typeof(PageSingle), new PropertyMetadata(SvgFileName));
Expand All @@ -35,7 +34,7 @@ private void OnPageLoaded(object sender, RoutedEventArgs e)
{
string workingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

string svgFilePath = Path.Combine(workingDir, SvgFileName);
string svgFilePath = Path.GetFullPath(Path.Combine(workingDir, SvgFileName));
if (File.Exists(svgFilePath))
{
inputBox.Text = svgFilePath;
Expand Down
8 changes: 4 additions & 4 deletions Source/SVGImage/DotNetProjects.SVGImage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<Product>DotNetProjects.SVGImage</Product>
<Copyright>2020-2023 DotNetProjects</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<AssemblyVersion>5.0.117.0</AssemblyVersion>
<FileVersion>5.0.117.0</FileVersion>
<Version>5.0.117</Version>
<AssemblyVersion>5.1.0.0</AssemblyVersion>
<FileVersion>5.1.0.0</FileVersion>
<Version>5.1.0</Version>
<OutputType>Library</OutputType>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
Expand All @@ -31,7 +31,7 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<EnablePackageValidation>true</EnablePackageValidation>
<!-- NOTE: Detect breaking changes from a previous version -->
<PackageValidationBaselineVersion>5.0.117</PackageValidationBaselineVersion>
<PackageValidationBaselineVersion>5.0.118</PackageValidationBaselineVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
60 changes: 55 additions & 5 deletions Source/SVGImage/SVG/SVGImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ public enum eSizeType
DependencyProperty.Register("OverrideColor", typeof(Color?), typeof(SVGImage),
new FrameworkPropertyMetadata(default, FrameworkPropertyMetadataOptions.AffectsRender, OverrideColorPropertyChanged));

public static readonly DependencyProperty OverrideFillColorProperty =
DependencyProperty.Register("OverrideFillColor", typeof(Color?), typeof(SVGImage),
new FrameworkPropertyMetadata(default, FrameworkPropertyMetadataOptions.AffectsRender, OverrideFillColorPropertyChanged));

public static readonly DependencyProperty OverrideStrokeColorProperty =
DependencyProperty.Register("OverrideStrokeColor", typeof(Color?), typeof(SVGImage),
new FrameworkPropertyMetadata(default, FrameworkPropertyMetadataOptions.AffectsRender, OverrideStrokeColorPropertyChanged));

public static readonly DependencyProperty CustomBrushesProperty = DependencyProperty.Register(nameof(CustomBrushes),
typeof(Dictionary<string, Brush>), typeof(SVGImage), new FrameworkPropertyMetadata(default,
FrameworkPropertyMetadataOptions.AffectsRender, CustomBrushesPropertyChanged));
Expand Down Expand Up @@ -167,6 +175,18 @@ public Color? OverrideColor
set { SetValue(OverrideColorProperty, value); }
}

public Color? OverrideFillColor
{
get { return (Color?)GetValue(OverrideFillColorProperty); }
set { SetValue(OverrideFillColorProperty, value); }
}

public Color? OverrideStrokeColor
{
get { return (Color?)GetValue(OverrideStrokeColorProperty); }
set { SetValue(OverrideStrokeColorProperty, value); }
}

public double? OverrideStrokeWidth
{
get { return (double?)GetValue(OverrideStrokeWidthProperty); }
Expand Down Expand Up @@ -234,6 +254,8 @@ public void ReRenderSvg()
_render = new SVGRender();
_render.ExternalFileLoader = this.ExternalFileLoader;
_render.OverrideColor = OverrideColor;
_render.OverrideFillColor = OverrideFillColor;
_render.OverrideStrokeColor = OverrideStrokeColor;
_render.CustomBrushes = CustomBrushes;
_render.OverrideStrokeWidth = OverrideStrokeWidth;
_render.UseAnimations = this.UseAnimations;
Expand All @@ -256,6 +278,8 @@ public void SetImage(string svgFilename)
_render.ExternalFileLoader = this.ExternalFileLoader;
_render.UseAnimations = false;
_render.OverrideColor = OverrideColor;
_render.OverrideFillColor = OverrideFillColor;
_render.OverrideStrokeColor = OverrideStrokeColor;
_render.CustomBrushes = CustomBrushes;
_render.OverrideStrokeWidth = OverrideStrokeWidth;

Expand All @@ -276,6 +300,8 @@ public void SetImage(Stream stream)
_render = new SVGRender();
_render.ExternalFileLoader = this.ExternalFileLoader;
_render.OverrideColor = OverrideColor;
_render.OverrideFillColor = OverrideFillColor;
_render.OverrideStrokeColor = OverrideStrokeColor;
_render.CustomBrushes = CustomBrushes;
_render.OverrideStrokeWidth = OverrideStrokeWidth;
_render.UseAnimations = false;
Expand All @@ -298,6 +324,8 @@ public void SetImage(Uri uriSource)
_render = new SVGRender();
_render.ExternalFileLoader = this.ExternalFileLoader;
_render.OverrideColor = OverrideColor;
_render.OverrideFillColor = OverrideFillColor;
_render.OverrideStrokeColor = OverrideStrokeColor;
_render.CustomBrushes = CustomBrushes;
_render.OverrideStrokeWidth = OverrideStrokeWidth;
_render.UseAnimations = false;
Expand Down Expand Up @@ -326,6 +354,8 @@ protected override void OnInitialized(EventArgs e)
_render = new SVGRender();
_render.ExternalFileLoader = this.ExternalFileLoader;
_render.OverrideColor = OverrideColor;
_render.OverrideFillColor = OverrideFillColor;
_render.OverrideStrokeColor = OverrideStrokeColor;
_render.CustomBrushes = CustomBrushes;
_render.OverrideStrokeWidth = OverrideStrokeWidth;
_render.UseAnimations = this.UseAnimations;
Expand Down Expand Up @@ -694,7 +724,7 @@ DrawingGroup LoadDrawing(Uri svgSource)
//case "ftp":
case "https":
case "http":
using (FileSvgReader reader = new FileSvgReader(this.OverrideColor))
using (FileSvgReader reader = new FileSvgReader(this.OverrideColor, this.OverrideFillColor, this.OverrideStrokeColor))
{
DrawingGroup drawGroup = reader.Read(svgSource, _render);

Expand Down Expand Up @@ -729,7 +759,7 @@ DrawingGroup LoadDrawing(Uri svgSource)
{
using (var zipStream = new GZipStream(svgStream, CompressionMode.Decompress))
{
using (FileSvgReader reader = new FileSvgReader(this.OverrideColor))
using (FileSvgReader reader = new FileSvgReader(this.OverrideColor, this.OverrideFillColor, this.OverrideStrokeColor))
{
DrawingGroup drawGroup = reader.Read(zipStream, _render);

Expand All @@ -745,7 +775,7 @@ DrawingGroup LoadDrawing(Uri svgSource)
{
using (svgStream)
{
using (FileSvgReader reader = new FileSvgReader(this.OverrideColor))
using (FileSvgReader reader = new FileSvgReader(this.OverrideColor, this.OverrideFillColor, this.OverrideStrokeColor))
{
DrawingGroup drawGroup = reader.Read(svgStream, _render);

Expand Down Expand Up @@ -781,7 +811,7 @@ DrawingGroup LoadDrawing(Uri svgSource)
{
using (GZipStream zipStream = new GZipStream(stream, CompressionMode.Decompress))
{
using (var reader = new FileSvgReader(this.OverrideColor))
using (var reader = new FileSvgReader(this.OverrideColor, this.OverrideFillColor, this.OverrideStrokeColor))
{
DrawingGroup drawGroup = reader.Read(zipStream, _render);
if (drawGroup != null)
Expand All @@ -796,7 +826,7 @@ DrawingGroup LoadDrawing(Uri svgSource)
{
using (var stream = new MemoryStream(imageBytes))
{
using (var reader = new FileSvgReader(this.OverrideColor))
using (var reader = new FileSvgReader(this.OverrideColor, this.OverrideFillColor, this.OverrideStrokeColor))
{
DrawingGroup drawGroup = reader.Read(stream, _render);
if (drawGroup != null)
Expand Down Expand Up @@ -875,6 +905,26 @@ private static void OverrideColorPropertyChanged(DependencyObject d, DependencyP
}
}

private static void OverrideFillColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is SVGImage svgImage && e.NewValue is Color newColor && svgImage._render != null)
{
svgImage._render.OverrideFillColor = newColor;
svgImage.InvalidateVisual();
svgImage.ReRenderSvg();
}
}

private static void OverrideStrokeColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is SVGImage svgImage && e.NewValue is Color newColor && svgImage._render != null)
{
svgImage._render.OverrideStrokeColor = newColor;
svgImage.InvalidateVisual();
svgImage.ReRenderSvg();
}
}

private static void OverrideStrokeWidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is SVGImage svgImage && e.NewValue is double newStrokeWidth && svgImage._render != null)
Expand Down
Loading