From 89965f12786b74331fac4bc5a876aab459fd6812 Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 10 Sep 2013 12:46:23 +0000 Subject: [PATCH] Fix possible symbol font discrepancy in tables Allow options for handling foldout page if first page. --- PROMS/Volian.Controls.Library/StepRTB.cs | 12 ++++-- PROMS/Volian.Controls.Library/VlnFlexGrid.cs | 40 ++++++++++++++++--- PROMS/Volian.Print.Library/PromsPrinter.cs | 28 ++++++++++--- .../Volian.Print.Library/VlnSvgPageHelper.cs | 11 ++++- PROMS/Volian.Print.Library/vlnParagraph.cs | 6 +-- 5 files changed, 78 insertions(+), 19 deletions(-) diff --git a/PROMS/Volian.Controls.Library/StepRTB.cs b/PROMS/Volian.Controls.Library/StepRTB.cs index 99dd6756..e4e9c67e 100644 --- a/PROMS/Volian.Controls.Library/StepRTB.cs +++ b/PROMS/Volian.Controls.Library/StepRTB.cs @@ -212,7 +212,7 @@ namespace Volian.Controls.Library public static FontFamily MyFontFamily { get { return StepRTB._MyFontFamily; } - set + set { _MyFontFamily = value; if (value != null) @@ -226,12 +226,16 @@ namespace Volian.Controls.Library font = new Font(value, 10, FontStyle.Italic); using (StepRTB srtb = new StepRTB()) { - if (srtb.FontIsFixed(font)) _MySymbolFontName = "VESymbFix"; - else _MySymbolFontName = "Arial Unicode MS"; + if (srtb.FontIsFixed(font)) MySymbolFontName = "VESymbFix"; + else MySymbolFontName = "Arial Unicode MS"; + } + } + else + { + MySymbolFontName = null; } } } - } // use newer rich text box.... //[DllImport("kernel32.dll", CharSet = CharSet.Auto)] //static extern IntPtr LoadLibrary(string lpFileName); diff --git a/PROMS/Volian.Controls.Library/VlnFlexGrid.cs b/PROMS/Volian.Controls.Library/VlnFlexGrid.cs index 91b48970..de49c4d2 100644 --- a/PROMS/Volian.Controls.Library/VlnFlexGrid.cs +++ b/PROMS/Volian.Controls.Library/VlnFlexGrid.cs @@ -796,17 +796,45 @@ namespace Volian.Controls.Library private static Regex _ReplaceVESymbFix = new Regex(@"({\\f[0-9]+[^ ]* )(VESymbFix)(;})"); private static Regex _ReplaceArialUnicodeMS = new Regex(@"({\\f[0-9]+[^ ]* )(Arial Unicode MS)(;})"); private static Regex _ReplaceTextFont = new Regex(@"({\\f[0-9]+[^ ]* )(?((?!VESymbFix)(?!Arial Unicode MS))([^;]*)|(!!!!))(;})"); + private bool FontIsFixed(Font myFont) + { + Graphics grph = Graphics.FromHwnd(this.Handle); + SizeF sfW = grph.MeasureString("W", myFont); + SizeF sfE = grph.MeasureString("!", myFont); + if (sfW.Width == sfE.Width) return true; + return false; + } public void LoadGrid(ItemInfo itemInfo) { _MyItemInfo = itemInfo; string str = itemInfo.MyContent.MyGrid.Data; VE_Font vefont = _MyItemInfo.GetItemFont(); - FontFamily ff = StepRTB.MyFontFamily ?? vefont.WindowsFont.FontFamily; // TODO: Does not change fixed font. - if (StepRTB.MySymbolFontName != "VESymbFix") - str = _ReplaceVESymbFix.Replace(str, "$1" + StepRTB.MySymbolFontName + "$3"); - if (StepRTB.MySymbolFontName != "Arial Unicode MS") - str = _ReplaceArialUnicodeMS.Replace(str, "$1" + StepRTB.MySymbolFontName + "$3"); - str = _ReplaceTextFont.Replace(str, "$1" + ff.Name + "$4"); + + // the following code is used to be sure that the font used for symbols is the correct font + // based on whether the font for non-symbol text is fixed or proportional. Each steprtb has + // a font for the non-symbol AND the symbol text, and these must be the correct association, i.e. + // for fixed fonts, the symbol font is 'VESymbFix', for proportional fonts, the symbol font is + // 'Arial Unicode MS'. The underlying flexgrid stores the fonts, and if the table font was + // reset for some reason (for example from the drop-down font selection in the user interface), + // this code 'cleans' up if there is a mismatch. + if (StepRTB.MyFontFamily != null) + { + FontFamily ff = StepRTB.MyFontFamily; + if (StepRTB.MySymbolFontName != "VESymbFix") + str = _ReplaceVESymbFix.Replace(str, "$1" + StepRTB.MySymbolFontName + "$3"); + if (StepRTB.MySymbolFontName != "Arial Unicode MS") + str = _ReplaceArialUnicodeMS.Replace(str, "$1" + StepRTB.MySymbolFontName + "$3"); + str = _ReplaceTextFont.Replace(str, "$1" + ff.Name + "$4"); + } + else + { + FontFamily ff = vefont.WindowsFont.FontFamily; + if (FontIsFixed(vefont.WindowsFont)) + str = _ReplaceArialUnicodeMS.Replace(str, "$1" + "VESymbFix" + "$3"); + else + str = _ReplaceVESymbFix.Replace(str, "$1" + "Arial Unicode MS" + "$3"); + str = _ReplaceTextFont.Replace(str, "$1" + ff.Name + "$4"); + } // To prevent scroll bars from being flashed on/off // - save an image of the current grid // - set Visible to false diff --git a/PROMS/Volian.Print.Library/PromsPrinter.cs b/PROMS/Volian.Print.Library/PromsPrinter.cs index d1b3675f..ef1c5e22 100644 --- a/PROMS/Volian.Print.Library/PromsPrinter.cs +++ b/PROMS/Volian.Print.Library/PromsPrinter.cs @@ -462,7 +462,7 @@ namespace Volian.Print.Library PdfReader readerWord = null; string myPdfFile = null; _MyHelper.FinalMessageSectionID = finalMessageSectionID; // set VlnSvgPageHelper with the finalMessageSectionID - //SectionConfig sc = mySection.MyConfig as SectionConfig; + if (mySection.IsAutoTOCSection) GenerateTOC(mySection, myProcedure, cb, _TextLayer); else @@ -471,10 +471,10 @@ namespace Volian.Print.Library { if (mySection.Steps != null && mySection.Steps.Count > 0) { - // get first step to send to floading foldout indx.&& MyItemInfo.FoldoutIndex>-1) + // get first step to send to floating foldout indx.&& MyItemInfo.FoldoutIndex>-1) ItemInfo firstStep = mySection.Steps[0]; if (firstStep.FoldoutIndex() > -1) - DoFoldoutPage(cb, "Beginning of Step Section", _TextLayer, _MyHelper, firstStep.FoldoutIndex()); + DoFoldoutPage(cb, "Beginning of Step Section", _TextLayer, _MyHelper, firstStep.FoldoutIndex(), InsertBlankPages); else if (!_MyHelper.CreatingFoldoutPage && _MyFoldoutReader.Count > 0 && InsertBlankPages) { // only insert a blank page if this section does not have a foldout (but the procedure as a whole does) @@ -554,7 +554,7 @@ namespace Volian.Print.Library { int pageNumber = 1 + ii; if (((mySection.MyDocStyle.StructureStyle.Style ?? 0) & E_DocStructStyle.UseSectionFoldout) != 0) - DoFoldoutPage(cb, "Word Document", _TextLayer, _MyHelper, 0); + DoFoldoutPage(cb, "Word Document", _TextLayer, _MyHelper, 0, false); if (readerWord != null) { bool doimport2 = true; @@ -876,9 +876,27 @@ namespace Volian.Print.Library cb.PdfDocument.NewPage(); // Temporary for foldout/16bit-32bit page alignment //_MyLog.InfoFormat("NewPage 7 {0}", cb.PdfWriter.CurrentPageNumber); } - public static void DoFoldoutPage(PdfContentByte cb, string str, PdfLayer textLayer, VlnSvgPageHelper myPageHelper, int foldoutindx) + public static void DoFoldoutPage(PdfContentByte cb, string str, PdfLayer textLayer, VlnSvgPageHelper myPageHelper, int foldoutindx, bool insertBlankPages) { if (_MyFoldoutSection == null || _MyFoldoutSection.Count==0) return; + + // if the very first page to be output is a 'foldout', treat this as a special case, since + // if duplex printing is on, the foldout should always be on the left side, i.e. or behind + // the document text. The option PROMS provides is to either: + // 1) Skip doing the foldout before the first page, if the 'InsertBlankPages' isn't set, by not checking + // the checkbox on the print dialog. + // 2) Insert a blank page as the first page, if the 'InsertBlankPages' is set. + if (!myPageHelper.PrintedAPage && !insertBlankPages) return; + if (!myPageHelper.PrintedAPage) + { + // only insert a blank page if this is the very first page printed & section has a foldout + // and the checkbox on the print dialog to add blank pages is checked. This will put out a blank page as + // as the first page so that duplex printing is correct for this condition. + myPageHelper.OnBlankPage = true; + cb.PdfDocument.Add(new iTextSharp.text.Table(1)); + cb.PdfDocument.NewPage(); + } + SectionInfo saveSect = myPageHelper.MySection; myPageHelper.MySection = _MyFoldoutSection[foldoutindx]; myPageHelper.OnFoldoutPage = true; diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index 18d5ee90..1f750aa4 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -98,6 +98,15 @@ namespace Volian.Print.Library get { return _OnBlankPage; } set { _OnBlankPage = value; } } + // when false, no page has been printed yet (for determining whether a blank page before print + // needs done if first section has foldouts) + private bool _PrintedAPage = false; + public bool PrintedAPage + { + get { return _PrintedAPage; } + set { _PrintedAPage = value; } + } + private bool _AddBlankPagesForDuplexPrinting = false; public bool AddBlankPagesForDuplexPrinting // Tells us if a the option to add a blank page is turn on (for procedures with duplex foldouts) { @@ -140,7 +149,7 @@ namespace Volian.Print.Library PageListTopCheckOffHeader = null; PageListLastCheckOffHeader = null; YMultiplier = 1; - + PrintedAPage = true; } private Gaps _MyGaps; public Gaps MyGaps diff --git a/PROMS/Volian.Print.Library/vlnParagraph.cs b/PROMS/Volian.Print.Library/vlnParagraph.cs index 735349c4..06dc82fd 100644 --- a/PROMS/Volian.Print.Library/vlnParagraph.cs +++ b/PROMS/Volian.Print.Library/vlnParagraph.cs @@ -690,7 +690,7 @@ namespace Volian.Print.Library } // Only do foldout page if not done for section break, i.e. check the there's a previous step. if (MyItemInfo.MyPrevious != null && MyItemInfo.FoldoutIndex() > -1) - PromsPrinter.DoFoldoutPage(cb, "HLS", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.FoldoutIndex()); + PromsPrinter.DoFoldoutPage(cb, "HLS", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.FoldoutIndex(), false); else if (PromsPrinter.MyFoldoutReader.Count > 0 && MyPageHelper.MyPromsPrinter.InsertBlankPages) { // insert a blank page if this step section had a foldout associated and the checkbox @@ -752,7 +752,7 @@ namespace Volian.Print.Library ResetDocStyleAndValues(ref yTopMargin, ref yBottomMargin); DebugText.WriteLine("Paginate2"); if (MyItemInfo.MyHLS.FoldoutIndex() > -1) - PromsPrinter.DoFoldoutPage(cb, "Break within Step", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.MyHLS.FoldoutIndex()); // temporary foldout + PromsPrinter.DoFoldoutPage(cb, "Break within Step", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.MyHLS.FoldoutIndex(), false); // temporary foldout else if (PromsPrinter.MyFoldoutReader.Count > 0 && MyPageHelper.MyPromsPrinter.InsertBlankPages) { MyPageHelper.OnBlankPage = true; @@ -822,7 +822,7 @@ namespace Volian.Print.Library MyPageHelper.PageBookmarks.Add(MyItemInfo, ((si.DisplayNumber ?? "") == "" ? "" : si.DisplayNumber + " - ") + si.DisplayText, null); } if (MyItemInfo.FoldoutIndex() > -1) - PromsPrinter.DoFoldoutPage(cb, "HLS (7 lpi) break", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.FoldoutIndex()); + PromsPrinter.DoFoldoutPage(cb, "HLS (7 lpi) break", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.FoldoutIndex(), false); else if (PromsPrinter.MyFoldoutReader.Count > 0 && MyPageHelper.MyPromsPrinter.InsertBlankPages) { // insert a blank page if this step section had a foldout associated and the checkbox