CSLA - Extension
This commit is contained in:
@@ -12,19 +12,10 @@ namespace VEPROMS.CSLA.Library
|
||||
Rtf = rtf;
|
||||
WithBorder = withBorder;
|
||||
}
|
||||
private string _Rtf;
|
||||
public string Rtf
|
||||
{
|
||||
get { return _Rtf; }
|
||||
set { _Rtf = value; }
|
||||
}
|
||||
private bool _WithBorder;
|
||||
public bool WithBorder
|
||||
{
|
||||
get { return _WithBorder; }
|
||||
set { _WithBorder = value; }
|
||||
}
|
||||
private RtfLines _Lines;
|
||||
|
||||
public string Rtf { get; set; }
|
||||
public bool WithBorder { get; set; }
|
||||
private RtfLines _Lines;
|
||||
public RtfLines Lines
|
||||
{
|
||||
get
|
||||
@@ -43,11 +34,8 @@ namespace VEPROMS.CSLA.Library
|
||||
Lines.Add(new RtfLine(maxWidth, WithBorder ? @"\u9492?" : " ", WithBorder ? @"\u9472?" : " ", WithBorder ? @"\u9496?" : " ")); // Insert bottom line
|
||||
Lines.ReplaceLines(WithBorder);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Lines.ToString();
|
||||
}
|
||||
}
|
||||
public override string ToString() => Lines.ToString();
|
||||
}
|
||||
public class RtfLines : List<RtfLine>
|
||||
{
|
||||
public static Regex _RegReplaceLine = new Regex(@"\\line((\\[^ \[\]\\\(\)]*) )");
|
||||
@@ -58,7 +46,6 @@ namespace VEPROMS.CSLA.Library
|
||||
// split text into lines
|
||||
string[] breaks = { "\r\n" };
|
||||
string[] lines = txt.Split(breaks, StringSplitOptions.None);
|
||||
//string lastLine = lines[lines.Length - 1];
|
||||
foreach (string line in lines)
|
||||
Add(new RtfLine(line.Replace("\\bullet","*")));
|
||||
}
|
||||
@@ -89,19 +76,19 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
private static Regex _RegRightCheck = new Regex(@"-|\\u9472?|\\u8209\?");
|
||||
private static Regex _RegAboveCheck = new Regex(@"\||\\u9474\?|\\u9492\?|\\u9516\?|\\u9532\?|\\u9500\?|\\u9484\?|\\u9524\?|\\u9488\?|\\u9508\?");
|
||||
private static Regex _RegLeftCheck = new Regex(@"-|\\u9472\?|\\u9508\?|\\u9516\?|\\u9500\?|\\u9532\?|\\u9484\?|\\u9488\?|\\u9492\?|\\u8209\?");
|
||||
private static Regex _RegBelowCheck = new Regex(@"\||\\u9474\?");
|
||||
private static readonly Regex _RegRightCheck = new Regex(@"-|\\u9472?|\\u8209\?");
|
||||
private static readonly Regex _RegAboveCheck = new Regex(@"\||\\u9474\?|\\u9492\?|\\u9516\?|\\u9532\?|\\u9500\?|\\u9484\?|\\u9524\?|\\u9488\?|\\u9508\?");
|
||||
private static readonly Regex _RegLeftCheck = new Regex(@"-|\\u9472\?|\\u9508\?|\\u9516\?|\\u9500\?|\\u9532\?|\\u9484\?|\\u9488\?|\\u9492\?|\\u8209\?");
|
||||
private static readonly Regex _RegBelowCheck = new Regex(@"\||\\u9474\?");
|
||||
|
||||
private static Regex _RegRightCheck1 = new Regex(@"\\u9474\?");
|
||||
private static Regex _RegAboveCheck1 = new Regex(@"\\u9472\?|\\u8209\?");
|
||||
private static Regex _RegLeftCheck1 = new Regex(@"\\u9474\?");
|
||||
private static Regex _RegBelowCheck1 = new Regex(@"\\u9472\?|\\u8209\?");
|
||||
private static readonly Regex _RegRightCheck1 = new Regex(@"\\u9474\?");
|
||||
private static readonly Regex _RegAboveCheck1 = new Regex(@"\\u9472\?|\\u8209\?");
|
||||
private static readonly Regex _RegLeftCheck1 = new Regex(@"\\u9474\?");
|
||||
private static readonly Regex _RegBelowCheck1 = new Regex(@"\\u9472\?|\\u8209\?");
|
||||
|
||||
private static Regex _RegHorizontalCheck = new Regex(@"-|\\u9472\?|\\u8209\?");
|
||||
private static Regex _RegVerticalCheck = new Regex(@"\||\\u9474\?");
|
||||
static private string[] TableCharsU = {
|
||||
private static readonly Regex _RegHorizontalCheck = new Regex(@"-|\\u9472\?|\\u8209\?");
|
||||
private static readonly Regex _RegVerticalCheck = new Regex(@"\||\\u9474\?");
|
||||
private static readonly string[] TableCharsU = {
|
||||
"\x0", // HEX"\x0", // No character
|
||||
@"\u9472?", // HEX@"\u2500",// - Horizontal line - 16-bit char: '\xC4'
|
||||
@"\u9474?", // HEX@"\u2502",// | Vertical line - 16-bit char: '\xB3'
|
||||
@@ -159,24 +146,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ListItems(string loc, string str)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(string.Format("{0} = @\"", loc));
|
||||
string sep = "";
|
||||
foreach (char c in str)
|
||||
{
|
||||
if (c < 127)
|
||||
sb.Append(sep + c.ToString());
|
||||
else
|
||||
sb.Append(sep + string.Format("\\u{0}?", (int)c));
|
||||
sep = "|";
|
||||
}
|
||||
Console.WriteLine(sb.ToString());
|
||||
}
|
||||
}
|
||||
public class RtfLine : List<RtfPiece>
|
||||
{
|
||||
private static Regex _RegRtfText = new Regex(@"((\\[^'u ]*|\\up[0-9]|\\ul|\\ulnone)+( |$|(?=\\['u])))?(<START\]|#Link.*?\[END>|\\'[0-9a-fA-F]{2}|\\u[0-9]*\?|[^\\]{1}|$|)");
|
||||
private static readonly Regex _RegRtfText = new Regex(@"((\\[^'u ]*|\\up[0-9]|\\ul|\\ulnone)+( |$|(?=\\['u])))?(<START\]|#Link.*?\[END>|\\'[0-9a-fA-F]{2}|\\u[0-9]*\?|[^\\]{1}|$|)");
|
||||
public RtfLine(string text)
|
||||
{
|
||||
MatchCollection matches = _RegRtfText.Matches(text);
|
||||
@@ -192,15 +165,13 @@ namespace VEPROMS.CSLA.Library
|
||||
nextIndex = match.Index + match.Length;
|
||||
string rtfPart = match.Groups[1].ToString();
|
||||
if (match.Groups[1].ToString().TrimEnd(" ".ToCharArray()).Length + match.Groups[4].ToString().Length > 0)
|
||||
this.Add(new RtfPiece(match.Groups[1].ToString().TrimEnd(" ".ToCharArray()), match.Groups[4].ToString()));
|
||||
//if (match.Groups[1].ToString().Length + match.Groups[4].ToString().Length > 0)
|
||||
// this.Add(new RtfPiece(match.Groups[1].ToString(), match.Groups[4].ToString()));
|
||||
Add(new RtfPiece(match.Groups[1].ToString().TrimEnd(" ".ToCharArray()), match.Groups[4].ToString()));
|
||||
}
|
||||
}
|
||||
public RtfLine(int width, string left, string fill, string right)
|
||||
{
|
||||
Add(new RtfPiece("", left));
|
||||
for (int i = 0; i < width; i++) this.Add(new RtfPiece("", fill)); // Pad
|
||||
for (int i = 0; i < width; i++) Add(new RtfPiece("", fill)); // Pad
|
||||
Add(new RtfPiece("", right));
|
||||
}
|
||||
public int MaximumWidth
|
||||
@@ -223,9 +194,9 @@ namespace VEPROMS.CSLA.Library
|
||||
internal void Pad(int maxWidth, string edge)
|
||||
{
|
||||
int pad = maxWidth - MaximumWidth;
|
||||
this.Insert(0, new RtfPiece("", edge)); // Left Edge
|
||||
for (int i = 0; i < pad; i++) this.Add(new RtfPiece("", " ")); // Pad
|
||||
this.Add(new RtfPiece("", edge)); // Right Edge
|
||||
Insert(0, new RtfPiece("", edge)); // Left Edge
|
||||
for (int i = 0; i < pad; i++) Add(new RtfPiece("", " ")); // Pad
|
||||
Add(new RtfPiece("", edge)); // Right Edge
|
||||
}
|
||||
public new RtfPiece this[int index]
|
||||
{
|
||||
@@ -246,61 +217,23 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public class RtfPiece
|
||||
{
|
||||
private string _Rtf;
|
||||
public string Rtf
|
||||
{
|
||||
get { return _Rtf; }
|
||||
set { _Rtf = value; }
|
||||
}
|
||||
private string _Text = "";
|
||||
public string Text
|
||||
{
|
||||
get { return _Text; }
|
||||
set { _Text = value; }
|
||||
}
|
||||
public int TextLength
|
||||
{
|
||||
get { return Text.Length; }
|
||||
}
|
||||
public int MaximumWidth
|
||||
{
|
||||
get { return Text == "" ? 0 : 1; }
|
||||
}
|
||||
private static Regex _RegStartLink = new Regex(@"<START\]");
|
||||
private static Regex _RegEndLink = new Regex(@"#Link.*?\[END>");
|
||||
public string Rtf { get; set; }
|
||||
public string Text { get; set; } = "";
|
||||
public int TextLength => Text.Length;
|
||||
public int MaximumWidth => Text == "" ? 0 : 1;
|
||||
private static readonly Regex _RegStartLink = new Regex(@"<START\]");
|
||||
private static readonly Regex _RegEndLink = new Regex(@"#Link.*?\[END>");
|
||||
public RtfPiece(string rtf, string text)
|
||||
{
|
||||
_Rtf = rtf;
|
||||
Rtf = rtf;
|
||||
if (_RegStartLink.IsMatch(text) || _RegEndLink.IsMatch(text))
|
||||
_Rtf += (rtf == "" ? "" : " ") + text;
|
||||
Rtf += (rtf == "" ? "" : " ") + text;
|
||||
else
|
||||
{
|
||||
_Rtf += rtf == "" ? "" : " ";
|
||||
_Text = text;
|
||||
Rtf += rtf == "" ? "" : " ";
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return _Rtf + _Text;
|
||||
//string retval = _RegUnicode.Replace(_Text, new MatchEvaluator(RtfUnicodeCharacter));
|
||||
//retval = _RegHex.Replace(retval, new MatchEvaluator(RtfHexCharacter));
|
||||
//return retval;
|
||||
}
|
||||
//private static Regex _RegUnicode = new Regex(@"\\u([0-9ABCDEF]*)\?");
|
||||
//internal static string RtfUnicodeCharacter(Match myMatch)
|
||||
//{
|
||||
// string hexStr = myMatch.Groups[1].ToString();
|
||||
// int i = int.Parse(hexStr);
|
||||
// Char schar = Convert.ToChar(i);
|
||||
// return schar.ToString();
|
||||
//}
|
||||
//private static Regex _RegHex = new Regex(@"\\'([0-9A-Fa-f]{2})");
|
||||
//internal static string RtfHexCharacter(Match myMatch)
|
||||
//{
|
||||
// string hexStr = myMatch.Groups[1].ToString();
|
||||
// int i = int.Parse(hexStr, System.Globalization.NumberStyles.HexNumber);
|
||||
// Char schar = Convert.ToChar(i);
|
||||
// return schar.ToString();
|
||||
//}
|
||||
}
|
||||
public override string ToString() => Rtf + Text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user