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 StrategyWidthMax {
4
  var $_limit;
5
  var $_maxw;
6
  var $_cmaxw;
7
 
8
  function StrategyWidthMax($limit = 10E6) {
9
    $this->_limit = $limit;
10
  }
11
 
12
  function add_width($delta) {
13
    if ($this->_cmaxw + $delta > $this->_limit) {
14
      $this->line_break();
15
    };
16
    $this->_cmaxw += $delta;
17
  }
18
 
19
  function line_break() {
20
    $this->_maxw  = max($this->_maxw, $this->_cmaxw);
21
    $this->_cmaxw = 0;
22
  }
23
 
24
  function apply(&$box, &$context) {
25
    $this->_maxw = 0;
26
 
27
    // We need to add text indent to the max width
28
    $text_indent = $box->get_css_property(CSS_TEXT_INDENT);
29
    $this->_cmaxw = $text_indent->calculate($box);
30
 
31
    for ($i=0, $size = count($box->content); $i<$size; $i++) {
32
      $child =& $box->content[$i];
33
 
34
      if ($child->isLineBreak()) {
35
        $this->line_break();
36
 
37
      } elseif (!$child->out_of_flow()) {
38
        if (is_inline($child) ||
39
            $child->get_css_property(CSS_FLOAT) !== FLOAT_NONE) {
40
          $this->add_width($child->get_max_width($context, $this->_limit));
41
        } else {
42
          $this->line_break();
43
          $this->add_width($child->get_max_width($context, $this->_limit));
44
 
45
          // Process special case with percentage constrained table
46
          $item_wc = $child->get_css_property(CSS_WIDTH);
47
 
48
          if (is_a($child,    "TableBox") &&
49
              is_a($item_wc, "WCFraction")) {
50
            $this->_cmaxw = max($this->_cmaxw,
51
                                $item_wc->apply($box->get_width(),
52
                                                $box->parent->get_expandable_width()));
53
          };
54
          $this->line_break();
55
        };
56
      };
57
    }
58
 
59
    // Check if last line have maximal width
60
    //
61
    $this->line_break();
62
 
63
    // Note that max width cannot differ from constrained width,
64
    // if any width constraints apply
65
    //
66
    $wc = $box->get_css_property(CSS_WIDTH);
67
    if ($wc->applicable($box)) {
68
      if ($box->parent) {
69
        $this->_maxw = $wc->apply($this->_maxw, $box->parent->get_width());
70
      } else {
71
        $this->_maxw = $wc->apply($this->_maxw, $this->_maxw);
72
      };
73
    };
74
 
75
    return $this->_maxw + $box->_get_hor_extra();
76
  }
77
}
78
 
79
?>