B2019-116 Consolidated and Genericized font registration for iTextSharp

This commit is contained in:
Rich
2019-08-15 15:59:59 +00:00
parent da3a87e892
commit a804f2f716
4 changed files with 49 additions and 203 deletions

View File

@@ -5,6 +5,7 @@ using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using Microsoft.Win32;
using Volian.Base.Library;
namespace Volian.Print.Library
{
@@ -118,28 +119,11 @@ namespace Volian.Print.Library
}
public static iTextSharp.text.Font GetFont(string fontName, float fontSize, int fontStyle, Color fontColor)
{
RegisterFont(fontName);
// B2019-116 Use Volian.Base.Library.VlnItextFont
// This is a generic class for dealing with iTextSharp Fonts
// Code moved and consolidated from Volian.Print.Library, Volian PDF.Library and VG
VlnItextFont.RegisterFont(fontName);
return iTextSharp.text.FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, fontSize, fontStyle, fontColor);
}
public static void RegisterFont(string fontName)
{
if (!iTextSharp.text.FontFactory.IsRegistered(fontName))
{
foreach (string name in FontKey.GetValueNames())
{
if (name.StartsWith(fontName))
{
string fontFile = (string)FontKey.GetValue(name);
iTextSharp.text.FontFactory.Register(fontFile.Contains("\\") ? fontFile : FontFolder + "\\" + fontFile);
}
}
}
}
private static RegistryKey _FontKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("Fonts");
public static RegistryKey FontKey
{ get { return _FontKey; } }
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; } }
}
}