// // Copyright (c) PlaceholderCompany. All rights reserved. // using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace UCDraw.RTF { public class RtfElement { public static bool operator ==(RtfElement a, RtfElement b) { // If both are null, or both are same instance, return true. if (object.ReferenceEquals(a, b)) { return true; } return a.Equals(b); } public static bool operator !=(RtfElement a, RtfElement b) { return !(a == b); } } /// /// 1abcde /// public class RtfValueElement : RtfElement { public static bool operator ==(RtfValueElement a, RtfValueElement b) { // If both are null, or both are same instance, return true. return a.Equals(b); } public static bool operator !=(RtfValueElement a, RtfValueElement b) { return !(a == b); } public RtfValueElement() { } public RtfValueElement(string data) { this.Data = data; } public string Data { get; set; } public override bool Equals(System.Object obj) { // If both are null, or both are same instance, return true. if (object.ReferenceEquals(this, obj)) { return true; } // If parameter cannot be cast to RtfValueElement return false: RtfValueElement p = obj as RtfValueElement; if ((object)p == null) { return false; } // Return true if the fields match: return Data.Equals(p.Data); } /// public override string ToString() { return $"{Data}"; } } /// /// \ansi /// public class RtfControlElement : RtfElement { public override bool Equals(System.Object obj) { // If both are null, or both are same instance, return true. if (object.ReferenceEquals(this, obj)) { return true; } // If parameter cannot be cast to RtfValueElement return false: RtfControlElement p = obj as RtfControlElement; if ((object)p == null) { return false; } // Return true if the fields match: return ControlWord.Equals(p.ControlWord); } public RtfControlElement() { } public RtfControlElement(string controlWord) { this.ControlWord = controlWord; } public string ControlWord { get; set; } /// public override string ToString() { return $"\\{ControlWord}"; } } /// /// \rtf1 /// public class RtfControlNumElement : RtfControlElement { public override bool Equals(System.Object obj) { // If both are null, or both are same instance, return true. if (object.ReferenceEquals(this, obj)) { return true; } // If parameter cannot be cast to RtfValueElement return false: RtfControlNumElement p = obj as RtfControlNumElement; if ((object)p == null) { return false; } // Return true if the fields match: return ControlWord.Equals(p.ControlWord) && Number == p.Number; } public RtfControlNumElement() { } public RtfControlNumElement(string control, int number) { this.ControlWord = control; this.Number = number; } public int Number { get; set; } /// public override string ToString() { return $"\\{ControlWord}{Number}"; } } /// /// \'b1 \'a8 \'cb \'f7 \generator Riched20 10.0.19041 /// public class RtfControlDataElement : RtfControlElement { public override bool Equals(System.Object obj) { // If both are null, or both are same instance, return true. if (object.ReferenceEquals(this, obj)) { return true; } // If parameter cannot be cast to RtfValueElement return false: RtfControlDataElement p = obj as RtfControlDataElement; if ((object)p == null) { return false; } // Return true if the fields match: return ControlWord.Equals(p.ControlWord) && Data.Equals(p.Data); } public RtfControlDataElement() { } public RtfControlDataElement(string control, string data) { this.ControlWord = control; this.Data = data; } public string Data { get; set; } /// public override string ToString() { return $"\\{ControlWord}{Data}"; } } public class RtfControlSplitDataElement : RtfControlDataElement { public RtfControlSplitDataElement(string control, string data) : base(control, data) {; } public override string ToString() { return $"\\{ControlWord} {Data}"; } } public class RtfWChar : RtfControlDataElement { public RtfWChar() { this.ControlWord = "'"; } public RtfWChar(char[] chars) { Chars = chars; } public RtfWChar(string chars) : this(chars.ToCharArray()) { } private char[] chars; public char[] Chars { get { if (chars == null) { chars = new char[2]; } return chars; } set { if (chars == null) { chars = new char[2]; } chars[0] = value[0]; chars[1] = value[1]; this.ControlWord = "'"; this.Data = $"{chars[0]}{chars[1]}"; } } /// public override string ToString() { if (Chars == null || Chars.Length < 2) { return string.Empty; } return $"\\'{chars[0]}{chars[1]}"; } } }