annotate vendor/jcalderonzumba/gastonjs/src/Browser/BrowserRenderTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Zumba\GastonJS\Browser;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Trait BrowserRenderTrait
Chris@0 7 * @package Zumba\GastonJS\Browser
Chris@0 8 */
Chris@0 9 trait BrowserRenderTrait {
Chris@0 10 /**
Chris@0 11 * Check and fix render options
Chris@0 12 * @param $options
Chris@0 13 * @return mixed
Chris@0 14 */
Chris@0 15 protected function checkRenderOptions($options) {
Chris@0 16 //Default is full and no selection
Chris@0 17 if (count($options) === 0) {
Chris@0 18 $options["full"] = true;
Chris@0 19 $options["selector"] = null;
Chris@0 20 }
Chris@0 21
Chris@0 22 if (isset($options["full"]) && isset($options["selector"])) {
Chris@0 23 if ($options["full"]) {
Chris@0 24 //Whatever it is, full is more powerful than selection
Chris@0 25 $options["selector"] = null;
Chris@0 26 }
Chris@0 27 } else {
Chris@0 28 if (!isset($options["full"]) && isset($options["selector"])) {
Chris@0 29 $options["full"] = false;
Chris@0 30 }
Chris@0 31 }
Chris@0 32 return $options;
Chris@0 33 }
Chris@0 34
Chris@0 35 /**
Chris@0 36 * Renders a page or selection to a file given by path
Chris@0 37 * @param string $path
Chris@0 38 * @param array $options
Chris@0 39 * @return mixed
Chris@0 40 */
Chris@0 41 public function render($path, $options = array()) {
Chris@0 42 $fixedOptions = $this->checkRenderOptions($options);
Chris@0 43 return $this->command('render', $path, $fixedOptions["full"], $fixedOptions["selector"]);
Chris@0 44 }
Chris@0 45
Chris@0 46 /**
Chris@0 47 * Renders base64 a page or selection to a file given by path
Chris@0 48 * @param string $imageFormat (PNG, GIF, JPEG)
Chris@0 49 * @param array $options
Chris@0 50 * @return mixed
Chris@0 51 */
Chris@0 52 public function renderBase64($imageFormat, $options = array()) {
Chris@0 53 $fixedOptions = $this->checkRenderOptions($options);
Chris@0 54 return $this->command('render_base64', $imageFormat, $fixedOptions["full"], $fixedOptions["selector"]);
Chris@0 55 }
Chris@0 56
Chris@0 57 /**
Chris@0 58 * Sets the paper size, useful when saving to PDF
Chris@0 59 * @param $paperSize
Chris@0 60 * @return mixed
Chris@0 61 */
Chris@0 62 public function setPaperSize($paperSize) {
Chris@0 63 return $this->command('set_paper_size', $paperSize);
Chris@0 64 }
Chris@0 65 }