1<?php
2// $Header: /cvsroot/html2ps/css.border.inc.php,v 1.25 2006/11/11 13:43:52 Konstantin Exp $
3
4require_once(HTML2PS_DIR.'css.border.color.inc.php');
5require_once(HTML2PS_DIR.'css.border.style.inc.php');
6require_once(HTML2PS_DIR.'css.border.width.inc.php');
7
8require_once(HTML2PS_DIR.'css.border.top.inc.php');
9require_once(HTML2PS_DIR.'css.border.right.inc.php');
10require_once(HTML2PS_DIR.'css.border.left.inc.php');
11require_once(HTML2PS_DIR.'css.border.bottom.inc.php');
12
13require_once(HTML2PS_DIR.'css.border.top.color.inc.php');
14require_once(HTML2PS_DIR.'css.border.right.color.inc.php');
15require_once(HTML2PS_DIR.'css.border.left.color.inc.php');
16require_once(HTML2PS_DIR.'css.border.bottom.color.inc.php');
17
18require_once(HTML2PS_DIR.'css.border.top.style.inc.php');
19require_once(HTML2PS_DIR.'css.border.right.style.inc.php');
20require_once(HTML2PS_DIR.'css.border.left.style.inc.php');
21require_once(HTML2PS_DIR.'css.border.bottom.style.inc.php');
22
23require_once(HTML2PS_DIR.'css.border.top.width.inc.php');
24require_once(HTML2PS_DIR.'css.border.right.width.inc.php');
25require_once(HTML2PS_DIR.'css.border.left.width.inc.php');
26require_once(HTML2PS_DIR.'css.border.bottom.width.inc.php');
27
28require_once(HTML2PS_DIR.'value.generic.length.php');
29require_once(HTML2PS_DIR.'value.border.class.php');
30require_once(HTML2PS_DIR.'value.border.edge.class.php');
31
32define('BORDER_VALUE_COLOR',1);
33define('BORDER_VALUE_WIDTH',2);
34define('BORDER_VALUE_STYLE',3);
35
36class 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();
125CSS::register_css_property($border);
126
127CSS::register_css_property(new CSSBorderColor($border));
128CSS::register_css_property(new CSSBorderWidth($border));
129CSS::register_css_property(new CSSBorderStyle($border));
130
131CSS::register_css_property(new CSSBorderTop($border, 'top'));
132CSS::register_css_property(new CSSBorderRight($border, 'right'));
133CSS::register_css_property(new CSSBorderBottom($border, 'bottom'));
134CSS::register_css_property(new CSSBorderLeft($border, 'left'));
135
136CSS::register_css_property(new CSSBorderLeftColor($border));
137CSS::register_css_property(new CSSBorderTopColor($border));
138CSS::register_css_property(new CSSBorderRightColor($border));
139CSS::register_css_property(new CSSBorderBottomColor($border));
140
141CSS::register_css_property(new CSSBorderLeftStyle($border));
142CSS::register_css_property(new CSSBorderTopStyle($border));
143CSS::register_css_property(new CSSBorderRightStyle($border));
144CSS::register_css_property(new CSSBorderBottomStyle($border));
145
146CSS::register_css_property(new CSSBorderLeftWidth($border));
147CSS::register_css_property(new CSSBorderTopWidth($border));
148CSS::register_css_property(new CSSBorderRightWidth($border));
149CSS::register_css_property(new CSSBorderBottomWidth($border));
150
151?>