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

Stub for non-Windows DPI; possible fix for #427 #450

Merged
merged 3 commits into from
May 9, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Tests/**/*.suo
Source/TestResults/
Source/.vs
/Source/Svg.sln.DotSettings.user
/Source/Svg.XML
5 changes: 0 additions & 5 deletions Source/DataTypes/SvgUnitConverter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;

namespace Svg
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Document Structure/SvgGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override void Render(ISvgRenderer renderer)
}

/// <summary>
/// Gets the <see cref="GraphicsPath"/> for this element.
/// Gets the <see cref="System.Drawing.Drawing2D.GraphicsPath"/> for this element.
/// </summary>
/// <value></value>
public override GraphicsPath Path(ISvgRenderer renderer)
Expand Down
2 changes: 1 addition & 1 deletion Source/Painting/EnumConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public EnumBaseConverter() { }

/// <summary>Creates a new instance.</summary>
/// <param name="defaultValue">Specified the default value of the enum.</param>
/// <param name="caseHandling">Specified the case.</param>
/// <param name="caseHandling">Defines if the value shall be converted to lower camel case or lower case</param>
public EnumBaseConverter(T defaultValue, CaseHandling caseHandling = CaseHandling.CamelCase)
{
this.DefaultValue = defaultValue;
Expand Down
4 changes: 1 addition & 3 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -32,8 +31,7 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.4.3.*")]
//[assembly: AssemblyFileVersion("1.0.1.*")]
[assembly: AssemblyVersion("2.4.5.0")]

[assembly: CLSCompliant(true)]

Expand Down
494 changes: 119 additions & 375 deletions Source/Svg.csproj

Large diffs are not rendered by default.

55 changes: 21 additions & 34 deletions Source/Svg.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Svg", "Svg.csproj", "{886A98C5-37C0-4E8B-885E-30C1D2F98B47}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Svg", "Svg.csproj", "{886A98C5-37C0-4E8B-885E-30C1D2F98B47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVGViewer", "..\Samples\SVGViewer\SVGViewer.csproj", "{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Svg.UnitTests", "..\Tests\Svg.UnitTests\Svg.UnitTests.csproj", "{E702EB7D-D01D-438A-BADD-E72D4E49109F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Svg.UnitTests", "..\Tests\Svg.UnitTests\Svg.UnitTests.csproj", "{E702EB7D-D01D-438A-BADD-E72D4E49109F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A417AF1E-BEDB-4715-B4FD-D795579217F9}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -18,7 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgW3CTestRunner", "..\Tests\SvgW3CTestRunner\SvgW3CTestRunner.csproj", "{8ED74C39-6CFF-421E-952A-30F9E6957108}"
EndProject
Project("{FF286327-C783-4F7A-AB73-9BCBAD0D4460}") = "Svg.Package", "SvgNuget\Svg.Package.nuproj", "{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVGViewer", "..\Samples\SVGViewer\SVGViewer.csproj", "{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -40,18 +38,6 @@ Global
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|x86.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.Build.0 = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.Build.0 = Debug|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.ActiveCfg = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.Build.0 = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Any CPU.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand All @@ -62,34 +48,35 @@ Global
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|x86.ActiveCfg = Release|Any CPU
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Any CPU.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Any CPU.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Any CPU.ActiveCfg = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Mixed Platforms.Build.0 = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|x86.ActiveCfg = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|x86.Build.0 = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Any CPU.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Any CPU.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Mixed Platforms.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Mixed Platforms.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|x86.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|x86.Build.0 = Release|x86
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|x86.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|x86.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Any CPU.Build.0 = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|x86.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|x86.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.Build.0 = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.Build.0 = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.ActiveCfg = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.Build.0 = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.ActiveCfg = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5096EEB3-8F41-44B5-BCF9-58743A59AB21}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Svg.vsmdi
EndGlobalSection
Expand Down
53 changes: 37 additions & 16 deletions Source/SvgDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,29 @@ public class SvgDocument : SvgFragment, ITypeDescriptorContext
private Dictionary<string, IEnumerable<SvgFontFace>> _fontDefns = null;

private static int GetSystemDpi()
{
IntPtr hDC = GetDC(IntPtr.Zero);
const int LOGPIXELSY = 90;
int result = GetDeviceCaps(hDC, LOGPIXELSY);
ReleaseDC(IntPtr.Zero, hDC);
return result;
{
bool isWindows;

#if NETCORE
isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
isWindows = true;
#endif

if (isWindows)
{
// NOTE: starting with Windows 8.1, the DPI is no longer system-wide but screen-specific
IntPtr hDC = GetDC(IntPtr.Zero);
const int LOGPIXELSY = 90;
int result = GetDeviceCaps(hDC, LOGPIXELSY);
ReleaseDC(IntPtr.Zero, hDC);
return result;
}
else
{
// hack for macOS and Linux
return 96;
}
}

[DllImport("gdi32.dll")]
Expand Down Expand Up @@ -104,7 +121,7 @@ public void OverwriteIdManager(SvgElementIdManager manager)
/// </summary>
public string ExternalCSSHref { get; set; }

#region ITypeDescriptorContext Members
#region ITypeDescriptorContext Members

IContainer ITypeDescriptorContext.Container
{
Expand Down Expand Up @@ -136,7 +153,7 @@ object IServiceProvider.GetService(Type serviceType)
throw new NotImplementedException();
}

#endregion
#endregion

/// <summary>
/// Retrieves the <see cref="SvgElement"/> with the specified ID.
Expand Down Expand Up @@ -230,9 +247,10 @@ public static SvgDocument Open(string path)

using (var strReader = new System.IO.StringReader(svg))
{
var reader = new SvgTextReader(strReader, null);
reader.XmlResolver = new SvgDtdResolver();
reader.WhitespaceHandling = WhitespaceHandling.None;
var reader = new SvgTextReader(strReader, null)
{
XmlResolver = new SvgDtdResolver(), WhitespaceHandling = WhitespaceHandling.None
};
return Open<T>(reader);
}
}
Expand All @@ -251,9 +269,10 @@ public static SvgDocument Open(string path)
}

// Don't close the stream via a dispose: that is the client's job.
var reader = new SvgTextReader(stream, entities);
reader.XmlResolver = new SvgDtdResolver();
reader.WhitespaceHandling = WhitespaceHandling.None;
var reader = new SvgTextReader(stream, entities)
{
XmlResolver = new SvgDtdResolver(), WhitespaceHandling = WhitespaceHandling.None
};
return Open<T>(reader);
}

Expand Down Expand Up @@ -621,8 +640,10 @@ public override void Write(XmlTextWriter writer)
public void Write(Stream stream, bool useBom = true)
{

var xmlWriter = new XmlTextWriter(stream, useBom ? Encoding.UTF8 : new System.Text.UTF8Encoding(false));
xmlWriter.Formatting = Formatting.Indented;
var xmlWriter = new XmlTextWriter(stream, useBom ? Encoding.UTF8 : new System.Text.UTF8Encoding(false))
{
Formatting = Formatting.Indented
};
xmlWriter.WriteStartDocument();
xmlWriter.WriteDocType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null);

Expand Down
6 changes: 6 additions & 0 deletions Source/SvgElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,13 @@ private Dictionary<string, string> WritePropertyAttributes(XmlTextWriter writer)
}
}

#if NETFULL
var value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
#else
// dotnetcore throws exception if input is null
string value = propertyValue==null?null:(string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
#endif

if (propertyValue != null)
{
var type = propertyValue.GetType();
Expand Down
4 changes: 3 additions & 1 deletion Source/Web/SvgHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NET35 || NET40 || NET452 || NET472
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -230,4 +231,5 @@ public WaitHandle AsyncWaitHandle
}
}
}
}
}
#endif
21 changes: 21 additions & 0 deletions Tests/Svg.UnitTests/DpiTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Svg.UnitTests
{
/// <summary>
/// Test that basic graphics operations work. Currently only supported
/// on Windows, macOS, and Linux.
/// </summary>
[TestClass]
public class DpiTest
{
/// <summary>
/// We should get a valid dpi (probably 72, 96 or similar).
/// </summary>
[TestMethod]
public void TestDpiAboveZero()
{
Assert.IsTrue(SvgDocument.PointsPerInch > 0);
}
}
}
Loading