Eps.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Classes to create relation schema in EPS format.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Plugins\Schema\Eps;
  9. use PhpMyAdmin\Core;
  10. use PhpMyAdmin\Response;
  11. /**
  12. * This Class is EPS Library and
  13. * helps in developing structure of EPS Schema Export
  14. *
  15. * @package PhpMyAdmin
  16. * @access public
  17. * @see https://secure.php.net/manual/en/book.xmlwriter.php
  18. */
  19. class Eps
  20. {
  21. public $font;
  22. public $fontSize;
  23. public $stringCommands;
  24. /**
  25. * The "Eps" constructor
  26. *
  27. * Upon instantiation This starts writing the EPS Document.
  28. * %!PS-Adobe-3.0 EPSF-3.0 This is the MUST first comment to include
  29. * it shows/tells that the Post Script document is purely under
  30. * Document Structuring Convention [DSC] and is Compliant
  31. * Encapsulated Post Script Document
  32. */
  33. public function __construct()
  34. {
  35. $this->stringCommands = "";
  36. $this->stringCommands .= "%!PS-Adobe-3.0 EPSF-3.0 \n";
  37. }
  38. /**
  39. * Set document title
  40. *
  41. * @param string $value sets the title text
  42. *
  43. * @return void
  44. */
  45. public function setTitle($value)
  46. {
  47. $this->stringCommands .= '%%Title: ' . $value . "\n";
  48. }
  49. /**
  50. * Set document author
  51. *
  52. * @param string $value sets the author
  53. *
  54. * @return void
  55. */
  56. public function setAuthor($value)
  57. {
  58. $this->stringCommands .= '%%Creator: ' . $value . "\n";
  59. }
  60. /**
  61. * Set document creation date
  62. *
  63. * @param string $value sets the date
  64. *
  65. * @return void
  66. */
  67. public function setDate($value)
  68. {
  69. $this->stringCommands .= '%%CreationDate: ' . $value . "\n";
  70. }
  71. /**
  72. * Set document orientation
  73. *
  74. * @param string $orientation sets the orientation
  75. *
  76. * @return void
  77. */
  78. public function setOrientation($orientation)
  79. {
  80. $this->stringCommands .= "%%PageOrder: Ascend \n";
  81. if ($orientation == "L") {
  82. $orientation = "Landscape";
  83. $this->stringCommands .= '%%Orientation: ' . $orientation . "\n";
  84. } else {
  85. $orientation = "Portrait";
  86. $this->stringCommands .= '%%Orientation: ' . $orientation . "\n";
  87. }
  88. $this->stringCommands .= "%%EndComments \n";
  89. $this->stringCommands .= "%%Pages 1 \n";
  90. $this->stringCommands .= "%%BoundingBox: 72 150 144 170 \n";
  91. }
  92. /**
  93. * Set the font and size
  94. *
  95. * font can be set whenever needed in EPS
  96. *
  97. * @param string $value sets the font name e.g Arial
  98. * @param integer $size sets the size of the font e.g 10
  99. *
  100. * @return void
  101. */
  102. public function setFont($value, $size)
  103. {
  104. $this->font = $value;
  105. $this->fontSize = $size;
  106. $this->stringCommands .= "/" . $value . " findfont % Get the basic font\n";
  107. $this->stringCommands .= ""
  108. . $size . " scalefont % Scale the font to $size points\n";
  109. $this->stringCommands
  110. .= "setfont % Make it the current font\n";
  111. }
  112. /**
  113. * Get the font
  114. *
  115. * @return string return the font name e.g Arial
  116. */
  117. public function getFont()
  118. {
  119. return $this->font;
  120. }
  121. /**
  122. * Get the font Size
  123. *
  124. * @return string return the size of the font e.g 10
  125. */
  126. public function getFontSize()
  127. {
  128. return $this->fontSize;
  129. }
  130. /**
  131. * Draw the line
  132. *
  133. * drawing the lines from x,y source to x,y destination and set the
  134. * width of the line. lines helps in showing relationships of tables
  135. *
  136. * @param integer $x_from The x_from attribute defines the start
  137. * left position of the element
  138. * @param integer $y_from The y_from attribute defines the start
  139. * right position of the element
  140. * @param integer $x_to The x_to attribute defines the end
  141. * left position of the element
  142. * @param integer $y_to The y_to attribute defines the end
  143. * right position of the element
  144. * @param integer $lineWidth Sets the width of the line e.g 2
  145. *
  146. * @return void
  147. */
  148. public function line(
  149. $x_from = 0,
  150. $y_from = 0,
  151. $x_to = 0,
  152. $y_to = 0,
  153. $lineWidth = 0
  154. ) {
  155. $this->stringCommands .= $lineWidth . " setlinewidth \n";
  156. $this->stringCommands .= $x_from . ' ' . $y_from . " moveto \n";
  157. $this->stringCommands .= $x_to . ' ' . $y_to . " lineto \n";
  158. $this->stringCommands .= "stroke \n";
  159. }
  160. /**
  161. * Draw the rectangle
  162. *
  163. * drawing the rectangle from x,y source to x,y destination and set the
  164. * width of the line. rectangles drawn around the text shown of fields
  165. *
  166. * @param integer $x_from The x_from attribute defines the start
  167. * left position of the element
  168. * @param integer $y_from The y_from attribute defines the start
  169. * right position of the element
  170. * @param integer $x_to The x_to attribute defines the end
  171. * left position of the element
  172. * @param integer $y_to The y_to attribute defines the end
  173. * right position of the element
  174. * @param integer $lineWidth Sets the width of the line e.g 2
  175. *
  176. * @return void
  177. */
  178. public function rect($x_from, $y_from, $x_to, $y_to, $lineWidth)
  179. {
  180. $this->stringCommands .= $lineWidth . " setlinewidth \n";
  181. $this->stringCommands .= "newpath \n";
  182. $this->stringCommands .= $x_from . " " . $y_from . " moveto \n";
  183. $this->stringCommands .= "0 " . $y_to . " rlineto \n";
  184. $this->stringCommands .= $x_to . " 0 rlineto \n";
  185. $this->stringCommands .= "0 -" . $y_to . " rlineto \n";
  186. $this->stringCommands .= "closepath \n";
  187. $this->stringCommands .= "stroke \n";
  188. }
  189. /**
  190. * Set the current point
  191. *
  192. * The moveto operator takes two numbers off the stack and treats
  193. * them as x and y coordinates to which to move. The coordinates
  194. * specified become the current point.
  195. *
  196. * @param integer $x The x attribute defines the left position of the element
  197. * @param integer $y The y attribute defines the right position of the element
  198. *
  199. * @return void
  200. */
  201. public function moveTo($x, $y)
  202. {
  203. $this->stringCommands .= $x . ' ' . $y . " moveto \n";
  204. }
  205. /**
  206. * Output/Display the text
  207. *
  208. * @param string $text The string to be displayed
  209. *
  210. * @return void
  211. */
  212. public function show($text)
  213. {
  214. $this->stringCommands .= '(' . $text . ") show \n";
  215. }
  216. /**
  217. * Output the text at specified co-ordinates
  218. *
  219. * @param string $text String to be displayed
  220. * @param integer $x X attribute defines the left position of the element
  221. * @param integer $y Y attribute defines the right position of the element
  222. *
  223. * @return void
  224. */
  225. public function showXY($text, $x, $y)
  226. {
  227. $this->moveTo($x, $y);
  228. $this->show($text);
  229. }
  230. /**
  231. * Ends EPS Document
  232. *
  233. * @return void
  234. */
  235. public function endEpsDoc()
  236. {
  237. $this->stringCommands .= "showpage \n";
  238. }
  239. /**
  240. * Output EPS Document for download
  241. *
  242. * @param string $fileName name of the eps document
  243. *
  244. * @return void
  245. */
  246. public function showOutput($fileName)
  247. {
  248. // if(ob_get_clean()){
  249. //ob_end_clean();
  250. //}
  251. $output = $this->stringCommands;
  252. Response::getInstance()
  253. ->disable();
  254. Core::downloadHeader(
  255. $fileName,
  256. 'image/x-eps',
  257. strlen($output)
  258. );
  259. print $output;
  260. }
  261. }