Canvas.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Pdf
  17. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. require_once 'Zend/Pdf/Canvas/Abstract.php';
  22. /**
  23. * Canvas is an abstract rectangle drawing area which can be dropped into
  24. * page object at specified place.
  25. *
  26. * @package Zend_Pdf
  27. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Pdf_Canvas extends Zend_Pdf_Canvas_Abstract
  31. {
  32. /**
  33. * Canvas procedure sets.
  34. *
  35. * @var array
  36. */
  37. protected $_procSet = array();
  38. /**
  39. * Canvas width expressed in default user space units (1/72 inch)
  40. *
  41. * @var float
  42. */
  43. protected $_width;
  44. /**
  45. * Canvas height expressed in default user space units (1/72 inch)
  46. *
  47. * @var float
  48. */
  49. protected $_height;
  50. protected $_resources = array('Font' => array(),
  51. 'XObject' => array(),
  52. 'ExtGState' => array());
  53. /**
  54. * Object constructor
  55. *
  56. * @param float $width
  57. * @param float $height
  58. */
  59. public function __construct($width, $height)
  60. {
  61. $this->_width = $width;
  62. $this->_height = $height;
  63. }
  64. /**
  65. * Add procedure set to the canvas description
  66. *
  67. * @param string $procSetName
  68. */
  69. protected function _addProcSet($procSetName)
  70. {
  71. $this->_procset[$procSetName] = 1;
  72. }
  73. /**
  74. * Attach resource to the canvas
  75. *
  76. * Method returns a name of the resource which can be used
  77. * as a resource reference within drawing instructions stream
  78. * Allowed types: 'XObject' (image), 'Font', 'ExtGState'
  79. *
  80. * @param string $type
  81. * @param Zend_Pdf_Resource $resource
  82. * @return string
  83. */
  84. protected function _attachResource($type, Zend_Pdf_Resource $resource)
  85. {
  86. // Check, that resource is already attached to resource set.
  87. $resObject = $resource->getResource();
  88. foreach ($this->_resources[$type] as $resName => $collectedResObject) {
  89. if ($collectedResObject === $resObject) {
  90. return $resName;
  91. }
  92. }
  93. $idCounter = 1;
  94. do {
  95. $newResName = $type[0] . $idCounter++;
  96. } while (isset($this->_resources[$type][$newResName]));
  97. $this->_resources[$type][$newResName] = $resObject;
  98. return $newResName;
  99. }
  100. /**
  101. * Return the height of this page in points.
  102. *
  103. * @return float
  104. */
  105. public function getHeight()
  106. {
  107. return $this->_height;
  108. }
  109. /**
  110. * Return the width of this page in points.
  111. *
  112. * @return float
  113. */
  114. public function getWidth()
  115. {
  116. return $this->_width;
  117. }
  118. }