1<?php
2
3require_once(HTML2PS_DIR.'value.padding.class.php');
4
5class CSSPadding extends CSSPropertyHandler {
6  var $default_value;
7
8  function CSSPadding() {
9    $this->default_value = $this->parse("0");
10    $this->CSSPropertyHandler(false, false);
11  }
12
13  function default_value() { return $this->default_value->copy(); }
14
15  function parse_in($value) {
16    $values = preg_split('/\s+/', trim($value));
17    switch (count($values)) {
18    case 1:
19      $v1 = $values[0];
20      return array($v1, $v1, $v1, $v1);
21    case 2:
22      $v1 = $values[0];
23      $v2 = $values[1];
24      return array($v1, $v2, $v1, $v2);
25    case 3:
26      $v1 = $values[0];
27      $v2 = $values[1];
28      $v3 = $values[2];
29      return array($v1, $v2, $v3, $v2);
30    case 4:
31      $v1 = $values[0];
32      $v2 = $values[1];
33      $v3 = $values[2];
34      $v4 = $values[3];
35      return array($v1, $v2, $v3, $v4);
36    default:
37      // We newer should get there, because 'padding' value can contain from 1 to 4 widths
38      return array(0,0,0,0);
39    };
40  }
41
42  function parse($string) {
43    if ($string === 'inherit') {
44      return CSS_PROPERTY_INHERIT;
45    };
46
47    $values = $this->parse_in($string);
48    $padding = PaddingValue::init($values);
49
50    return $padding;
51  }
52
53  function get_property_code() {
54    return CSS_PADDING;
55  }
56
57  function get_property_name() {
58    return 'padding';
59  }
60}
61
62class CSSPaddingTop extends CSSSubFieldProperty {
63  function parse($value) {
64    if ($value === 'inherit') { return CSS_PROPERTY_INHERIT; };
65    return PaddingSideValue::init($value);
66  }
67
68  function get_property_code() {
69    return CSS_PADDING_TOP;
70  }
71
72  function get_property_name() {
73    return 'padding-top';
74  }
75}
76
77class CSSPaddingRight extends CSSSubFieldProperty {
78  function parse($value) {
79    if ($value === 'inherit') { return CSS_PROPERTY_INHERIT; };
80    $result = PaddingSideValue::init($value);
81    return $result;
82  }
83
84  function get_property_code() {
85    return CSS_PADDING_RIGHT;
86  }
87
88  function get_property_name() {
89    return 'padding-right';
90  }
91}
92
93class CSSPaddingLeft extends CSSSubFieldProperty {
94  function parse($value) {
95    if ($value === 'inherit') { return CSS_PROPERTY_INHERIT; };
96    return PaddingSideValue::init($value);
97  }
98
99  function get_property_code() {
100    return CSS_PADDING_LEFT;
101  }
102
103  function get_property_name() {
104    return 'padding-left';
105  }
106}
107
108class CSSPaddingBottom extends CSSSubFieldProperty {
109  function parse($value) {
110    if ($value === 'inherit') {
111      return CSS_PROPERTY_INHERIT;
112    };
113
114    return PaddingSideValue::init($value);
115  }
116
117  function get_property_code() {
118    return CSS_PADDING_BOTTOM;
119  }
120
121  function get_property_name() {
122    return 'padding-bottom';
123  }
124}
125
126$ph = new CSSPadding;
127CSS::register_css_property($ph);
128CSS::register_css_property(new CSSPaddingLeft($ph,   'left'));
129CSS::register_css_property(new CSSPaddingRight($ph,  'right'));
130CSS::register_css_property(new CSSPaddingTop($ph,    'top'));
131CSS::register_css_property(new CSSPaddingBottom($ph, 'bottom'));
132
133?>
134