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
{
[DefaultProperty("Text")]
[SvgElement("desc")]
public class SvgDescription : SvgElement
public class SvgDescription : SvgElement, ISvgDescriptiveElement
{
public override string ToString()
{
......
......@@ -6,7 +6,7 @@ using System.ComponentModel;
namespace Svg
{
[SvgElement("title")]
public class SvgTitle : SvgElement
public class SvgTitle : SvgElement, ISvgDescriptiveElement
{
public override string ToString()
{
......
......@@ -1198,6 +1198,10 @@ namespace Svg
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
{
SvgElement Parent {get;}
......
......@@ -276,7 +276,7 @@ namespace Svg
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)
{
......@@ -319,10 +319,9 @@ namespace Svg
/// <param name="state">State of the drawing operation</param>
private void SetPath(TextDrawingState state, bool doMeasurements)
{
SvgTextBase inner;
TextDrawingState newState;
TextDrawingState origState = null;
bool alignOnBaseline = state.BaselinePath != null && (this.TextAnchor == SvgTextAnchor.Middle || this.TextAnchor == SvgTextAnchor.End);
if (doMeasurements)
{
if (this.TextLength != SvgUnit.None)
......@@ -338,15 +337,17 @@ namespace Svg
foreach (var node in GetContentNodes())
{
inner = node as SvgTextBase;
if (inner == null)
SvgTextBase textNode = node as SvgTextBase;
if (textNode == null)
{
if (!string.IsNullOrEmpty(node.Content)) state.DrawString(PrepareText(node.Content));
}
else
{
newState = new TextDrawingState(state, inner);
inner.SetPath(newState);
TextDrawingState newState= new TextDrawingState(state, textNode);
textNode.SetPath(newState);
state.NumChars += newState.NumChars;
state.Current = newState.Current;
}
......
......@@ -20,14 +20,20 @@ namespace Svg
internal override IEnumerable<ISvgNode> GetContentNodes()
{
var refText = this.OwnerDocument.IdManager.GetElementById(this.ReferencedElement) as SvgTextBase;
IEnumerable<ISvgNode> contentNodes = null;
if (refText == null)
{
return base.GetContentNodes();
contentNodes = base.GetContentNodes();
}
else
{
return refText.GetContentNodes();
contentNodes = refText.GetContentNodes();
}
contentNodes = contentNodes.Where(o => !(o is ISvgDescriptiveElement));
return contentNodes;
}
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