From 8df668c5e2c61781fd959b7ff739d27d939c473b Mon Sep 17 00:00:00 2001 From: Rich Date: Mon, 19 Jan 2015 20:58:05 +0000 Subject: [PATCH] Added Profile debug Changed NextItem property to use GetNextItem method when printing Changed RegisterFont to improve print performance --- .../Volian.Print.Library/VlnSvgPageHelper.cs | 3 + PROMS/Volian.Print.Library/vlnPrintObject.cs | 8 ++- PROMS/Volian.Print.Library/vlnTab.cs | 4 +- PROMS/Volian.Svg.Library/iTextSharp.cs | 64 ++++++++++++++++--- 4 files changed, 67 insertions(+), 12 deletions(-) diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index 436e42d3..8e276916 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -8,6 +8,7 @@ using Volian.Svg.Library; using System.Text.RegularExpressions; using System.Xml; using VEPROMS.CSLA.Library; +using Volian.Base.Library; namespace Volian.Print.Library { @@ -200,6 +201,7 @@ namespace Volian.Print.Library //} public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document) { + int profileDepth = ProfileTimer.Push(">>>> OnEndPage"); InitialsPrinted = false; MyPromsPrinter.OnStatusChanged(string.Format("Page {0}", CurrentPageNumber+1)); bool onBlankPage = OnBlankPage; @@ -286,6 +288,7 @@ namespace Volian.Print.Library PageListLastCheckOffHeader = null; YMultiplier = 1; PrintedAPage = true; + ProfileTimer.Pop(profileDepth); } private void DrawVertical(PdfContentByte cb, float x, float top, float bottom) diff --git a/PROMS/Volian.Print.Library/vlnPrintObject.cs b/PROMS/Volian.Print.Library/vlnPrintObject.cs index b8e6b0fc..201adf5c 100644 --- a/PROMS/Volian.Print.Library/vlnPrintObject.cs +++ b/PROMS/Volian.Print.Library/vlnPrintObject.cs @@ -10,6 +10,7 @@ using Itenso.Rtf.Interpreter; using Itenso.Rtf.Support; using Volian.Controls.Library; using VEPROMS.CSLA.Library; +using Volian.Base.Library; namespace Volian.Print.Library { @@ -90,7 +91,10 @@ namespace Volian.Print.Library { if (_IParagraph == null) { - _IParagraph = RtfToParagraph(Rtf, HasIndent); + int profileDepth = ProfileTimer.Push(">>>> VlnPrintObject.IParagraph"); + string myRtf = Rtf; + _IParagraph = RtfToParagraph(myRtf, HasIndent); + ProfileTimer.Pop(profileDepth); } return _IParagraph; } @@ -107,8 +111,10 @@ namespace Volian.Print.Library { get { + int profileDepth = ProfileTimer.Push(">>>> vlnPrintObject.Height"); if (_Height == 0) _Height = GetParagraphHeight(MyContentByte, IParagraph, Width); + ProfileTimer.Pop(profileDepth); return _Height; } set { _Height = value; } diff --git a/PROMS/Volian.Print.Library/vlnTab.cs b/PROMS/Volian.Print.Library/vlnTab.cs index eeca6b62..bde78a23 100644 --- a/PROMS/Volian.Print.Library/vlnTab.cs +++ b/PROMS/Volian.Print.Library/vlnTab.cs @@ -162,7 +162,7 @@ namespace Volian.Print.Library // Because of the different font sizes, when the Caution/Note did have have a bullet, the positioning // was off by the lenght of IdentB (the bullet string), thus the "alignAsIfBulleted" bool if ((myparent.MyItemInfo.FormatStepData != null) && myparent.MyItemInfo.FormatStepData.TabData.Bullet.Separate) - if (myparent.MyItemInfo.MyPrevious != null || myparent.MyItemInfo.GetNextItem() != null) + if (myparent.MyItemInfo.MyPrevious != null || myparent.MyItemInfo.NextItem != null) SeparateBullet = true; else alignAsIfBulleted = true; @@ -260,7 +260,7 @@ namespace Volian.Print.Library Rtf = Rtf.Replace("Caution ", @"\u61472?\u61472?\u61472?\u61472?\u61472?\u61472?\u61472?\u61472?\u61472?"); else { - if (myparent.MyItemInfo.FormatStepData != null && !myparent.MyItemInfo.FormatStepData.AlwaysTab && myparent.MyItemInfo.GetNextItem() == null) + if (myparent.MyItemInfo.FormatStepData != null && !myparent.MyItemInfo.FormatStepData.AlwaysTab && myparent.MyItemInfo.NextItem == null) Rtf = Rtf.Replace(@"\u9679?", ""); Rtf = Rtf.Replace("Caution ", @"\u61507?\u61537?\u61557?\u61556?\u61545?\u61551?\u61550?\u61472?\u61472?"); } diff --git a/PROMS/Volian.Svg.Library/iTextSharp.cs b/PROMS/Volian.Svg.Library/iTextSharp.cs index fa4f6c76..b0e4b966 100644 --- a/PROMS/Volian.Svg.Library/iTextSharp.cs +++ b/PROMS/Volian.Svg.Library/iTextSharp.cs @@ -14,11 +14,45 @@ using Microsoft.Win32; using System.Text.RegularExpressions; using System.Xml; using System.IO; +using Volian.Base.Library; namespace Volian.Svg.Library { + public static class FontFind + { + public static string FileName(string fontName) + { + string baseFont = string.Empty; + Regex find = new Regex(fontName + @" ?\(.*\)", RegexOptions.IgnoreCase); + RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Fonts"); + string[] values = regKey.GetValueNames(); + baseFont = regKey.GetValue(values[0]).ToString(); + foreach (string valueName in regKey.GetValueNames()) + if (find.IsMatch(valueName)) + return regKey.GetValue(valueName).ToString(); + return baseFont; + } + public static string FullFileName(string fontName) + { + return FontDir + @"\" + FileName(fontName); + } + 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"); + _FontDir = regKey.GetValue("Fonts").ToString(); + } + return _FontDir; + } + } + } public static class VolianPdf { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public static int PageCount(string fileName) { PdfReader pdfr = new PdfReader(fileName); @@ -28,18 +62,30 @@ namespace Volian.Svg.Library } public static void RegisterFont(string fontName) { + int profileDepth = ProfileTimer.Push(">>>> RegisterFont"); 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); - // } - //} - iTextSharp.text.FontFactory.RegisterDirectories(); + int profileDepth1 = ProfileTimer.Push(">>>> RegisterDirectory"); + iTextSharp.text.FontFactory.RegisterDirectory(FontFind.FontDir); + ProfileTimer.Pop(profileDepth1); + if (!iTextSharp.text.FontFactory.IsRegistered(fontName)) + { + _MyLog.WarnFormat("Problem with Font {0} in {1}", fontName, FontFind.FontDir); + iTextSharp.text.FontFactory.RegisterDirectory(FontFind.FontDir); + int profileDepth2 = ProfileTimer.Push(">>>> RegisterDirectories"); + iTextSharp.text.FontFactory.RegisterDirectories(); + ProfileTimer.Pop(profileDepth2); + if (!iTextSharp.text.FontFactory.IsRegistered(fontName)) + { + _MyLog.WarnFormat("Font {0} could not be found!", fontName); + } + else + { + iTextSharp.text.Font fnt = iTextSharp.text.FontFactory.GetFont(fontName, 10); + } + } } + ProfileTimer.Pop(profileDepth); } private static RegistryKey _FontKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("Fonts"); public static RegistryKey FontKey