| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
require_once(HTML2PS_DIR.'value.generic.php');
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* @package HTML2PS
|
|
|
7 |
* @subpackage Document
|
|
|
8 |
* Represents the 'background' CSS property value (including 'background-...' subproperties).
|
|
|
9 |
*
|
|
|
10 |
* @link http://www.w3.org/TR/CSS21/colors.html#propdef-background CSS 2.1 'background' property description
|
|
|
11 |
*/
|
|
|
12 |
class Background extends CSSValue {
|
|
|
13 |
/**
|
|
|
14 |
* @var Color Contains the 'background-color' CSS subproperty value
|
|
|
15 |
* @access private
|
|
|
16 |
*/
|
|
|
17 |
var $_color;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* @var BackgroundImage Contains the 'background-image' CSS subproperty value
|
|
|
21 |
* @access private
|
|
|
22 |
*/
|
|
|
23 |
var $_image;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* @var int Contains the 'background-repeat' CSS subproperty value (enumeration)
|
|
|
27 |
* @access private
|
|
|
28 |
*/
|
|
|
29 |
var $_repeat;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* @var BackgroundPosition Containg the 'background-position' CSS subproperty value
|
|
|
33 |
* @access private
|
|
|
34 |
*/
|
|
|
35 |
var $_position;
|
|
|
36 |
|
|
|
37 |
var $_attachment;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Constructs a new object containing a background information
|
|
|
41 |
*
|
|
|
42 |
* @param Color $color 'background-color' value
|
|
|
43 |
* @param BackgroundImage $image 'background-image' value
|
|
|
44 |
* @param int $repeat 'background-repeat' value
|
|
|
45 |
* @param BackgroundPosition $position 'background-position' value
|
|
|
46 |
*/
|
|
|
47 |
function Background($color, $image, $repeat, $position, $attachment) {
|
|
|
48 |
$this->_color = $color;
|
|
|
49 |
$this->_image = $image;
|
|
|
50 |
$this->_repeat = $repeat;
|
|
|
51 |
$this->_position = $position;
|
|
|
52 |
$this->_attachment = $attachment;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* "Deep copy" routine
|
|
|
57 |
*
|
|
|
58 |
* @return Background A copy of current object
|
|
|
59 |
*/
|
|
|
60 |
function ©() {
|
|
|
61 |
$value =& new Background(is_null($this->_color) ? null : $this->_color->copy(),
|
|
|
62 |
is_null($this->_image) ? null : $this->_image->copy(),
|
|
|
63 |
$this->_repeat,
|
|
|
64 |
is_null($this->_position) ? null : $this->_position->copy(),
|
|
|
65 |
$this->_attachment);
|
|
|
66 |
|
|
|
67 |
return $value;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Tests if the 'background' CSS property value is the default property value; e.g.
|
|
|
72 |
* all subproperty values are set to defaults.
|
|
|
73 |
*
|
|
|
74 |
* @return bool Flag indicating if current object have default value
|
|
|
75 |
*
|
|
|
76 |
* @see CSSBackgroundColor::default_value
|
|
|
77 |
* @see BackgroundImage::is_default
|
|
|
78 |
* @see CSSBackgroundRepeat::default_value
|
|
|
79 |
* @see BackgroundPosition::is_default
|
|
|
80 |
*/
|
|
|
81 |
function is_default() {
|
|
|
82 |
return
|
|
|
83 |
$this->_color->equals(CSSBackgroundColor::default_value()) &&
|
|
|
84 |
$this->_image->is_default() &&
|
|
|
85 |
$this->_repeat == CSSBackgroundRepeat::default_value() &&
|
|
|
86 |
$this->_position->is_default() &&
|
|
|
87 |
$this->_attachment->is_default();
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Renders the background for the given box object using an output driver
|
|
|
92 |
*
|
|
|
93 |
* @param OutputDriver $driver Output driver to be used
|
|
|
94 |
* @param GenericFormattedBox $box Box the background is rendered for
|
|
|
95 |
*
|
|
|
96 |
* @uses GenericFormattedBox
|
|
|
97 |
* @uses OutputDriver
|
|
|
98 |
*/
|
|
|
99 |
function show(&$driver, &$box) {
|
|
|
100 |
/**
|
|
|
101 |
* Fill box with background color
|
|
|
102 |
*
|
|
|
103 |
* @see Color::apply
|
|
|
104 |
* @see OutputDriver::moveto
|
|
|
105 |
* @see OutputDriver::lineto
|
|
|
106 |
* @see OutputDriver::closepath
|
|
|
107 |
* @see OutputDriver::fill
|
|
|
108 |
*/
|
|
|
109 |
if (!$this->_color->transparent) {
|
|
|
110 |
$this->_color->apply($driver);
|
|
|
111 |
$driver->moveto($box->get_left_background(), $box->get_top_background());
|
|
|
112 |
$driver->lineto($box->get_right_background(), $box->get_top_background());
|
|
|
113 |
$driver->lineto($box->get_right_background(), $box->get_bottom_background());
|
|
|
114 |
$driver->lineto($box->get_left_background(), $box->get_bottom_background());
|
|
|
115 |
$driver->closepath();
|
|
|
116 |
$driver->fill();
|
|
|
117 |
};
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
* Render background image
|
|
|
121 |
*
|
|
|
122 |
* @see BackgroundImage::show
|
|
|
123 |
*/
|
|
|
124 |
$this->_image->show($driver, $box, $this->_repeat, $this->_position, $this->_attachment);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
/**
|
|
|
128 |
* Converts the absolute lengths used in subproperties (if any) to the device points
|
|
|
129 |
*
|
|
|
130 |
* @param float $font_size Font size to use during conversion of 'ex' and 'em' units
|
|
|
131 |
*/
|
|
|
132 |
function units2pt($font_size) {
|
|
|
133 |
$this->_position->units2pt($font_size);
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
function doInherit(&$state) {
|
|
|
137 |
if ($this->_color === CSS_PROPERTY_INHERIT) {
|
|
|
138 |
$value =& $state->getInheritedProperty(CSS_BACKGROUND_COLOR);
|
|
|
139 |
$this->_color = $value->copy();
|
|
|
140 |
};
|
|
|
141 |
|
|
|
142 |
if ($this->_image === CSS_PROPERTY_INHERIT) {
|
|
|
143 |
$value =& $state->getInheritedProperty(CSS_BACKGROUND_IMAGE);
|
|
|
144 |
$this->_image = $value->copy();
|
|
|
145 |
};
|
|
|
146 |
|
|
|
147 |
if ($this->_position === CSS_PROPERTY_INHERIT) {
|
|
|
148 |
$value =& $state->getInheritedProperty(CSS_BACKGROUND_POSITION);
|
|
|
149 |
$this->_position = $value->copy();
|
|
|
150 |
};
|
|
|
151 |
|
|
|
152 |
if ($this->_repeat === CSS_PROPERTY_INHERIT) {
|
|
|
153 |
$this->_repeat = $state->getInheritedProperty(CSS_BACKGROUND_REPEAT);
|
|
|
154 |
};
|
|
|
155 |
|
|
|
156 |
if ($this->_attachment === CSS_PROPERTY_INHERIT) {
|
|
|
157 |
$this->_attachment =& $state->getInheritedProperty(CSS_BACKGROUND_ATTACHMENT);
|
|
|
158 |
};
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
?>
|