1<?php
2
3require_once(HTML2PS_DIR.'value.generic.php');
4require_once(HTML2PS_DIR.'value.generic.length.php');
5
6define('VALUE_NORMAL', 0);
7define('VALUE_AUTO',   1);
8define('VALUE_PERCENTAGE', 2);
9
10class CSSValuePercentage extends CSSValue {
11  var $_value;
12  var $_status;
13
14  function init($value, $status) {
15    $this->_value = $value;
16    $this->_status = $status;
17  }
18
19  function &_fromString($value, &$class_object) {
20    if ($value == 'inherit') {
21      $dummy = CSS_PROPERTY_INHERIT;
22      return $dummy;
23    };
24
25    if ($value == 'auto' || $value == '') {
26      $class_object->init(null, VALUE_AUTO);
27      return $class_object;
28    };
29
30    $strlen = strlen($value);
31    if ($value{$strlen-1} == '%') {
32      $class_object->init((float)$value, VALUE_PERCENTAGE);
33      return $class_object;
34    };
35
36    $class_object->init(Value::fromString($value), VALUE_NORMAL);
37    return $class_object;
38  }
39
40  function units2pt($font_size) {
41    if ($this->isNormal()) {
42      $this->_value->units2pt($font_size);
43    };
44  }
45
46  function getPoints($base_size = 0) {
47    if ($this->isPercentage()) {
48      return $base_size * $this->getPercentage();
49    } else {
50      return $this->_value->getPoints();
51    };
52  }
53
54  function isAuto() {
55    return $this->_status == VALUE_AUTO;
56  }
57
58  function isNormal() {
59    return $this->_status == VALUE_NORMAL;
60  }
61
62  function isPercentage() {
63    return $this->_status == VALUE_PERCENTAGE;
64  }
65
66  function &_copy(&$value) {
67    if ($this->isNormal()) {
68      $value->_value  = $this->_value->copy();
69    } else {
70      $value->_value  = $this->_value;
71    };
72
73    $value->_status = $this->_status;
74    return $value;
75  }
76
77  function getPercentage() {
78    if ($this->_status != VALUE_PERCENTAGE) {
79      die("Invalid percentage value type");
80    };
81
82    return $this->_value;
83  }
84}
85
86?>