canvas_factory.cls.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. /**
  9. * Create canvas instances
  10. *
  11. * The canvas factory creates canvas instances based on the
  12. * availability of rendering backends and config options.
  13. *
  14. * @package dompdf
  15. */
  16. class Canvas_Factory {
  17. /**
  18. * Constructor is private: this is a static class
  19. */
  20. private function __construct() { }
  21. /**
  22. * @param DOMPDF $dompdf
  23. * @param string|array $paper
  24. * @param string $orientation
  25. * @param string $class
  26. *
  27. * @return Canvas
  28. */
  29. static function get_instance(DOMPDF $dompdf, $paper = null, $orientation = null, $class = null) {
  30. $backend = strtolower(DOMPDF_PDF_BACKEND);
  31. if ( isset($class) && class_exists($class, false) ) {
  32. $class .= "_Adapter";
  33. }
  34. else if ( (DOMPDF_PDF_BACKEND === "auto" || $backend === "pdflib" ) &&
  35. class_exists("PDFLib", false) ) {
  36. $class = "PDFLib_Adapter";
  37. }
  38. // FIXME The TCPDF adapter is not ready yet
  39. //else if ( (DOMPDF_PDF_BACKEND === "auto" || $backend === "cpdf") )
  40. // $class = "CPDF_Adapter";
  41. else if ( $backend === "tcpdf" ) {
  42. $class = "TCPDF_Adapter";
  43. }
  44. else if ( $backend === "gd" ) {
  45. $class = "GD_Adapter";
  46. }
  47. else {
  48. $class = "CPDF_Adapter";
  49. }
  50. return new $class($paper, $orientation, $dompdf);
  51. }
  52. }