| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package dompdf |
| 4 |
* @link https://github.com/dompdf/dompdf |
| 5 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 6 |
*/ |
| 7 |
namespace Dompdf; |
| 8 |
|
| 9 |
/** |
| 10 |
* Create canvas instances |
| 11 |
* |
| 12 |
* The canvas factory creates canvas instances based on the |
| 13 |
* availability of rendering backends and config options. |
| 14 |
* |
| 15 |
* @package dompdf |
| 16 |
*/ |
| 17 |
class CanvasFactory |
| 18 |
{ |
| 19 |
/** |
| 20 |
* Constructor is private: this is a static class |
| 21 |
*/ |
| 22 |
private function __construct() |
| 23 |
{ |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* @param Dompdf $dompdf |
| 28 |
* @param string|array $paper |
| 29 |
* @param string $orientation |
| 30 |
* @param string $class |
| 31 |
* |
| 32 |
* @return Canvas |
| 33 |
*/ |
| 34 |
static function get_instance(Dompdf $dompdf, $paper = null, $orientation = null, $class = null) |
| 35 |
{ |
| 36 |
$backend = strtolower($dompdf->getOptions()->getPdfBackend()); |
| 37 |
|
| 38 |
if (isset($class) && class_exists($class, false)) { |
| 39 |
$class .= "_Adapter"; |
| 40 |
} else { |
| 41 |
if (($backend === "auto" || $backend === "pdflib") && |
| 42 |
class_exists("PDFLib", false) |
| 43 |
) { |
| 44 |
$class = "Dompdf\\Adapter\\PDFLib"; |
| 45 |
} |
| 46 |
|
| 47 |
else { |
| 48 |
if ($backend === "gd" && extension_loaded('gd')) { |
| 49 |
$class = "Dompdf\\Adapter\\GD"; |
| 50 |
} else { |
| 51 |
$class = "Dompdf\\Adapter\\CPDF"; |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
return new $class($paper, $orientation, $dompdf); |
| 57 |
} |
| 58 |
} |
| 59 |
|