1<?php 2// $Header: /cvsroot/html2ps/css.background.color.inc.php,v 1.16 2007/01/24 18:55:50 Konstantin Exp $ 3 4// 'background-color' and color part of 'background' CSS properies handler 5 6class CSSBackgroundColor extends CSSSubFieldProperty { 7 function get_property_code() { 8 return CSS_BACKGROUND_COLOR; 9 } 10 11 function get_property_name() { 12 return 'background-color'; 13 } 14 15 function default_value() { 16 // Transparent color 17 return new Color(array(0,0,0), true); 18 } 19 20 // Note: we cannot use parse_color_declaration here directly, as at won't process composite 'background' values 21 // containing, say, both background image url and background color; on the other side, 22 // parse_color_declaration slow down if we'll put this composite-value processing there 23 function parse($value) { 24 // We should not split terms at whitespaces immediately preceeded by ( or , symbols, as 25 // it would break "rgb( xxx, yyy, zzz)" notation 26 // 27 // As whitespace could be preceeded by another whitespace, we should prevent breaking 28 // value in the middle of long whitespace too 29 $terms = preg_split('/(?<![,(\s])\s+(?![,)\s])/ ',$value); 30 31 // Note that color declaration always will contain only one word; 32 // thus, we can split out value into words and try to parse each one as color 33 // if parse_color_declaration returns transparent value, it is possible not 34 // a color part of background declaration 35 foreach ($terms as $term) { 36 if ($term === 'inherit') { 37 return CSS_PROPERTY_INHERIT; 38 } 39 40 $color =& parse_color_declaration($term); 41 42 if (!$color->isTransparent()) { 43 return $color; 44 } 45 } 46 47 return CSSBackgroundColor::default_value(); 48 } 49 50 function get_visible_background_color() { 51 $owner =& $this->owner(); 52 53 for ($i=0, $size = count($owner->_stack); $i<$size; $i++) { 54 if ($owner->_stack[$i][0]->color[0] >= 0) { 55 return $owner->_stack[$i][0]->color; 56 }; 57 }; 58 return array(255,255,255); 59 } 60} 61 62?>