Skip to content

Commit

Permalink
Improvements in color, color-profile, coordinates, transforms and asp…
Browse files Browse the repository at this point in the history
…ect ratios. Support for slice alignment
  • Loading branch information
paulushub committed Sep 19, 2018
1 parent 5069cd8 commit db23aa3
Show file tree
Hide file tree
Showing 37 changed files with 697 additions and 376 deletions.
Binary file not shown.
Binary file modified Applications/ConvertersWpf/Output/SharpVectors.Core.dll
Binary file not shown.
Binary file modified Applications/ConvertersWpf/Output/SharpVectors.Css.dll
Binary file not shown.
Binary file modified Applications/ConvertersWpf/Output/SharpVectors.Dom.dll
Binary file not shown.
Binary file modified Applications/ConvertersWpf/Output/SharpVectors.Model.dll
Binary file not shown.
Binary file not shown.
Binary file modified Applications/ConvertersWpf/Output/SharpVectors.Runtime.Wpf.dll
Binary file not shown.
Binary file modified Applications/ConvertersWpf/Output/SharpVectors.exe
Binary file not shown.
Binary file modified Output/SharpVectors.Converters.Wpf.dll
Binary file not shown.
Binary file modified Output/SharpVectors.Core.dll
Binary file not shown.
Binary file modified Output/SharpVectors.Css.dll
Binary file not shown.
Binary file modified Output/SharpVectors.Dom.dll
Binary file not shown.
Binary file modified Output/SharpVectors.Model.dll
Binary file not shown.
Binary file modified Output/SharpVectors.Rendering.Gdi.dll
Binary file not shown.
Binary file modified Output/SharpVectors.Rendering.Wpf.dll
Binary file not shown.
Binary file modified Output/SharpVectors.Runtime.Wpf.dll
Binary file not shown.
30 changes: 25 additions & 5 deletions Samples/WpfSvgTestBox/SvgPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public bool LoadDocument(string documentFilePath)

if (this.SaveDocument() && File.Exists(_svgFilePath))
{
return this.ConvertDocument();
return this.ConvertDocument(documentFilePath);
}

return true;
Expand Down Expand Up @@ -286,7 +286,11 @@ private bool SaveDocument()

textEditor.Save(_backFilePath);

var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, XmlResolver = null };
var settings = new XmlReaderSettings
{
DtdProcessing = DtdProcessing.Parse,
XmlResolver = null
};

using (var textReader = new StreamReader(_backFilePath))
{
Expand All @@ -309,15 +313,19 @@ private bool SaveDocument()
}
}

private bool ConvertDocument()
private bool ConvertDocument(string filePath = null)
{
if (string.IsNullOrWhiteSpace(filePath) || File.Exists(filePath) == false)
{
filePath = _svgFilePath;
}
try
{
if (string.IsNullOrWhiteSpace(_svgFilePath) || File.Exists(_svgFilePath) == false)
if (string.IsNullOrWhiteSpace(filePath) || File.Exists(filePath) == false)
{
return false;
}
DrawingGroup drawing = _fileReader.Read(_svgFilePath, _directoryInfo);
DrawingGroup drawing = _fileReader.Read(filePath, _directoryInfo);
if (drawing == null)
{
return false;
Expand All @@ -332,6 +340,18 @@ private bool ConvertDocument()
// Delete the file after loading it...
File.Delete(_xamlFilePath);
}
else
{
string xamlFilePath = IoPath.Combine(_directoryInfo.FullName,
IoPath.GetFileNameWithoutExtension(filePath) + ".xaml");
if (File.Exists(xamlFilePath))
{
_xamlPage.LoadDocument(xamlFilePath);

// Delete the file after loading it...
File.Delete(xamlFilePath);
}
}
}
_currentDrawing = drawing;

Expand Down
8 changes: 4 additions & 4 deletions Samples/WpfW3cSvgTestSuite/Output/SvgTestResults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
<category label="Text" total="32" unknowns="0" failures="2" successes="19" partials="11" />
<category label="Metadata and Others" total="3" unknowns="0" failures="1" successes="1" partials="1" />
</result>
<result version="1.2.0.0" date="2018-09-16T15:52:59.8015125+09:00">
<result version="1.2.0.0" date="2018-09-19T19:11:12.9054489+09:00">
<category label="Animations" total="58" unknowns="0" failures="58" successes="0" partials="0" />
<category label="Colors" total="4" unknowns="0" failures="0" successes="3" partials="1" />
<category label="Coordinates and Transforms" total="14" unknowns="0" failures="0" successes="11" partials="3" />
<category label="Colors" total="4" unknowns="0" failures="0" successes="4" partials="0" />
<category label="Coordinates and Transforms" total="14" unknowns="0" failures="0" successes="14" partials="0" />
<category label="Filter Effects" total="17" unknowns="0" failures="17" successes="0" partials="0" />
<category label="Fonts" total="12" unknowns="0" failures="7" successes="0" partials="5" />
<category label="Interactivities" total="7" unknowns="0" failures="7" successes="0" partials="0" />
Expand All @@ -67,7 +67,7 @@
<category label="Rendering Groups" total="2" unknowns="0" failures="0" successes="0" partials="2" />
<category label="Scripting" total="4" unknowns="0" failures="4" successes="0" partials="0" />
<category label="Shapes" total="10" unknowns="0" failures="0" successes="10" partials="0" />
<category label="Structures" total="33" unknowns="1" failures="7" successes="24" partials="1" />
<category label="Structures" total="33" unknowns="1" failures="6" successes="24" partials="2" />
<category label="Styling" total="8" unknowns="0" failures="1" successes="5" partials="2" />
<category label="Text" total="32" unknowns="0" failures="2" successes="19" partials="11" />
<category label="Metadata and Others" total="3" unknowns="0" failures="1" successes="1" partials="1" />
Expand Down
10 changes: 5 additions & 5 deletions Samples/WpfW3cSvgTestSuite/Output/SvgTestSuite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<test source="animate-elem-85-t.svg" title="animate-elem-85-t" state="failure" comment="SVG animation is currently not supported." description="" />
</category>
<category label="Colors">
<test source="color-prof-01-f.svg" title="color-prof-01-f" state="partial" comment="The effect is different. All browsers produce the same results as the converted image, but Apache's Batik and Inkspace give the same result as the expected." description="Basic test of ICC profile with an image." />
<test source="color-prof-01-f.svg" title="color-prof-01-f" state="success" comment="The effect is different. All browsers produce the same results as the previous converted image, but Apache's Batik and Inkspace give the same result as the expected." description="Basic test of ICC profile with an image." />
<test source="color-prop-01-b.svg" title="color-prop-01-b" state="success" comment="" description="Test that viewer has the basic capability to process the color property" />
<test source="color-prop-02-f.svg" title="color-prop-02-f" state="success" comment="" description="Test that viewer has the basic capability to render X11colors, using any of the equivalent forms." />
<test source="color-prop-03-t.svg" title="color-prop-03-t" state="success" comment="" description="Test that viewer has the basic capability to render colors, specified as CSS attributes, using any of the equivalent forms." />
Expand All @@ -75,11 +75,11 @@
<test source="coords-trans-04-t.svg" title="coords-trans-04-t" state="success" comment="" description="Validates elementary transforms and transformation nesting" />
<test source="coords-trans-05-t.svg" title="coords-trans-05-t" state="success" comment="" description="Validates elementary transforms and transformation nesting" />
<test source="coords-trans-06-t.svg" title="coords-trans-06-t" state="success" comment="" description="Validates elementary transforms and transformation nesting" />
<test source="coords-units-01-b.svg" title="coords-units-01-b" state="partial" comment="" description="This test validates the processing rules for converting coordinates and length defined in fractions of the current object's bounding box to user space coordinates and length. Note that this test assumes that linear and radial gradients, as well as patterns are implemented." />
<test source="coords-units-01-b.svg" title="coords-units-01-b" state="success" comment="" description="This test validates the processing rules for converting coordinates and length defined in fractions of the current object's bounding box to user space coordinates and length. Note that this test assumes that linear and radial gradients, as well as patterns are implemented." />
<test source="coords-units-02-b.svg" title="coords-units-02-b" state="success" comment="" description="This test validates the processing rules for converting coordinates and length in CSS units to user space coordinate values." />
<test source="coords-units-03-b.svg" title="coords-units-03-b" state="success" comment="" description="Validates simple initial viewport size and basic units handling." />
<test source="coords-viewattr-01-b.svg" title="coords-viewattr-01-b" state="partial" comment="Slice is not yet supported." description="Validates viewBox specification and the preserveAspectRatio attribute" />
<test source="coords-viewattr-02-b.svg" title="coords-viewattr-02-b" state="partial" comment="Slice is not yet supported." description="Validates viewBox specification and the preserveAspectRatio attribute" />
<test source="coords-viewattr-01-b.svg" title="coords-viewattr-01-b" state="success" comment="Slice is not yet supported." description="Validates viewBox specification and the preserveAspectRatio attribute" />
<test source="coords-viewattr-02-b.svg" title="coords-viewattr-02-b" state="success" comment="Slice is now supported." description="Validates viewBox specification and the preserveAspectRatio attribute" />
<test source="coords-viewattr-03-b.svg" title="coords-viewattr-03-b" state="success" comment="" description="Tests the viewBox attribute on SVG elements" />
</category>
<category label="Filter Effects">
Expand Down Expand Up @@ -265,7 +265,7 @@
<test source="struct-image-08-t.svg" title="struct-image-08-t" state="success" comment="" description="" />
<test source="struct-image-09-t.svg" title="struct-image-09-t" state="success" comment="" description="" />
<test source="struct-image-10-t.svg" title="struct-image-10-t" state="success" comment="" description="" />
<test source="struct-symbol-01-b.svg" title="struct-symbol-01-b" state="failure" comment="" description="Test the creation of symbol elements and the instantiation by the use element" />
<test source="struct-symbol-01-b.svg" title="struct-symbol-01-b" state="partial" comment="Image viewport not well supported." description="Test the creation of symbol elements and the instantiation by the use element" />
<test source="struct-use-01-t.svg" title="struct-use-01-t" state="success" comment="" description="Test that viewer has the basic capability to handle different font sizes" />
<test source="struct-use-03-t.svg" title="struct-use-03-t" state="success" comment="" description="Tests proper handling of x/y/width/height attributes on the &lt;use&gt; element" />
<test source="struct-use-05-b.svg" title="struct-use-05-b" state="success" comment="" description="Tests external references and computed inherited values" />
Expand Down
60 changes: 22 additions & 38 deletions Source/SharpVectorConvertersWpf/FileSvgReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,16 @@ public DrawingGroup Read(string svgFileName)
{
if (svgFileName == null)
{
throw new ArgumentNullException("svgFileName",
throw new ArgumentNullException(nameof(svgFileName),
"The SVG source file cannot be null (or Nothing).");
}
if (svgFileName.Length == 0)
{
throw new ArgumentException(
"The SVG source file cannot be empty.", "svgFileName");
throw new ArgumentException("The SVG source file cannot be empty.", nameof(svgFileName));
}
if (!File.Exists(svgFileName))
{
throw new ArgumentException(
"The SVG source file must exists.", "svgFileName");
throw new ArgumentException("The SVG source file must exists.", nameof(svgFileName));
}

if (_workingDir == null)
Expand Down Expand Up @@ -276,7 +274,7 @@ public DrawingGroup Read(Uri svgUri)
{
if (svgUri == null)
{
throw new ArgumentNullException("svgUri",
throw new ArgumentNullException(nameof(svgUri),
"The SVG source file cannot be null (or Nothing).");
}

Expand All @@ -302,7 +300,7 @@ public DrawingGroup Read(Stream svgStream)
{
if (svgStream == null)
{
throw new ArgumentNullException("svgStream",
throw new ArgumentNullException(nameof(svgStream),
"The SVG source file cannot be null (or Nothing).");
}

Expand Down Expand Up @@ -331,7 +329,7 @@ public DrawingGroup Read(TextReader svgTextReader)
{
if (svgTextReader == null)
{
throw new ArgumentNullException("svgTextReader",
throw new ArgumentNullException(nameof(svgTextReader),
"The SVG source file cannot be null (or Nothing).");
}

Expand Down Expand Up @@ -478,7 +476,7 @@ public bool Save(TextWriter textWriter)
{
if (textWriter == null)
{
throw new ArgumentNullException("textWriter",
throw new ArgumentNullException(nameof(textWriter),
"The text writer parameter is required and cannot be null (or Nothing).");
}
if (_drawing == null)
Expand All @@ -494,7 +492,7 @@ public bool Save(Stream stream)
{
if (stream == null)
{
throw new ArgumentNullException("stream",
throw new ArgumentNullException(nameof(stream),
"The stream parameter is required and cannot be null (or Nothing).");
}
if (_drawing == null)
Expand Down Expand Up @@ -522,8 +520,7 @@ public bool Save(Stream stream)

string outputExt = GetImageFileExtention(encoderType);

string fileNameWithoutExt = Path.GetFileNameWithoutExtension(
fileName);
string fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName);

string imageFileName = Path.Combine(imageFileDir.FullName,
fileNameWithoutExt + outputExt);
Expand Down Expand Up @@ -665,19 +662,16 @@ private bool SaveFile(Stream stream)
writerSettings.Indent = true;
writerSettings.OmitXmlDeclaration = true;
writerSettings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(
stream, writerSettings))
using (XmlWriter writer = XmlWriter.Create(stream, writerSettings))
{
System.Windows.Markup.XamlWriter.Save(
_drawing, writer);
System.Windows.Markup.XamlWriter.Save(_drawing, writer);
}
}
else
{
try
{
XmlXamlWriter xamlWriter = new XmlXamlWriter(
this.DrawingSettings);
XmlXamlWriter xamlWriter = new XmlXamlWriter(this.DrawingSettings);

xamlWriter.Save(_drawing, stream);
}
Expand All @@ -691,11 +685,9 @@ private bool SaveFile(Stream stream)
writerSettings.Indent = true;
writerSettings.OmitXmlDeclaration = true;
writerSettings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(
stream, writerSettings))
using (XmlWriter writer = XmlWriter.Create(stream, writerSettings))
{
System.Windows.Markup.XamlWriter.Save(
_drawing, writer);
System.Windows.Markup.XamlWriter.Save(_drawing, writer);
}
}
else
Expand All @@ -718,19 +710,16 @@ private bool SaveFile(TextWriter textWriter)
writerSettings.Indent = true;
writerSettings.OmitXmlDeclaration = true;
writerSettings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(
textWriter, writerSettings))
using (XmlWriter writer = XmlWriter.Create(textWriter, writerSettings))
{
System.Windows.Markup.XamlWriter.Save(
_drawing, writer);
System.Windows.Markup.XamlWriter.Save(_drawing, writer);
}
}
else
{
try
{
XmlXamlWriter xamlWriter = new XmlXamlWriter(
this.DrawingSettings);
XmlXamlWriter xamlWriter = new XmlXamlWriter(this.DrawingSettings);

xamlWriter.Save(_drawing, textWriter);
}
Expand Down Expand Up @@ -789,20 +778,17 @@ private bool SaveFile(string fileName)
writerSettings.Encoding = Encoding.UTF8;
using (FileStream xamlFile = File.Create(xamlFileName))
{
using (XmlWriter writer = XmlWriter.Create(
xamlFile, writerSettings))
using (XmlWriter writer = XmlWriter.Create(xamlFile, writerSettings))
{
System.Windows.Markup.XamlWriter.Save(
_drawing, writer);
System.Windows.Markup.XamlWriter.Save(_drawing, writer);
}
}
}
else
{
try
{
XmlXamlWriter xamlWriter = new XmlXamlWriter(
this.DrawingSettings);
XmlXamlWriter xamlWriter = new XmlXamlWriter(this.DrawingSettings);

using (FileStream xamlFile = File.Create(xamlFileName))
{
Expand All @@ -827,11 +813,9 @@ private bool SaveFile(string fileName)
writerSettings.Encoding = Encoding.UTF8;
using (FileStream xamlFile = File.Create(xamlFileName))
{
using (XmlWriter writer = XmlWriter.Create(
xamlFile, writerSettings))
using (XmlWriter writer = XmlWriter.Create(xamlFile, writerSettings))
{
System.Windows.Markup.XamlWriter.Save(
_drawing, writer);
System.Windows.Markup.XamlWriter.Save(_drawing, writer);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions Source/SharpVectorCore/Svg/BasicTypes/ISvgFitToViewBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ namespace SharpVectors.Dom.Svg
{
/// <summary>
/// Interface SvgFitToViewBox defines DOM attributes that apply to
/// elements which have XML attributes viewBox and
/// preserveAspectRatio.
/// elements which have XML attributes viewBox and preserveAspectRatio.
/// </summary>
public interface ISvgFitToViewBox
{
ISvgAnimatedRect ViewBox{get;}
ISvgAnimatedPreserveAspectRatio PreserveAspectRatio{get;}
ISvgAnimatedRect ViewBox { get; }
ISvgAnimatedPreserveAspectRatio PreserveAspectRatio { get; }
}
}
12 changes: 6 additions & 6 deletions Source/SharpVectorModel/BasicTypes/SvgFitToViewBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public ISvgAnimatedRect ViewBox
string attr = _ownerElement.GetAttribute("viewBox").Trim();
if (string.IsNullOrWhiteSpace(attr))
{
double x = 0;
double y = 0;
double width = 0;
double x = 0;
double y = 0;
double width = 0;
double height = 0;
if (_ownerElement is SvgSvgElement)
{
SvgSvgElement svgSvgElm = _ownerElement as SvgSvgElement;

x = svgSvgElm.X.AnimVal.Value;
y = svgSvgElm.Y.AnimVal.Value;
width = svgSvgElm.Width.AnimVal.Value;
x = svgSvgElm.X.AnimVal.Value;
y = svgSvgElm.Y.AnimVal.Value;
width = svgSvgElm.Width.AnimVal.Value;
height = svgSvgElm.Height.AnimVal.Value;
}
_viewBox = new SvgAnimatedRect(new SvgRect(x, y, width, height));
Expand Down

0 comments on commit db23aa3

Please sign in to comment.