class ColorCMY in Color Field 8.2
ColorCMY represents the CMY color format.
Hierarchy
- class \Drupal\color_field\ColorBase implements ColorInterface
- class \Drupal\color_field\ColorCMY
Expanded class hierarchy of ColorCMY
File
- src/
ColorCMY.php, line 8
Namespace
Drupal\color_fieldView source
class ColorCMY extends ColorBase {
/**
* The cyan.
*
* @var float
*/
private $cyan;
/**
* The magenta.
*
* @var float
*/
private $magenta;
/**
* The yellow.
*
* @var float
*/
private $yellow;
/**
* Create a new CMYK color.
*
* @param float $cyan
* The cyan.
* @param float $magenta
* The magenta.
* @param float $yellow
* The yellow.
* @param float $opacity
* The opacity.
*/
public function __construct($cyan, $magenta, $yellow, $opacity) {
$this->cyan = $cyan;
$this->magenta = $magenta;
$this->yellow = $yellow;
$this->opacity = floatval($opacity);
}
/**
* Get the amount of Cyan.
*
* @return int
* The amount of cyan.
*/
public function getCyan() {
return $this->cyan;
}
/**
* Get the amount of Magenta.
*
* @return int
* The amount of magenta.
*/
public function getMagenta() {
return $this->magenta;
}
/**
* Get the amount of Yellow.
*
* @return int
* The amount of yellow.
*/
public function getYellow() {
return $this->yellow;
}
/**
* A string representation of this color in the current format.
*
* @param bool $opacity
* Whether or not to display the opacity.
*
* @return string
* The color in format: #RRGGBB.
*/
public function toString($opacity = TRUE) {
return $this
->toHex()
->toString($opacity);
}
/**
* {@inheritdoc}
*/
public function toHex() {
return $this
->toRgb()
->toHex();
}
/**
* {@inheritdoc}
*/
public function toRgb() {
$red = (1 - $this->cyan) * 255;
$green = (1 - $this->magenta) * 255;
$blue = (1 - $this->yellow) * 255;
return new ColorRGB($red, $green, $blue, $this
->getOpacity());
}
/**
* {@inheritdoc}
*/
public function toCmy() {
$cyan = $this->cyan * (1 - $this->key) + $this->key;
$magenta = $this->magenta * (1 - $this->key) + $this->key;
$yellow = $this->yellow * (1 - $this->key) + $this->key;
return new ColorCMY($cyan, $magenta, $yellow);
}
/**
* {@inheritdoc}
*/
public function toHsl() {
return $this
->toRgb()
->toHsl();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ColorBase:: |
public static | property | Named HTML colors. | |
ColorBase:: |
protected | property | The opacity of the color. | |
ColorBase:: |
public static | property | Regexes to match various color formats. | |
ColorBase:: |
public | function | Get the opacity. | |
ColorBase:: |
public | function | Set the opacity. | |
ColorCMY:: |
private | property | The cyan. | |
ColorCMY:: |
private | property | The magenta. | |
ColorCMY:: |
private | property | The yellow. | |
ColorCMY:: |
public | function | Get the amount of Cyan. | |
ColorCMY:: |
public | function | Get the amount of Magenta. | |
ColorCMY:: |
public | function | Get the amount of Yellow. | |
ColorCMY:: |
public | function | ||
ColorCMY:: |
public | function |
Get the color as a hex instance. Overrides ColorInterface:: |
|
ColorCMY:: |
public | function |
Get the color as a HSL instance. Overrides ColorInterface:: |
|
ColorCMY:: |
public | function |
Get the color as a RGB instance. Overrides ColorInterface:: |
|
ColorCMY:: |
public | function |
A string representation of this color in the current format. Overrides ColorInterface:: |
|
ColorCMY:: |
public | function | Create a new CMYK color. |