Skip to content

Commit e841590

Browse files
authored
Merge pull request #26 from williamgarner/master
Feature - Override Stroke Width
2 parents 45ff435 + f210b1a commit e841590

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Source/SVGImage/SVG/SVGImage.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,29 @@ public Color? OverrideColor
103103
public static readonly DependencyProperty OverrideColorProperty =
104104
DependencyProperty.Register("OverrideColor", typeof(Color?), typeof(SVGImage), new PropertyMetadata(null));
105105

106+
public double? OverrideStrokeWidth
107+
{
108+
get { return (double?)GetValue(OverrideStrokeWidthProperty); }
109+
set { SetValue(OverrideStrokeWidthProperty, value); }
110+
}
111+
112+
public static readonly DependencyProperty OverrideStrokeWidthProperty =
113+
DependencyProperty.Register(nameof(OverrideStrokeWidth),
114+
typeof(double?),
115+
typeof(SVGImage),
116+
new FrameworkPropertyMetadata(default, FrameworkPropertyMetadataOptions.AffectsRender, OverrideStrokeWidthPropertyChanged));
117+
118+
private static void OverrideStrokeWidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
119+
{
120+
if (d is SVGImage svgImage && e.NewValue is double newStrokeWidth && svgImage._render != null)
121+
{
122+
svgImage._render.OverrideStrokeWidth = newStrokeWidth;
123+
svgImage.InvalidateVisual();
124+
svgImage.ReRenderSvg();
125+
}
126+
}
127+
128+
106129
public Dictionary<string, Brush> CustomBrushes
107130
{
108131
get { return (Dictionary<string, Brush>)GetValue(CustomBrushesProperty); }
@@ -183,6 +206,7 @@ public void SetImage(string svgFilename)
183206
_render.UseAnimations = false;
184207
_render.OverrideColor = OverrideColor;
185208
_render.CustomBrushes = CustomBrushes;
209+
_render.OverrideStrokeWidth = OverrideStrokeWidth;
186210
loadImage(_render);
187211
loadImage = null;
188212
}
@@ -215,6 +239,7 @@ public void SetImage(Stream stream)
215239
_render.ExternalFileLoader = this.ExternalFileLoader;
216240
_render.OverrideColor = OverrideColor;
217241
_render.CustomBrushes = CustomBrushes;
242+
_render.OverrideStrokeWidth = OverrideStrokeWidth;
218243
_render.UseAnimations = false;
219244
loadImage(_render);
220245
loadImage = null;
@@ -232,6 +257,7 @@ protected override void OnInitialized(EventArgs e)
232257
_render.ExternalFileLoader = this.ExternalFileLoader;
233258
_render.OverrideColor = OverrideColor;
234259
_render.CustomBrushes = CustomBrushes;
260+
_render.OverrideStrokeWidth = OverrideStrokeWidth;
235261
_render.UseAnimations = this.UseAnimations;
236262
loadImage(_render);
237263
loadImage = null;

Source/SVGImage/SVG/SVGRender.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public SVGRender()
3030
public bool UseAnimations { get; set; }
3131

3232
public Color? OverrideColor { get; set; }
33+
34+
public double? OverrideStrokeWidth { get; set; }
3335

3436
private Dictionary<string, Brush> m_customBrushes;
3537

@@ -102,6 +104,10 @@ private GeometryDrawing NewDrawingItem(Shape shape, Geometry geometry)
102104
Stroke stroke = shape.Stroke;
103105
if (stroke != null)
104106
{
107+
if(OverrideStrokeWidth.HasValue)
108+
{
109+
stroke.Width = OverrideStrokeWidth.Value;
110+
}
105111
var brush = stroke.StrokeBrush(this.SVG, this, shape, shape.Opacity, geometry.Bounds);
106112
if (OverrideColor != null)
107113
brush = new SolidColorBrush(Color.FromArgb((byte)(255 * shape.Opacity), OverrideColor.Value.R, OverrideColor.Value.G, OverrideColor.Value.B));

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 4.0.{build}
1+
version: 4.1.{build}
22

33
image: Visual Studio 2019
44

0 commit comments

Comments
 (0)