B2019-069 – Consider the monitor’s scaling factor when generating an X/Y Plot, B2019-090 – Reset the Word sections printed text color to black after printing with overlay (compare)
This commit is contained in:
parent
cba19044d8
commit
ef3d04b4aa
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user