Made some regx usages static to help with memory usage

Logic to support clipboard paste of screen shot into a table cell
This commit is contained in:
John Jenko 2015-11-24 18:28:59 +00:00
parent ba3bceadae
commit df37f61cb5
5 changed files with 147 additions and 58 deletions

View File

@ -1184,6 +1184,16 @@ namespace Volian.Controls.Library
}
return "";//Strip All
}
private static Regex reg1 = new Regex(@"\\par\r\n(?!\\)");
private static Regex reg2 = new Regex(@"[\r\n]", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
private static Regex reg3 = new Regex(@"^\{(.*)\}$", RegexOptions.Singleline); // Strip Opening and Closing Braces
private static Regex reg4 = new Regex(@"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
private static Regex reg5 = new Regex( @"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
private static Regex reg6 = new Regex(@"(\\[^' \\?\r\n\t]+)(?=\\)"); // add space after token if followed by token
private static Regex reg7 = new Regex(@"(\\[^' \\?\r\n\t]+ )"); // take backslash xyz and evaluates them
private static Regex reg8 = new Regex( @"(\\[^' \\?\r\n\t]+) (?=\\)"); // remove space between tokens
private static Regex reg9 = new Regex( @"(\\[^' \\?\r\n\t]+) (?=\r\n)"); // remove space before /r/n
public string StripRtfCommands(string rtf)
{
// replace \{ & \} with (![ & (!] respectively and then redo at end. The curly braces
@ -1193,16 +1203,28 @@ namespace Volian.Controls.Library
// remove carriage return/newlines after \par commands (these are introduced by rtb
// for hard returns, goes into rtb as \par and comes out as \par\r\n):
retval = Regex.Replace(retval, @"\\par\r\n(?!\\)", "\\par ");
retval = reg1.Replace(retval, "\\par ");
retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment
retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+)(?=\\)", "$1 "); // add space after token if followed by token
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+ )", new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+) (?=\\)", "$1"); // remove space between tokens
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+) (?=\r\n)", "$1"); // remove space before /r/n
retval = reg2.Replace(retval, ""); // Strip Carriage Returns and Newlines
retval = reg3.Replace(retval, "$1"); // Strip Opening and Closing Braces
retval = reg4.Replace(retval, ""); // Strip Clauses - remove anything from curly braces
retval = reg5.Replace(retval, ""); // Strip Clauses - remove anything from curly braces
retval = reg6.Replace(retval, "$1 "); // add space after token if followed by token
retval = reg7.Replace(retval, new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
retval = reg8.Replace(retval, "$1"); // remove space between tokens
retval = reg9.Replace(retval, "$1"); // remove space before /r/n
//retval = Regex.Replace(retval, @"\\par\r\n(?!\\)", "\\par ");
//retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment
//retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
//retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
//retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
//retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+)(?=\\)", "$1 "); // add space after token if followed by token
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+ )", new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+) (?=\\)", "$1"); // remove space between tokens
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+) (?=\r\n)", "$1"); // remove space before /r/n
// remove \r\n at end of string if the string has 2 or more characters
if (retval.EndsWith("\r\n")) retval = retval.Remove(retval.Length - 2, 2);
if (retval.Length == 0) return "";
@ -1213,6 +1235,18 @@ namespace Volian.Controls.Library
retval = retval.TrimEnd(' ');
return retval;
}
private static Regex sreg1 = new Regex(@"\\par\r\n(?!\\)");
private static Regex sreg2 = new Regex(@"[\r\n]",RegexOptions.Singleline); // Strip Carriage Returns and Newlines
private static Regex sreg3 = new Regex(@"^\{(.*)\}$", RegexOptions.Singleline); // Strip Opening and Closing Braces
private static Regex sreg4 = new Regex(@"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
private static Regex sreg5 = new Regex(@"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
private static Regex sreg6 = new Regex(@"(\\[^' \\?\r\n\t]+)(?=\\)"); // add space after token if followed by token
private static Regex sreg7 = new Regex(@"(\\[^ \\?\r\n\t]+ )"); // take backslash xyz and evaluates them
private static Regex sreg8 = new Regex(@"(\\[^ \\?\r\n\t]+) (?=\\)"); // remove space between tokens
private static Regex sreg9 = new Regex(@"(\\[^ \\?\r\n\t]+) (?=\r\n)"); // remove space before /r/n
// This is used in the DataLoader
public static string StaticStripRtfCommands(string rtf)
{
@ -1231,26 +1265,39 @@ namespace Volian.Controls.Library
// remove carriage return/newlines after \par commands (these are introduced by rtb
// for hard returns, goes into rtb as \par and comes out as \par\r\n):
retval = Regex.Replace(retval, @"\\par\r\n(?!\\)", "\\par ");
//retval = Regex.Replace(retval, @"\\par\r\n(?=\\)", "\\par");
retval = sreg1.Replace(retval, "\\par ");
retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment
retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+)\\f[0-9] ", "$1 "); // remove font command - if next to another command, keep other command and space
// OLD: The following two lines are replaced by the more generic replace above.
//retval = Regex.Replace(retval, @"\\v\\f[0-9] ", "\\v "); // remove font command - if next to Comment keep space
//retval = Regex.Replace(retval, @"\\line\\f[0-9] ", "\\line "); // remove font command - if next to Line keep space
//retval = Regex.Replace(retval, @"\\f[0-9] ", ""); // remove font command with ending space
//retval = Regex.Replace(retval, @"\\f[0-9]", ""); // remove font command without ending space
//retval = Regex.Replace(retval, @"\\par ", "\r\n");
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+)(?=\\)", "$1 "); // add space after token if followed by token
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+)(\\)", "$1 $2"); // take backslash xyz and evaluates them
retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+ )", new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+) (?=\\)", "$1"); // remove space between tokens
retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+) (?=\r\n)", "$1"); // remove space before /r/n
retval = sreg2.Replace(retval,""); // Strip Carriage Returns and Newlines
retval = sreg3.Replace(retval, "$1"); // Strip Opening and Closing Braces
retval = sreg4.Replace(retval, ""); // Strip Clauses - remove anything from curly braces
retval = sreg5.Replace(retval, ""); // Strip Clauses - remove anything from curly braces
retval = sreg6.Replace(retval,"$1 "); // add space after token if followed by token
retval = sreg7.Replace(retval, new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
retval = sreg8.Replace(retval, "$1"); // remove space between tokens
retval = sreg9.Replace(retval, "$1"); // remove space before /r/n
//retval = Regex.Replace(retval, @"\\par\r\n(?!\\)", "\\par ");
////retval = Regex.Replace(retval, @"\\par\r\n(?=\\)", "\\par");
//retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment
//retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
//retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
//retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
//retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
////retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+)\\f[0-9] ", "$1 "); // remove font command - if next to another command, keep other command and space
//// OLD: The following two lines are replaced by the more generic replace above.
////retval = Regex.Replace(retval, @"\\v\\f[0-9] ", "\\v "); // remove font command - if next to Comment keep space
////retval = Regex.Replace(retval, @"\\line\\f[0-9] ", "\\line "); // remove font command - if next to Line keep space
////retval = Regex.Replace(retval, @"\\f[0-9] ", ""); // remove font command with ending space
////retval = Regex.Replace(retval, @"\\f[0-9]", ""); // remove font command without ending space
////retval = Regex.Replace(retval, @"\\par ", "\r\n");
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+)(?=\\)", "$1 "); // add space after token if followed by token
////retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+)(\\)", "$1 $2"); // take backslash xyz and evaluates them
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+ )", new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+) (?=\\)", "$1"); // remove space between tokens
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+) (?=\r\n)", "$1"); // remove space before /r/n
// remove a space if there is one as the first character or the last character
//if (retval[0] == ' ') retval = retval.Remove(0, 1);
//retval = retval.TrimEnd(' ');

View File

@ -806,7 +806,7 @@ namespace Volian.Controls.Library
private bool _ContextMenuStripChanged = false;
private void StepRTB_MouseDown(object sender, MouseEventArgs e)
{
_MouseDown = true;
//Console.WriteLine("vvvvvvvvvv StepRTB Mouse Down id= {0}",MyItemInfo.ItemID);
bool inPsi = this.Parent.FindForm().Name.Contains("frmPSI");
if (!_ContextMenuStripChanged)
@ -1932,6 +1932,12 @@ namespace Volian.Controls.Library
private bool IsControlChar = false;
private bool _SendBackSpace = false;
private int _ImageWidth = 0;
public int ImageWidth
{
get { return _ImageWidth; }
set { _ImageWidth = value; }
}
void StepRTB_KeyDown(object sender, KeyEventArgs e)
{
// added jcb 20130103 to support set ro from word doc with annotation when right click menu is opened by keyboard
@ -1980,6 +1986,15 @@ namespace Volian.Controls.Library
// maps the Ctrl-V to btnPaste for those StepRTB's that are associated with the StepTabRibbon, i.e.
// EditItems & Grid cells.
IDataObject iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Dib)) // Device Independent Bitmap
{
System.Drawing.Image img = Clipboard.GetImage();
ImageWidth = img.Width;
Width = ImageWidth + 2;
Paste();
}
else
{
if (!iData.GetDataPresent(DataFormats.Text) && !iData.GetDataPresent(DataFormats.Rtf))
{
MessageBox.Show("Cannot paste, text has special characters or symbols that will not paste correctly.");
@ -1990,6 +2005,7 @@ namespace Volian.Controls.Library
if (!PasteRtfAsText(true)) Paste();
if (SelectionLength == 0) SelectionFont = MyStyleFont.WindowsFont;
}
}
e.Handled = true;
return;
case Keys.Home:

View File

@ -927,6 +927,8 @@ namespace Volian.Controls.Library
// monitor is different than the DPI setting saved in the grid record, table height/width of rows/columns
// will be incorrect, i.e. lots of extra white space. The reason behind this is that the height/width
// of table cells are stored as dots (from the monitor) in the underlying component one flexgrid.
try
{
str = AdjustHeightAndWidthForDPI(str);
using (StringReader sr = new StringReader(str))
{
@ -935,6 +937,11 @@ namespace Volian.Controls.Library
sr.Close();
}
}
catch
{
;
}
}
private string AdjustHeightAndWidthForDPI(string str)
{
@ -1087,6 +1094,7 @@ namespace Volian.Controls.Library
CellRange cr = GetMergedRange(Row, Col);
int oH = cr.UserData == null ? curHeight : (int)cr.UserData;
int nH = _tableCellEditor.Height; //.ContentsRectangle.Height;
int nW = _tableCellEditor.Width; // Width
int Hadj = (nH - curHeight);//oH);
cr.UserData = _tableCellEditor.Height; //.ContentsRectangle.Height;
//int cellHeight = GetCellHeight(Row, Col);
@ -1112,6 +1120,10 @@ namespace Volian.Controls.Library
AdjustGridControlSize();
}
}
if (_tableCellEditor is StepRTB && (_tableCellEditor as StepRTB).ImageWidth > 0)
{
Width = Cols[0].Width = (_tableCellEditor as StepRTB).ImageWidth;
}
}
void VlnFlexGrid_KeyUp(object sender, KeyEventArgs e)
{

View File

@ -512,12 +512,13 @@ namespace Volian.Print.Library
}
private void TrimNewlines(Paragraph myPara)
{
while (myPara.Chunks.Count > 0 && ParaEndsWithNewLine(myPara))
myPara.RemoveAt(myPara.Chunks.Count - 1);
while (myPara.Count > 0 && ParaEndsWithNewLine(myPara))
myPara.RemoveAt(myPara.Count - 1);
}
private bool ParaEndsWithNewLine(Paragraph myPara)
{
Chunk chk = myPara.Chunks[myPara.Chunks.Count - 1] as Chunk;
Chunk chk = myPara[myPara.Count - 1] as Chunk;
if (chk == null) return false;
if (chk.Content == "\n") return true;
return false;
}
@ -1056,6 +1057,17 @@ namespace Volian.Print.Library
MyPara.MultipliedLeading *= _MyPageHelper.YMultiplier;
vlnCells.FixHyphens(MyPara, MyTable);
myColumnText1.AddElement(MyPara);
foreach(object obj in MyPara)
{
if(obj is iTextSharp.text.Image)
{
iTextSharp.text.Image img = obj as iTextSharp.text.Image;
img.SetAbsolutePosition(left,top-h);
img.ScaleAbsoluteWidth(w);
img.ScaleAbsoluteHeight(h);
myColumnText.Canvas.AddImage(img);
}
}
float posBefore = myColumnText1.YLine; // RHM20150429 - Table Scrunch
myColumnText1.Go();
float posAfter = myColumnText1.YLine; // RHM20150429 - Table Scrunch

View File

@ -152,7 +152,7 @@ namespace Volian.Print.Library
switch (visualBreak.BreakKind)
{
case RtfVisualBreakKind.Line:
Chunk ck = new Chunk("".PadLeft(200));
Chunk ck = HasIndent ? new Chunk("".PadLeft(200)) : new Chunk("".PadLeft(200));
_MyParagraph.Add(ck);
break;
case RtfVisualBreakKind.Page:
@ -392,21 +392,23 @@ namespace Volian.Print.Library
// ----------------------------------------------------------------------
protected override void DoVisitImage(IRtfVisualImage visualImage)
{
_MyParagraph.Add(new Chunk("<Image>"));
//WriteStartElement("rtfVisualImage");
//_MyParagraph.Add(new Chunk("<Image>"));
DateTime dt1 = DateTime.Now;
//System.Drawing.Image img2 = visualImage.ImageForDrawing;
//Console.WriteLine("1 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
//img2.Save(@"c:\datacvrt\x.png");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
//WriteElementString("format", visualImage.Format.ToString());
//WriteElementString("width", visualImage.Width.ToString());
//WriteElementString("height", visualImage.Height.ToString());
//WriteElementString("desiredWidth", visualImage.DesiredWidth.ToString());
//WriteElementString("desiredHeight", visualImage.DesiredHeight.ToString());
//WriteElementString("scaleWidthPercent", visualImage.ScaleWidthPercent.ToString());
//WriteElementString("scaleHeightPercent", visualImage.ScaleHeightPercent.ToString());
//WriteElementString("alignment", visualImage.Alignment.ToString());
//WriteElementString("image", visualImage.ImageDataHex.ToString());
//WriteEndElement();
//Console.WriteLine("2 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
Console.WriteLine("Size {0}", visualImage.ImageForDrawing.Size);
visualImage.ImageForDrawing.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
//Console.WriteLine("3 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
ms.Seek(0, System.IO.SeekOrigin.Begin);
//Console.WriteLine("4 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms);
//Console.WriteLine("5 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
_MyParagraph.Add(img);
Console.WriteLine("6 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
} // DoVisitImage
}