Commit 131eb6bc authored by Tebjan Halm's avatar Tebjan Halm
Browse files

Merge pull request #146 from JoshMcCullough/#145

Fixed #145 - SVG incorrectly renders <title> elements.
parents 6104ff9e 84c22eb1
...@@ -7,7 +7,7 @@ namespace Svg ...@@ -7,7 +7,7 @@ namespace Svg
{ {
[DefaultProperty("Text")] [DefaultProperty("Text")]
[SvgElement("desc")] [SvgElement("desc")]
public class SvgDescription : SvgElement public class SvgDescription : SvgElement, ISvgDescriptiveElement
{ {
public override string ToString() public override string ToString()
{ {
......
...@@ -6,7 +6,7 @@ using System.ComponentModel; ...@@ -6,7 +6,7 @@ using System.ComponentModel;
namespace Svg namespace Svg
{ {
[SvgElement("title")] [SvgElement("title")]
public class SvgTitle : SvgElement public class SvgTitle : SvgElement, ISvgDescriptiveElement
{ {
public override string ToString() public override string ToString()
{ {
......
...@@ -1198,6 +1198,10 @@ namespace Svg ...@@ -1198,6 +1198,10 @@ namespace Svg
string Content { get; } string Content { get; }
} }
/// <summary>This interface mostly indicates that a node is not to be drawn when rendering the SVG.</summary>
public interface ISvgDescriptiveElement {
}
internal interface ISvgElement internal interface ISvgElement
{ {
SvgElement Parent {get;} SvgElement Parent {get;}
......
...@@ -276,7 +276,7 @@ namespace Svg ...@@ -276,7 +276,7 @@ namespace Svg
internal virtual IEnumerable<ISvgNode> GetContentNodes() internal virtual IEnumerable<ISvgNode> GetContentNodes()
{ {
return (this.Nodes == null || this.Nodes.Count < 1 ? this.Children.OfType<ISvgNode>() : this.Nodes); return (this.Nodes == null || this.Nodes.Count < 1 ? this.Children.OfType<ISvgNode>().Where(o => !(o is ISvgDescriptiveElement)) : this.Nodes);
} }
protected virtual GraphicsPath GetBaselinePath(ISvgRenderer renderer) protected virtual GraphicsPath GetBaselinePath(ISvgRenderer renderer)
{ {
...@@ -319,10 +319,9 @@ namespace Svg ...@@ -319,10 +319,9 @@ namespace Svg
/// <param name="state">State of the drawing operation</param> /// <param name="state">State of the drawing operation</param>
private void SetPath(TextDrawingState state, bool doMeasurements) private void SetPath(TextDrawingState state, bool doMeasurements)
{ {
SvgTextBase inner;
TextDrawingState newState;
TextDrawingState origState = null; TextDrawingState origState = null;
bool alignOnBaseline = state.BaselinePath != null && (this.TextAnchor == SvgTextAnchor.Middle || this.TextAnchor == SvgTextAnchor.End); bool alignOnBaseline = state.BaselinePath != null && (this.TextAnchor == SvgTextAnchor.Middle || this.TextAnchor == SvgTextAnchor.End);
if (doMeasurements) if (doMeasurements)
{ {
if (this.TextLength != SvgUnit.None) if (this.TextLength != SvgUnit.None)
...@@ -338,15 +337,17 @@ namespace Svg ...@@ -338,15 +337,17 @@ namespace Svg
foreach (var node in GetContentNodes()) foreach (var node in GetContentNodes())
{ {
inner = node as SvgTextBase; SvgTextBase textNode = node as SvgTextBase;
if (inner == null)
if (textNode == null)
{ {
if (!string.IsNullOrEmpty(node.Content)) state.DrawString(PrepareText(node.Content)); if (!string.IsNullOrEmpty(node.Content)) state.DrawString(PrepareText(node.Content));
} }
else else
{ {
newState = new TextDrawingState(state, inner); TextDrawingState newState= new TextDrawingState(state, textNode);
inner.SetPath(newState);
textNode.SetPath(newState);
state.NumChars += newState.NumChars; state.NumChars += newState.NumChars;
state.Current = newState.Current; state.Current = newState.Current;
} }
......
...@@ -20,14 +20,20 @@ namespace Svg ...@@ -20,14 +20,20 @@ namespace Svg
internal override IEnumerable<ISvgNode> GetContentNodes() internal override IEnumerable<ISvgNode> GetContentNodes()
{ {
var refText = this.OwnerDocument.IdManager.GetElementById(this.ReferencedElement) as SvgTextBase; var refText = this.OwnerDocument.IdManager.GetElementById(this.ReferencedElement) as SvgTextBase;
IEnumerable<ISvgNode> contentNodes = null;
if (refText == null) if (refText == null)
{ {
return base.GetContentNodes(); contentNodes = base.GetContentNodes();
} }
else else
{ {
return refText.GetContentNodes(); contentNodes = refText.GetContentNodes();
} }
contentNodes = contentNodes.Where(o => !(o is ISvgDescriptiveElement));
return contentNodes;
} }
public override SvgElement DeepCopy() public override SvgElement DeepCopy()
......
<svg version="1.1" style="font-family:Arial;font-size:12px;font-weight:normal;" xmlns="http://www.w3.org/2000/svg" width="600" height="200">
<text x="200" y="100" text-anchor="end" style="color:red;font-size:12px;fill:red;">
<tspan>This is visible text.</tspan>
<title>THIS SHOULD NOT BE SEEN! THIS SHOULD NOT BE SEEN!</title>
</text>
</svg>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment