Skip to content

Commit

Permalink
Merge pull request svg-net#300 from mrbean-bremen/pr/test
Browse files Browse the repository at this point in the history
Fixed inheritance of  text-anchor and baseline-shift attributes
  • Loading branch information
tebjan committed Mar 25, 2017
2 parents bb69f2b + 0858935 commit 6896260
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Source/Document Structure/SvgUse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ protected override void Render(ISvgRenderer renderer)
{
var origParent = element.Parent;
element._parent = this;
// as the new parent may have other styles that are inherited,
// we have to redraw the paths for the children
element.InvalidateChildPaths();
element.RenderElement(renderer);
element._parent = origParent;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/SvgElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ public string ID
}

/// <summary>
/// Gets or sets the text anchor.
/// Gets or sets the space handling.
/// </summary>
/// <value>The text anchor.</value>
/// <value>The space handling.</value>
[SvgAttribute("space", SvgAttributeAttribute.XmlNamespace)]
public virtual XmlSpaceHandling SpaceHandling
{
Expand Down
32 changes: 32 additions & 0 deletions Source/SvgElementStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ protected virtual bool IsPathDirty
set { this._dirty = value; }
}

/// <summary>
/// Force recreation of the paths for the element and it's children.
/// </summary>
public void InvalidateChildPaths()
{
this.IsPathDirty = true;
foreach (SvgElement element in this.Children)
{
element.InvalidateChildPaths();
}
}

protected static float FixOpacityValue(float value)
{
const float max = 1.0f;
Expand Down Expand Up @@ -157,6 +169,26 @@ public virtual SvgShapeRendering ShapeRendering
set { this.Attributes["shape-rendering"] = value; }
}

/// <summary>
/// Gets or sets the text anchor.
/// </summary>
[SvgAttribute("text-anchor", true)]
public virtual SvgTextAnchor TextAnchor
{
get { return this.Attributes.GetInheritedAttribute<SvgTextAnchor>("text-anchor"); }
set { this.Attributes["text-anchor"] = value; this.IsPathDirty = true; }
}

/// <summary>
/// Specifies dominant-baseline positioning of text.
/// </summary>
[SvgAttribute("baseline-shift", true)]
public virtual string BaselineShift
{
get { return this.Attributes.GetInheritedAttribute<string>("baseline-shift"); }
set { this.Attributes["baseline-shift"] = value; this.IsPathDirty = true; }
}

/// <summary>
/// Indicates which font family is to be used to render the text.
/// </summary>
Expand Down
18 changes: 0 additions & 18 deletions Source/Text/SvgTextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,6 @@ public virtual string Text
}
}

/// <summary>
/// Gets or sets the text anchor.
/// </summary>
/// <value>The text anchor.</value>
[SvgAttribute("text-anchor", true)]
public virtual SvgTextAnchor TextAnchor
{
get { return (this.Attributes["text-anchor"] == null) ? SvgTextAnchor.Inherit : (SvgTextAnchor)this.Attributes["text-anchor"]; }
set { this.Attributes["text-anchor"] = value; this.IsPathDirty = true; }
}

[SvgAttribute("baseline-shift", true)]
public virtual string BaselineShift
{
get { return this.Attributes["baseline-shift"] as string; }
set { this.Attributes["baseline-shift"] = value; this.IsPathDirty = true; }
}

public override XmlSpaceHandling SpaceHandling
{
get { return base.SpaceHandling; }
Expand Down
2 changes: 2 additions & 0 deletions Tests/W3CTestSuite/PassingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,13 @@ text-text-08-b.svg
text-text-09-t.svg
text-text-10-t.svg
text-text-11-t.svg
text-text-12-t.svg
text-tref-01-b.svg
text-tspan-01-b.svg
text-ws-01-t.svg
text-ws-02-t.svg
text-ws-03-t.svg
types-basic-01-f.svg
painting-stroke-02-t.svg
coords-viewattr-04-f.svg
fonts-desc-01-t.svg
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions Tests/W3CTestSuite/svg/__Flag_of_the_United_States.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6896260

Please sign in to comment.