/framework/vendor/zend/Zend/Pdf/Color/Cmyk.php

http://zoop.googlecode.com/ · PHP · 126 lines · 36 code · 16 blank · 74 comment · 8 complexity · 1b8f16c0597db04e7d11e7b3146aa9a4 MD5 · raw file

  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: Cmyk.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. /** Internally used classes */
  22. require_once 'Zend/Pdf/Element/Numeric.php';
  23. /** Zend_Pdf_Color */
  24. require_once 'Zend/Pdf/Color.php';
  25. /**
  26. * CMYK color implementation
  27. *
  28. * @category Zend
  29. * @package Zend_Pdf
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Pdf_Color_Cmyk extends Zend_Pdf_Color
  34. {
  35. /**
  36. * Cyan level.
  37. * 0.0 (zero concentration) - 1.0 (maximum concentration)
  38. *
  39. * @var Zend_Pdf_Element_Numeric
  40. */
  41. private $_c;
  42. /**
  43. * Magenta level.
  44. * 0.0 (zero concentration) - 1.0 (maximum concentration)
  45. *
  46. * @var Zend_Pdf_Element_Numeric
  47. */
  48. private $_m;
  49. /**
  50. * Yellow level.
  51. * 0.0 (zero concentration) - 1.0 (maximum concentration)
  52. *
  53. * @var Zend_Pdf_Element_Numeric
  54. */
  55. private $_y;
  56. /**
  57. * Key (BlacK) level.
  58. * 0.0 (zero concentration) - 1.0 (maximum concentration)
  59. *
  60. * @var Zend_Pdf_Element_Numeric
  61. */
  62. private $_k;
  63. /**
  64. * Object constructor
  65. *
  66. * @param float $c
  67. * @param float $m
  68. * @param float $y
  69. * @param float $k
  70. */
  71. public function __construct($c, $m, $y, $k)
  72. {
  73. if ($c < 0) { $c = 0; }
  74. if ($c > 1) { $c = 1; }
  75. if ($m < 0) { $m = 0; }
  76. if ($m > 1) { $m = 1; }
  77. if ($y < 0) { $y = 0; }
  78. if ($y > 1) { $y = 1; }
  79. if ($k < 0) { $k = 0; }
  80. if ($k > 1) { $k = 1; }
  81. $this->_c = new Zend_Pdf_Element_Numeric($c);
  82. $this->_m = new Zend_Pdf_Element_Numeric($m);
  83. $this->_y = new Zend_Pdf_Element_Numeric($y);
  84. $this->_k = new Zend_Pdf_Element_Numeric($k);
  85. }
  86. /**
  87. * Instructions, which can be directly inserted into content stream
  88. * to switch color.
  89. * Color set instructions differ for stroking and nonstroking operations.
  90. *
  91. * @param boolean $stroking
  92. * @return string
  93. */
  94. public function instructions($stroking)
  95. {
  96. return $this->_c->toString() . ' '
  97. . $this->_m->toString() . ' '
  98. . $this->_y->toString() . ' '
  99. . $this->_k->toString() . ($stroking? " K\n" : " k\n");
  100. }
  101. /**
  102. * Get color components (color space dependent)
  103. *
  104. * @return array
  105. */
  106. public function getComponents()
  107. {
  108. return array($this->_c->value, $this->_m->value, $this->_y->value, $this->_k->value);
  109. }
  110. }