diff --git a/PROMS/Volian.Base.Library/vlnFont.cs b/PROMS/Volian.Base.Library/vlnFont.cs new file mode 100644 index 00000000..6e8aef13 --- /dev/null +++ b/PROMS/Volian.Base.Library/vlnFont.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; +using System.Drawing.Text; +using System.Windows.Forms; + +namespace Volian.Base.Library +{ + public static class vlnFont + { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private static InstalledFontCollection _MyFontCollection = new InstalledFontCollection(); + private static string _ProportionalSymbolFont = null; + // C2017-036 Look for suitable proportional font that will support the symbol characters used in PROMS + // Microsoft removed Arial Unicode MS starting with Word16 (office 365 containing that version of Word) + public static string ProportionalSymbolFont + { + get { + if (_ProportionalSymbolFont == null) + { + if (FindFontFamily("Arial Unicode MS")) + _ProportionalSymbolFont = "Arial Unicode MS"; // microsoft no longer supplies this font as of Word16 + else if (FindFontFamily("FreeSerif")) + _ProportionalSymbolFont = "FreeSerif"; // volian supplied font but regular chars look like Times Roman + else if (FindFontFamily("FreeMono")) + _ProportionalSymbolFont = "FreeMono"; // volian suppllied font but regular chars are fixed spaced and look like Courier + else + { + MessageBox.Show("A suitable font for symbol characters could not be found.\n\n" + +"Please install Arial Unicode MS and/or the Volian supplied fonts", "Symbol Font"); + _MyLog.Error("Could Not File a Proportional Symbol Font to use."); + _ProportionalSymbolFont = "Arial"; // if volian fonts not installed, default to plain Arial (which does not have all of the symbols that we use) + } + } + return _ProportionalSymbolFont; + } + } + + + // C2017-036 Look for suitable proportional font that will support the symbol characters used in PROMS + // Microsoft removed Arial Unicode MS starting with Word16 (office 365 containing that version of Word) + // This font (below) is used only for the Reports - trying to find a font similar to Arial Unicode MS + private static string _ReportsFont = null; + + public static string ReportsFont + { + get { + if (_ReportsFont == null) + { + if (FindFontFamily("Arial Unicode MS")) // microsoft no longer supplies this font as of Word16 + _ReportsFont = "Arial Unicode MS"; + else if (FindFontFamily("Meiryo")) // is a Japanise font (standard windows font) but cannot be used along with the Arial font - will shift text up half a character when mixing the two fonts. + _ReportsFont = "Meiryo"; + else if (FindFontFamily("FreeSerif")) // volian supplied font but regular chars look like Times Roman + _ReportsFont = "FreeSerif"; + else if (FindFontFamily("FreeMono")) // volian suppllied font but regular chars are fixed spaced and look like Courier + _ReportsFont = "FreeMono"; + else + { + MessageBox.Show("A suitable font to use to generate Reports could not be found.\n\n" + +"Please install Arial Unicode MS and/or the Volian supplied fonts", "Report Font"); + _MyLog.Error("Could Not File a font to use for Report generation."); + _ReportsFont = "Arial"; + } + } + return _ReportsFont; + } + } + + // see if the given font exists on the computer running PROMS + private static bool FindFontFamily(string name) + { + foreach (FontFamily ff in _MyFontCollection.Families) + if (ff.Name == name) return true; + return false; + } + } +}