Line_Box

The line box class.

Defined (1)

The class is defined in the following location(s).

/lib/dompdf/include/line_box.cls.php  
  1. class Line_Box { 
  2.  
  3. /** 
  4. * @var Block_Frame_Decorator 
  5. */ 
  6. protected $_block_frame; 
  7.  
  8. /** 
  9. * @var Frame[] 
  10. */ 
  11. protected $_frames = array(); 
  12.  
  13. /** 
  14. * @var integer 
  15. */ 
  16. public $wc = 0; 
  17.  
  18. /** 
  19. * @var float 
  20. */ 
  21. public $y = null; 
  22.  
  23. /** 
  24. * @var float 
  25. */ 
  26. public $w = 0.0; 
  27.  
  28. /** 
  29. * @var float 
  30. */ 
  31. public $h = 0.0; 
  32.  
  33. /** 
  34. * @var float 
  35. */ 
  36. public $left = 0.0; 
  37.  
  38. /** 
  39. * @var float 
  40. */ 
  41. public $right = 0.0; 
  42.  
  43. /** 
  44. * @var Frame 
  45. */ 
  46. public $tallest_frame = null; 
  47.  
  48. /** 
  49. * @var bool[] 
  50. */ 
  51. public $floating_blocks = array(); 
  52.  
  53. /** 
  54. * @var bool 
  55. */ 
  56. public $br = false; 
  57.  
  58. /** 
  59. * Class constructor 
  60. * @param Block_Frame_Decorator $frame the Block_Frame_Decorator containing this line 
  61. */ 
  62. function __construct(Block_Frame_Decorator $frame, $y = 0) { 
  63. $this->_block_frame = $frame; 
  64. $this->_frames = array(); 
  65. $this->y = $y; 
  66.  
  67. $this->get_float_offsets(); 
  68.  
  69. /** 
  70. * Returns the floating elements inside the first floating parent 
  71. * @param Page_Frame_Decorator $root 
  72. * @return Frame[] 
  73. */ 
  74. function get_floats_inside(Page_Frame_Decorator $root) { 
  75. $floating_frames = $root->get_floating_frames(); 
  76.  
  77. if ( count($floating_frames) == 0 ) { 
  78. return $floating_frames; 
  79.  
  80. // Find nearest floating element 
  81. $p = $this->_block_frame; 
  82. while( $p->get_style()->float === "none" ) { 
  83. $parent = $p->get_parent(); 
  84.  
  85. if ( !$parent ) { 
  86. break; 
  87.  
  88. $p = $parent; 
  89.  
  90. if ( $p == $root ) { 
  91. return $floating_frames; 
  92.  
  93. $parent = $p; 
  94.  
  95. $childs = array(); 
  96.  
  97. foreach ($floating_frames as $_floating) { 
  98. $p = $_floating->get_parent(); 
  99.  
  100. while (($p = $p->get_parent()) && $p !== $parent); 
  101.  
  102. if ( $p ) { 
  103. $childs[] = $p; 
  104.  
  105. return $childs; 
  106.  
  107. function get_float_offsets() { 
  108. $enable_css_float = $this->_block_frame->get_dompdf()->get_option("enable_css_float"); 
  109. if ( !$enable_css_float ) { 
  110. return; 
  111.  
  112. static $anti_infinite_loop = 500; // FIXME smelly hack 
  113.  
  114. $reflower = $this->_block_frame->get_reflower(); 
  115.  
  116. if ( !$reflower ) { 
  117. return; 
  118.  
  119. $cb_w = null; 
  120.  
  121. $block = $this->_block_frame; 
  122. $root = $block->get_root(); 
  123.  
  124. if ( !$root ) { 
  125. return; 
  126.  
  127. $floating_frames = $this->get_floats_inside($root); 
  128.  
  129. foreach ( $floating_frames as $child_key => $floating_frame ) { 
  130. $id = $floating_frame->get_id(); 
  131.  
  132. if ( isset($this->floating_blocks[$id]) ) { 
  133. continue; 
  134.  
  135. $floating_style = $floating_frame->get_style(); 
  136. $float = $floating_style->float; 
  137.  
  138. $floating_width = $floating_frame->get_margin_width(); 
  139.  
  140. if (!$cb_w) { 
  141. $cb_w = $floating_frame->get_containing_block("w"); 
  142.  
  143. $line_w = $this->get_width(); 
  144.  
  145. if ( !$floating_frame->_float_next_line && ($cb_w <= $line_w + $floating_width) && ($cb_w > $line_w) ) { 
  146. $floating_frame->_float_next_line = true; 
  147. continue; 
  148.  
  149. // If the child is still shifted by the floating element 
  150. if ( $anti_infinite_loop-- > 0 && 
  151. $floating_frame->get_position("y") + $floating_frame->get_margin_height() > $this->y &&  
  152. $block->get_position("x") + $block->get_margin_width() > $floating_frame->get_position("x") 
  153. ) { 
  154. if ( $float === "left" ) 
  155. $this->left += $floating_width; 
  156. else 
  157. $this->right += $floating_width; 
  158.  
  159. $this->floating_blocks[$id] = true; 
  160.  
  161. // else, the floating element won't shift anymore 
  162. else { 
  163. $root->remove_floating_frame($child_key); 
  164.  
  165. /** 
  166. * @return float 
  167. */ 
  168. function get_width() { 
  169. return $this->left + $this->w + $this->right; 
  170.  
  171. /** 
  172. * @return Block_Frame_Decorator 
  173. */ 
  174. function get_block_frame() { 
  175. return $this->_block_frame; 
  176.  
  177. /** 
  178. * @return Frame[] 
  179. */ 
  180. function &get_frames() { 
  181. return $this->_frames; 
  182.  
  183. /** 
  184. * @param Frame $frame 
  185. */ 
  186. function add_frame(Frame $frame) { 
  187. $this->_frames[] = $frame; 
  188.  
  189. function __toString() { 
  190. $props = array("wc", "y", "w", "h", "left", "right", "br"); 
  191. $s = ""; 
  192. foreach($props as $prop) { 
  193. $s .= "$prop: ".$this->$prop."\n"; 
  194. $s .= count($this->_frames)." frames\n"; 
  195. return $s; 
  196. /**function __get($prop) { 
  197. if (!isset($this->{"_$prop"})) return; 
  198. return $this->{"_$prop"}; 
  199. }*/