1<?php 2 3class StrategyWidthMinNowrap { 4 var $_maxw; 5 var $_cmaxw; 6 7 function StrategyWidthMinNowrap() { 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 $this->_maxw = 0; 21 22 // We need to add text indent to the width 23 $ti = $box->get_css_property(CSS_TEXT_INDENT); 24 $this->add_width($ti->calculate($box)); 25 26 for ($i=0, $size = count($box->content); $i<$size; $i++) { 27 $child =& $box->content[$i]; 28 if ($child->isLineBreak()) { 29 $this->line_break(); 30 } elseif (!$child->out_of_flow()) { 31 if (is_inline($child)) { 32 // Inline boxes content will not be wrapped, so we may calculate its max width 33 $this->add_width($child->get_max_width($context)); 34 } else { 35 // Non-inline boxes cause line break 36 $this->line_break(); 37 $this->add_width($child->get_min_width($context)); 38 $this->line_break(); 39 } 40 }; 41 } 42 43 // Check if last line have maximal width 44 $this->line_break(); 45 46 // Apply width constraint to min width. Return maximal value 47 $wc = $box->get_css_property(CSS_WIDTH); 48 return max($this->_maxw, $wc->apply($this->_maxw, $box->parent->get_width())) + $box->_get_hor_extra(); 49 } 50} 51 52?>