PPMLDocument.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Xml;
  5. using System.IO;
  6. using System.Drawing;
  7. using System.Globalization;
  8. using FastReport.Export.PS;
  9. namespace FastReport.Export.Ppml
  10. {
  11. /// <summary>
  12. /// Contains Dashes enum
  13. /// </summary>
  14. public enum Dashes
  15. {
  16. /// <summary>
  17. /// Specifies the Dash.
  18. /// </summary>
  19. Dash,
  20. /// <summary>
  21. /// Specifies the Dot.
  22. /// </summary>
  23. Dot,
  24. /// <summary>
  25. /// Specifies the DashDot.
  26. /// </summary>
  27. DashDot,
  28. /// <summary>
  29. /// Specifies the DashDotDot.
  30. /// </summary>
  31. DashDotDot,
  32. /// <summary>
  33. /// Specifies the Double line.
  34. /// </summary>
  35. Double
  36. }
  37. class PPMLDocument : PSDocument
  38. {
  39. private XmlAttribute nsAttribute;
  40. private XmlElement root;
  41. private List<XmlElement> pages = new List<XmlElement>();
  42. private XmlElement internalData;
  43. private XmlElement mark;
  44. private XmlElement document;
  45. private XmlDocument doc = new XmlDocument();
  46. /// <summary>
  47. /// Create Window.
  48. /// </summary>
  49. public new void CreateWindow(string name, float Width, float Height)
  50. {
  51. windowHeight = Height;
  52. windowWidth = Width;
  53. XmlDeclaration xml_vers = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
  54. doc.AppendChild(xml_vers);
  55. root = doc.CreateElement("PPML");
  56. nsAttribute = doc.CreateAttribute("xmlns");
  57. nsAttribute.Value = "urn://www.podi.org/ppml/ppml3";
  58. root.Attributes.Append(nsAttribute);
  59. nsAttribute = doc.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");
  60. nsAttribute.Value = "http://www.w3.org/2001/XMLSchema-instance";
  61. root.Attributes.Append(nsAttribute);
  62. nsAttribute = doc.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
  63. nsAttribute.Value = "urn://www.podi.org/ppml/ppml3 http://www.podi.org/ppml/ppml300.xsd";
  64. root.Attributes.Append(nsAttribute);
  65. nsAttribute = doc.CreateAttribute("Version");
  66. nsAttribute.Value = "3.0";
  67. root.Attributes.Append(nsAttribute);
  68. doc.AppendChild(root);
  69. XmlElement PAGE_DESIGN = doc.CreateElement("PAGE_DESIGN");
  70. nsAttribute = doc.CreateAttribute("TrimBox");
  71. nsAttribute.Value = "0 0 " + FloatToString(Width) + " " + FloatToString(Height);
  72. PAGE_DESIGN.Attributes.Append(nsAttribute);
  73. root.AppendChild(PAGE_DESIGN);
  74. XmlElement JOB = doc.CreateElement("JOB");
  75. root.AppendChild(JOB);
  76. document = doc.CreateElement("DOCUMENT");
  77. JOB.AppendChild(document);
  78. }
  79. public void AddPage()
  80. {
  81. XmlElement PAGE = doc.CreateElement("PAGE");
  82. document.AppendChild(PAGE);
  83. mark = doc.CreateElement("MARK");
  84. nsAttribute = doc.CreateAttribute("Position");
  85. nsAttribute.Value = FloatToString(0) + " " + FloatToString(0);
  86. mark.Attributes.Append(nsAttribute);
  87. PAGE.AppendChild(mark);
  88. XmlElement OBJECT = doc.CreateElement("OBJECT");
  89. nsAttribute = doc.CreateAttribute("Position");
  90. nsAttribute.Value = "0 0";
  91. OBJECT.Attributes.Append(nsAttribute);
  92. mark.AppendChild(OBJECT);
  93. XmlElement SOURCE = doc.CreateElement("SOURCE");
  94. nsAttribute = doc.CreateAttribute("Format");
  95. nsAttribute.Value = "application/postscript";
  96. SOURCE.Attributes.Append(nsAttribute);
  97. nsAttribute = doc.CreateAttribute("Dimensions");
  98. nsAttribute.Value = FloatToString(windowWidth) + " " + FloatToString(windowHeight);
  99. SOURCE.Attributes.Append(nsAttribute);
  100. OBJECT.AppendChild(SOURCE);
  101. internalData = doc.CreateElement("INTERNAL_DATA");
  102. SOURCE.AppendChild(internalData);
  103. }
  104. /// <summary>
  105. /// Add image as PPMLObject
  106. /// </summary>
  107. /// <param name="filename"></param>
  108. /// <param name="left"></param>
  109. /// <param name="top"></param>
  110. /// <param name="width"></param>
  111. /// <param name="height"></param>
  112. public void AddImage(string filename, float left, float top, float width, float height)
  113. {
  114. if (!String.IsNullOrEmpty(filename))
  115. {
  116. XmlElement OBJECT = doc.CreateElement("OBJECT");
  117. nsAttribute = doc.CreateAttribute("Position");
  118. nsAttribute.Value = FloatToString(left) + " " + FloatToString(windowHeight - height - top);
  119. OBJECT.Attributes.Append(nsAttribute);
  120. mark.AppendChild(OBJECT);
  121. XmlElement SOURCE = doc.CreateElement("SOURCE");
  122. nsAttribute = doc.CreateAttribute("Format");
  123. nsAttribute.Value = "image/jpeg";
  124. SOURCE.Attributes.Append(nsAttribute);
  125. nsAttribute = doc.CreateAttribute("Dimensions");
  126. nsAttribute.Value = FloatToString(width) + " " + FloatToString(height);
  127. SOURCE.Attributes.Append(nsAttribute);
  128. OBJECT.AppendChild(SOURCE);
  129. XmlElement EXTERNAL_DATA = doc.CreateElement("EXTERNAL_DATA");
  130. nsAttribute = doc.CreateAttribute("Src");
  131. nsAttribute.Value = filename;
  132. EXTERNAL_DATA.Attributes.Append(nsAttribute);
  133. SOURCE.AppendChild(EXTERNAL_DATA);
  134. }
  135. }
  136. /// <summary>
  137. /// Save svg file.
  138. /// </summary>
  139. public new void Save(string filename)
  140. {
  141. doc.Save(filename);
  142. }
  143. /// <summary>
  144. /// Save svg stream.
  145. /// </summary>
  146. public new void Save(Stream stream)
  147. {
  148. doc.Save(stream);
  149. }
  150. public new void Finish()
  151. {
  152. internalData.InnerText = psData.ToString();
  153. psData.Length = 0;
  154. }
  155. /// <param name="name"></param>
  156. /// <param name="Width"></param>
  157. /// <param name="Height"></param>
  158. public PPMLDocument(string name, float Width, float Height)
  159. {
  160. CreateWindow(name, Width, Height);
  161. }
  162. private string FloatToString(double flt)
  163. {
  164. return ExportUtils.FloatToString(flt);
  165. }
  166. }
  167. }