本文整理汇总了PHP中Color::colorSplit方法的典型用法代码示例。如果您正苦于以下问题:PHP Color::colorSplit方法的具体用法?PHP Color::colorSplit怎么用?PHP Color::colorSplit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Color
的用法示例。
在下文中一共展示了Color::colorSplit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: svg_apply_css_funcs
function svg_apply_css_funcs($element, &$raw_data)
{
// Setup functions for using on values.
// Note using custom versions of svg-*-gradient().
static $functions;
if (!$functions) {
$functions = new \stdClass();
$functions->fill = new Functions(array('svg-linear-gradient' => 'CssCrush\\svg_fn_linear_gradient', 'svg-radial-gradient' => 'CssCrush\\svg_fn_radial_gradient', 'pattern' => 'CssCrush\\svg_fn_pattern'));
$functions->generic = new Functions(array_diff_key(Crush::$process->functions->register, $functions->fill->register));
}
foreach ($raw_data as $property => &$value) {
$value = $functions->generic->apply($value);
// Only capturing fills for fill and stoke properties.
if ($property === 'fill' || $property === 'stroke') {
$value = $functions->fill->apply($value, $element);
// If the value is a color with alpha component we split the color
// and set the corresponding *-opacity property because Webkit doesn't
// support rgba()/hsla() in SVG.
if ($components = Color::colorSplit($value)) {
list($color, $opacity) = $components;
$raw_data[$property] = $color;
if ($opacity < 1) {
$raw_data += array("{$property}-opacity" => $opacity);
}
}
}
}
}
示例2: parse_gradient_color_stops
function parse_gradient_color_stops(array $color_stop_args)
{
$offsets = array();
$colors = array();
$offset_patt = '~ +([\\d\\.]+%)$~';
$last_index = count($color_stop_args) - 1;
foreach ($color_stop_args as $index => $color_arg) {
if (preg_match($offset_patt, $color_arg, $m)) {
$offsets[] = floatval($m[1]);
$color = preg_replace($offset_patt, '', $color_arg);
} else {
if ($index === 0) {
$offsets[] = 0;
} elseif ($index === $last_index) {
$offsets[] = 100;
} else {
$offsets[] = null;
}
$color = $color_arg;
}
// For hsla()/rgba() extract alpha component from color values and
// convert to hsl()/rgb().
// Webkit doesn't support them for SVG colors.
$colors[] = Color::colorSplit($color);
}
// For unspecified color offsets fill in the blanks.
$next_index_not_null = 0;
$prev_index_not_null = 0;
$n = count($offsets);
foreach ($offsets as $index => $offset) {
if (!isset($offset)) {
// Scan for next non-null offset.
for ($i = $index; $i < $n; $i++) {
if (isset($offsets[$i])) {
$next_index_not_null = $i;
break;
}
}
// Get the difference between previous 'not null' offset and the next 'not null' offset.
// Divide by the number of null offsets to get a value for padding between them.
$padding_increment = ($offsets[$next_index_not_null] - $offsets[$prev_index_not_null]) / ($next_index_not_null - $index + 1);
$padding = $padding_increment;
for ($i = $index; $i < $n; $i++) {
if (isset($offsets[$i])) {
break;
}
// Replace the null offset with the new padded value.
$offsets[$i] = $offsets[$prev_index_not_null] + $padding;
// Bump the padding for the next null offset.
$padding += $padding_increment;
}
} else {
$prev_index_not_null = $index;
}
}
$stops = '';
foreach (array_combine($offsets, $colors) as $offset => $color) {
list($color_value, $opacity) = $color;
$stop_opacity = $opacity < 1 ? " stop-opacity=\"{$opacity}\"" : '';
$stops .= "<stop offset=\"{$offset}%\" stop-color=\"{$color_value}\"{$stop_opacity}/>";
}
return $stops;
}