1<?php
2
3require_once(HTML2PS_DIR.'value.generic.php');
4
5class PaddingSideValue {
6  var $value;
7  var $auto;
8  var $percentage;
9  var $_units;
10
11  function calcPercentage($base) {
12    if (is_null($this->percentage)) {
13      return;
14    };
15
16    $this->value = $base * $this->percentage / 100;
17  }
18
19  function &copy() {
20    $value =& new PaddingSideValue;
21    $value->value      = $this->value;
22    $value->auto       = $this->auto;
23    $value->percentage = $this->percentage;
24    $value->_units     = $this->_units;
25    return $value;
26  }
27
28  function get_value() {
29    return $this->value;
30  }
31
32  function is_default() {
33    return
34      $this->value == 0 &&
35      !$this->auto &&
36      !$this->percentage;
37  }
38
39  function init($data) {
40    $len = strlen($data);
41    $is_percentage = false;
42    if ($len > 0) {
43      $is_percentage = ($data{$len-1} === '%');
44    };
45
46    $value = new PaddingSideValue;
47    $value->_units     = Value::fromString($data);
48    $value->value      = $data;
49    $value->percentage = $is_percentage ? (int)($data) : null;
50    $value->auto       = $data === 'auto';
51    return $value;
52  }
53
54  function units2pt($base) {
55    if (is_null($this->percentage)) {
56      $this->value = $this->_units->toPt($base);
57    };
58  }
59}
60
61class PaddingValue extends CSSValue {
62  var $top;
63  var $bottom;
64  var $left;
65  var $right;
66
67  function doInherit(&$state) {
68    if ($this->top === CSS_PROPERTY_INHERIT) {
69      $value = $state->getInheritedProperty(CSS_PADDING_TOP);
70      $this->top = $value->copy();
71    };
72
73    if ($this->bottom === CSS_PROPERTY_INHERIT) {
74      $value = $state->getInheritedProperty(CSS_PADDING_BOTTOM);
75      $this->bottom = $value->copy();
76    };
77
78    if ($this->right === CSS_PROPERTY_INHERIT) {
79      $value = $state->getInheritedProperty(CSS_PADDING_RIGHT);
80      $this->right = $value->copy();
81    };
82
83    if ($this->left === CSS_PROPERTY_INHERIT) {
84      $value = $state->getInheritedProperty(CSS_PADDING_LEFT);
85      $this->left = $value->copy();
86    };
87  }
88
89  function &copy() {
90    $value =& new PaddingValue;
91    $value->top    = ($this->top    === CSS_PROPERTY_INHERIT) ? CSS_PROPERTY_INHERIT : $this->top->copy();
92    $value->bottom = ($this->bottom === CSS_PROPERTY_INHERIT) ? CSS_PROPERTY_INHERIT : $this->bottom->copy();
93    $value->left   = ($this->left   === CSS_PROPERTY_INHERIT) ? CSS_PROPERTY_INHERIT : $this->left->copy();
94    $value->right  = ($this->right  === CSS_PROPERTY_INHERIT) ? CSS_PROPERTY_INHERIT : $this->right->copy();
95    return $value;
96  }
97
98  function is_default() {
99    return
100      $this->left->is_default() &&
101      $this->right->is_default() &&
102      $this->top->is_default() &&
103      $this->bottom->is_default();
104  }
105
106  function init($data) {
107    $value = new PaddingValue;
108    $value->top    = PaddingSideValue::init($data[0]);
109    $value->right  = PaddingSideValue::init($data[1]);
110    $value->bottom = PaddingSideValue::init($data[2]);
111    $value->left   = PaddingSideValue::init($data[3]);
112    return $value;
113  }
114
115  function units2pt($base) {
116    $this->top->units2pt($base);
117    $this->bottom->units2pt($base);
118    $this->left->units2pt($base);
119    $this->right->units2pt($base);
120  }
121
122  function calcPercentages($base) {
123    $this->top->calcPercentage($base);
124    $this->bottom->calcPercentage($base);
125    $this->left->calcPercentage($base);
126    $this->right->calcPercentage($base);
127  }
128}
129
130?>