1<?php 2 3require_once(HTML2PS_DIR.'inline.content.builder.php'); 4 5class InlineContentBuilderNormal extends InlineContentBuilder { 6 function InlineContentBuilderNormal() { 7 $this->InlineContentBuilder(); 8 } 9 10 /** 11 * CSS 2.1 p.16.6 12 * white-space: normal 13 * This value directs user agents to collapse sequences of whitespace, and break lines as necessary to fill line boxes. 14 */ 15 function build(&$box, $text, &$pipeline) { 16 $text = $this->remove_leading_linefeeds($text); 17 $text = $this->remove_trailing_linefeeds($text); 18 19 $content = $this->collapse_whitespace($text); 20 21 // Whitespace-only text nodes sill result on only one whitespace box 22 if (trim($content) === '') { 23 $whitespace =& WhitespaceBox::create($pipeline); 24 $box->add_child($whitespace); 25 return; 26 } 27 28 // Add leading whispace box, if content stars with a space 29 if (preg_match('/ /u', substr($content,0,1))) { 30 $whitespace =& WhitespaceBox::create($pipeline); 31 $box->add_child($whitespace); 32 } 33 34 $words = $this->break_into_words($content); 35 36 $size = count($words); 37 $pos = 0; 38 39 // Check if text content has trailing whitespace 40 $last_whitespace = substr($content, strlen($content) - 1, 1) == ' '; 41 42 foreach ($words as $word) { 43 $box->process_word($word, $pipeline); 44 $pos++; 45 46 $is_last_word = ($pos == $size); 47 48 // Whitespace boxes should be added 49 // 1) between words 50 // 2) after the last word IF there was a space at the content end 51 if (!$is_last_word || 52 $last_whitespace) { 53 $whitespace =& WhitespaceBox::create($pipeline); 54 $box->add_child($whitespace); 55 }; 56 }; 57 } 58} 59 60?>