Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Samples/Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
<ProjectReference Include="..\..\Source\SVGImage\DotNetProjects.SVGImage.csproj" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\acid1_TextOnly.svg" />
<Resource Include="Images\brush.svg" />
<Resource Include="Images\error.svg" />
<Resource Include="Images\example radgrad01.svg" />
<Resource Include="Images\boldgreen.svg" />
<Resource Include="Images\rect.svg" />
<Resource Include="Images\test_3.svg" />
<Resource Include="Images\tombigel_green_router.svg" />
Expand Down
160 changes: 160 additions & 0 deletions Samples/Example/Images/acid1_TextOnly.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions Samples/Example/Images/boldgreen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Source/SVGImage/DotNetProjects.SVGImage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageIcon>images\dotnetprojects.png</PackageIcon>
<PackageTags>svg wpf svg-icons svg-to-png svg-to-xaml svgimage svgimage-control</PackageTags>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<EnablePackageValidation>true</EnablePackageValidation>
<!--<EnablePackageValidation>false</EnablePackageValidation>-->
<!-- NOTE: Detect breaking changes from a previous version -->
<PackageValidationBaselineVersion>5.1.0</PackageValidationBaselineVersion>
</PropertyGroup>
Expand Down
17 changes: 10 additions & 7 deletions Source/SVGImage/SVG/PaintServers/PaintServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ public static Color ParseHexColor(string value)
newval |= (@int & 0x00000f);
u = newval;
}
else {
u = Convert.ToUInt64(value.Substring(start), 16);
}

else
{
u = Convert.ToUInt64(value.Substring(start), 16);
}

byte a = (byte)((u & 0xff000000) >> 24);
byte r = (byte)((u & 0x00ff0000) >> 16);
byte g = (byte)((u & 0x0000ff00) >> 8);
Expand Down Expand Up @@ -223,10 +224,12 @@ private int ParseColorNumber(string value)
{
if (value.EndsWith("%"))
{
var nr = int.Parse(value.Substring(0, value.Length - 1));
var nr = double.Parse(value.Substring(0, value.Length - 1));
if (nr < 0)
nr = 255 - nr;
return nr * 255 / 100;
nr = 255 - nr; //TODO: what is this trying to do?
var result = (int)Math.Round((nr * 255) / 100);

return MathUtil.Clamp(result, 0, 255);
}

return int.Parse(value);
Expand Down
33 changes: 30 additions & 3 deletions Source/SVGImage/SVG/SVGRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Xml;
using System.Linq;
using System.Collections.Generic;
using SVGImage.SVG.Utils;

using System.Windows;
using System.Windows.Media;
Expand Down Expand Up @@ -115,7 +116,8 @@ public DrawingGroup LoadDrawing(Stream stream)

public DrawingGroup CreateDrawing(SVG svg)
{
return this.LoadGroup(svg.Elements, svg.ViewBox, false);
var drawingGroup = this.LoadGroup(svg.Elements, svg.ViewBox, false);
return drawingGroup;
}

public DrawingGroup CreateDrawing(Shape shape)
Expand Down Expand Up @@ -443,9 +445,9 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
GeometryGroup gp = textRender2.BuildTextGeometry(textShape);
if (gp != null)
{
foreach (Geometry gm in gp.Children)
foreach (Geometry gm in GetStyledSpans(gp))
{
if (TextRenderBase.GetElement(gm) is TextShapeBase tspan)
if (TextRender.GetElement(gm) is TextShapeBase tspan)
{
var di = this.NewDrawingItem(tspan, gm);
AddDrawingToGroup(grp, shape, di);
Expand Down Expand Up @@ -480,6 +482,31 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
return grp;
}

private static IEnumerable<Geometry> GetStyledSpans(Geometry geometry)
{
if (geometry is GeometryGroup gg)
{
if (!(TextRender.GetElement(gg) is null))
{
yield return geometry;
}
else
{
foreach (var g in gg.Children)
{
foreach (var subg in GetStyledSpans(g))
{
yield return subg;
}
}
}
}
else
{
yield return geometry;
}
}

private void AddDrawingToGroup(DrawingGroup grp, Shape shape, Drawing drawing)
{
if (shape.Clip != null || shape.Transform != null || shape.Filter != null)
Expand Down
8 changes: 4 additions & 4 deletions Source/SVGImage/SVG/Shapes/LengthPercentageOrNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SVGImage.SVG.Shapes

public struct LengthPercentageOrNumber
{
private static readonly Regex _lengthRegex = new Regex(@"(?<Value>\d+(?:\.\d+)?)\s*(?<Unit>%|\w+)?", RegexOptions.Compiled | RegexOptions.Singleline);
private static readonly Regex _lengthRegex = new Regex(@"(?<Value>-?\d+(?:\.\d+)?)\s*(?<Unit>%|\w+)?", RegexOptions.Compiled | RegexOptions.Singleline);
private readonly LengthContext _context;
private readonly double _value;
/// <summary>
Expand Down Expand Up @@ -180,12 +180,12 @@ public static LengthPercentageOrNumber Parse(Shape owner, string value, LengthOr
}
else
{
// Default to pixels if no unit is specified
context = new LengthContext(owner, LengthUnit.px);
// Default to Number if no unit is specified
context = new LengthContext(owner, LengthUnit.Number);
}
return new LengthPercentageOrNumber(d, context);
}

}


Expand Down
7 changes: 6 additions & 1 deletion Source/SVGImage/SVG/Shapes/Shape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public Stroke Stroke
}

protected virtual Fill DefaultFill()
{
return null;
}

protected virtual Fill GetParentFill()
{
var parent = this.Parent;
while (parent != null)
Expand All @@ -141,7 +146,7 @@ protected virtual Fill DefaultFill()

public Fill Fill
{
get => m_fill ?? DefaultFill();
get => m_fill ?? GetParentFill() ?? DefaultFill();
set => m_fill = value;
}

Expand Down
Loading
Loading