From 41d6ce948313b01a7e7d406961d08ce86051d972 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 18 Jul 2019 14:03:53 +0000 Subject: [PATCH] =?UTF-8?q?Code=20cleanup=20=E2=80=93=20fixed=20typo=20C20?= =?UTF-8?q?19-028=20Code=20Cleanup=20=E2=80=93=20Added=20call=20to=20.NET?= =?UTF-8?q?=204.6.1=20method=20to=20get=20windows=20font=20folder,=20added?= =?UTF-8?q?=20null=20check,=20and=20added=20info=20to=20the=20error=20log?= =?UTF-8?q?=20to=20tell=20us=20the=20location=20of=20the=20fonts=20being?= =?UTF-8?q?=20used.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frmPDFStatusForm.cs | 2 +- PROMS/Volian.Svg.Library/iTextSharp.cs | 38 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/PROMS/VEPROMS User Interface/frmPDFStatusForm.cs b/PROMS/VEPROMS User Interface/frmPDFStatusForm.cs index 75ad44bd..0dc5a6bc 100644 --- a/PROMS/VEPROMS User Interface/frmPDFStatusForm.cs +++ b/PROMS/VEPROMS User Interface/frmPDFStatusForm.cs @@ -89,7 +89,7 @@ namespace VEPROMS InitializeComponent(); // if the version number of PROMS is 1.0, then we are running a Demo version. // When running a Demo version, force a "Sample" watermark when printing. - MyPromsPrinter = new PromsPrinter(myItem, rev, (VlnSettings.ReleaseMode.Equals("DEMO")) ? "Sample" : watermark, debugOutput, origPgBrk, pdfPath + @"\\Compare", false, overWrite, cbd, pdfFile, insertBlankPages, allOrAuto,Prefix,saveLinks,removeTrailingHardReturnsAndManualPageBreaks, blankPageText, DidAll); + MyPromsPrinter = new PromsPrinter(myItem, rev, (VlnSettings.ReleaseMode.Equals("DEMO")) ? "Sample" : watermark, debugOutput, origPgBrk, pdfPath + @"\Compare", false, overWrite, cbd, pdfFile, insertBlankPages, allOrAuto,Prefix,saveLinks,removeTrailingHardReturnsAndManualPageBreaks, blankPageText, DidAll); MyPromsPrinter.PromsVersion = (showPROMSVer) ? AboutVEPROMS.PROMSVersion : ""; //C2018-009 print PROMS version PDFPath = pdfPath; this.Text = "Creating PDF of " + myItem.DisplayNumber; diff --git a/PROMS/Volian.Svg.Library/iTextSharp.cs b/PROMS/Volian.Svg.Library/iTextSharp.cs index 5d6f495f..845f9d9c 100644 --- a/PROMS/Volian.Svg.Library/iTextSharp.cs +++ b/PROMS/Volian.Svg.Library/iTextSharp.cs @@ -20,6 +20,7 @@ namespace Volian.Svg.Library { public static class FontFind { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public static string FileName(string fontName) { string baseFont = string.Empty; @@ -38,16 +39,34 @@ namespace Volian.Svg.Library } private static string _FontDir = null; public static string FontDir - { + { get { if (_FontDir == null) { - RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"); - if (regKey != null) - _FontDir = regKey.GetValue("Fonts").ToString(); - if (_FontDir == null) // Not allowed or cannot find the fonts folder value in the registry. - _FontDir = @"C:\Windows\Fonts"; // default to C:\Windows\Fonts + if (_FontDir == null) + { + RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"); + if (regKey != null) + { + object obj = regKey.GetValue("Fonts"); + _MyLog.WarnFormat("Font regkey.fonts = {0}", obj); // C2019-028 Add info in the error log + // C2019-028 Add Null check before attempt to convert to string + if (obj != null) + _FontDir = obj.ToString(); + else + { + // C2019-028 Add call to .Net 4.6.1 method to get the system's windows font folder + _FontDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts); + _MyLog.WarnFormat("Font Folder = {0}", _FontDir); // C2019-028 Add info in the error log + } + } + if (_FontDir == null) // Not allowed or cannot find the fonts folder value in the registry. + { + _FontDir = @"C:\Windows\Fonts"; // default to C:\Windows\Fonts + _MyLog.WarnFormat("FontDir set to default = {0}", _FontDir); // C2019-028 Add info in the error log + } + } } return _FontDir; } @@ -116,8 +135,15 @@ namespace Volian.Svg.Library private static string _FontFolder = (String)Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Explorer").OpenSubKey("Shell Folders").GetValue("Fonts"); public static string FontFolder { get { return _FontFolder; } } + // keep for debug + //private static List _RegFonts = new List(); public static iTextSharp.text.Font GetFont(string fontName, int size, int style) { + //if (!_RegFonts.Contains(fontName)) + //{ + //_MyLog.WarnFormat("Registering Font {0}", fontName); + //_RegFonts.Add(fontName); + //} RegisterFont(fontName); return iTextSharp.text.FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, size / 2, style); }