Inline_Renderer

Renders inline frames.

Defined (1)

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

/lib/dompdf/include/inline_renderer.cls.php  
  1. class Inline_Renderer extends Abstract_Renderer { 
  2.  
  3. //........................................................................ 
  4.  
  5. function render(Frame $frame) { 
  6. $style = $frame->get_style(); 
  7.  
  8. if ( !$frame->get_first_child() ) 
  9. return; // No children, no service 
  10.  
  11. // Draw the left border if applicable 
  12. $bp = $style->get_border_properties(); 
  13. $widths = array($style->length_in_pt($bp["top"]["width"]),  
  14. $style->length_in_pt($bp["right"]["width"]),  
  15. $style->length_in_pt($bp["bottom"]["width"]),  
  16. $style->length_in_pt($bp["left"]["width"])); 
  17.  
  18. // Draw the background & border behind each child. To do this we need 
  19. // to figure out just how much space each child takes: 
  20. list($x, $y) = $frame->get_first_child()->get_position(); 
  21. $w = null; 
  22. $h = 0; 
  23. // $x += $widths[3]; 
  24. // $y += $widths[0]; 
  25.  
  26. $this->_set_opacity( $frame->get_opacity( $style->opacity ) ); 
  27.  
  28. $first_row = true; 
  29.  
  30. foreach ($frame->get_children() as $child) { 
  31. list($child_x, $child_y, $child_w, $child_h) = $child->get_padding_box(); 
  32.  
  33. if ( !is_null($w) && $child_x < $x + $w ) { 
  34. //This branch seems to be supposed to being called on the first part 
  35. //of an inline html element, and the part after the if clause for the 
  36. //parts after a line break. 
  37. //But because $w initially mostly is 0, and gets updated only on the next 
  38. //round, this seem to be never executed and the common close always. 
  39.  
  40. // The next child is on another line. Draw the background & 
  41. // borders on this line. 
  42.  
  43. // Background: 
  44. if ( ($bg = $style->background_color) !== "transparent" ) 
  45. $this->_canvas->filled_rectangle( $x, $y, $w, $h, $bg); 
  46.  
  47. if ( ($url = $style->background_image) && $url !== "none" ) { 
  48. $this->_background_image($url, $x, $y, $w, $h, $style); 
  49.  
  50. // If this is the first row, draw the left border 
  51. if ( $first_row ) { 
  52.  
  53. if ( $bp["left"]["style"] !== "none" && $bp["left"]["color"] !== "transparent" && $bp["left"]["width"] > 0 ) { 
  54. $method = "_border_" . $bp["left"]["style"];  
  55. $this->$method($x, $y, $h + $widths[0] + $widths[2], $bp["left"]["color"], $widths, "left"); 
  56. $first_row = false; 
  57.  
  58. // Draw the top & bottom borders 
  59. if ( $bp["top"]["style"] !== "none" && $bp["top"]["color"] !== "transparent" && $bp["top"]["width"] > 0 ) { 
  60. $method = "_border_" . $bp["top"]["style"]; 
  61. $this->$method($x, $y, $w + $widths[1] + $widths[3], $bp["top"]["color"], $widths, "top"); 
  62.  
  63. if ( $bp["bottom"]["style"] !== "none" && $bp["bottom"]["color"] !== "transparent" && $bp["bottom"]["width"] > 0 ) { 
  64. $method = "_border_" . $bp["bottom"]["style"]; 
  65. $this->$method($x, $y + $h + $widths[0] + $widths[2], $w + $widths[1] + $widths[3], $bp["bottom"]["color"], $widths, "bottom"); 
  66.  
  67. // Handle anchors & links 
  68. $link_node = null; 
  69. if ( $frame->get_node()->nodeName === "a" ) { 
  70. $link_node = $frame->get_node(); 
  71. else if ( $frame->get_parent()->get_node()->nodeName === "a" ) { 
  72. $link_node = $frame->get_parent()->get_node(); 
  73.  
  74. if ( $link_node && $href = $link_node->getAttribute("href") ) { 
  75. $this->_canvas->add_link($href, $x, $y, $w, $h); 
  76.  
  77. $x = $child_x; 
  78. $y = $child_y; 
  79. $w = $child_w; 
  80. $h = $child_h; 
  81. continue; 
  82.  
  83. if ( is_null($w) ) 
  84. $w = $child_w; 
  85. else 
  86. $w += $child_w; 
  87.  
  88. $h = max($h, $child_h); 
  89.  
  90. if (DEBUG_LAYOUT && DEBUG_LAYOUT_INLINE) { 
  91. $this->_debug_layout($child->get_border_box(), "blue"); 
  92. if (DEBUG_LAYOUT_PADDINGBOX) { 
  93. $this->_debug_layout($child->get_padding_box(), "blue", array(0.5, 0.5)); 
  94.  
  95.  
  96. // Handle the last child 
  97. if ( ($bg = $style->background_color) !== "transparent" )  
  98. $this->_canvas->filled_rectangle( $x + $widths[3], $y + $widths[0], $w, $h, $bg); 
  99.  
  100. //On continuation lines (after line break) of inline elements, the style got copied. 
  101. //But a non repeatable background image should not be repeated on the next line. 
  102. //But removing the background image above has never an effect, and removing it below 
  103. //removes it always, even on the initial line. 
  104. //Need to handle it elsewhere, e.g. on certain ...clone()... usages.  
  105. // Repeat not given: default is Style::__construct 
  106. // ... && (!($repeat = $style->background_repeat) || $repeat === "repeat" ... 
  107. //different position? $this->_background_image($url, $x, $y, $w, $h, $style); 
  108. if ( ($url = $style->background_image) && $url !== "none" )  
  109. $this->_background_image($url, $x + $widths[3], $y + $widths[0], $w, $h, $style); 
  110.  
  111. // Add the border widths 
  112. $w += $widths[1] + $widths[3]; 
  113. $h += $widths[0] + $widths[2]; 
  114.  
  115. // make sure the border and background start inside the left margin 
  116. $left_margin = $style->length_in_pt($style->margin_left); 
  117. $x += $left_margin; 
  118.  
  119. // If this is the first row, draw the left border too 
  120. if ( $first_row && $bp["left"]["style"] !== "none" && $bp["left"]["color"] !== "transparent" && $widths[3] > 0 ) { 
  121. $method = "_border_" . $bp["left"]["style"]; 
  122. $this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left"); 
  123.  
  124. // Draw the top & bottom borders 
  125. if ( $bp["top"]["style"] !== "none" && $bp["top"]["color"] !== "transparent" && $widths[0] > 0 ) { 
  126. $method = "_border_" . $bp["top"]["style"]; 
  127. $this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top"); 
  128.  
  129. if ( $bp["bottom"]["style"] !== "none" && $bp["bottom"]["color"] !== "transparent" && $widths[2] > 0 ) { 
  130. $method = "_border_" . $bp["bottom"]["style"]; 
  131. $this->$method($x, $y + $h, $w, $bp["bottom"]["color"], $widths, "bottom"); 
  132.  
  133. // pre_var_dump(get_class($frame->get_next_sibling())); 
  134. // $last_row = get_class($frame->get_next_sibling()) !== 'Inline_Frame_Decorator'; 
  135. // Draw the right border if this is the last row 
  136. if ( $bp["right"]["style"] !== "none" && $bp["right"]["color"] !== "transparent" && $widths[1] > 0 ) { 
  137. $method = "_border_" . $bp["right"]["style"]; 
  138. $this->$method($x + $w, $y, $h, $bp["right"]["color"], $widths, "right"); 
  139.  
  140. // Only two levels of links frames 
  141. $link_node = null; 
  142. if ( $frame->get_node()->nodeName === "a" ) { 
  143. $link_node = $frame->get_node(); 
  144.  
  145. if ( ($name = $link_node->getAttribute("name")) || ($name = $link_node->getAttribute("id")) ) { 
  146. $this->_canvas->add_named_dest($name); 
  147.  
  148. if ( $frame->get_parent() && $frame->get_parent()->get_node()->nodeName === "a" ) { 
  149. $link_node = $frame->get_parent()->get_node(); 
  150.  
  151. // Handle anchors & links 
  152. if ( $link_node ) { 
  153. if ( $href = $link_node->getAttribute("href") ) 
  154. $this->_canvas->add_link($href, $x, $y, $w, $h);