"Fossies" - the Fresh Open Source Software Archive

Member "phpMyAdmin-5.1.0-english/libraries/classes/Plugins/Schema/Eps/Eps.php" (24 Feb 2021, 7880 Bytes) of package /linux/www/phpMyAdmin-5.1.0-english.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Eps.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.0.4-english_vs_5.1.0-english.

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