Page_Frame_Reflower

Reflows pages.

Defined (1)

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

/lib/dompdf/include/page_frame_reflower.cls.php  
  1. class Page_Frame_Reflower extends Frame_Reflower { 
  2.  
  3. /** 
  4. * Cache of the callbacks array 
  5. *  
  6. * @var array 
  7. */ 
  8. private $_callbacks; 
  9.  
  10. /** 
  11. * Cache of the canvas 
  12. * @var Canvas 
  13. */ 
  14. private $_canvas; 
  15.  
  16. function __construct(Page_Frame_Decorator $frame) { parent::__construct($frame); } 
  17.  
  18. function apply_page_style(Frame $frame, $page_number) { 
  19. $style = $frame->get_style(); 
  20. $page_styles = $style->get_stylesheet()->get_page_styles(); 
  21.  
  22. // http://www.w3.org/TR/CSS21/page.html#page-selectors 
  23. if ( count($page_styles) > 1 ) { 
  24. $odd = $page_number % 2 == 1; 
  25. $first = $page_number == 1; 
  26.  
  27. $style = clone $page_styles["base"]; 
  28.  
  29. // FIXME RTL 
  30. if ( $odd && isset($page_styles[":right"]) ) { 
  31. $style->merge($page_styles[":right"]); 
  32.  
  33. if ( $odd && isset($page_styles[":odd"]) ) { 
  34. $style->merge($page_styles[":odd"]); 
  35.  
  36. // FIXME RTL 
  37. if ( !$odd && isset($page_styles[":left"]) ) { 
  38. $style->merge($page_styles[":left"]); 
  39.  
  40. if ( !$odd && isset($page_styles[":even"]) ) { 
  41. $style->merge($page_styles[":even"]); 
  42.  
  43. if ( $first && isset($page_styles[":first"]) ) { 
  44. $style->merge($page_styles[":first"]); 
  45.  
  46. $frame->set_style($style); 
  47.  
  48. //........................................................................ 
  49.  
  50. /** 
  51. * Paged layout: 
  52. * http://www.w3.org/TR/CSS21/page.html 
  53. */ 
  54. function reflow(Block_Frame_Decorator $block = null) { 
  55. $fixed_children = array(); 
  56. $prev_child = null; 
  57. $child = $this->_frame->get_first_child(); 
  58. $current_page = 0; 
  59.  
  60. while ($child) { 
  61. $this->apply_page_style($this->_frame, $current_page + 1); 
  62.  
  63. $style = $this->_frame->get_style(); 
  64.  
  65. // Pages are only concerned with margins 
  66. $cb = $this->_frame->get_containing_block(); 
  67. $left = $style->length_in_pt($style->margin_left, $cb["w"]); 
  68. $right = $style->length_in_pt($style->margin_right, $cb["w"]); 
  69. $top = $style->length_in_pt($style->margin_top, $cb["h"]); 
  70. $bottom = $style->length_in_pt($style->margin_bottom, $cb["h"]); 
  71.  
  72. $content_x = $cb["x"] + $left; 
  73. $content_y = $cb["y"] + $top; 
  74. $content_width = $cb["w"] - $left - $right; 
  75. $content_height = $cb["h"] - $top - $bottom; 
  76.  
  77. // Only if it's the first page, we save the nodes with a fixed position 
  78. if ($current_page == 0) { 
  79. $children = $child->get_children(); 
  80. foreach ($children as $onechild) { 
  81. if ($onechild->get_style()->position === "fixed") { 
  82. $fixed_children[] = $onechild->deep_copy(); 
  83. $fixed_children = array_reverse($fixed_children); 
  84.  
  85. $child->set_containing_block($content_x, $content_y, $content_width, $content_height); 
  86.  
  87. // Check for begin reflow callback 
  88. $this->_check_callbacks("begin_page_reflow", $child); 
  89.  
  90. //Insert a copy of each node which have a fixed position 
  91. if ($current_page >= 1) { 
  92. foreach ($fixed_children as $fixed_child) { 
  93. $child->insert_child_before($fixed_child->deep_copy(), $child->get_first_child()); 
  94.  
  95. $child->reflow(); 
  96. $next_child = $child->get_next_sibling(); 
  97.  
  98. // Check for begin render callback 
  99. $this->_check_callbacks("begin_page_render", $child); 
  100.  
  101. // Render the page 
  102. $this->_frame->get_renderer()->render($child); 
  103.  
  104. // Check for end render callback 
  105. $this->_check_callbacks("end_page_render", $child); 
  106.  
  107. if ( $next_child ) { 
  108. $this->_frame->next_page(); 
  109.  
  110. // Wait to dispose of all frames on the previous page 
  111. // so callback will have access to them 
  112. if ( $prev_child ) { 
  113. $prev_child->dispose(true); 
  114. $prev_child = $child; 
  115. $child = $next_child; 
  116. $current_page++; 
  117.  
  118. // Dispose of previous page if it still exists 
  119. if ( $prev_child ) { 
  120. $prev_child->dispose(true); 
  121. }  
  122.  
  123. //........................................................................ 
  124.  
  125. /** 
  126. * Check for callbacks that need to be performed when a given event 
  127. * gets triggered on a page 
  128. * @param string $event the type of event 
  129. * @param Frame $frame the frame that event is triggered on 
  130. */ 
  131. protected function _check_callbacks($event, $frame) { 
  132. if (!isset($this->_callbacks)) { 
  133. $dompdf = $this->_frame->get_dompdf(); 
  134. $this->_callbacks = $dompdf->get_callbacks(); 
  135. $this->_canvas = $dompdf->get_canvas(); 
  136.  
  137. if (is_array($this->_callbacks) && isset($this->_callbacks[$event])) { 
  138. $info = array(0 => $this->_canvas, "canvas" => $this->_canvas,  
  139. 1 => $frame, "frame" => $frame); 
  140. $fs = $this->_callbacks[$event]; 
  141. foreach ($fs as $f) { 
  142. if (is_callable($f)) { 
  143. if (is_array($f)) { 
  144. $f[0]->$f[1]($info); 
  145. } else { 
  146. $f($info); 
  147. }