Skip to content

Commit

Permalink
Use DPI setting from system instead of using a hard-coded value
Browse files Browse the repository at this point in the history
- see #384
  • Loading branch information
mrbean-bremen committed Dec 27, 2018
1 parent ec2c12c commit 41f66eb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Source/SvgDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading;
using System.Globalization;
using Svg.Exceptions;
using System.Runtime.InteropServices;

namespace Svg
{
Expand All @@ -22,10 +23,29 @@ namespace Svg
/// </summary>
public class SvgDocument : SvgFragment, ITypeDescriptorContext
{
public static readonly int PointsPerInch = 96;
public static readonly int PointsPerInch = GetSystemDpi();
private SvgElementIdManager _idManager;

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;
}

[DllImport("gdi32.dll")]
private static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

[DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);

[DllImport("user32.dll")]
private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

internal Dictionary<string, IEnumerable<SvgFontFace>> FontDefns()
{
if (_fontDefns == null)
Expand Down

0 comments on commit 41f66eb

Please sign in to comment.