B2020-018: table font size – short cut keys not catching limits & selection not kept when using buttons

This commit is contained in:
2020-02-13 13:46:09 +00:00
parent c4026b688e
commit 9fae7d8e38
3 changed files with 52 additions and 38 deletions

View File

@@ -2531,50 +2531,15 @@ namespace Volian.Controls.Library
MyStepRTB.Select(0, 0);
break;
}
SetFontSize(MyStepRTB, increase);
MyStepRTB.SetFontSize(increase);
}
MyFlexGrid.Select(cr);
}
else
SetFontSize(MyStepRTB, increase); // not in a grid, apply style to current step type
MyStepRTB.SetFontSize(increase); // not in a grid, apply style to current step type
}
else
SetFontSize(MyStepRTB, increase);
}
// SetFontSize: replace rtf string of selection or entire rtb
private void SetFontSize(StepRTB MyStepRTB, bool increase)
{
if (MyStepRTB.SelectedText == null || MyStepRTB.SelectedText == "")
MyStepRTB.Rtf = SetFontSizeReplace(MyStepRTB.Rtf, increase);
else
MyStepRTB.SelectedRtf = SetFontSizeReplace(MyStepRTB.SelectedRtf, increase);
}
// SetFontSizeReplace: for the input string, increase or decrease the font size - use a regular expression to get
// all current font sizes in the string & increase them all.
private string SetFontSizeReplace(string rtf, bool increase)
{
MatchCollection mc = Regex.Matches(rtf, @"\\fs([0-9]+)");
bool didMsg = false;
foreach (Match match in mc)
{
float sz = float.Parse(match.Groups[1].Value);
float repwith = increase ? sz + 1 : sz - 1;
if (repwith > 36 || repwith < 16) // Font size can be increased to 18 and decreased to 8 (note that \fs## has number 2 * pt)
{
if (!didMsg) // only put out message once.
{
MessageBox.Show(increase ? "Reached maximum font size, cannot increase." : "Reached minimum font size, cannot decrease.", "Warning font size change");
didMsg = true;
}
}
else
{
string repsz = match.Value; // use \fs## rather than number in replace in case text contains the number
string repwithsz = match.Value.Replace(sz.ToString(), ((int)repwith).ToString());
rtf = rtf.Replace(repsz, repwithsz);
}
}
return rtf;
MyStepRTB.SetFontSize(increase);
}
private void ToggleBold()
{