@param string $color
@param string[] $PDFAXwarnings

@return bool|float[]
770320
private function convertPlain($color, array &$PDFAXwarnings = [])
	{
		$c = false;

		if (preg_match('/^[\d]+$/', $color)) {
			$c = [static::MODE_GRAYSCALE, $color]; // i.e. integer only
		} elseif (strpos($color, '#') === 0) { // case of #nnnnnn or #nnn
			$c = $this->processHashColor($color);
		} elseif (preg_match('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl|spot)\((.*?)\)/', $color, $m)) {
			$c = $this->processModeColor($m[1], explode(',', $m[2]));
		}

		if ($this->mpdf->PDFA || $this->mpdf->PDFX || $this->mpdf->restrictColorSpace) {
			$c = $this->restrictColorSpace($c, $color, $PDFAXwarnings);
		}

		return $c;
	}
441213
public static function hsl(Color $color)
    {
        $hsl = $color->getHsl();

        return sprintf(
            'hsl(%s, %s%%, %s%%)',
            sprintf('%0.1f', $hsl['h'] * 360) + 0,
            sprintf('%0.1f', $hsl['s'] * 100) + 0,
            sprintf('%0.1f', $hsl['l'] * 100) + 0
        );
    }
137074
public function getRgbaString(Color $color)
    {
        return 'rgba('. $color->red . ', ' . $color->green . ', ' . $color->blue . ', ' . $color->alpha . ')';
    }
1118462
public static function fromHex(string $color): Color
    {
        if (!Validator::isValidHex($color)) {
            throw new InvalidColorException('Invalid hex value');
        }

        return new self(...array_values(self::hexToRgb($color)));
    }
723612
public static function hex2rgb(string $colour)
    {
        if ($colour[0] == '#')
            $colour = substr($colour, 1);

        if (strlen($colour) == 6)
            list($r, $g, $b) = array($colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5]);
        elseif (strlen($colour) == 3)
            list($r, $g, $b) = array($colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2]);
        else
            return false;

        $r = hexdec($r);
        $g = hexdec($g);
        $b = hexdec($b);
        return array('red' => $r, 'green' => $g, 'blue' => $b);
    }
1350941
private function convertColor($color)
    {
        if (is_array($color)) {
            return $color;
        }

        if (preg_match('/^#?([a-z\d])([a-z\d])([a-z\d])$/i', $color, $matches)) {
            $color = $matches[1].$matches[1];
            $color .= $matches[2].$matches[2];
            $color .= $matches[3].$matches[3];
        }

        preg_match('/#?([a-z\d]{2})([a-z\d]{2})([a-z\d]{2})$/i', $color, $matches);

        return array_map(function ($value) {
            return hexdec($value);
        }, array_slice($matches, 1, 3));
    }
480163
protected function _drawCurve($pt, $color)
    {
        $this->pdf->SetFillColorArray($color);

        if (count($pt) == 10) {
            $this->pdf->drawCurve($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7], $pt[8], $pt[9]);
        } else {
            $this->pdf->drawCorner($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7]);
        }
    }
90104
public static function getColorCode($color, $options = array())
    {
        $code = (int) $color;
        if (is_string($color)) {
            $options = array_merge(explode('+', strtolower($color)), $options);
            $color = array_shift($options);
            if (!isset(self::$colors[$color])) {
                throw new ConsoleException("Unknown color '$color'");
            }
            $code = self::$colors[$color];
        }
        foreach ($options as $opt) {
            $opt = strtolower($opt);
            if (!isset(self::$options[$opt])) {
                throw new ConsoleException("Unknown option '$color'");
            }
            $code = $code | self::$options[$opt];
        }
        return $code;
    }
743701
public function cmyk2rgb($c)
	{
		$rgb = [];
		$colors = 255 - ($c[4] * 2.55);
		$rgb[0] = (int) ($colors * (255 - ($c[1] * 2.55)) / 255);
		$rgb[1] = (int) ($colors * (255 - ($c[2] * 2.55)) / 255);
		$rgb[2] = (int) ($colors * (255 - ($c[3] * 2.55)) / 255);
		if ($c[0] == 6) {
			return [5, $rgb[0], $rgb[1], $rgb[2], $c[5]];
		}

		return [3, $rgb[0], $rgb[1], $rgb[2]];
	}
352785
public function getRgbaHexString(Color $color)
    {
        $alpha = dechex(255 * $color->alpha);
        return '#' . $color->hex . $alpha;
    }
881371
public static function explodeColor($hexColor, int $dr = null, int $dg = null, int $db = null): array
    {
        $colors = [];
        preg_match_all('/^#?([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$/', trim($hexColor), $colors);
        if (isset($colors[1][0]) && isset($colors[2][0]) && isset($colors[3][0])) {
            return [hexdec($colors[1][0]), hexdec($colors[2][0]), hexdec($colors[3][0])];
        }
        return [$dr, $dg, $db];
    }
1371959
private static function charToCode($color)
    {
        if (is_array($color)) {
            return $color;
        } else if (is_string($color)) {
            list($color, $option) = explode('+', strtolower($color));
            if (!isset(self::$colors[$color])) {
                throw new \InvalidArgumentException("Unknown color '$color'");
            }

            if ($option && !isset(self::$options[$option])) {
                throw new \InvalidArgumentException("Unknown option '$option'");
            }

            $code = self::$colors[$color];
            $option = $option ? self::$options[$option] : 0;
            return [$code, $option];
        } else {
            return [$color, 0];
        }
    }
662731
protected function initialize($color)
    {
        return list($this->hue, $this->saturation, $this->value) = explode(',', $color);
    }
673047
public static function isColour(?string $colour, string $enforceType = 'any') 
    {
        if (! in_array($enforceType, ['any', 'hex', 'rgb', 'rgba', 'hsl', 'hsla']) || empty($colour))
            return false;

        $colour = str_replace(' ', '', $colour);

        $regex = "/^(#?([a-f\d]{3}|[a-f\d]{6}))$/";
        if (preg_match($regex, $colour) && in_array($enforceType, ['any', 'hex'])) {
            if (strlen($colour) === 6)
                $colour = '#'.$colour;
            if (strlen($colour) === 3) {
                $x = '#';
                for($i=0; $i<3; $i++)
                    $x .= $colour[$i].$colour[$i];
                $colour = $x;
            }
            return $colour;
        }
        $regex = "/^rgb\((0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d)\)$/";

        if (preg_match($regex, $colour) && in_array($enforceType, ['any', 'rgb']))
            return $colour;

        $regex = "/^rgba\((0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),(0?\.([\d]{1,2})|1(\.0)?)\)$/";

        if (preg_match($regex, $colour) && in_array($enforceType, ['any', 'rgba']))
            return $colour;

        $regex = "/^hsl\((0|360|35\d|3[0-4]\d|[12]\d\d|0?\d?\d),(0|100|\d{1,2})%,(0|100|\d{1,2})%\)$/";

        if (preg_match($regex, $colour) && in_array($enforceType, ['any', 'hsl']))
            return $colour;

        $regex = "/^hsla\((0|360|35\d|3[0-4]\d|[12]\d\d|0?\d?\d),(0|100|\d{1,2})%,(0|100|\d{1,2})%,(0?\.\d|1(\.0)?)\)$/";

        if (preg_match($regex, $colour) && in_array($enforceType, ['any', 'hsla']))
            return $colour;

        return false;
    }
596467
protected function initialize($color)
    {
        return list($this->red, $this->green, $this->blue) = str_split($color, 2);
    }
174839
public void setColorFill(Color color) {
    	PdfXConformanceImp.checkPDFXConformance(writer, PdfXConformanceImp.PDFXKEY_COLOR, color);
        int type = ExtendedColor.getType(color);
        switch (type) {
            case ExtendedColor.TYPE_GRAY: {
                setGrayFill(((GrayColor)color).getGray());
                break;
            }
            case ExtendedColor.TYPE_CMYK: {
                CMYKColor cmyk = (CMYKColor)color;
                setCMYKColorFillF(cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack());
                break;
            }
            case ExtendedColor.TYPE_SEPARATION: {
                SpotColor spot = (SpotColor)color;
                setColorFill(spot.getPdfSpotColor(), spot.getTint());
                break;
            }
            case ExtendedColor.TYPE_PATTERN: {
                PatternColor pat = (PatternColor) color;
                setPatternFill(pat.getPainter());
                break;
            }
            case ExtendedColor.TYPE_SHADING: {
                ShadingColor shading = (ShadingColor) color;
                setShadingFill(shading.getPdfShadingPattern());
                break;
            }
            default:
                setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
        }
    }
364133
private function restrictCmykColorSpace($c, $color, &$PDFAXwarnings = [])
	{
		if ($this->mpdf->PDFA && $this->mode != 3) {
			if ($this->mpdf->PDFA && !$this->mpdf->PDFAauto) {
				$PDFAXwarnings[] = "CMYK color specified '" . $color . "' (converted to RGB)";
			}
			$c = $this->colorModeConverter->cmyk2rgb($c);
		} elseif ($this->mode == 1) {
			$c = $this->colorModeConverter->cmyk2gray($c);
		} elseif ($this->mode == 2) {
			$c = $this->colorModeConverter->cmyk2rgb($c);
		}

		return $c;
	}