diff --git a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs index 95e6a425..d9fb293e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs @@ -88,6 +88,26 @@ namespace VEPROMS.CSLA.Library _WinFontLookup.Add(key, new Font(family, size, style)); return _WinFontLookup[key]; } + // part of bug B2017-117 and for conservation of winow handles to reduce the frequency of + // the Out of Window Handles error when editing and printing. + // we are now using a common dictionary for font usages + public static Font GetWinSysFont(string family, float size, FontStyle style) + { + return GetFont(family, size, style); + } + public static Font GetWinSysFont(string family, float size) + { + return GetFont(family, size, FontStyle.Regular); + } + public static Font GetWinSysFont(FontFamily ffamily, float size, FontStyle style) + { + return GetFont(ffamily.Name, size, style); + } + public static Font GetWinSysFont(Font font, FontStyle style) + { + return GetFont(font.Name, font.Size, style); + } + private Font _WindowsFont; public Font WindowsFont { diff --git a/PROMS/Volian.Controls.Library/EditItem.cs b/PROMS/Volian.Controls.Library/EditItem.cs index 867f4db7..56d17045 100644 --- a/PROMS/Volian.Controls.Library/EditItem.cs +++ b/PROMS/Volian.Controls.Library/EditItem.cs @@ -2456,9 +2456,9 @@ namespace Volian.Controls.Library nextEditItem.Top = newTop; if (nextEditItem.Top != newTop) { - _MyLog.InfoFormat("'TryAgainLater',{0},{1},{2},{3},{4},'{5}'", - oldTop, nextEditItem.Top, newTop, MyStepPanel.Height, nextEditItem.MyID, nextEditItem.MyItemInfo.ShortPath); - nextEditItem.TryAgainLater = true; + _MyLog.InfoFormat("'TryAgainLater',{0},{1},{2},{3},{4},'{5}'", + oldTop, nextEditItem.Top, newTop, MyStepPanel.Height, nextEditItem.MyID, nextEditItem.MyItemInfo.ShortPath); + nextEditItem.TryAgainLater = true; } nextEditItem.LastMethodsPop(); MyStepPanel.ItemMoving--; @@ -3694,7 +3694,10 @@ namespace Volian.Controls.Library foreach (EnhancedDocument ed in MyItemInfo.GetMyEnhancedDocuments()) { DVEnhancedDocument dved = dveds.GetByType(ed.Type); - Font fnt = new System.Drawing.Font("Arial", 5); + // 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 + Font fnt = VE_Font.GetWinSysFont("Arial", 5); //g.DrawLine(Pens.DarkGreen, 18, 1, 18, 6); //g.DrawLine(Pens.DarkGreen, 18, 1, 21, 1); //g.DrawLine(Pens.DarkGreen, 18, 3, 21, 3); diff --git a/PROMS/Volian.Controls.Library/StepRTB.cs b/PROMS/Volian.Controls.Library/StepRTB.cs index fa7ec067..5c8dd4c6 100644 --- a/PROMS/Volian.Controls.Library/StepRTB.cs +++ b/PROMS/Volian.Controls.Library/StepRTB.cs @@ -473,14 +473,21 @@ namespace Volian.Controls.Library _MyLog.Error(string.Format("MyItemInfo: {0} - {1} Problem doing RefreshDisplay",MyItemInfo.ItemID,MyItemInfo.ShortPath), ex); } } + private static string FontKey(System.Drawing.Font font) + { + return string.Format("{0}_{1}_{2}", font.FontFamily.Name, font.Size, font.Style); + } // RefreshDisplay is used to update the rtb for an entire Item as defined by MyItemInfo. public void RefreshDisplay(bool activeMode) { if (IsExperimenting) return; + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "RefreshDisplay 1"); ActiveMode = activeMode; OnAdjustTableWidth(this, new StepRTBTableWidthEventArgs(true)); + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "RefreshDisplay 2"); _InitializingRTB = true; DisplayText vlntxt = new DisplayText(MyItemInfo, E_EditPrintMode.Edit, VwMode, !ActiveMode, FieldToEdit, true,null, null,false); + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "RefreshDisplay 3"); //if (_origDisplayText != null && vlntxt.StartText == _origDisplayText.StartText) //{ // ReadOnly = !(EpMode == E_EditPrintMode.Edit && VwMode == E_ViewMode.Edit); @@ -488,6 +495,7 @@ namespace Volian.Controls.Library // return; //} OrigDisplayText = vlntxt; + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "RefreshDisplay 4"); // RHM 20101201 - Don't reset the text. Calculate the text and compare it with the existing text in AddRTFText //Text = ""; // Initialize text before add text @@ -495,16 +503,47 @@ namespace Volian.Controls.Library // was confusing the 'handle' of the rtf box. //Console.WriteLine("'font',{0}", Font); //if(Text == "")SelectionFont = Font; // Initialize SelectionFont + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "1"); if (FieldToEdit == E_FieldToEdit.StepText) { if (MyItemInfo != null) { - if (MyItemInfo.IsStep) Font = MyFontFamily == null ? MyItemInfo.FormatStepData.Font.WindowsFont : new Font(MyFontFamily, MyItemInfo.FormatStepData.Font.WindowsFont.Size, MyItemInfo.FormatStepData.Font.WindowsFont.Style); - else Font = Font = MyFontFamily == null ? MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont : new Font(MyFontFamily, MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont.Size, MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont.Style); + //if (MyItemInfo.IsStep) Font = MyFontFamily == null ? MyItemInfo.FormatStepData.Font.WindowsFont : new Font(MyFontFamily, MyItemInfo.FormatStepData.Font.WindowsFont.Size, MyItemInfo.FormatStepData.Font.WindowsFont.Style); + //else Font = Font = MyFontFamily == null ? MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont : new Font(MyFontFamily, MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont.Size, MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont.Style); + if (MyItemInfo.IsStep) + { + if (MyFontFamily == null) + { + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "Before WindowsFont1"); + System.Drawing.Font fnt = MyItemInfo.FormatStepData.Font.WindowsFont; + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "After WindowsFont1a"); + Application.DoEvents(); + if (FontKey(Font) != FontKey(fnt)) + Font = fnt; + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "After WindowsFont1b"); + } + else + Font = VE_Font.GetWinSysFont(MyFontFamily, MyItemInfo.FormatStepData.Font.WindowsFont.Size, MyItemInfo.FormatStepData.Font.WindowsFont.Style); + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "RefreshDisplay 4"); + } + else + { + if (MyFontFamily == null) + { + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "Before WindowsFont2"); + Font = MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont; + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "After WindowsFont2"); + } + else + Font = VE_Font.GetWinSysFont(MyFontFamily, MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont.Size, MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font.WindowsFont.Style); + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "RefreshDisplay 5"); + } LastRtf = Rtf; } } + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "StepRTB.RefreshDisplay Before SetLineSpacing"); RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT); + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "StepRTB.RefreshDisplay After SetLineSpacing"); bool readOnlyStep = MyItemInfo == null || MyItemInfo.FormatStepData == null ? false : MyItemInfo.FormatStepData.ReadOnly; if (!readOnlyStep) { @@ -513,7 +552,9 @@ namespace Volian.Controls.Library readOnlyStep = true; } ReadOnly = readOnlyStep || VwMode == E_ViewMode.View || ActiveMode == false; + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "Before AddRTFText"); AddRtfText(vlntxt.StartText); + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "After AddRTFText"); //AddRtfStyles(); // set readonly based on initial modes, however, these may change if // user selected view mode. @@ -534,13 +575,16 @@ namespace Volian.Controls.Library // // Setting the RightMargin to the Width minus one, accounts for the slight indent (1 pixel) of // the text within the RichTextBox. - RightMargin = Width > 0 ? Width - 1 : 0; + //RightMargin = Width > 0 ? Width - 1 : 0; + RightMargin = ActiveMode ? Width : Width > 0 ? Width - 1 : 0; // > 0 ? Width - 1 : 0; // figure out if needs outlined, depends on table/figure type if (!ActiveMode) { RemoveEventHandlers(); OnAdjustTableWidth(this, new StepRTBTableWidthEventArgs(false));// View Mode + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "Before SelectAll"); SelectAll(); + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "After SelectAll"); //if (SelectionHangingIndent !=0) SelectionHangingIndent = 0; int indchar = 0; string indentToken = MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IndentToken; @@ -604,7 +648,10 @@ namespace Volian.Controls.Library _InitializingRTB = false; AdjustSizeForContents(!ActiveMode); + //Volian.Base.Library.HWndCounter.GetWindowHandlesForCurrentProcess(this.Handle, "After RefreshDisplay"); + Application.DoEvents(); } + private bool IsDerived(StepConfig sc) { foreach (EnhancedDocument ed in sc.MyEnhancedDocuments) @@ -828,7 +875,7 @@ namespace Volian.Controls.Library private void SetUpStepRTB() { DetectUrls = false; - SpellCheckStatus = false; + SpellCheckStatus = false; this.Height = 10; // initialize the height to 10, the default height was too big for the cells in grid tables BorderStyle = System.Windows.Forms.BorderStyle.None; this.ScrollBars = RichTextBoxScrollBars.None; @@ -1143,7 +1190,13 @@ namespace Volian.Controls.Library } else { - base.WndProc(ref m); + try + { + base.WndProc(ref m); + } + catch (Exception ex) + { + } } } private static void AddFontTable(StringBuilder selectedRtfSB, Font myFont, bool isFixed) @@ -2088,85 +2141,89 @@ namespace Volian.Controls.Library // verify that data in clipboard is valid for this type. If inserting an equation, need to verify that // input data has an 'equation', and if not inserting into an equation step type, it must not have // equation data. - DataFormats.Format frm = DataFormats.GetFormat("Embed Source"); - System.Windows.Forms.RichTextBox richTextBox1; - richTextBox1 = new System.Windows.Forms.RichTextBox(); - richTextBox1.Location = new System.Drawing.Point(35, 32); - richTextBox1.Name = "richTextBox1"; - richTextBox1.Size = new System.Drawing.Size(67, 58); - richTextBox1.TabIndex = 0; - richTextBox1.Text = ""; - richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None; - bool hasEquation = false; - try + //DataFormats.Format frm = DataFormats.GetFormat("Embed Source"); + //System.Windows.Forms.RichTextBox richTextBox1; + using (System.Windows.Forms.RichTextBox richTextBox1 = new System.Windows.Forms.RichTextBox()) { - richTextBox1.Paste(frm); - if (richTextBox1.Rtf.ToUpper().Contains("OBJCLASS EQU")) hasEquation = true; - if (richTextBox1.Rtf.ToUpper().Contains("OBJCLASS VIS")) hasEquation = true; // Support Visio - } - catch (Exception ex) - { - hasEquation = true; - } - if (MyItemInfo != null && MyItemInfo.IsRtfRaw && MyItemInfo.FormatStepData.Type.ToUpper().Contains("EQUATION") && !hasEquation) - { - MessageBox.Show("Cannot paste non-equation data into an equation step type.", "Invalid data", MessageBoxButtons.OK); - richTextBox1.Dispose(); - e.Handled = true; - return; - } - // if inserting anything other than equation, be sure that an equation is not in the buffer: - else if (hasEquation && (MyItemInfo==null || (MyItemInfo != null && !MyItemInfo.IsRtfRaw && !MyItemInfo.FormatStepData.Type.ToUpper().Contains("EQUATION")))) - { - MessageBox.Show("Cannot paste equation data into an non-equation step type.", "Invalid data", MessageBoxButtons.OK); - richTextBox1.Dispose(); - e.Handled = true; - return; - } - - // only allow the paste of a screen shot image if using the shortcut switch "/EmbedImages" - if (Volian.Base.Library.VlnSettings.GetCommandFlag("EmbedImages") && iData.GetDataPresent(DataFormats.Dib)) // Device Independent Bitmap - { - System.Drawing.Image img = Clipboard.GetImage(); - ImageWidth = img.Width; - Width = ImageWidth + 2; - Paste(); - e.Handled = true; - return; - } - else if (iData.GetDataPresent("Embed Source")) //DS Equation") || iData.GetDataPresent("MathType EF")) - { - Size sz = RtfRawItem.GetRtfRawSize(richTextBox1.Rtf); - this.Rtf = richTextBox1.Rtf; - Width = sz.Width; - Height = sz.Height; - e.Handled = true; - return; - } - else if (iData.GetDataPresent(DataFormats.Dib)) - { - System.Drawing.Image img = Clipboard.GetImage(); - ImageWidth = img.Width; - Width = ImageWidth + 2; - Paste(); - e.Handled = true; - return; - } - else - { - if (!iData.GetDataPresent(DataFormats.Text) && !iData.GetDataPresent(DataFormats.Rtf)) + richTextBox1.Location = new System.Drawing.Point(35, 32); + richTextBox1.Name = "richTextBox1"; + richTextBox1.Size = new System.Drawing.Size(67, 58); + richTextBox1.TabIndex = 0; + richTextBox1.Text = ""; + richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None; + bool hasEquation = false; + try { - MessageBox.Show("Cannot paste, text has special characters or symbols that will not paste correctly."); + DataFormats.Format frm = DataFormats.GetFormat("Embed Source"); + richTextBox1.Paste(frm); + if (richTextBox1.Rtf.ToUpper().Contains("OBJCLASS EQU")) hasEquation = true; + if (richTextBox1.Rtf.ToUpper().Contains("OBJCLASS VIS")) hasEquation = true; // Support Visio + } + catch (Exception ex) + { + hasEquation = true; + } + if (MyItemInfo != null && MyItemInfo.IsRtfRaw && MyItemInfo.FormatStepData.Type.ToUpper().Contains("EQUATION") && !hasEquation) + { + MessageBox.Show("Cannot paste non-equation data into an equation step type.", "Invalid data", MessageBoxButtons.OK); + //richTextBox1.Dispose(); + e.Handled = true; + return; + } + // if inserting anything other than equation, be sure that an equation is not in the buffer: + else if (hasEquation && (MyItemInfo == null || (MyItemInfo != null && !MyItemInfo.IsRtfRaw && !MyItemInfo.FormatStepData.Type.ToUpper().Contains("EQUATION")))) + { + MessageBox.Show("Cannot paste equation data into an non-equation step type.", "Invalid data", MessageBoxButtons.OK); + //richTextBox1.Dispose(); + e.Handled = true; + return; + } + + // only allow the paste of a screen shot image if using the shortcut switch "/EmbedImages" + if (Volian.Base.Library.VlnSettings.GetCommandFlag("EmbedImages") && iData.GetDataPresent(DataFormats.Dib)) // Device Independent Bitmap + { + System.Drawing.Image img = Clipboard.GetImage(); + ImageWidth = img.Width; + Width = ImageWidth + 2; + Paste(); + e.Handled = true; + return; + } + else if (iData.GetDataPresent("Embed Source")) //DS Equation") || iData.GetDataPresent("MathType EF")) + { + Size sz = RtfRawItem.GetRtfRawSize(richTextBox1.Rtf); + this.Rtf = richTextBox1.Rtf; + Width = sz.Width; + Height = sz.Height; + e.Handled = true; + return; + } + else if (iData.GetDataPresent(DataFormats.Dib)) + { + System.Drawing.Image img = Clipboard.GetImage(); + ImageWidth = img.Width; + Width = ImageWidth + 2; + Paste(); + e.Handled = true; + return; } else { - // if contains bad rtf (from Word), paste as text, otherwise, do the paste here. - if (!PasteRtfAsText(true)) Paste(); - if (SelectionLength == 0 && MyStyleFont != null) SelectionFont = MyStyleFont.WindowsFont; // B2017-023 null reference check for empty workdraft set information dialog + if (!iData.GetDataPresent(DataFormats.Text) && !iData.GetDataPresent(DataFormats.Rtf)) + { + MessageBox.Show("Cannot paste, text has special characters or symbols that will not paste correctly."); + } + else + { + // if contains bad rtf (from Word), paste as text, otherwise, do the paste here. + if (!PasteRtfAsText(true)) Paste(); + if (SelectionLength == 0 && MyStyleFont != null) SelectionFont = MyStyleFont.WindowsFont; // B2017-023 null reference check for empty workdraft set information dialog + } } - } + } // end using e.Handled = true; return; + case Keys.Home: StepRTB_HomeEndPressed(e); e.Handled = true; @@ -3409,6 +3466,7 @@ namespace Volian.Controls.Library } } + // the grid uses this to reference the same instance of the spell checker public C1.Win.C1SpellChecker.C1SpellChecker SpellCheckerInstance { diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.cs index 4f3992cf..81312011 100644 --- a/PROMS/Volian.Controls.Library/StepTabRibbon.cs +++ b/PROMS/Volian.Controls.Library/StepTabRibbon.cs @@ -1468,26 +1468,33 @@ namespace Volian.Controls.Library try // RHM20150506 Multiline ItemID TextBox { IDataObject iData = Clipboard.GetDataObject(); - DataFormats.Format frm = DataFormats.GetFormat("Embed Source"); - System.Windows.Forms.RichTextBox richTextBox1; - richTextBox1 = new System.Windows.Forms.RichTextBox(); - richTextBox1.Location = new System.Drawing.Point(35, 32); - richTextBox1.Name = "richTextBox1"; - richTextBox1.Size = new System.Drawing.Size(67, 58); - richTextBox1.TabIndex = 0; - richTextBox1.Text = ""; - richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None; bool noEquationData = true; - try + // part of bug B2017-117 we were running out of window handles when printing, found this similar use of + // creating a new richtextbox just for some processing. Put a Using around this to ensure the window handle + // is free'd + using (System.Windows.Forms.RichTextBox richTextBox1 = new System.Windows.Forms.RichTextBox()) { - richTextBox1.Paste(frm); - if (richTextBox1.Rtf.ToUpper().Contains("OBJCLASS EQU")) noEquationData = false; - if (richTextBox1.Rtf.ToUpper().Contains("OBJCLASS VIS")) noEquationData = false; - } - catch (Exception ex) - { - noEquationData = false; - } + DataFormats.Format frm = DataFormats.GetFormat("Embed Source"); + //System.Windows.Forms.RichTextBox richTextBox1; + //richTextBox1 = new System.Windows.Forms.RichTextBox(); + richTextBox1.Location = new System.Drawing.Point(35, 32); + richTextBox1.Name = "richTextBox1"; + richTextBox1.Size = new System.Drawing.Size(67, 58); + richTextBox1.TabIndex = 0; + richTextBox1.Text = ""; + richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None; + //bool noEquationData = true; + try + { + richTextBox1.Paste(frm); + if (richTextBox1.Rtf.ToUpper().Contains("OBJCLASS EQU")) noEquationData = false; + if (richTextBox1.Rtf.ToUpper().Contains("OBJCLASS VIS")) noEquationData = false; + } + catch (Exception ex) + { + noEquationData = false; + } + } // end using //btnEdit3CMPaste.Enabled = btnPasteText.Enabled = btnCMPasteText.Enabled = btnCMPaste.Enabled = btnPaste.Enabled = (iData.GetDataPresent(DataFormats.Text) || iData.GetDataPresent(DataFormats.Rtf)); //btnPasteText.Enabled = btnPasteStepText.Enabled = btnPaste.Enabled = (iData.GetDataPresent(DataFormats.Text) || iData.GetDataPresent(DataFormats.Rtf)); btnPaste.Enabled = noEquationData && (iData.GetDataPresent(DataFormats.Text) || iData.GetDataPresent(DataFormats.Rtf)); diff --git a/PROMS/Volian.Print.Library/ContActionSum.cs b/PROMS/Volian.Print.Library/ContActionSum.cs index 22575ea5..632a53e3 100644 --- a/PROMS/Volian.Print.Library/ContActionSum.cs +++ b/PROMS/Volian.Print.Library/ContActionSum.cs @@ -190,7 +190,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/Grid2Pdf.cs b/PROMS/Volian.Print.Library/Grid2Pdf.cs index 880ae1c2..c5810f80 100644 --- a/PROMS/Volian.Print.Library/Grid2Pdf.cs +++ b/PROMS/Volian.Print.Library/Grid2Pdf.cs @@ -566,7 +566,8 @@ namespace Volian.Print.Library { // if there was no text following the hypen, then use the font defined for tables in the plant's format VEPROMS.CSLA.Library.VE_Font vfnt = myTable.MyFlexGrid.GetMyItemInfo().FormatStepData.Font; - System.Drawing.Font ffont = new System.Drawing.Font(vfnt.Family, (float)vfnt.Size); + //System.Drawing.Font ffont = new System.Drawing.Font(vfnt.Family, (float)vfnt.Size); + System.Drawing.Font ffont = VE_Font.GetWinSysFont(vfnt.Family, (float)vfnt.Size); fnt = Volian.Svg.Library.VolianPdf.GetFont(ffont); fnt.SetStyle(myPara.Font.Style); fnt.SetColor(myPara.Font.Color.R,myPara.Font.Color.G,myPara.Font.Color.B); @@ -630,7 +631,8 @@ namespace Volian.Print.Library { // if there was no text following the hypen, then use the font defined for tables in the plant's format VEPROMS.CSLA.Library.VE_Font vfnt = myTable.MyFlexGrid.GetMyItemInfo().FormatStepData.Font; - System.Drawing.Font ffont = new System.Drawing.Font(vfnt.Family, (float)vfnt.Size); + //System.Drawing.Font ffont = new System.Drawing.Font(vfnt.Family, (float)vfnt.Size); + System.Drawing.Font ffont = VE_Font.GetWinSysFont(vfnt.Family, (float)vfnt.Size); fnt = Volian.Svg.Library.VolianPdf.GetFont(ffont); fnt.SetStyle(myPara.Font.Style); fnt.SetColor(myPara.Font.Color.R, myPara.Font.Color.G, myPara.Font.Color.B); @@ -782,78 +784,85 @@ namespace Volian.Print.Library // Only do this if the text contains symbols. if (rtf.Contains("VESymbFix")) { - System.Windows.Forms.RichTextBox rtb = new System.Windows.Forms.RichTextBox(); - rtb.Rtf = rtf.Replace(@"\u9586?", "");// rename backslash character to avoid RTF confusion - string strRTF = 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 = (MyFlexGrid.GetMyItemInfo().ActiveFormat != null) ? MyFlexGrid.GetMyItemInfo().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 the character is a printable character set the font to the text font - if (rtb.SelectionLength == 0 && strRTF != null && rtb.SelectionFont.FontFamily.Name == "VESymbFix") + rtb.Rtf = rtf.Replace(@"\u9586?", "");// rename backslash character to avoid RTF confusion + string strRTF = 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 = (MyFlexGrid.GetMyItemInfo().ActiveFormat != null) ? MyFlexGrid.GetMyItemInfo().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++) { - // Add debug information to the error log if the selection length is zero - _MyLog.WarnFormat("Font Issues in Table Cell rtf= {0}, \nI= {1}, TXT = {2}", strRTF,i,rtb.Text.Substring(0,i)); - strRTF = null; - } - // bug fix: B2017-046 - check for selection length of zero to fix index out of bounds error - // System.Windows.Forms.RichTextBox is having issues selection text in some cases (ex. Symbol char followed by a RO reference - without a space between them) - if (rtb.SelectionLength > 0 && rtb.SelectionFont.FontFamily.Name == "VESymbFix" && rtb.SelectedText[0] > ' ' && rtb.SelectedText[0] <= '\xFF') - { - //use bolding underline italics from local font - System.Drawing.Font fnt = rtb.SelectionFont; - rtb.SelectionFont = new System.Drawing.Font(DefaultFont, fnt.Style); - changed = true; - } - if ((rtb.SelectionFont.FontFamily.Name == "VESymbFix" || rtb.SelectionFont.FontFamily.Name.StartsWith("Arial Unicode")) && rtb.SelectedText.Length > 0) - { - for (int j=0; j 0 && rtb.SelectionFont.FontFamily.Name == "VESymbFix" && rtb.SelectedText[0] > ' ' && rtb.SelectedText[0] <= '\xFF') + { + //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 + //rtb.SelectionFont = new System.Drawing.Font(DefaultFont, fnt.Style); + rtb.SelectionFont = VE_Font.GetWinSysFont(DefaultFont, fnt.Style); + changed = true; + } + if ((rtb.SelectionFont.FontFamily.Name == "VESymbFix" || rtb.SelectionFont.FontFamily.Name.StartsWith("Arial Unicode")) && rtb.SelectedText.Length > 0) + { + 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; + //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("", @"\u9586?"); } - if (changed) return rtb.Rtf.Replace("", @"\u9586?"); } return rtf; }