diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 8a8aa5e1b4..43c94e20de 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -514,6 +514,28 @@ function color_scheme_form_submit($form, FormStateInterface $form_state) { function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) { // Prepare color conversion table. $conversion = $palette; + + $indent = str_pad(' ', 6); + $lines = explode("\n", var_export($palette, TRUE)); + array_shift($lines); + $message = " 'PaletteName' => array(\n"; + $message .= $indent . "'title' => t('PaletteName'),\n"; + $message .= $indent . "'colors' => array(\n"; + $last_line = $indent . array_pop($lines) . ','; + foreach ($lines as $line) { + if (strpos($line, ' => ') !== FALSE) { + $parts = explode(' => ', $line); + $message .= $indent . $parts[0] . str_pad(' ', (46 - strlen($line))) . '=> ' . $parts[1]; + } else { + $message .= "$indent $line"; + } + $message .= "\n"; + } + $message .= "$last_line\n"; + $message .= " ),\n"; + $message = '
' . $message . '
'; + watchdog('Custom color palette', $message); + foreach ($conversion as $k => $v) { $v = mb_strtolower($v); $conversion[$k] = Color::normalizeHexLength($v); @@ -527,7 +549,7 @@ function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) { } // Find all colors in the stylesheet and the chunks in between. - $style = preg_split('/(#[0-9a-f]{6}|#[0-9a-f]{3})/i', $style, -1, PREG_SPLIT_DELIM_CAPTURE); + $style = preg_split('/(#[0-9a-f]{6}|#[0-9a-f]{3}|rgba\(\d{0,3},\d{0,3},\d{0,3},\d+(\.\d+)?\))/i', $style, -1, PREG_SPLIT_DELIM_CAPTURE); $is_color = FALSE; $output = ''; $base = 'base'; @@ -538,6 +560,10 @@ function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) { $chunk = mb_strtolower($chunk); $chunk = Color::normalizeHexLength($chunk); // Check if this is one of the colors in the default palette. + if ($is_rgba = (strpos($chunk, 'rgba(') !== FALSE)) { + $rgba = $chunk; + $chunk = _color_rgba2hex($chunk); + } if ($key = array_search($chunk, $default)) { $chunk = $conversion[$key]; } @@ -545,6 +571,9 @@ function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) { else { $chunk = _color_shift($palette[$base], $default[$base], $chunk, $info['blend_target']); } + if ($is_rgba) { + $chunk = _color_hex2rgba($rgba, $chunk); + } } else { // Determine the most suitable base color for the next color. @@ -816,6 +845,49 @@ function _color_hue2rgb($m1, $m2, $h) { return $m1; } +/* + * Create a css hex string from a css rgba string + */ +function _color_rgba2hex($rgba) { + $re = <<