From bba52a736a22960efc1b71c475a6fdaac8bef261 Mon Sep 17 00:00:00 2001 From: mschill Date: Tue, 3 Dec 2024 15:12:04 -0500 Subject: [PATCH] =?UTF-8?q?B2024-003=5FB2023-113=5FB2024-093=20Updating=20?= =?UTF-8?q?RO=20Values=20inside=20a=20text=20Grid,=20adding=20a=20caret=20?= =?UTF-8?q?and/or=20dash=20into=20the=20RO=20value=20and=20then=20updating?= =?UTF-8?q?=20RO=20values=20changed=20to=20question=20marks=20in=20the=20U?= =?UTF-8?q?I.=20This=20also=20fixes=20restoring=20a=20deleted=20RO=20table?= =?UTF-8?q?=20column=20that=20has=20a=20hyphen=20in=20it.=20Also,=20Dashes?= =?UTF-8?q?/Hyphens=20and=20Carets=20in=20RO=20TABLES=20were=20behaving=20?= =?UTF-8?q?differently=20in=20different=20data=20sets=20due=20to=20differe?= =?UTF-8?q?nt=20fonts=20=E2=80=93=20this=20fixes=20so=20that=20carats=20wh?= =?UTF-8?q?en=20ConvertCaretToDelta=20is=20set=20in=20the=20format,=20will?= =?UTF-8?q?=20properly=20restore/store=20as=20Deltas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extension/ContentExt.cs | 103 +++++++++++++++++- 1 file changed, 97 insertions(+), 6 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs index 6194565b..b731c4ee 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -695,17 +695,28 @@ namespace VEPROMS.CSLA.Library if (m == null) newvalue = newvalue.Replace(@"\u8209?", "-"); else if (m.Groups[1].Value == "") - newvalue = newvalue.Replace(@"\u8209?", @"\f1\u8209?\f0 "); + newvalue = newvalue.Replace(@"\u8209?", "-"); else newvalue = newvalue.Replace(@"\u8209?", m.Groups[1].Value + @"\u8209?" + m.Groups[3].Value); } + int indx_to_addfont = -1; if (newvalue.Contains(@"\u916?")) { Match m = Regex.Match(newvalue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); if (m == null) newvalue = newvalue.Replace(@"\u916?", "^"); + else if (m.Groups[1].Value == "" && !ContentItems[0].MyItem.MyItemInfo.MyDocVersion.MyFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta) + newvalue = newvalue.Replace(@"\u916?", "^"); else if (m.Groups[1].Value == "") - newvalue = newvalue.Replace(@"\u916?", @"\f1\u916?\f0 "); + { + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // adding a caret and/or dash into the RO value and then updating RO values changed to question marks in the UI. + // This is to handle if ConvertCaretToDelta is true + // since delta is not part of the standard ascii + // may need to add a font to handle it. + newvalue = newvalue.Replace(@"\u916?", @"\f9\u916?\f0 "); + indx_to_addfont = GetLocationToInsertFontInGrid(myIndex); + } else newvalue = newvalue.Replace(@"\u916?", m.Groups[1].Value + @"\u916?" + m.Groups[3].Value); } @@ -715,7 +726,7 @@ namespace VEPROMS.CSLA.Library if (m == null) newvalue = newvalue.Replace(@"\u8593?", "^"); else if (m.Groups[1].Value == "") - newvalue = newvalue.Replace(@"\u8593?", @"\f1\u8593?\f0 "); + newvalue = newvalue.Replace(@"\u8593?", "^"); else newvalue = newvalue.Replace(@"\u8593?", m.Groups[1].Value + @"\u8593?" + m.Groups[3].Value); } @@ -725,7 +736,7 @@ namespace VEPROMS.CSLA.Library if (m == null) newvalue = newvalue.Replace(@"\u9586?", @"\\"); else if (m.Groups[1].Value == "") - newvalue = newvalue.Replace(@"\u9586?", @"\f1\u9586?\f0 "); + newvalue = newvalue.Replace(@"\u9586?", @"\\"); else newvalue = newvalue.Replace(@"\u9586?", m.Groups[1].Value + @"\u9586?" + m.Groups[3].Value); } @@ -737,7 +748,17 @@ namespace VEPROMS.CSLA.Library if (gg != newvalue) { retval = gg; - MyGrid.Data = MyGrid.Data.Substring(0, myIndex) + newvalue + MyGrid.Data.Substring(myIndex + myLength); + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // adding a caret and/or dash into the RO value and then updating RO values changed to question marks in the UI. + // This is to handle if ConvertCaretToDelta is true + // since delta is not part of the standard ascii + // may need to add a font to handle it. + string begin_str = MyGrid.Data.Substring(0, myIndex); + if (indx_to_addfont > -1) + begin_str = begin_str.Insert(indx_to_addfont, @"{\f9\fnil\fcharset0 FreeMono;}"); + + MyGrid.Data = begin_str + newvalue + MyGrid.Data.Substring(myIndex + myLength); + MyGrid.Save(); break; } } @@ -747,6 +768,64 @@ namespace VEPROMS.CSLA.Library return retval; } + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // adding a caret and/or dash into the RO value and then updating RO values changed to question marks in the UI. + // This is to handle if ConvertCaretToDelta is true + // since delta is not part of the standard ascii + // may need to add a font to handle it. + // startIndex = Index in the Grid at which the text we want to replace is starting + //basic Grid data partitioning using the variables in this sub is as follows: + // + // [indexOfPrefix] [indx] + // | | + // [text before last occurrence of prefix] {prefix} [rest of fonts] [text after fonts] + private int GetLocationToInsertFontInGrid(int startIndex) + { + //searches backwards from the srtIndex for the last previous occurrence of the prefix + string prefix = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{"; + int indexOfPrefix = MyGrid.Data.LastIndexOf(prefix, startIndex); + + //find the end of the font section + //by passing in the Grid data + //with the following removed: + // - Everything before the last occurrence of the prefix + // - the prefix itself removed + int indx = GetIndexOfCloseBracket(MyGrid.Data.Substring(indexOfPrefix + prefix.Length, startIndex - indexOfPrefix - prefix.Length)); + + if (indx > -1) + { + indx += indexOfPrefix; + indx += prefix.Length; + } + + //indx will contain last spot inside the font section + return indx; + + } + + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // this function will find the corresponding occurrence of a closing bracket : + // usage is you pass in some text after an opening bracket, and it will tell you what the index is for it closing + private int GetIndexOfCloseBracket(string text) + { + int indx = 0; + Stack stk = new System.Collections.Generic.Stack(); + + foreach (char c in text) + { + if (c == '{') + stk.Push('{'); + else if (c == '}' && stk.Count == 0) + return indx; + else if (c == '}') + stk.Pop(); + + indx++; + } + + return -1; + } + public static string MakeConsistentFormat(string gg) { // replace degree, bullet dash, hardspace @@ -1325,7 +1404,19 @@ namespace VEPROMS.CSLA.Library else newvalue = newvalue.Replace(@"\u8209?", m.Groups[1].Value + @"\u8209?" + m.Groups[3].Value); } - + //B2024-003, B2023-113, B2024-093 - Updating RO Values inside a text Grid, + // This will handle if there is a delta and the column/row of the grid is removed + //then restored from history + if (newvalue.Contains(@"\u916?")) + { + Match m = Regex.Match(gg, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); + if (m.Groups.Count < 3 && !ContentItems[0].MyDocVersion.MyFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta) + newvalue = newvalue.Replace(@"\u916?", "^"); + else if (m.Groups.Count < 3) + newvalue = newvalue.Replace(@"\u916?", $"{(char)916}"); + else + newvalue = newvalue.Replace(@"\u916?", m.Groups[1].Value + @"\u916?" + m.Groups[3].Value); + } if (newvalue.Contains(@"\u8593?")) { Match m = Regex.Match(newvalue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); -- 2.47.2