From ef3d04b4aafdb25485375da4222c2e09d7d7e8b3 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 26 Jun 2019 16:57:33 +0000 Subject: [PATCH] =?UTF-8?q?B2019-069=20=E2=80=93=20Consider=20the=20monito?= =?UTF-8?q?r=E2=80=99s=20scaling=20factor=20when=20generating=20an=20X/Y?= =?UTF-8?q?=20Plot,=20B2019-090=20=E2=80=93=20Reset=20the=20Word=20section?= =?UTF-8?q?s=20printed=20text=20color=20to=20black=20after=20printing=20wi?= =?UTF-8?q?th=20overlay=20(compare)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extension/DocumentExt.cs | 88 ++++++++++++------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index d2f126d1..8e3d8b7b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -13,6 +13,7 @@ using LBWordLibrary; using System.Drawing.Imaging; using Volian.Base.Library; using System.Diagnostics; +using System.Runtime.InteropServices; namespace VEPROMS.CSLA.Library @@ -725,6 +726,7 @@ namespace VEPROMS.CSLA.Library { MSWordToPDF.OverrideColor = overrideColor; PdfInfo myPdf = PdfInfo.Get(sect,DocReplace!=null); + MSWordToPDF.OverrideColor = Color.Black; // B2019-090 reset to black text (when a Complete RO Report was created after printing procedure, X/Y Plot was in red text) return true; } // B2018-071 Save list of DocIDs for invalid document so that error log messages are not repeated @@ -1525,6 +1527,26 @@ namespace VEPROMS.CSLA.Library string fileName = VlnSettings.TemporaryFolder + @"\Doc_" + sect.MyContent.MyEntry.DocID.ToString()+".Pdf"; // +" " + (sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber); return fileName; } + [DllImport("User32.dll")] + static extern IntPtr GetDC(IntPtr hwnd); + [DllImport("User32.dll")] + static extern int ReleaseDC(IntPtr hwnd, IntPtr dc); + [DllImport("gdi32.dll")] + static extern int GetDeviceCaps(IntPtr hdc, int nIndex); + public enum DeviceCap + { + VERTRES = 10, + DESKTOPVERTRES = 117 + } + // B2019-069 needed to get the monitor's scaling factor - used in generating RO X/Y plot + private static float ScalingFactor() + { + IntPtr desktop = GetDC(IntPtr.Zero); + int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES); + int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES); + ReleaseDC(IntPtr.Zero, desktop); + return (float)PhysicalScreenHeight / (float)LogicalScreenHeight; // a value of 1.50 represents monitor scaling set to 150% + } public static RectangleF CreatePlot(string pngFile, string xyPlot, float resolution, System.Windows.Forms.Form myForm) { RectangleF retval = new RectangleF(0, 0, 0, 0); @@ -1532,37 +1554,41 @@ namespace VEPROMS.CSLA.Library System.Windows.Forms.Form frm = myForm; Graphics grfx = frm.CreateGraphics(); string emfFile = pngFile.Replace(".png", ".emf"); - Metafile mf = new Metafile(emfFile, grfx.GetHdc()); - grfx.Dispose(); - grfx = Graphics.FromImage(mf); - float dpi = grfx.DpiX; - //grfx.ScaleTransform(resolution / grfx.DpiX, (resolution +1F) / grfx.DpiY); - grfx.ScaleTransform(resolution / grfx.DpiX, resolution / grfx.DpiY); - grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; - grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; - grfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; - grfx.Clear(MSWordToPDF.DebugStatus==1 ? System.Drawing.Color.Transparent : System.Drawing.Color.White); - //grfx.Clear(System.Drawing.Color.SlateGray); - XYPlots.XYPlot.BlackColor = MSWordToPDF.OverrideColor == Color.Red ? Color.Red : Color.Black; - XYPlots.XYPlot myPlot = new XYPlots.XYPlot(xyPlot); - myPlot.SetMargins(0, 0, 0, 0); - VG.IVGOutput vgOut = new VG.VGOut_Graphics(grfx); - vgOut.DebugStatus = MSWordToPDF.DebugStatus; - myPlot.Process(vgOut); - GC.Collect(); // memory garbage collection (Regex bug) - grfx.Dispose(); - GraphicsUnit gu = new GraphicsUnit(); - retval = mf.GetBounds(ref gu); - retval.Width *= dpi / resolution; - retval.Height *= dpi / resolution; - retval.X *= dpi / resolution; - retval.Y *= dpi / resolution; - //retval.X = myPlot.Width-retval.Width; - //AddInfo("{0},{1},{2},{3},{4},{5}", myPlot.Width, myPlot.Height, retval.Width, retval.Height,retval.X,retval.Y); - //Console.Write("{0},{1},{2},{3}", myPlot.Width, myPlot.Height, retval.Width, retval.Height); - mf.Save(pngFile, ImageFormat.Png); - //Console.WriteLine("'pngfile','{0}'", pngFile); - mf.Dispose(); + using (Metafile mf = new Metafile(emfFile, grfx.GetHdc())) + { + grfx.Dispose(); + grfx = Graphics.FromImage(mf); + float dpi = grfx.DpiX; + float sf = ScalingFactor(); // B2019-069 get monitor scaling factor + //grfx.ScaleTransform(resolution / grfx.DpiX, (resolution +1F) / grfx.DpiY); + grfx.ScaleTransform(sf * resolution / grfx.DpiX, sf * resolution / grfx.DpiY); // B2019-069 multiply the monitor's scaling factor + grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; + grfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; + grfx.Clear(MSWordToPDF.DebugStatus == 1 ? System.Drawing.Color.Transparent : System.Drawing.Color.White); + //grfx.Clear(System.Drawing.Color.SlateGray); + XYPlots.XYPlot.BlackColor = MSWordToPDF.OverrideColor == Color.Red ? Color.Red : Color.Black; + XYPlots.XYPlot myPlot = new XYPlots.XYPlot(xyPlot); + myPlot.SetMargins(0, 0, 0, 0); + VG.IVGOutput vgOut = new VG.VGOut_Graphics(grfx); + vgOut.DebugStatus = MSWordToPDF.DebugStatus; + myPlot.Process(vgOut); + GC.Collect(); // memory garbage collection (Regex bug) + grfx.Dispose(); + GraphicsUnit gu = new GraphicsUnit(); + retval = mf.GetBounds(ref gu); + retval.Width *= dpi / resolution; + retval.Height *= dpi / resolution; + retval.X *= dpi / resolution; + retval.Y *= dpi / resolution; + //retval.X = myPlot.Width-retval.Width; + //AddInfo("{0},{1},{2},{3},{4},{5}", myPlot.Width, myPlot.Height, retval.Width, retval.Height,retval.X,retval.Y); + //Console.Write("{0},{1},{2},{3}", myPlot.Width, myPlot.Height, retval.Width, retval.Height); + //mf.Save(pngFile, ImageFormat.Png); + //Console.WriteLine("'pngfile','{0}'", pngFile); + } + using(Metafile mf2 = new Metafile(emfFile)) + mf2.Save(pngFile, ImageFormat.Png); FileInfo myFile = new System.IO.FileInfo(emfFile); myFile.Delete(); return retval;