diff --git a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/DpiHelpers.cs b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/DpiHelpers.cs new file mode 100644 index 0000000..5d73466 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/DpiHelpers.cs @@ -0,0 +1,63 @@ +// Copyright © 2017 Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace QuickLook.Plugin.HtmlViewer +{ + internal static class DpiHelper + { + public enum DeviceCap + { + /// + /// Logical pixels inch in X + /// + LOGPIXELSX = 88, + /// + /// Logical pixels inch in Y + /// + LOGPIXELSY = 90 + } + + public const float DEFAULT_DPI = 96; + + public static Dpi GetCurrentDpi() + { + var g = Graphics.FromHwnd(IntPtr.Zero); + var desktop = g.GetHdc(); + + var dpi = new Dpi + { + HorizontalDpi = GetDeviceCaps(desktop, (int) DeviceCap.LOGPIXELSX), + VerticalDpi = GetDeviceCaps(desktop, (int) DeviceCap.LOGPIXELSY) + }; + + return dpi; + } + + [DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] + public static extern int GetDeviceCaps(IntPtr hDC, int nIndex); + } + + internal class Dpi + { + public float HorizontalDpi { get; set; } + public float VerticalDpi { get; set; } + } +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/QuickLook.Plugin.HtmlViewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/QuickLook.Plugin.HtmlViewer.csproj index c441b9b..d32b61b 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/QuickLook.Plugin.HtmlViewer.csproj +++ b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/QuickLook.Plugin.HtmlViewer.csproj @@ -56,6 +56,7 @@ + 4.0 @@ -65,6 +66,7 @@ + MSBuild:Compile diff --git a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml index 93268d0..a40ecbc 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml +++ b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml @@ -7,6 +7,6 @@ mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> - + \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml.cs index dea1aac..4c04bed 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml.cs @@ -31,6 +31,8 @@ namespace QuickLook.Plugin.HtmlViewer public WebpagePanel() { InitializeComponent(); + + browser.Zoom = (int) (100 * DpiHelper.GetCurrentDpi().HorizontalDpi / DpiHelper.DEFAULT_DPI); } public void Dispose()