CanvasFactory.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  7. */
  8. namespace Dompdf;
  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. * @param Dompdf $dompdf
  27. * @param string|array $paper
  28. * @param string $orientation
  29. * @param string $class
  30. *
  31. * @return Canvas
  32. */
  33. static function get_instance(Dompdf $dompdf, $paper = null, $orientation = null, $class = null)
  34. {
  35. $backend = strtolower($dompdf->getOptions()->getPdfBackend());
  36. if (isset($class) && class_exists($class, false)) {
  37. $class .= "_Adapter";
  38. } else {
  39. if (($backend === "auto" || $backend === "pdflib") &&
  40. class_exists("PDFLib", false)
  41. ) {
  42. $class = "Dompdf\\Adapter\\PDFLib";
  43. }
  44. else {
  45. if ($backend === "gd" && extension_loaded('gd')) {
  46. $class = "Dompdf\\Adapter\\GD";
  47. } else {
  48. $class = "Dompdf\\Adapter\\CPDF";
  49. }
  50. }
  51. }
  52. return new $class($paper, $orientation, $dompdf);
  53. }
  54. }