TextStyle.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System;
  2. using System.Drawing;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7. using System.Threading.Tasks;
  8. namespace ConsoleApplication
  9. {
  10. public class TextStyle
  11. {
  12. private Boolean _bold, _underline, _italic;
  13. private int _fontSize;
  14. private string _font, _fontColor, _alignment;
  15. private XmlDocument _rootOfDocument;
  16. public TextStyle()
  17. {
  18. _bold = false;
  19. _underline = false;
  20. _italic = false;
  21. _fontSize = 0;
  22. _fontColor = "";
  23. _font = "Arial";
  24. _alignment = "";
  25. }
  26. public string attrubiteValue()
  27. {
  28. string style = "k";
  29. if(_bold)
  30. style += "b";
  31. if(_underline)
  32. style += "u";
  33. if(_italic)
  34. style += "i";
  35. return _font + "," + _fontSize.ToString() + "," + _fontColor.ToString() + "," + style;
  36. }
  37. private XmlAttribute getStylesAttributes()
  38. {
  39. XmlAttribute attrStyle = _rootOfDocument.CreateAttribute("style");
  40. attrStyle.Value = attrubiteValue();
  41. return attrStyle;
  42. }
  43. public XmlElement getStylesChild()
  44. {
  45. XmlElement child = _rootOfDocument.CreateElement("s");
  46. child.Attributes.Append(getStylesAttributes());
  47. return child;
  48. }
  49. public XmlElement getFontNode()
  50. {
  51. XmlElement FONT = _rootOfDocument.CreateElement("FONT");
  52. return FONT;
  53. }
  54. public string getTextNode(string text)
  55. {
  56. string temp = text;
  57. if (Bold)
  58. temp = "<B>" + text + "</B>";
  59. if(Italic)
  60. temp = "<I>" + text + "</I>";
  61. if(Underline)
  62. temp = "<U>" + text + "</U>";
  63. return temp;
  64. }
  65. public void setXMLDocumentRoot(ref XmlDocument rootOfDocument)
  66. {
  67. _rootOfDocument = rootOfDocument;
  68. }
  69. public string Font
  70. {
  71. get { return _font; }
  72. set { _font = value; }
  73. }
  74. public string FontColor
  75. {
  76. get { return _fontColor; }
  77. set { _fontColor = value; }
  78. }
  79. public int FontColorInteger()
  80. {
  81. return int.Parse(_fontColor, System.Globalization.NumberStyles.HexNumber);
  82. }
  83. public int FontSize
  84. {
  85. get { return _fontSize; }
  86. set { _fontSize = value; }
  87. }
  88. public Boolean Italic
  89. {
  90. get { return _italic; }
  91. set { _italic = value; }
  92. }
  93. public Boolean Underline
  94. {
  95. get { return _underline; }
  96. set { _underline = value; }
  97. }
  98. public Boolean Bold
  99. {
  100. get { return _bold; }
  101. set { _bold = value; }
  102. }
  103. public bool isEqual(object obj)
  104. {
  105. TextStyle other = obj as TextStyle;
  106. if (other == null)
  107. return false;
  108. if ((Font == other.Font) && (FontColor == other.FontColor) && (FontSize == other.FontSize) && (Italic == other.Italic) && (Underline == other.Underline) && (Bold == other.Bold) && (Alignment == other.Alignment))
  109. {
  110. return true;
  111. }
  112. else
  113. {
  114. return false;
  115. }
  116. /* return (Font == other.Font)
  117. && (FontColor == other.FontColor)
  118. && (FontSize == other.FontSize)
  119. && (Italic == other.Italic)
  120. && (Underline == other.Underline)
  121. && (Bold == other.Bold);*/
  122. }
  123. public string Alignment
  124. {
  125. get { return _alignment; }
  126. set {
  127. if(value.ToLower() == "r" || value.ToLower() == "right")
  128. _alignment = "right";
  129. if (value.ToLower() == "l" || value.ToLower() == "left")
  130. _alignment = "left";
  131. if (value.ToLower() == "c" || value.ToLower() == "ctr" || value.ToLower() == "center")
  132. _alignment = "center";
  133. }
  134. }
  135. //public static bool operator ==(TextStyle x, TextStyle y)
  136. //{
  137. // if (x == null || y == null)
  138. // return false;
  139. // return (x.Font == y.Font)
  140. // && (x.FontColor == y.FontColor)
  141. // && (x.FontSize == y.FontSize)
  142. // && (x.Italic == y.Italic)
  143. // && (x.Underline == y.Underline)
  144. // && (x.Bold == y.Bold);
  145. //}
  146. //public static bool operator !=(TextStyle x, TextStyle y)
  147. //{
  148. // if (x == null || y == null)
  149. // return false;
  150. // return !(x == y);
  151. //}
  152. public string toString()
  153. {
  154. return "Font: " + _font + "\n" +
  155. "Size: " + _fontSize + "\n" +
  156. "Color: " + _fontColor + "\n" +
  157. "B U I: (" + _bold + ", " + _underline + ", " + _italic + ") \n";
  158. }
  159. }
  160. }