ColorCMYK.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace Drupal\color_field;
  3. /**
  4. * ColorCMYK represents the CMYK color format.
  5. */
  6. class ColorCMYK extends ColorBase {
  7. /**
  8. * The cyan
  9. * @var float
  10. */
  11. private $cyan;
  12. /**
  13. * The magenta
  14. * @var float
  15. */
  16. private $magenta;
  17. /**
  18. * The yellow
  19. * @var float
  20. */
  21. private $yellow;
  22. /**
  23. * The key (black)
  24. * @var float
  25. */
  26. private $key;
  27. /**
  28. * Create a new CMYK color
  29. *
  30. * @param float $cyan The cyan
  31. * @param float $magenta The magenta
  32. * @param float $yellow The yellow
  33. * @param float $key The key (black)
  34. * @param float $opacity
  35. * The opacity
  36. */
  37. public function __construct($cyan, $magenta, $yellow, $key, $opacity) {
  38. $this->cyan = $cyan;
  39. $this->magenta = $magenta;
  40. $this->yellow = $yellow;
  41. $this->key = $key;
  42. $this->opacity = floatval($opacity);
  43. }
  44. /**
  45. * Get the amount of Cyan
  46. *
  47. * @return int The amount of cyan
  48. */
  49. public function getCyan() {
  50. return $this->cyan;
  51. }
  52. /**
  53. * Get the amount of Magenta
  54. *
  55. * @return int The amount of magenta
  56. */
  57. public function getMagenta() {
  58. return $this->magenta;
  59. }
  60. /**
  61. * Get the amount of Yellow
  62. *
  63. * @return int The amount of yellow
  64. */
  65. public function getYellow() {
  66. return $this->yellow;
  67. }
  68. /**
  69. * Get the key (black)
  70. *
  71. * @return int The amount of black
  72. */
  73. public function getKey() {
  74. return $this->key;
  75. }
  76. /**
  77. * A string representation of this color in the current format
  78. *
  79. * @param bool $opacity
  80. * Whether or not to display the opacity.
  81. *
  82. * @return string
  83. * The color in format: #RRGGBB
  84. */
  85. public function toString($opacity = TRUE) {
  86. }
  87. /**
  88. * {@inheritdoc}
  89. */
  90. public function toHex() {
  91. return $this->toRGB()->toHex();
  92. }
  93. /**
  94. * {@inheritdoc}
  95. */
  96. public function toRGB() {
  97. return $this->toCMY()->toRGB();
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function toCMY() {
  103. $cyan = ($this->cyan * (1 - $this->key) + $this->key);
  104. $magenta = ($this->magenta * (1 - $this->key) + $this->key);
  105. $yellow = ($this->yellow * (1 - $this->key) + $this->key);
  106. return new ColorCMY($cyan, $magenta, $yellow, $this->getOpacity());
  107. }
  108. }