Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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