Same name and namespace in other branches
  1. 8.x-2.x src/ColorCMYK.php \Drupal\color_field\ColorCMYK 1 comment

ColorCMYK represents the CMYK color format.

Hierarchy

Expanded class hierarchy of ColorCMYK

File

src/ColorCMYK.php, line 10

Namespace

Drupal\color_field
View source
class ColorCMYK extends ColorCMY {
    
    /**
     * The key (black).
     *
     * @var int
     */
    protected int $key;
    
    /**
     * Create a new CMYK color.
     *
     * @param int $cyan
     *   The cyan.
     * @param int $magenta
     *   The magenta.
     * @param int $yellow
     *   The yellow.
     * @param int $key
     *   The key (black).
     * @param float $opacity
     *   The opacity.
     */
    public function __construct(int $cyan, int $magenta, int $yellow, int $key, float $opacity) {
        parent::__construct($cyan, $magenta, $yellow, $opacity);
        $this->key = $key;
    }
    
    /**
     * Get the key (black).
     *
     * @return int
     *   The amount of black.
     */
    public function getKey() : int {
        return $this->key;
    }
    
    /**
     * {@inheritdoc}
     */
    public function toRgb() : ColorRGB {
        return $this->toCmy()
            ->toRgb();
    }
    
    /**
     * {@inheritdoc}
     */
    public function toCmy() : ColorCMY {
        $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, $this->getOpacity());
    }
    
    /**
     * {@inheritdoc}
     */
    public function toHsl() : ColorHSL {
        return $this->toRgb()
            ->toHsl();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ColorBase::$namedColors public static property Named HTML colors.
ColorBase::$opacity protected property The opacity of the color.
ColorBase::$patterns public static property Regexes to match various color formats.
ColorBase::getOpacity public function Get the opacity.
ColorBase::setOpacity public function Set the opacity.
ColorCMY::$cyan protected property The cyan.
ColorCMY::$magenta protected property The magenta.
ColorCMY::$yellow protected property The yellow.
ColorCMY::getCyan public function Get the amount of Cyan.
ColorCMY::getMagenta public function Get the amount of Magenta.
ColorCMY::getYellow public function Get the amount of Yellow.
ColorCMY::toCmyk public function
ColorCMY::toHex public function Get the color as a hex instance. Overrides ColorInterface::toHex
ColorCMY::toString public function A string representation of this color in the current format. Overrides ColorInterface::toString
ColorCMYK::$key protected property The key (black).
ColorCMYK::getKey public function Get the key (black).
ColorCMYK::toCmy public function
ColorCMYK::toHsl public function Get the color as an HSL instance. Overrides ColorCMY::toHsl
ColorCMYK::toRgb public function Get the color as an RGB instance. Overrides ColorCMY::toRgb
ColorCMYK::__construct public function Create a new CMYK color. Overrides ColorCMY::__construct