Use method from VE_Font to get a font reference (uses dictionary so redundant Window Handles are not created) B2017-117

Add a Using statement when we temporarily create a RichTextBox to ensure the Window Handle is free’d. Also use method from VE_Font to get a font reference (uses dictionary so redundant Window Handles are not created)  B2017-117
This commit is contained in:
John Jenko 2017-06-12 17:58:30 +00:00
parent 74898f5e4e
commit 0d0bd7661b
6 changed files with 122 additions and 61 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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,10 +4388,13 @@ 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(@"\\","<dblbs>"); // rename backslash character to avoid RTF confusion
// 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.Rtf = rtf.Replace(@"\\", "<dblbs>"); // 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
@ -4403,9 +4410,7 @@ namespace Volian.Print.Library
//
//<!--example of replacing a symbol character (VESymbFix)-->
//<!--ReplaceSymbolChars>
// <ReplaceChar Unicode=[decimal char #] Replace=[optional char #] Family=[option font family name] Style=[optional font style] Size=[optional font size]>
// <ReplaceChar Unicode="9633" Size="20"/> < this will resize the VESYMBFix box character to 20 point>
// <ReplaceChar Unicode="9633" Replace="0163" Family ="WingDings 2" Size="16"/> <this will replace the VESYMBFix box char with a 16 point "WingDing 2" char>
// <ReplaceChar Index="#" Unicode=[decimal char #] Replace=[optional char #] Family=[option font family name] Style=[optional font style] Size=[optional font size]>
//</ReplaceSymbolChars-->
//
// get the list of symbol replacements
@ -4417,17 +4422,21 @@ namespace Volian.Print.Library
rtb.Select(i, 1);
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++)
for (int j = 0; j < SymReplaceList.MaxIndex; j++)
{
ReplaceChar rc = SymReplaceList[j];
if (rc.Unicode != null)
if (rc.Unicode != null && (rc.Family != null || rc.Size != null || rc.Style != null))
{
char rc_uchar = Convert.ToChar(Convert.ToInt32(rc.Unicode));
if (rc_uchar == rtb.SelectedText[0])
{
//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);
// 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)
{
@ -4441,7 +4450,8 @@ namespace Volian.Print.Library
}
}
}
if (changed) return rtb.Rtf.Replace("<dblbs>",@"\\"); // put back the backslash character
if (changed) return rtb.Rtf.Replace("<dblbs>", @"\\"); // 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 != "")

View File

@ -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;