Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass styling-css-08-f. #692

Merged
merged 4 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/Css/SvgElementOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public SvgElementOps(SvgElementFactory elementFactory)

public Selector<SvgElement> Type(NamespacePrefix prefix, string name)
{
SvgElementFactory.ElementInfo type = null;
if (_elementFactory.AvailableElements.TryGetValue(name, out type))
var types = _elementFactory.AvailableElements.Where(e => e.ElementName.Equals(name)).Select(e => e.ElementType);
if (types.Any())
{
return nodes => nodes.Where(n => n.GetType() == type.ElementType);
return nodes => nodes.Where(n => types.Contains(n.GetType()));
}
return nodes => Enumerable.Empty<SvgElement>();
}
Expand Down
14 changes: 6 additions & 8 deletions Source/SvgElementFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace Svg
/// </summary>
internal class SvgElementFactory
{
private Dictionary<string, ElementInfo> availableElements;
private List<ElementInfo> availableElements;
private Parser cssParser = new Parser();

/// <summary>
/// Gets a list of available types that can be used when creating an <see cref="SvgElement"/>.
/// </summary>
public Dictionary<string, ElementInfo> AvailableElements
public List<ElementInfo> AvailableElements
{
get
{
Expand All @@ -31,10 +31,7 @@ internal class SvgElementFactory
&& t.IsSubclassOf(typeof(SvgElement))
select new ElementInfo { ElementName = ((SvgElementAttribute)t.GetCustomAttributes(typeof(SvgElementAttribute), true)[0]).ElementName, ElementType = t };

availableElements = (from t in svgTypes
where t.ElementName != "svg"
group t by t.ElementName into types
select types).ToDictionary(e => e.Key, e => e.SingleOrDefault());
availableElements = svgTypes.ToList();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple <svg> elements.

  • SvgFragment
  • SvgDocument

}

return availableElements;
Expand Down Expand Up @@ -94,8 +91,9 @@ private SvgElement CreateElement<T>(XmlReader reader, bool fragmentIsDocument, S
}
else
{
ElementInfo validType = null;
if (AvailableElements.TryGetValue(elementName, out validType))
ElementInfo validType;
if (AvailableElements.Where(e => !e.ElementName.Equals("svg", StringComparison.OrdinalIgnoreCase))
.ToDictionary(e => e.ElementName, e => e).TryGetValue(elementName, out validType))
{
createdElement = (SvgElement)Activator.CreateInstance(validType.ElementType);
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Svg.UnitTests/PassingTests.csv
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ styling-css-01-b
styling-css-02-b
styling-css-03-b
styling-css-07-f
styling-css-08-f
styling-inherit-01-b
styling-pres-01-t
text-align-01-b
Expand Down
1 change: 1 addition & 0 deletions Tests/W3CTestSuite/PassingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ styling-css-02-b.svg
styling-css-03-b.svg
styling-css-04-f.svg
styling-css-07-f.svg
styling-css-08-f.svg
styling-inherit-01-b.svg
styling-pres-01-t.svg
text-align-01-b.svg
Expand Down