Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
class StrategyWidthMin {
4
  var $_maxw;
5
  var $_cmaxw;
6
 
7
  function StrategyWidthMin() {
8
  }
9
 
10
  function add_width($delta) {
11
    $this->_cmaxw += $delta;
12
  }
13
 
14
  function line_break() {
15
    $this->_maxw  = max($this->_maxw, $this->_cmaxw);
16
    $this->_cmaxw = 0;
17
  }
18
 
19
  function apply(&$box, &$context) {
20
    $content_size = count($box->content);
21
 
22
    /**
23
     * If box does not have any context, its minimal width is determined by extra horizontal space:
24
     * padding, border width and margins
25
     */
26
    if ($content_size == 0) {
27
      $min_width = $box->_get_hor_extra();
28
      return $min_width;
29
    };
30
 
31
    /**
32
     * If we're in 'nowrap' mode, minimal and maximal width will be equal
33
     */
34
    $white_space = $box->get_css_property(CSS_WHITE_SPACE);
35
    $pseudo_nowrap = $box->get_css_property(CSS_HTML2PS_NOWRAP);
36
    if ($white_space   == WHITESPACE_NOWRAP ||
37
        $pseudo_nowrap == NOWRAP_NOWRAP) {
38
      $min_width = $box->get_min_nowrap_width($context);
39
      return $min_width;
40
    }
41
 
42
    /**
43
     * We need to add text indent size to the with of the first item
44
     */
45
    $start_index = 0;
46
    while ($start_index < $content_size &&
47
           $box->content[$start_index]->out_of_flow()) {
48
      $start_index++;
49
    };
50
 
51
    if ($start_index < $content_size) {
52
      $ti = $box->get_css_property(CSS_TEXT_INDENT);
53
      $minw =
54
        $ti->calculate($box) +
55
        $box->content[$start_index]->get_min_width($context);
56
    } else {
57
      $minw = 0;
58
    };
59
 
60
    for ($i=$start_index; $i<$content_size; $i++) {
61
      $item =& $box->content[$i];
62
      if (!$item->out_of_flow()) {
63
        $minw = max($minw, $item->get_min_width($context));
64
      };
65
    };
66
 
67
    /**
68
     * Apply width constraint to min width. Return maximal value
69
     */
70
    $wc = $box->get_css_property(CSS_WIDTH);
71
    $containing_block = $box->_get_containing_block();
72
 
73
    $min_width = max($minw,
74
                     $wc->apply($minw, $containing_block['right'] - $containing_block['left'])) + $box->_get_hor_extra();
75
    return $min_width;
76
  }
77
}
78
 
79
?>