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 System.Drawing;
using iTextSharp.text.pdf;
using iTextSharp.text.factories;
using Microsoft.Win32;
using Volian.Base.Library;
namespace VG
{
@@ -149,36 +150,13 @@ namespace VG
{ get { return 1; } } // Changed to adjust for Screen DPI Setting
public static iTextSharp.text.Font GetFont(string fontName)
{
RegisterFont(fontName);
/// <summary>
/// B2019-116 Volian.Base.Library This is a generic class for dealing with iTextSharp Fonts
/// Code moved and consolidated from Volian.Print.Library Volian PDF.Library and VG
/// </summary>
VlnItextFont.RegisterFont(fontName);
return iTextSharp.text.FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
}
//private void RegisterFonts()
// {
// //if (!FontFactory.IsRegistered("Arial"))
// //{
// // RegisterFont("Prestige Elite Tall");
// //}
//}
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; } }
private float ScaleY(float y)
{
return _VGOutput.PdfWriter.PageSize.Height - y;