From 0d0bd7661bcb60e92489805bccbb38b5a7da5fd8 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 12 Jun 2017 17:58:30 +0000 Subject: [PATCH] =?UTF-8?q?Use=20method=20from=20VE=5FFont=20to=20get=20a?= =?UTF-8?q?=20font=20reference=20(uses=20dictionary=20so=20redundant=20Win?= =?UTF-8?q?dow=20Handles=20are=20not=20created)=20=20B2017-117=20Add=20a?= =?UTF-8?q?=20Using=20statement=20when=20we=20temporarily=20create=20a=20R?= =?UTF-8?q?ichTextBox=20to=20ensure=20the=20Window=20Handle=20is=20free?= =?UTF-8?q?=E2=80=99d.=20Also=20use=20method=20from=20VE=5FFont=20to=20get?= =?UTF-8?q?=20a=20font=20reference=20(uses=20dictionary=20so=20redundant?= =?UTF-8?q?=20Window=20Handles=20are=20not=20created)=20=20B2017-117?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PROMS/Volian.Print.Library/Placekeeper.cs | 6 +- .../Volian.Print.Library/VlnSvgPageHelper.cs | 6 +- PROMS/Volian.Print.Library/vlnBox.cs | 9 +- PROMS/Volian.Print.Library/vlnChangeBar.cs | 9 +- PROMS/Volian.Print.Library/vlnParagraph.cs | 126 +++++++++++------- PROMS/Volian.Print.Library/vlnTab.cs | 27 +++- 6 files changed, 122 insertions(+), 61 deletions(-) diff --git a/PROMS/Volian.Print.Library/Placekeeper.cs b/PROMS/Volian.Print.Library/Placekeeper.cs index 81212921..a206f917 100644 --- a/PROMS/Volian.Print.Library/Placekeeper.cs +++ b/PROMS/Volian.Print.Library/Placekeeper.cs @@ -216,7 +216,11 @@ namespace Volian.Print.Library } private float GetTextWidth(string txt) { - System.Drawing.Font font = new System.Drawing.Font(_pkFont.Family, (float)_pkFont.Size); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //System.Drawing.Font font = new System.Drawing.Font(_pkFont.Family, (float)_pkFont.Size); + System.Drawing.Font font = VE_Font.GetWinSysFont(_pkFont.Family, (float)_pkFont.Size); iTextSharp.text.Font iFont = Volian.Svg.Library.VolianPdf.GetFont(font); float w = 0; foreach (char c in txt) diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index 1be654d3..5824450d 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -1360,7 +1360,11 @@ namespace Volian.Print.Library // to do that was to add a "{PAGE}" token to every page that is flagged as not to be printed. if (sPag == SectionConfig.SectionPagination.Separate) { - SvgText st = new SvgText(new System.Drawing.PointF(300, 300), "Non-printing {PAGE}", new System.Drawing.Font("Arial", 10), System.Drawing.Color.Black); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //SvgText st = new SvgText(new System.Drawing.PointF(300, 300), "Non-printing {PAGE}", new System.Drawing.Font("Arial", 10), System.Drawing.Color.Black); + SvgText st = new SvgText(new System.Drawing.PointF(300, 300), "Non-printing {PAGE}", VE_Font.GetWinSysFont("Arial", 10), System.Drawing.Color.Black); svgGroup.Add(st); } if (svgGroup.Count>0) mySvg.Add(svgGroup); diff --git a/PROMS/Volian.Print.Library/vlnBox.cs b/PROMS/Volian.Print.Library/vlnBox.cs index 45330343..f90999e8 100644 --- a/PROMS/Volian.Print.Library/vlnBox.cs +++ b/PROMS/Volian.Print.Library/vlnBox.cs @@ -329,8 +329,13 @@ namespace Volian.Print.Library private float GetTextWidth(VE_Font vefont, string txt) { string symblFontName = (vefont.FontIsProportional()) ? "Arial Unicode MS" : "VESymbFix"; - System.Drawing.Font font = new System.Drawing.Font(vefont.Family, (float)vefont.Size, GetSysFontStyle(vefont)); - System.Drawing.Font symbFont = new System.Drawing.Font(symblFontName, (float)vefont.Size); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle + //System.Drawing.Font font = new System.Drawing.Font(vefont.Family, (float)vefont.Size, GetSysFontStyle(vefont)); + //System.Drawing.Font symbFont = new System.Drawing.Font(symblFontName, (float)vefont.Size); + System.Drawing.Font font = VE_Font.GetWinSysFont(vefont.Family, (float)vefont.Size, GetSysFontStyle(vefont)); + System.Drawing.Font symbFont = VE_Font.GetWinSysFont(symblFontName, (float)vefont.Size); iTextSharp.text.Font iFont = Volian.Svg.Library.VolianPdf.GetFont(font); iTextSharp.text.Font iSymblFont = Volian.Svg.Library.VolianPdf.GetFont(symbFont); float w = 0; diff --git a/PROMS/Volian.Print.Library/vlnChangeBar.cs b/PROMS/Volian.Print.Library/vlnChangeBar.cs index f29679f1..6fc4a870 100644 --- a/PROMS/Volian.Print.Library/vlnChangeBar.cs +++ b/PROMS/Volian.Print.Library/vlnChangeBar.cs @@ -216,8 +216,13 @@ namespace Volian.Print.Library { // use bigger font if revnum msg - iTextSharp.text.Font iFont = _IsRev? Volian.Svg.Library.VolianPdf.GetFont(new System.Drawing.Font("Letter Gothic", 10F)): - Volian.Svg.Library.VolianPdf.GetFont(new System.Drawing.Font("Letter Gothic", 5.5F)); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B21017-117 + //iTextSharp.text.Font iFont = _IsRev? Volian.Svg.Library.VolianPdf.GetFont(new System.Drawing.Font("Letter Gothic", 10F)): + // Volian.Svg.Library.VolianPdf.GetFont(new System.Drawing.Font("Letter Gothic", 5.5F)); + iTextSharp.text.Font iFont = _IsRev? Volian.Svg.Library.VolianPdf.GetFont(VE_Font.GetWinSysFont("Letter Gothic", 10F)): + Volian.Svg.Library.VolianPdf.GetFont(VE_Font.GetWinSysFont("Letter Gothic", 5.5F)); Chunk chk = new Chunk(vcbm.Message.IndexOf(@"\n") > -1 ? vcbm.Message.Substring(0, vcbm.Message.IndexOf(@"\n")) : vcbm.Message, iFont); Paragraph myparagraph = new Paragraph(chk); diff --git a/PROMS/Volian.Print.Library/vlnParagraph.cs b/PROMS/Volian.Print.Library/vlnParagraph.cs index fc905dac..40fa075b 100644 --- a/PROMS/Volian.Print.Library/vlnParagraph.cs +++ b/PROMS/Volian.Print.Library/vlnParagraph.cs @@ -665,7 +665,11 @@ namespace Volian.Print.Library float lpi = MyPageHelper.YMultiplier == 1.0 ? SixLinesPerInch : _SevenLinesPerInch; bool savedebug = Rtf2Pdf.PdfDebug; Rtf2Pdf.PdfDebug = false; - System.Drawing.Font symbFont = new System.Drawing.Font("VESymbFix", (float)ii.FormatStepData.Font.Size); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //System.Drawing.Font symbFont = new System.Drawing.Font("VESymbFix", (float)ii.FormatStepData.Font.Size); + System.Drawing.Font symbFont = VE_Font.GetWinSysFont("VESymbFix", (float)ii.FormatStepData.Font.Size); iTextSharp.text.Font iSymblFont = Volian.Svg.Library.VolianPdf.GetFont(symbFont); iSymblFont.Color = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Black)); // The vertPos array from the format defines the column locations: @@ -4384,64 +4388,70 @@ namespace Volian.Print.Library private string FixRTFToPrint(string rtf) { // Only do this if the text contains symbols. - if (rtf.Contains("VESymbFix") || rtf.Contains("Arial Unicode")) + if ((rtf.Contains("VESymbFix") || rtf.Contains("Arial Unicode"))) { - System.Windows.Forms.RichTextBox rtb = new System.Windows.Forms.RichTextBox(); - rtb.Rtf = rtf.Replace(@"\\",""); // rename backslash character to avoid RTF confusion - //string showRTF = rtf; - bool changed = false; - // C2017-008 - WCN wants the box symbol to look like their checkoff/signoff box - // Check for a list of replacement character for symbols in the format file - // ReplaceSymbolChars lets you do one or more of the following with a symbol character: - // - change the point size - // - change the style - // - change the font family - // - change the symbol character - // - // below is taken from the BaseAll format file - is currently commentout and there for reference - // Wolf Creek (WCN) currently uses this to increase the size of the box symbol - // - // - // - // - // get the list of symbol replacements - FormatData fmtdata = (MyItemInfo.ActiveFormat != null) ? MyItemInfo.ActiveFormat.PlantFormat.FormatData : FormatInfo.PROMSBaseFormat.FormatData; - ReplaceSymbolCharList SymReplaceList = (fmtdata != null && fmtdata.SectData.ReplaceSymbolCharList != null) ? fmtdata.SectData.ReplaceSymbolCharList : null; - // Look at one character at a time - for (int i = 0; i < rtb.TextLength; i++) + // bug fix: B2017-117 was getting an out of window handles error when doing a print all for Bryon + // add the using statment to free up window handle that is created doing a New RichTextBox() + using (System.Windows.Forms.RichTextBox rtb = new System.Windows.Forms.RichTextBox()) { - rtb.Select(i, 1); - if ((rtb.SelectionFont.FontFamily.Name == "VESymbFix" || rtb.SelectionFont.FontFamily.Name.StartsWith("Arial Unicode")) && rtb.SelectedText.Length > 0) + rtb.Rtf = rtf.Replace(@"\\", ""); // rename backslash character to avoid RTF confusion + //string showRTF = rtf; + bool changed = false; + // C2017-008 - WCN wants the box symbol to look like their checkoff/signoff box + // Check for a list of replacement character for symbols in the format file + // ReplaceSymbolChars lets you do one or more of the following with a symbol character: + // - change the point size + // - change the style + // - change the font family + // - change the symbol character + // + // below is taken from the BaseAll format file - is currently commentout and there for reference + // Wolf Creek (WCN) currently uses this to increase the size of the box symbol + // + // + // + // + // get the list of symbol replacements + FormatData fmtdata = (MyItemInfo.ActiveFormat != null) ? MyItemInfo.ActiveFormat.PlantFormat.FormatData : FormatInfo.PROMSBaseFormat.FormatData; + ReplaceSymbolCharList SymReplaceList = (fmtdata != null && fmtdata.SectData.ReplaceSymbolCharList != null) ? fmtdata.SectData.ReplaceSymbolCharList : null; + // Look at one character at a time + for (int i = 0; i < rtb.TextLength; i++) { - for (int j=0; j 0) { - ReplaceChar rc = SymReplaceList[j]; - if (rc.Unicode != null) + for (int j = 0; j < SymReplaceList.MaxIndex; j++) { - char rc_uchar = Convert.ToChar(Convert.ToInt32(rc.Unicode)); - if (rc_uchar == rtb.SelectedText[0]) + ReplaceChar rc = SymReplaceList[j]; + if (rc.Unicode != null && (rc.Family != null || rc.Size != null || rc.Style != null)) { - //use bolding underline italics from local font - System.Drawing.Font fnt = rtb.SelectionFont; - System.Drawing.Font fntw = new System.Drawing.Font((rc.Family != null)?rc.Family:fnt.FontFamily.Name, (rc.Size != null)?(float)rc.Size:fnt.Size, (rc.Style != null)?(System.Drawing.FontStyle)rc.Style:fnt.Style); - rtb.SelectionFont = fntw; - if (rc.Replace != null) + char rc_uchar = Convert.ToChar(Convert.ToInt32(rc.Unicode)); + if (rc_uchar == rtb.SelectedText[0]) { - char rc_RplChar = Convert.ToChar(Convert.ToInt32(rc.Replace)); - rtb.SelectedText = rc_RplChar.ToString(); + //use bolding underline italics from local font + System.Drawing.Font fnt = rtb.SelectionFont; + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //System.Drawing.Font fntw = new System.Drawing.Font((rc.Family != null) ? rc.Family : fnt.FontFamily.Name, (rc.Size != null) ? (float)rc.Size : fnt.Size, (rc.Style != null) ? (System.Drawing.FontStyle)rc.Style : fnt.Style); + System.Drawing.Font fntw = VE_Font.GetWinSysFont((rc.Family != null) ? rc.Family : fnt.FontFamily.Name, (rc.Size != null) ? (float)rc.Size : fnt.Size, (rc.Style != null) ? (System.Drawing.FontStyle)rc.Style : fnt.Style); + rtb.SelectionFont = fntw; + if (rc.Replace != null) + { + char rc_RplChar = Convert.ToChar(Convert.ToInt32(rc.Replace)); + rtb.SelectedText = rc_RplChar.ToString(); + } + changed = true; + break; // break out of foreach loop since we changed the character } - changed = true; - break; // break out of foreach loop since we changed the character } } } } + if (changed) return rtb.Rtf.Replace("", @"\\"); // put back the backslash character } - if (changed) return rtb.Rtf.Replace("",@"\\"); // put back the backslash character } return rtf; } @@ -5034,27 +5044,43 @@ namespace Volian.Print.Library DisplayText vlntxt = new DisplayText(itemInfo, E_EditPrintMode.Print, E_ViewMode.View, true, E_FieldToEdit.StepText, false, prefix, suffix,MyPageHelper.MyPromsPrinter.RemoveTrailingHardReturnsAndManualPageBreaks); System.Drawing.Font myFont = vlntxt.TextFont.WindowsFont; if (!itemInfo.IsTable && StepRTB.MyFontFamily != null) - myFont = new System.Drawing.Font(StepRTB.MyFontFamily, myFont.Size, myFont.Style); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //myFont = new System.Drawing.Font(StepRTB.MyFontFamily, myFont.Size, myFont.Style); + myFont = VE_Font.GetWinSysFont(StepRTB.MyFontFamily, myFont.Size, myFont.Style); string stText = null; // if Calvert (BGE) Alarms, the text is included in the macro, so save text as a blank: if (HasCalvertMacro) { stText = " "; // turn underline off - myFont = new System.Drawing.Font(myFont.FontFamily, myFont.Size, System.Drawing.FontStyle.Regular); //myFont.Style. | FontStyle.Underline); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //myFont = new System.Drawing.Font(myFont.FontFamily, myFont.Size, System.Drawing.FontStyle.Regular); //myFont.Style. | FontStyle.Underline); + myFont = VE_Font.GetWinSysFont(myFont.FontFamily, myFont.Size, System.Drawing.FontStyle.Regular); //myFont.Style. | FontStyle.Underline); } else stText = vlntxt.StartText; if (itemInfo.IsHigh && itemInfo.MyDocStyle.UndSpecialStepsFoldout) { - myFont = new System.Drawing.Font(myFont.FontFamily, myFont.Size, myFont.Style | System.Drawing.FontStyle.Underline); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //myFont = new System.Drawing.Font(myFont.FontFamily, myFont.Size, myFont.Style | System.Drawing.FontStyle.Underline); + myFont = VE_Font.GetWinSysFont(myFont.FontFamily, myFont.Size, myFont.Style | System.Drawing.FontStyle.Underline); stText = stText.Replace(@"\ulnone ", ""); stText = stText.Replace(@"\ulnone", ""); } if (stText.Contains("{IND}")) stText = stText.Replace("{IND}", "\x5"); if (itemInfo.IsSection && itemInfo.ActiveFormat.PlantFormat.FormatData.SectData.SectionNumber.Level0Big && itemInfo.MyParent.IsProcedure) - myFont = new System.Drawing.Font(myFont.FontFamily, 14, myFont.Style | System.Drawing.FontStyle.Bold); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //myFont = new System.Drawing.Font(myFont.FontFamily, 14, myFont.Style | System.Drawing.FontStyle.Bold); + myFont = VE_Font.GetWinSysFont(myFont.FontFamily, 14, myFont.Style | System.Drawing.FontStyle.Bold); _RtfSB.Append(AddFontTable(myFont)); _RtfSB.Append(stText); if (_MyItemInfo.IsStep && !itemInfo.FormatStepData.UseSmartTemplate && _MyItemInfo.FormatStepData.Suffix != null && _MyItemInfo.FormatStepData.Suffix != "") diff --git a/PROMS/Volian.Print.Library/vlnTab.cs b/PROMS/Volian.Print.Library/vlnTab.cs index a79aef9d..d3b1cd09 100644 --- a/PROMS/Volian.Print.Library/vlnTab.cs +++ b/PROMS/Volian.Print.Library/vlnTab.cs @@ -83,8 +83,13 @@ namespace Volian.Print.Library } private float GetTextWidth(VE_Font vefont, string txt, string symblFontName) { - System.Drawing.Font font = new System.Drawing.Font(vefont.Family, (float)vefont.Size, GetSysFontStyle(vefont)); - System.Drawing.Font symbFont = new System.Drawing.Font(symblFontName, (float)vefont.Size); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //System.Drawing.Font font = new System.Drawing.Font(vefont.Family, (float)vefont.Size, GetSysFontStyle(vefont)); + //System.Drawing.Font symbFont = new System.Drawing.Font(symblFontName, (float)vefont.Size); + System.Drawing.Font font = VE_Font.GetWinSysFont(vefont.Family, (float)vefont.Size, GetSysFontStyle(vefont)); + System.Drawing.Font symbFont = VE_Font.GetWinSysFont(symblFontName, (float)vefont.Size); iTextSharp.text.Font iFont = Volian.Svg.Library.VolianPdf.GetFont(font); iTextSharp.text.Font iSymblFont = Volian.Svg.Library.VolianPdf.GetFont(symbFont); float w = 0; @@ -227,7 +232,11 @@ namespace Volian.Print.Library FontStyle style = FontStyle.Regular; if ((vFont.Style & E_Style.Bold) > 0) style |= FontStyle.Bold; if ((vFont.Style & E_Style.Italics) > 0) style |= FontStyle.Italic; - vFont.WindowsFont = new System.Drawing.Font(vFont.Family, (float)vFont.Size, style); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //vFont.WindowsFont = new System.Drawing.Font(vFont.Family, (float)vFont.Size, style); + vFont.WindowsFont = VE_Font.GetWinSysFont(vFont.Family, (float)vFont.Size, style); int indxC = origTab.IndexOf(":"); origTab = @"\ul " + origTab.Substring(0, indxC) + @"\ulnone" + origTab.Substring(indxC); } @@ -240,7 +249,11 @@ namespace Volian.Print.Library FontStyle style = FontStyle.Regular; if ((vFont.Style & E_Style.Bold) > 0) style |= FontStyle.Bold; if ((vFont.Style & E_Style.Italics) > 0) style |= FontStyle.Italic; - vFont.WindowsFont = new System.Drawing.Font(vFont.Family, (float)vFont.Size, style); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //vFont.WindowsFont = new System.Drawing.Font(vFont.Family, (float)vFont.Size, style); + vFont.WindowsFont = VE_Font.GetWinSysFont(vFont.Family, (float)vFont.Size, style); int indxC = origTab.IndexOf(ut.Text); string prefix = ((vFont.Style & E_Style.Bold) > 0) ? @"\b\ul " : @"\ul "; string suffix = ((vFont.Style & E_Style.Bold) > 0) ? @"\b0\ulnone " : @"\ulnone "; @@ -323,7 +336,11 @@ namespace Volian.Print.Library string txt = Text; if (alignAsIfBulleted) txt += myparent.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IdentB; - System.Drawing.Font font = new System.Drawing.Font(MyFont.Family, (float)MyFont.Size); + // follow through in fixing an Out of Window Handles bug, use new function to see if + // we can retrieve the font from a dictionary instead a doing a New and using another + // window handle B2017-117 + //System.Drawing.Font font = new System.Drawing.Font(MyFont.Family, (float)MyFont.Size); + System.Drawing.Font font = VE_Font.GetWinSysFont(MyFont.Family, (float)MyFont.Size); iTextSharp.text.Font iFont = Volian.Svg.Library.VolianPdf.GetFont(font); float w = iFont.BaseFont.GetWidthPointKerned(txt, (float)MyFont.Size); Width = w;