123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace PDFSettings
- {
- internal class Helpers
- {
-
-
-
- public static int Dpi { get; private set; }
-
-
-
- public static float ScaleDpi { get { return (96F/Dpi); } }
-
-
-
- public static double ScaleFactor { get { return (Dpi / 72D); } }
-
-
-
- public static double InvertScaleFactor { get { return (72D / Dpi); } }
- static Helpers()
- {
- try
- {
- var flags = BindingFlags.NonPublic | BindingFlags.Static;
- var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
- Dpi = (int)dpiProperty.GetValue(null, null);
-
- }
- catch (Exception ex)
- {
- }
- }
-
-
-
-
-
-
-
- public static int GetDpiUnrelatedNum(int oldValue)
- {
- return (int)(oldValue * ScaleDpi);
- }
-
-
-
-
-
-
- public static double GetDpiUnrelatedNum(double oldValue)
- {
- return (double)(oldValue * ScaleDpi);
- }
-
-
-
-
-
-
- public static double GetDpiRelatedNum(double oldValue)
- {
- return (oldValue / ScaleDpi);
- }
-
-
-
-
-
- public static Rect GetDpiUnrelatedRect(Rect oldValue)
- {
- return new Rect(GetDpiUnrelatedNum(oldValue.Left), GetDpiUnrelatedNum(oldValue.Top),
- GetDpiUnrelatedNum(oldValue.Width), GetDpiUnrelatedNum(oldValue.Height));
- }
-
-
-
-
-
- public static Rect GetRawRect(Rect oldValue)
- {
- Rect standRect= new Rect(GetDpiUnrelatedNum(oldValue.Left), GetDpiUnrelatedNum(oldValue.Top),
- GetDpiUnrelatedNum(oldValue.Width), GetDpiUnrelatedNum(oldValue.Height));
- return new Rect(standRect.Left * 72D / 96D, standRect.Top * 72D / 96D, standRect.Width * 72D / 96D, standRect.Height * 72D / 96D);
- }
-
-
-
-
-
- public static Rect GetDpiRelatedRect(Rect oldValue)
- {
- return new Rect(GetDpiRelatedNum(oldValue.Left), GetDpiRelatedNum(oldValue.Top),
- GetDpiRelatedNum(oldValue.Width), GetDpiRelatedNum(oldValue.Height));
- }
-
-
-
-
-
- public static Point GetDpiUnrelatedPoint(Point oldValue)
- {
- return new Point(GetDpiUnrelatedNum(oldValue.X), GetDpiUnrelatedNum(oldValue.Y));
- }
-
-
-
-
-
- public static Point GetDpiRelatedPoint(Point oldValue)
- {
- return new Point(GetDpiRelatedNum(oldValue.X), GetDpiRelatedNum(oldValue.Y));
- }
-
-
-
-
-
- public static Size GetDpiUnrelatedSize(Size oldValue)
- {
- return new Size(GetDpiUnrelatedNum(oldValue.Width), GetDpiUnrelatedNum(oldValue.Height));
- }
-
-
-
-
-
- public static Size GetDpiRelatedSize(Size oldValue)
- {
- return new Size(GetDpiRelatedNum(oldValue.Width), GetDpiRelatedNum(oldValue.Height));
- }
- }
- }
|