Skip to content

Commit 4e1d711

Browse files
authored
Merge pull request #109 from mwagnerEE/master
Text System Overhaul
2 parents 4b3bb8d + df22b6f commit 4e1d711

36 files changed

+2488
-316
lines changed

Source/SVGImage/DotNetProjects.SVGImage.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
<DefineConstants Condition=" '$(TargetFramework)' == 'net40' ">$(DefineConstants);DOTNET40;NETFULL</DefineConstants>
5353
<DefineConstants Condition="$(TargetFramework.StartsWith('net45'))">$(DefineConstants);DOTNET45;NETFULL</DefineConstants>
5454
<DefineConstants Condition="$(TargetFramework.StartsWith('net46'))">$(DefineConstants);DOTNET46;NETFULL</DefineConstants>
55-
<DefineConstants Condition="$(TargetFramework.StartsWith('net47'))">$(DefineConstants);DOTNET47;NETFULL</DefineConstants>
56-
<DefineConstants Condition="$(TargetFramework.StartsWith('net48'))">$(DefineConstants);DOTNET48;NETFULL</DefineConstants>
57-
<DefineConstants Condition="$(TargetFramework.StartsWith('netcore'))">$(DefineConstants);NETCORE</DefineConstants>
58-
<DefineConstants Condition="$(TargetFramework.StartsWith('net6'))">$(DefineConstants);NETCORE;NETNEXT</DefineConstants>
59-
<DefineConstants Condition="$(TargetFramework.StartsWith('net7'))">$(DefineConstants);NETCORE;NETNEXT</DefineConstants>
60-
<DefineConstants Condition="$(TargetFramework.StartsWith('net8'))">$(DefineConstants);NETCORE;NETNEXT</DefineConstants>
55+
<DefineConstants Condition="$(TargetFramework.StartsWith('net47'))">$(DefineConstants);DOTNET47;DPI_AWARE;NETFULL</DefineConstants>
56+
<DefineConstants Condition="$(TargetFramework.StartsWith('net48'))">$(DefineConstants);DOTNET48;DPI_AWARE;NETFULL</DefineConstants>
57+
<DefineConstants Condition="$(TargetFramework.StartsWith('netcore'))">$(DefineConstants);NETCORE;DPI_AWARE</DefineConstants>
58+
<DefineConstants Condition="$(TargetFramework.StartsWith('net6'))">$(DefineConstants);NETCORE;DPI_AWARE;NETNEXT</DefineConstants>
59+
<DefineConstants Condition="$(TargetFramework.StartsWith('net7'))">$(DefineConstants);NETCORE;DPI_AWARE;NETNEXT</DefineConstants>
60+
<DefineConstants Condition="$(TargetFramework.StartsWith('net8'))">$(DefineConstants);NETCORE;DPI_AWARE;NETNEXT</DefineConstants>
6161
<SignAssembly>True</SignAssembly>
6262
<AssemblyOriginatorKeyFile>SVGImage.snk</AssemblyOriginatorKeyFile>
6363
</PropertyGroup>

Source/SVGImage/SVG/SVGImage.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public enum eSizeType
7171
DependencyProperty.Register("UriSource", typeof(Uri), typeof(SVGImage),
7272
new FrameworkPropertyMetadata(null, OnUriSourceChanged));
7373

74-
public static DependencyProperty SizeTypeProperty = DependencyProperty.Register("SizeType",
74+
public static readonly DependencyProperty SizeTypeProperty = DependencyProperty.Register("SizeType",
7575
typeof(eSizeType), typeof(SVGImage), new FrameworkPropertyMetadata(eSizeType.ContentToSizeNoStretch,
7676
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
7777
new PropertyChangedCallback(OnSizeTypeChanged)));
@@ -84,7 +84,7 @@ public enum eSizeType
8484
public static readonly DependencyProperty FileSourceProperty = DependencyProperty.Register("FileSource",
8585
typeof(string), typeof(SVGImage), new PropertyMetadata(OnFileSourceChanged));
8686

87-
public static DependencyProperty ImageSourcePoperty = DependencyProperty.Register("ImageSource",
87+
public static readonly DependencyProperty ImageSourcePoperty = DependencyProperty.Register("ImageSource",
8888
typeof(Drawing), typeof(SVGImage), new FrameworkPropertyMetadata(null,
8989
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
9090
new PropertyChangedCallback(OnImageSourceChanged)));
@@ -247,6 +247,11 @@ public Uri BaseUri
247247
}
248248
}
249249

250+
251+
252+
/// <summary>
253+
/// Rerenders if CustomBrushesPropertyChanged, OverrideStrokeWidthPropertyChanged, OverrideStrokeColorPropertyChanged, OverrideFillColorPropertyChanged, OverrideColorPropertyChanged
254+
/// </summary>
250255
public void ReRenderSvg()
251256
{
252257
if (_render != null)
@@ -364,7 +369,17 @@ protected override void OnInitialized(EventArgs e)
364369
_render.OverrideStrokeWidth = OverrideStrokeWidth;
365370
_render.UseAnimations = this.UseAnimations;
366371

367-
_loadImage(_render);
372+
//This is to prevent double rendering because setting CustomBrushes = brushesFromSVG; invokes ReRenderSvg
373+
//Not sure if it has any side effects
374+
if (!String.IsNullOrEmpty(FileSource))
375+
{
376+
_render.LoadDrawingWithoutRender(FileSource);
377+
}
378+
else
379+
{
380+
_loadImage(_render);
381+
}
382+
//_loadImage(_render);
368383
_loadImage = null;
369384
var brushesFromSVG = new Dictionary<string, Brush>();
370385
foreach (var server in _render.SVG.PaintServers.GetServers())

Source/SVGImage/SVG/SVGRender.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ public DrawingGroup LoadDrawing(string filename)
6565
return this.CreateDrawing(this.SVG);
6666
}
6767

68+
internal void LoadDrawingWithoutRender(string filename)
69+
{
70+
this.SVG = new SVG(filename, ExternalFileLoader);
71+
}
72+
internal void LoadDrawingWithoutRender(Stream stream)
73+
{
74+
this.SVG = new SVG(stream, ExternalFileLoader);
75+
}
76+
6877
public DrawingGroup LoadXmlDrawing(string fileXml)
6978
{
7079
this.SVG = new SVG(this.ExternalFileLoader);
@@ -430,13 +439,13 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
430439
}
431440
if (shape is TextShape textShape)
432441
{
433-
GeometryGroup gp = TextRender.BuildTextGeometry(textShape);
442+
TextRender textRender2 = new TextRender();
443+
GeometryGroup gp = textRender2.BuildTextGeometry(textShape);
434444
if (gp != null)
435445
{
436446
foreach (Geometry gm in gp.Children)
437447
{
438-
TextSpan tspan = TextRender.GetElement(gm);
439-
if (tspan != null)
448+
if (TextRenderBase.GetElement(gm) is TextShapeBase tspan)
440449
{
441450
var di = this.NewDrawingItem(tspan, gm);
442451
AddDrawingToGroup(grp, shape, di);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
3+
namespace SVGImage.SVG.Shapes
4+
{
5+
/// <summary>
6+
/// Represents a per-character layout result.
7+
/// </summary>
8+
public class CharacterLayout
9+
{
10+
private CharacterLayout()
11+
{
12+
// Default constructor for array creation
13+
}
14+
public CharacterLayout(char character)
15+
{
16+
Character = character;
17+
}
18+
public char Character { get; set; } = '\0';
19+
public int GlobalIndex { get; set; }
20+
public double X { get; set; } = 0;
21+
public double Y { get; set; } = 0;
22+
public double DX { get; set; } = Double.NaN;
23+
public double DY { get; set; } = Double.NaN;
24+
public double Rotation { get; set; } = Double.NaN;
25+
public bool Hidden { get; set; } = false;
26+
public bool Addressable { get; set; } = true;
27+
public bool Middle { get; set; } = false;
28+
public bool AnchoredChunk { get; set; } = false;
29+
/// <summary>
30+
/// Not used, part of the SVG 2.0 spec.
31+
/// </summary>
32+
internal bool FirstCharacterInResolvedDescendant { get; set; }
33+
/// <summary>
34+
/// The character redefines the X position for anteceding characters.
35+
/// </summary>
36+
public bool DoesPositionX { get; internal set; }
37+
/// <summary>
38+
/// The character redefines the Y position for anteceding characters.
39+
/// </summary>
40+
public bool DoesPositionY { get; internal set; }
41+
42+
43+
}
44+
45+
46+
47+
48+
}

Source/SVGImage/SVG/Shapes/CircleShape.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@ namespace SVGImage.SVG.Shapes
88

99
public sealed class CircleShape : Shape
1010
{
11-
private static Fill DefaultFill = null;
12-
1311
public CircleShape(SVG svg, XmlNode node) : base(svg, node)
1412
{
15-
if (DefaultFill == null)
16-
{
17-
DefaultFill = Fill.CreateDefault(svg, "black");
18-
}
19-
2013
Rect? box = svg.ViewBox;
2114

2215
this.CX = XmlUtil.AttrValue(node, "cx", 0, box.HasValue ? box.Value.Width : svg.Size.Width);
@@ -27,14 +20,9 @@ public CircleShape(SVG svg, XmlNode node) : base(svg, node)
2720
diagRef = Math.Sqrt(box.Value.Width * box.Value.Width + box.Value.Height * box.Value.Height) / Math.Sqrt(2);
2821
this.R = XmlUtil.AttrValue(node, "r", 0, diagRef);
2922
}
30-
31-
public override Fill Fill
23+
protected override Fill DefaultFill()
3224
{
33-
get {
34-
Fill f = base.Fill;
35-
if (f == null) f = DefaultFill;
36-
return f;
37-
}
25+
return Fill.CreateDefault(Svg, "black");
3826
}
3927

4028
public double CX { get; set; }

Source/SVGImage/SVG/Shapes/EllipseShape.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@ namespace SVGImage.SVG.Shapes
88

99
public sealed class EllipseShape : Shape
1010
{
11-
private static Fill DefaultFill = null;
12-
1311
public EllipseShape(SVG svg, XmlNode node)
1412
: base(svg, node)
15-
{
16-
if (DefaultFill == null)
17-
{
18-
DefaultFill = Fill.CreateDefault(svg, "black");
19-
}
13+
{
2014

2115
Rect? box = svg.ViewBox;
2216

@@ -30,13 +24,9 @@ public EllipseShape(SVG svg, XmlNode node)
3024
this.RY = XmlUtil.AttrValue(node, "ry", 0, diagRef);
3125
}
3226

33-
public override Fill Fill
27+
protected override Fill DefaultFill()
3428
{
35-
get {
36-
Fill f = base.Fill;
37-
if (f == null) f = DefaultFill;
38-
return f;
39-
}
29+
return Fill.CreateDefault(Svg, "black");
4030
}
4131

4232
public double CX { get; set; }

Source/SVGImage/SVG/Shapes/Group.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private Shape AddToList(SVG svg, XmlNode childnode, Shape parent, bool isDefinit
8888
else if (nodeName == SVGTags.sAnimateTransform)
8989
retVal = new AnimateTransform(svg, childnode, parent);
9090
else if (nodeName == SVGTags.sText)
91+
//retVal = new TextShape(svg, childnode, parent);
9192
retVal = new TextShape(svg, childnode, parent);
9293
else if (nodeName == SVGTags.sLinearGradient)
9394
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace SVGImage.SVG.Shapes
2+
{
3+
public interface ITextChild : ITextNode
4+
{
5+
Shape Parent { get; set; }
6+
}
7+
8+
9+
10+
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace SVGImage.SVG.Shapes
2+
{
3+
public interface ITextNode
4+
{
5+
CharacterLayout GetFirstCharacter();
6+
CharacterLayout GetLastCharacter();
7+
string GetText();
8+
int GetLength();
9+
CharacterLayout[] GetCharacters();
10+
}
11+
12+
13+
14+
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace SVGImage.SVG.Shapes
2+
{
3+
public enum LengthAdjustment
4+
{
5+
None,
6+
/// <summary>
7+
/// Indicates that only the advance values are adjusted. The glyphs themselves are not stretched or compressed.
8+
/// </summary>
9+
Spacing,
10+
/// <summary>
11+
/// Indicates that the advance values are adjusted and the glyphs themselves stretched or compressed in one axis (i.e., a direction parallel to the inline-base direction).
12+
/// </summary>
13+
SpacingAndGlyphs
14+
}
15+
16+
17+
18+
19+
}

0 commit comments

Comments
 (0)