| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Header: /cvsroot/html2ps/css.border.inc.php,v 1.25 2006/11/11 13:43:52 Konstantin Exp $
|
|
|
3 |
|
|
|
4 |
require_once(HTML2PS_DIR.'css.border.color.inc.php');
|
|
|
5 |
require_once(HTML2PS_DIR.'css.border.style.inc.php');
|
|
|
6 |
require_once(HTML2PS_DIR.'css.border.width.inc.php');
|
|
|
7 |
|
|
|
8 |
require_once(HTML2PS_DIR.'css.border.top.inc.php');
|
|
|
9 |
require_once(HTML2PS_DIR.'css.border.right.inc.php');
|
|
|
10 |
require_once(HTML2PS_DIR.'css.border.left.inc.php');
|
|
|
11 |
require_once(HTML2PS_DIR.'css.border.bottom.inc.php');
|
|
|
12 |
|
|
|
13 |
require_once(HTML2PS_DIR.'css.border.top.color.inc.php');
|
|
|
14 |
require_once(HTML2PS_DIR.'css.border.right.color.inc.php');
|
|
|
15 |
require_once(HTML2PS_DIR.'css.border.left.color.inc.php');
|
|
|
16 |
require_once(HTML2PS_DIR.'css.border.bottom.color.inc.php');
|
|
|
17 |
|
|
|
18 |
require_once(HTML2PS_DIR.'css.border.top.style.inc.php');
|
|
|
19 |
require_once(HTML2PS_DIR.'css.border.right.style.inc.php');
|
|
|
20 |
require_once(HTML2PS_DIR.'css.border.left.style.inc.php');
|
|
|
21 |
require_once(HTML2PS_DIR.'css.border.bottom.style.inc.php');
|
|
|
22 |
|
|
|
23 |
require_once(HTML2PS_DIR.'css.border.top.width.inc.php');
|
|
|
24 |
require_once(HTML2PS_DIR.'css.border.right.width.inc.php');
|
|
|
25 |
require_once(HTML2PS_DIR.'css.border.left.width.inc.php');
|
|
|
26 |
require_once(HTML2PS_DIR.'css.border.bottom.width.inc.php');
|
|
|
27 |
|
|
|
28 |
require_once(HTML2PS_DIR.'value.generic.length.php');
|
|
|
29 |
require_once(HTML2PS_DIR.'value.border.class.php');
|
|
|
30 |
require_once(HTML2PS_DIR.'value.border.edge.class.php');
|
|
|
31 |
|
|
|
32 |
define('BORDER_VALUE_COLOR',1);
|
|
|
33 |
define('BORDER_VALUE_WIDTH',2);
|
|
|
34 |
define('BORDER_VALUE_STYLE',3);
|
|
|
35 |
|
|
|
36 |
class CSSBorder extends CSSPropertyHandler {
|
|
|
37 |
var $_defaultValue;
|
|
|
38 |
|
|
|
39 |
function CSSBorder() {
|
|
|
40 |
$this->CSSPropertyHandler(false, false);
|
|
|
41 |
|
|
|
42 |
$this->_defaultValue = BorderPDF::create(array('top' => array('width' => Value::fromString('2px'),
|
|
|
43 |
'color' => array(0,0,0),
|
|
|
44 |
'style' => BS_NONE),
|
|
|
45 |
'right' => array('width' => Value::fromString('2px'),
|
|
|
46 |
'color' => array(0,0,0),
|
|
|
47 |
'style' => BS_NONE),
|
|
|
48 |
'bottom' => array('width' => Value::fromString('2px'),
|
|
|
49 |
'color' => array(0,0,0),
|
|
|
50 |
'style' => BS_NONE),
|
|
|
51 |
'left' => array('width' => Value::fromString('2px'),
|
|
|
52 |
'color' => array(0,0,0),
|
|
|
53 |
'style' => BS_NONE)));
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
function default_value() {
|
|
|
57 |
return $this->_defaultValue;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
function parse($value) {
|
|
|
61 |
if ($value == 'inherit') {
|
|
|
62 |
return CSS_PROPERTY_INHERIT;
|
|
|
63 |
};
|
|
|
64 |
|
|
|
65 |
// Remove spaces between color values in rgb() color definition; this will allow us to tread
|
|
|
66 |
// this declaration as a single value
|
|
|
67 |
$value = preg_replace("/\s*,\s*/",",",$value);
|
|
|
68 |
|
|
|
69 |
// Remove spaces before and after parens in rgb color definition
|
|
|
70 |
$value = preg_replace("/rgb\s*\(\s*(.*?)\s*\)/", 'rgb(\1)', $value);
|
|
|
71 |
|
|
|
72 |
$subvalues = explode(" ", $value);
|
|
|
73 |
|
|
|
74 |
$border = CSS::getDefaultValue(CSS_BORDER);
|
|
|
75 |
|
|
|
76 |
foreach ($subvalues as $subvalue) {
|
|
|
77 |
$subvalue = trim(strtolower($subvalue));
|
|
|
78 |
|
|
|
79 |
switch (CSSBorder::detect_border_value_type($subvalue)) {
|
|
|
80 |
case BORDER_VALUE_COLOR:
|
|
|
81 |
$color_handler = CSS::get_handler(CSS_BORDER_COLOR);
|
|
|
82 |
$border_color = $color_handler->parse($subvalue);
|
|
|
83 |
$color_handler->set_value($border, $border_color);
|
|
|
84 |
break;
|
|
|
85 |
case BORDER_VALUE_WIDTH:
|
|
|
86 |
$width_handler = CSS::get_handler(CSS_BORDER_WIDTH);
|
|
|
87 |
$border_width = $width_handler->parse($subvalue);
|
|
|
88 |
$width_handler->set_value($border, $border_width);
|
|
|
89 |
break;
|
|
|
90 |
case BORDER_VALUE_STYLE:
|
|
|
91 |
$style_handler = CSS::get_handler(CSS_BORDER_STYLE);
|
|
|
92 |
$border_style = $style_handler->parse($subvalue);
|
|
|
93 |
$style_handler->set_value($border, $border_style);
|
|
|
94 |
break;
|
|
|
95 |
};
|
|
|
96 |
};
|
|
|
97 |
|
|
|
98 |
return $border;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
function get_property_code() {
|
|
|
102 |
return CSS_BORDER;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
function get_property_name() {
|
|
|
106 |
return 'border';
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
function detect_border_value_type($value) {
|
|
|
110 |
$color = _parse_color_declaration($value, $success);
|
|
|
111 |
if ($success) { return BORDER_VALUE_COLOR; };
|
|
|
112 |
|
|
|
113 |
// if (preg_match("/\b(transparent|black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua|rgb(.*?))\b/i",$value)) { return BORDER_VALUE_COLOR; };
|
|
|
114 |
// // We must detect hecadecimal values separately, as #-sign will not match the \b metacharacter at the beginning of previous regexp
|
|
|
115 |
// if (preg_match("/#([[:xdigit:]]{3}|[[:xdigit:]]{6})\b/i",$value)) { return BORDER_VALUE_COLOR; };
|
|
|
116 |
|
|
|
117 |
// Note that unit name is in general not required, so that we can meet rule like "border: 0" in CSS!
|
|
|
118 |
if (preg_match("/\b(thin|medium|thick|[+-]?\d+(.\d*)?(em|ex|px|in|cm|mm|pt|pc)?)\b/i",$value)) { return BORDER_VALUE_WIDTH; };
|
|
|
119 |
if (preg_match("/\b(none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset)\b/",$value)) { return BORDER_VALUE_STYLE; };
|
|
|
120 |
return;
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
$border = new CSSBorder();
|
|
|
125 |
CSS::register_css_property($border);
|
|
|
126 |
|
|
|
127 |
CSS::register_css_property(new CSSBorderColor($border));
|
|
|
128 |
CSS::register_css_property(new CSSBorderWidth($border));
|
|
|
129 |
CSS::register_css_property(new CSSBorderStyle($border));
|
|
|
130 |
|
|
|
131 |
CSS::register_css_property(new CSSBorderTop($border, 'top'));
|
|
|
132 |
CSS::register_css_property(new CSSBorderRight($border, 'right'));
|
|
|
133 |
CSS::register_css_property(new CSSBorderBottom($border, 'bottom'));
|
|
|
134 |
CSS::register_css_property(new CSSBorderLeft($border, 'left'));
|
|
|
135 |
|
|
|
136 |
CSS::register_css_property(new CSSBorderLeftColor($border));
|
|
|
137 |
CSS::register_css_property(new CSSBorderTopColor($border));
|
|
|
138 |
CSS::register_css_property(new CSSBorderRightColor($border));
|
|
|
139 |
CSS::register_css_property(new CSSBorderBottomColor($border));
|
|
|
140 |
|
|
|
141 |
CSS::register_css_property(new CSSBorderLeftStyle($border));
|
|
|
142 |
CSS::register_css_property(new CSSBorderTopStyle($border));
|
|
|
143 |
CSS::register_css_property(new CSSBorderRightStyle($border));
|
|
|
144 |
CSS::register_css_property(new CSSBorderBottomStyle($border));
|
|
|
145 |
|
|
|
146 |
CSS::register_css_property(new CSSBorderLeftWidth($border));
|
|
|
147 |
CSS::register_css_property(new CSSBorderTopWidth($border));
|
|
|
148 |
CSS::register_css_property(new CSSBorderRightWidth($border));
|
|
|
149 |
CSS::register_css_property(new CSSBorderBottomWidth($border));
|
|
|
150 |
|
|
|
151 |
?>
|