Eps.php 7.8 KB

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