Skip to content

Commit bb52acf

Browse files
authored
Merge pull request #110 from mwagnerEE/master
Text System Overhaul Fixes
2 parents 4dda201 + da53ceb commit bb52acf

20 files changed

+773
-63
lines changed

Samples/Example/Example.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
<ProjectReference Include="..\..\Source\SVGImage\DotNetProjects.SVGImage.csproj" />
4444
</ItemGroup>
4545
<ItemGroup>
46+
<Resource Include="Images\acid1_TextOnly.svg" />
4647
<Resource Include="Images\brush.svg" />
4748
<Resource Include="Images\error.svg" />
4849
<Resource Include="Images\example radgrad01.svg" />
50+
<Resource Include="Images\boldgreen.svg" />
4951
<Resource Include="Images\rect.svg" />
5052
<Resource Include="Images\test_3.svg" />
5153
<Resource Include="Images\tombigel_green_router.svg" />
Lines changed: 160 additions & 0 deletions
Loading

Samples/Example/Images/boldgreen.svg

Lines changed: 13 additions & 0 deletions
Loading

Source/SVGImage/DotNetProjects.SVGImage.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<PackageIcon>images\dotnetprojects.png</PackageIcon>
3030
<PackageTags>svg wpf svg-icons svg-to-png svg-to-xaml svgimage svgimage-control</PackageTags>
3131
<PackageReadmeFile>Readme.md</PackageReadmeFile>
32-
<EnablePackageValidation>true</EnablePackageValidation>
32+
<!--<EnablePackageValidation>false</EnablePackageValidation>-->
3333
<!-- NOTE: Detect breaking changes from a previous version -->
3434
<PackageValidationBaselineVersion>5.1.0</PackageValidationBaselineVersion>
3535
</PropertyGroup>

Source/SVGImage/SVG/PaintServers/PaintServerManager.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ public static Color ParseHexColor(string value)
160160
newval |= (@int & 0x00000f);
161161
u = newval;
162162
}
163-
else {
164-
u = Convert.ToUInt64(value.Substring(start), 16);
165-
}
166-
163+
else
164+
{
165+
u = Convert.ToUInt64(value.Substring(start), 16);
166+
}
167+
167168
byte a = (byte)((u & 0xff000000) >> 24);
168169
byte r = (byte)((u & 0x00ff0000) >> 16);
169170
byte g = (byte)((u & 0x0000ff00) >> 8);
@@ -223,10 +224,12 @@ private int ParseColorNumber(string value)
223224
{
224225
if (value.EndsWith("%"))
225226
{
226-
var nr = int.Parse(value.Substring(0, value.Length - 1));
227+
var nr = double.Parse(value.Substring(0, value.Length - 1));
227228
if (nr < 0)
228-
nr = 255 - nr;
229-
return nr * 255 / 100;
229+
nr = 255 - nr; //TODO: what is this trying to do?
230+
var result = (int)Math.Round((nr * 255) / 100);
231+
232+
return MathUtil.Clamp(result, 0, 255);
230233
}
231234

232235
return int.Parse(value);

Source/SVGImage/SVG/SVGRender.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Xml;
44
using System.Linq;
55
using System.Collections.Generic;
6+
using SVGImage.SVG.Utils;
67

78
using System.Windows;
89
using System.Windows.Media;
@@ -115,7 +116,8 @@ public DrawingGroup LoadDrawing(Stream stream)
115116

116117
public DrawingGroup CreateDrawing(SVG svg)
117118
{
118-
return this.LoadGroup(svg.Elements, svg.ViewBox, false);
119+
var drawingGroup = this.LoadGroup(svg.Elements, svg.ViewBox, false);
120+
return drawingGroup;
119121
}
120122

121123
public DrawingGroup CreateDrawing(Shape shape)
@@ -443,9 +445,9 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
443445
GeometryGroup gp = textRender2.BuildTextGeometry(textShape);
444446
if (gp != null)
445447
{
446-
foreach (Geometry gm in gp.Children)
448+
foreach (Geometry gm in GetStyledSpans(gp))
447449
{
448-
if (TextRenderBase.GetElement(gm) is TextShapeBase tspan)
450+
if (TextRender.GetElement(gm) is TextShapeBase tspan)
449451
{
450452
var di = this.NewDrawingItem(tspan, gm);
451453
AddDrawingToGroup(grp, shape, di);
@@ -480,6 +482,31 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
480482
return grp;
481483
}
482484

485+
private static IEnumerable<Geometry> GetStyledSpans(Geometry geometry)
486+
{
487+
if (geometry is GeometryGroup gg)
488+
{
489+
if (!(TextRender.GetElement(gg) is null))
490+
{
491+
yield return geometry;
492+
}
493+
else
494+
{
495+
foreach (var g in gg.Children)
496+
{
497+
foreach (var subg in GetStyledSpans(g))
498+
{
499+
yield return subg;
500+
}
501+
}
502+
}
503+
}
504+
else
505+
{
506+
yield return geometry;
507+
}
508+
}
509+
483510
private void AddDrawingToGroup(DrawingGroup grp, Shape shape, Drawing drawing)
484511
{
485512
if (shape.Clip != null || shape.Transform != null || shape.Filter != null)

Source/SVGImage/SVG/Shapes/LengthPercentageOrNumber.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SVGImage.SVG.Shapes
66

77
public struct LengthPercentageOrNumber
88
{
9-
private static readonly Regex _lengthRegex = new Regex(@"(?<Value>\d+(?:\.\d+)?)\s*(?<Unit>%|\w+)?", RegexOptions.Compiled | RegexOptions.Singleline);
9+
private static readonly Regex _lengthRegex = new Regex(@"(?<Value>-?\d+(?:\.\d+)?)\s*(?<Unit>%|\w+)?", RegexOptions.Compiled | RegexOptions.Singleline);
1010
private readonly LengthContext _context;
1111
private readonly double _value;
1212
/// <summary>
@@ -180,12 +180,12 @@ public static LengthPercentageOrNumber Parse(Shape owner, string value, LengthOr
180180
}
181181
else
182182
{
183-
// Default to pixels if no unit is specified
184-
context = new LengthContext(owner, LengthUnit.px);
183+
// Default to Number if no unit is specified
184+
context = new LengthContext(owner, LengthUnit.Number);
185185
}
186186
return new LengthPercentageOrNumber(d, context);
187187
}
188-
188+
189189
}
190190

191191

Source/SVGImage/SVG/Shapes/Shape.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ public Stroke Stroke
125125
}
126126

127127
protected virtual Fill DefaultFill()
128+
{
129+
return null;
130+
}
131+
132+
protected virtual Fill GetParentFill()
128133
{
129134
var parent = this.Parent;
130135
while (parent != null)
@@ -141,7 +146,7 @@ protected virtual Fill DefaultFill()
141146

142147
public Fill Fill
143148
{
144-
get => m_fill ?? DefaultFill();
149+
get => m_fill ?? GetParentFill() ?? DefaultFill();
145150
set => m_fill = value;
146151
}
147152

0 commit comments

Comments
 (0)