PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/application/helpers/dompdf/include/inline_renderer.cls.php

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