private void ReadParametersFormVectorImage(Stream fileStream, ref Size size)
{
XDocument xdocument = XDocument.Load(fileStream);
var root = xdocument.Root;
if (root == null || root.Name.LocalName != "svg")
{
const string message = "An error has ocurred while trying to read the file";
throw new ValidationException(() => message, message);
}
var attributes = root.Attributes().ToList();
var widthAttribute = attributes.FirstOrDefault(x => x.Name == "width");
var heightAttribute = attributes.FirstOrDefault(x => x.Name == "height");
/* Assume that attribute may look something like '1024px'. We need to match int value */
Match match;
int value;
var regex = new Regex(@"^\d+");
if (widthAttribute != null)
{
match = regex.Match(widthAttribute.Value);
if (int.TryParse(match.Value, out value))
{
size.Width = value;
}
}
if (heightAttribute != null)
{
match = regex.Match(heightAttribute.Value);
if (int.TryParse(match.Value, out value))
{
size.Height = value;
}
}
if (size.Height * size.Width == 0)
{
size.Height = -1;
size.Width = -1;
}
}