Skip to content

Fixed Conflicts of Pull Request https://github.com/svg-net/SVG/pull/1094 #1107

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

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Source/SvgDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public virtual TSvgElement GetElementById<TSvgElement>(string id) where TSvgElem
/// <exception cref="FileNotFoundException">The document at the specified <paramref name="path"/> cannot be found.</exception>
public static SvgDocument Open(string path)
{
return Open<SvgDocument>(path, null);
return Open<SvgDocument>(path, null, null);
}

/// <summary>
Expand All @@ -237,7 +237,7 @@ public static SvgDocument Open(string path)
/// <exception cref="FileNotFoundException">The document at the specified <paramref name="path"/> cannot be found.</exception>
public static T Open<T>(string path) where T : SvgDocument, new()
{
return Open<T>(path, null);
return Open<T>(path, null, null);
}

/// <summary>
Expand All @@ -247,7 +247,7 @@ public static SvgDocument Open(string path)
/// <param name="entities">A dictionary of custom entity definitions to be used when resolving XML entities within the document.</param>
/// <returns>An <see cref="SvgDocument"/> with the contents loaded.</returns>
/// <exception cref="FileNotFoundException">The document at the specified <paramref name="path"/> cannot be found.</exception>
public static T Open<T>(string path, Dictionary<string, string> entities) where T : SvgDocument, new()
public static T Open<T>(string path, Dictionary<string, string> entities, string css = null) where T : SvgDocument, new()
{
if (string.IsNullOrEmpty(path))
{
Expand All @@ -261,7 +261,7 @@ public static SvgDocument Open(string path)

using (var stream = File.OpenRead(path))
{
var doc = Open<T>(stream, entities);
var doc = Open<T>(stream, entities, css);
doc.BaseUri = new Uri(System.IO.Path.GetFullPath(path));
return doc;
}
Expand All @@ -282,7 +282,7 @@ public static SvgDocument Open(string path)
/// <param name="stream">The <see cref="Stream"/> containing the SVG document to open.</param>
/// <param name="entities">Custom entity definitions.</param>
/// <exception cref="ArgumentNullException">The <paramref name="stream"/> parameter cannot be <c>null</c>.</exception>
public static T Open<T>(Stream stream, Dictionary<string, string> entities) where T : SvgDocument, new()
public static T Open<T>(Stream stream, Dictionary<string, string> entities, string css = null) where T : SvgDocument, new()
{
if (stream == null)
{
Expand All @@ -296,7 +296,7 @@ public static SvgDocument Open(string path)
WhitespaceHandling = WhitespaceHandling.Significant,
DtdProcessing = DisableDtdProcessing ? DtdProcessing.Ignore : DtdProcessing.Parse,
};
return Create<T>(reader);
return Create<T>(reader, css);
}

/// <summary>
Expand Down Expand Up @@ -343,13 +343,16 @@ public static SvgDocument Open(string path)
}
}


private static T Create<T>(XmlReader reader) where T : SvgDocument, new()
private static T Create<T>(XmlReader reader, string css = null) where T : SvgDocument, new()
{
var styles = new List<ISvgNode>();
var elementFactory = new SvgElementFactory();

var svgDocument = Create<T>(reader, elementFactory, styles);

if (css != null) {
styles.Add(new SvgUnknownElement() { Content = css });
}

if (styles.Any())
{
Expand Down