Merge pull request 'B2023-095_U2022-004 - When Copy/Pasting Symbols, some of the symbols paste in an incorrect font' (#473) from B2023-095_U2022-004 into Development

good for testing phase
This commit is contained in:
John Jenko 2024-11-25 14:51:35 -05:00
commit 6bf116cbef
3 changed files with 39 additions and 60 deletions

View File

@ -17,10 +17,10 @@ namespace Volian.Base.Library
return new List<string>(text.Split(mySplit, StringSplitOptions.None));
}
int width = 0; // width of text, non-rtf
int start = 0; // start of line (index into string 'text'), includes rtf
int lastspace = 0; // location of lastspace (index into string 'text'), includes rtf
int startNonRtf = 0; // start of line, non-rtf (used for determining starting position to determine width if there was a break)
int width = 0; // width of text, non-rtf
int start = 0; // start of line (index into string 'text'), includes rtf
int lastspace = 0; // location of lastspace (index into string 'text'), includes rtf
int startNonRtf = 0; // start of line, non-rtf (used for determining starting position to determine width if there was a break)
string rtfprefix = "";
string nextprefix = "";
for (int indx = 0; indx < text.Length; indx++)
@ -125,32 +125,9 @@ namespace Volian.Base.Library
// converting the unicode \u8482? to \'99, but once this is done, PROMS StepRTB (edit windows) does not show it
rtnStr = rtnStr.Replace(@"\'99", @"\u8482?");
// convert \'ae to \u174? this is for the registered symbol. RTF converts the unicode character to \'ae
rtnStr = rtnStr.Replace(@"\'ae",@"\u174?");
rtnStr = rtnStr.Replace(@"\'ae", @"\u174?");
// convert \'a9 to \u169? this is for the copyright symbol. RTF converts the unicode character to \'a9
rtnStr = rtnStr.Replace(@"\'a9",@"\u169?");
// B2021-039: paste of the greek symbols was not working correctly, RTF was converting unicode, similar to above
// B2022-052: Division symbol converted to an x, caused by fix B2021-039. The code below was translating the division
// symbol but it should only be translated if the character's font is Greek or Baltic. Unfortunately this is not
// a complete solution since it converts characters it shouldn't, for example, using the following steps: all
// of Proms symbols are entered into a step; a ctrl-a/ctrl-c is used to copy these and then ctrl-v to paste
// into another new step. The paste (from the underlying richtextbox) causes some characters to be in plain
// arial font, and others to be in arial with Greek flag. Some character codes exist in each font, for example f7.
// The code below does not look into what font is used, just converts the character. Since any kind of font
// can occur during paste, if from an external program, a message will be given stating that a symbol may be incorrect
// because an unsupported font was pasted. It was felt that this was sufficient based on estimate of fix versus chance of
// occurrence. Note that the message was moved into StepRTB since this code is called by non-UI code (5/26/22)
if (str.ToUpper().Contains("GREEK") || str.ToUpper().Contains("BALTIC"))
{
//System.Windows.Forms.MessageBox.Show("Pasted text may use an unsupported font so some characters may not paste correctly and may require delete/reenter of character from within Proms.",
// "Paste Font Issue", System.Windows.Forms.MessageBoxButtons.OK);
for (int i = 0; i < 26; i++)
{
rtnStr = rtnStr.Replace(string.Format("\\'{0:x2}", 0xc0 + i) // upper case Greek
, string.Format("\\u{0}?", 912 + i));
rtnStr = rtnStr.Replace(string.Format("\\'{0:x2}", 0xe0 + i) // lower case Greek
, string.Format("\\u{0}?", 944 + i));
}
}
rtnStr = rtnStr.Replace(@"\'a9", @"\u169?");
return rtnStr;
}
}

View File

@ -11,6 +11,7 @@ using System.Text.RegularExpressions;
using VEPROMS.CSLA.Library;
using Volian.Base.Library;
using JR.Utils.GUI.Forms;
using System.Linq;
namespace Volian.Controls.Library
{
@ -2855,7 +2856,10 @@ namespace Volian.Controls.Library
return false;
}
public string GetPasteText(bool PasteNoReturnsSetting, IDataObject myDO)
//CSM B2023-095/U2022-004 When Copy/Pasting Symbols, some of the symbols paste in an incorrect font
// Changed this to put in the unicode code for any symbols outside the normal ascii range
// if supplied convertunicode flag is true
public string GetPasteText(bool PasteNoReturnsSetting, IDataObject myDO, bool convertunicode = false)
{
// B2021-0039: symbols not pasting correctly from ctrl-v:
// get base list of valid symbols, use base format if MyItemInfo is null. Use symbols from
@ -2871,40 +2875,31 @@ namespace Volian.Controls.Library
ptext = ptext.TrimEnd("\r\n\t ".ToCharArray());
if (PasteNoReturnsSetting) ptext = ptext.Replace("\r\n", " ");
StringBuilder sb = new StringBuilder();
bool didCharReplace = false;
StringBuilder sb = new StringBuilder();
bool hasBadChar = false;
for (int i = 0; i < ptext.Length; i++)
{
didCharReplace = false;
string sym = string.Format(@"{0}", Convert.ToInt32(ptext[i]));
if ((ptext[i] > 0x7e))
foreach (char c in ptext)
{
if ((c > 0x7e))
{
// is this an allowable symbol/character:
for (int j = 0; j < sl.Count; j++)
{
if (sym == allowableSymbols[j])
{
sb = sb.Append((char)(Convert.ToInt32(allowableSymbols[j])));
didCharReplace = true;
break;
}
}
// if not allowable, put in a "?" and give a message to user (below)
if (!didCharReplace)
if (allowableSymbols.Any(x => x == $@"{(short)c}"))
{
if (convertunicode)
sb.Append($"\\u{(short) c}?");
else
sb.Append(c);
}
else
{
sb = sb.Append("?");
didCharReplace = true;
hasBadChar = true;
sb.Append("?");
}
}
if (!didCharReplace)
sb = sb.Append(ptext[i]);
}
if (!didCharReplace)
sb = sb.Append(ptext[i]);
}
ptext = sb.ToString();
ptext = ptext.Replace("\u2013", "-"); // Replace EN Dash with hyphen
else
sb.Append(c);
}
ptext = sb.ToString();
ptext = ptext.Replace("\u2013", "-"); // Replace EN Dash with hyphen
ptext = ptext.Replace("\u2014", "-"); // Replace EM Dash with hyphen
ptext = ptext.Replace("\u2011", "-"); // Replace non-breaking hyphen with hyphen
ptext = ptext.Replace("\u2572", "\\"); // Replace backslash symbol with backslash character

View File

@ -2883,12 +2883,19 @@ namespace Volian.Controls.Library
tmpForLink = ItemInfo.ReplaceLinkWithNewID(tmpForLink);
myRtb.SelectedRtf = tmpForLink;
// Fix for B2014-071: if link, save after paste so that goto's don't crash (grid & step run through this code)
if (tmpForLink.Contains("<NewID>")) _MyStepRTB.OnDoSaveContents(this, new EventArgs());
if (tmpForLink.Contains("<NewID>")) _MyStepRTB.OnDoSaveContents(this, new EventArgs());
}
}
else if (myDO.GetDataPresent(DataFormats.Text))
myRtb.SelectedText = _MyStepRTB.GetPasteText(PasteNoReturnsSetting, myDO);
{
//CSM B2023-095/U2022-004 When Copy/Pasting Symbols, some of the symbols paste in an incorrect font
// Changed this to put in the unicode code for any symbols outside the normal ascii range
// Also need to input as an RTF so that correct font is used with these
// and unicode is converted to actual text
string clipboardtext = _MyStepRTB.GetPasteText(PasteNoReturnsSetting, myDO, true);
myRtb.SelectedRtf = _MyStepRTB.RtfPrefixForSymbols + clipboardtext + @"}";
}
if (myRtb.SelectionLength == 0 && myRtb is StepRTB) myRtb.SelectionFont = (myRtb as StepRTB).MyStyleFont.WindowsFont;
_PastePlainTextOvrRide = false;
_PasteStepTextOvrRide = false;