1<?php 2// $Header: /cvsroot/html2ps/box.whitespace.php,v 1.33 2007/01/24 18:55:46 Konstantin Exp $ 3 4class WhitespaceBox extends TextBox { 5 function &create(&$pipeline) { 6 $box =& new WhitespaceBox(); 7 $box->readCSS($pipeline->get_current_css_state()); 8 $box->add_subword(" ", 'iso-8859-1', array()); 9 return $box; 10 } 11 12 function readCSS(&$state) { 13 parent::readCSS($state); 14 15 $this->_readCSSLengths($state, 16 array(CSS_WORD_SPACING)); 17 } 18 19 function get_extra_bottom() { 20 return 0; 21 } 22 23 // "Pure" Text boxes never have margins/border/padding 24 function get_extra_left() { 25 return 0; 26 } 27 28 // "Pure" Text boxes never have margins/border/padding 29 function get_extra_right() { 30 return 0; 31 } 32 33 function get_extra_top() { 34 return 0; 35 } 36 37 function get_full_width() { 38 return $this->width; 39 } 40 41 function get_margin_top() { 42 return 0; 43 } 44 45 function get_min_width(&$context) { 46 return $this->width; 47 } 48 49 function get_max_width(&$context) { 50 return $this->width; 51 } 52 53 function WhitespaceBox() { 54 // Call parent constructor 55 $this->TextBox(); 56 } 57 58 // (!) SIDE EFFECT: current whitespace box can be replaced by a null box during reflow. 59 // callers of reflow should take this into account and possilby check for this 60 // after reflow returns. This can be detected by UID change. 61 // 62 function reflow(&$parent, &$context) { 63 // Check if there are any boxes in parent's line box 64 if ($parent->line_box_empty()) { 65 // The very first whitespace in the line box should not affect neither height nor baseline of the line box; 66 // because following boxes can be smaller that assumed whitespace height 67 // Example: <br>[whitespace]<img height="2" width="2"><br>; whitespace can overextend this line 68 69 $this->width = 0; 70 $this->height = 0; 71 } elseif (is_a($parent->last_in_line(),"WhitespaceBox")) { 72 // Duplicate whitespace boxes should not offset further content and affect the line box length 73 74 $this->width = 0; 75 $this->height = 0; 76 } elseif ($this->maybe_line_break($parent, $context)) { 77 $this->width = 0; 78 $this->height = 0; 79 }; 80 81 parent::reflow($parent, $context); 82 } 83 84 function reflow_text(&$driver) { 85 if (is_null(parent::reflow_text($driver))) { 86 return null; 87 }; 88 89 // Override widths 90 $letter_spacing = $this->get_css_property(CSS_LETTER_SPACING); 91 $word_spacing = $this->get_css_property(CSS_WORD_SPACING); 92 93 $this->width = 94 $this->height * WHITESPACE_FONT_SIZE_FRACTION + 95 $letter_spacing->getPoints() + 96 $word_spacing->getPoints(); 97 98 return true; 99 } 100 101 function reflow_whitespace(&$linebox_started, &$previous_whitespace) { 102 if (!$linebox_started || 103 ($linebox_started && $previous_whitespace)) { 104 105 $link_destination = $this->get_css_property(CSS_HTML2PS_LINK_DESTINATION); 106 if (is_null($link_destination)) { 107 $this->parent->remove($this); 108 return; 109 }; 110 111 $this->font_height = 0.001; 112 $this->height = 0; 113 $this->width = 0; 114 }; 115 116 $previous_whitespace = true; 117 118 // Note that there can (in theory) several whitespaces in a row, so 119 // we could not modify a flag until we met a real text box 120 } 121} 122?>