1<?php
2// $Header: /cvsroot/html2ps/css.border.style.inc.php,v 1.6 2006/11/11 13:43:52 Konstantin Exp $
3
4require_once(HTML2PS_DIR.'value.border.style.class.php');
5
6class CSSBorderStyle extends CSSSubProperty {
7  var $_defaultValue;
8
9  function CSSBorderStyle(&$owner) {
10    $this->CSSSubProperty($owner);
11
12    $this->_defaultValue = new BorderStyle(BS_NONE,
13                                           BS_NONE,
14                                           BS_NONE,
15                                           BS_NONE);
16  }
17
18  function set_value(&$owner_value, &$value) {
19    if ($value != CSS_PROPERTY_INHERIT) {
20      $owner_value->top->style    = $value->top;
21      $owner_value->right->style  = $value->right;
22      $owner_value->bottom->style = $value->bottom;
23      $owner_value->left->style   = $value->left;
24    } else {
25      $owner_value->top->style    = CSS_PROPERTY_INHERIT;
26      $owner_value->right->style  = CSS_PROPERTY_INHERIT;
27      $owner_value->bottom->style = CSS_PROPERTY_INHERIT;
28      $owner_value->left->style   = CSS_PROPERTY_INHERIT;
29    };
30  }
31
32  function get_value(&$owner_value) {
33    return new BorderStyle($owner_value->top->style,
34                           $owner_value->right->style,
35                           $owner_value->bottom->style,
36                           $owner_value->left->style);
37  }
38
39  function get_property_code() {
40    return CSS_BORDER_STYLE;
41  }
42
43  function get_property_name() {
44    return 'border-style';
45  }
46
47  function default_value() {
48    return $this->_defaultValue;
49  }
50
51  function parse_style($value) {
52    switch ($value) {
53    case "solid":
54      return BS_SOLID;
55    case "dashed":
56      return BS_DASHED;
57    case "dotted":
58      return BS_DOTTED;
59    case "double":
60      return BS_DOUBLE;
61    case "inset":
62      return BS_INSET;
63    case "outset":
64      return BS_OUTSET;
65    case "groove":
66      return BS_GROOVE;
67    case "ridge":
68      return BS_RIDGE;
69    default:
70      return BS_NONE;
71    };
72  }
73
74  function parse_in($value) {
75    $values = explode(" ",$value);
76
77    switch (count($values)) {
78    case 1:
79      $v1 = $this->parse_style($values[0]);
80      return array($v1, $v1, $v1, $v1);
81    case 2:
82      $v1 = $this->parse_style($values[0]);
83      $v2 = $this->parse_style($values[1]);
84      return array($v1, $v2, $v1, $v2);
85    case 3:
86      $v1 = $this->parse_style($values[0]);
87      $v2 = $this->parse_style($values[1]);
88      $v3 = $this->parse_style($values[2]);
89      return array($v1, $v2, $v3, $v2);
90    case 4:
91      $v1 = $this->parse_style($values[0]);
92      $v2 = $this->parse_style($values[1]);
93      $v3 = $this->parse_style($values[2]);
94      $v4 = $this->parse_style($values[3]);
95      return array($v1, $v2, $v3, $v4);
96    default:
97      return $this->default_value();
98    };
99  }
100
101  function parse($value) {
102    if ($value == 'inherit') {
103      return CSS_PROPERTY_INHERIT;
104    }
105
106    $values = $this->parse_in($value);
107
108    return new BorderStyle($values[0],
109                           $values[1],
110                           $values[2],
111                           $values[3]);
112  }
113}
114
115?>