HtmlText.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Text;
  3. using ClearSlideLibrary.Dom;
  4. namespace ClearSlideLibrary.HtmlController
  5. {
  6. internal class HtmlText : HtmlPresentationElement
  7. {
  8. public string id { get; set; }
  9. public string Text { get; set; }
  10. public bool PictureBullet { get; set; }
  11. public bool isBullet { get; set; }
  12. public const int DefaultBulletSize = 12;
  13. public int bulletSize { get; set; }
  14. private bool bold;
  15. private bool italic;
  16. private string underline;
  17. public int slideIndex;
  18. public int width { get; set; }
  19. public double Rotate { get; set; }
  20. public void setLeft(int newLeft)
  21. {
  22. left = newLeft;
  23. }
  24. public HtmlText(int left, int top, string fontFamily, string fontColor, double fontSize, bool isBullet,
  25. bool bold, bool italic, string underline, string id, int slideIndex)
  26. {
  27. base.fontSize = fontSize;
  28. base.left = left;
  29. base.top = top;
  30. base.fontFamily = fontFamily;
  31. this.isBullet = isBullet;
  32. base.fontColor = fontColor;
  33. this.bold = bold;
  34. this.italic = italic;
  35. this.id = id;
  36. this.slideIndex = slideIndex;
  37. if (underline != null)
  38. {
  39. if (underline.Equals("Single"))
  40. {
  41. this.underline = "underline";
  42. }
  43. else if (underline.Equals("None"))
  44. {
  45. this.underline = "none";
  46. }
  47. }
  48. else this.underline = "none";
  49. }
  50. public override string DrawElement()
  51. {
  52. if (id != null)
  53. {
  54. id = id.Substring(3);
  55. int tryParse = 0;
  56. if (int.TryParse(id, out tryParse))
  57. {
  58. if (PPTShape.effectShapes.Contains(slideIndex + "_" + tryParse))
  59. {
  60. return "";
  61. }
  62. }
  63. }
  64. string rot = "";
  65. if (Rotate != 0.0)
  66. {
  67. rot = "-o-transform:rotate(" + Rotate + "deg);-ms-transform:rotate(" + Rotate + "deg);-moz-transform:rotate(" + Rotate + "deg);-webkit-transform:rotate(" + Rotate + "deg);";
  68. }
  69. StringBuilder textBuilder = new StringBuilder();
  70. if (Text != null)
  71. {
  72. if (PictureBullet)
  73. {
  74. textBuilder.Append("<pre style=\"top:" + top.ToString() + "px;left:" + left.ToString() + "px;" + rot + "\">");
  75. textBuilder.Append("<br/><img width=\"" + bulletSize + "\" height=\"" + bulletSize + "\" src="+Text+">");
  76. textBuilder.Append("</pre>");
  77. }
  78. else
  79. {
  80. textBuilder.Append("<pre style=\"top:" + top.ToString() + "px;left:" + left.ToString() + "px; font-size:" + fontSize.ToString() + "px; color:" + fontColor + (italic ? ";font-style:italic" : "") + (bold ? ";font-weight:bold" : "") +(this.underline.Equals("none") ? "": ";text-decoration:" + this.underline) + ";font-family:" + fontFamily + ";" + rot + "\">");
  81. textBuilder.Append(Text);
  82. textBuilder.Append("</pre>");
  83. }
  84. }
  85. return textBuilder.ToString();
  86. }
  87. public override string ToString()
  88. {
  89. Console.WriteLine("The top is:" + top);
  90. Console.WriteLine("The left is:" + left);
  91. Console.WriteLine("The text is:" + Text);
  92. Console.WriteLine("The text color is:" + fontColor);
  93. Console.WriteLine("The text size is:" + fontSize);
  94. Console.WriteLine("The text family is:" + fontFamily);
  95. Console.WriteLine("The height is:" + height);
  96. return string.Format("[{0}, {1}, {2}, {3}, {4}, {5}]",
  97. top, left, Text, fontColor, fontSize, fontFamily);
  98. }
  99. public bool sameProps(HtmlText other)
  100. {
  101. if (other == null)
  102. {
  103. return false;
  104. }
  105. return this.top == other.top
  106. && this.fontSize == other.fontSize
  107. && this.fontColor == other.fontColor
  108. && this.italic == other.italic
  109. && this.bold == other.bold
  110. && this.underline == other.underline
  111. && this.fontFamily == other.fontFamily;
  112. }
  113. }
  114. }