block_renderer.cls.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * DOMPDF - PHP5 HTML to PDF renderer
  4. *
  5. * File: $RCSfile: block_renderer.cls.php,v $
  6. * Created on: 2004-06-03
  7. *
  8. * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this library in the file LICENSE.LGPL; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  23. * 02111-1307 USA
  24. *
  25. * Alternatively, you may distribute this software under the terms of the
  26. * PHP License, version 3.0 or later. A copy of this license should have
  27. * been distributed with this file in the file LICENSE.PHP . If this is not
  28. * the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
  29. *
  30. * The latest version of DOMPDF might be available at:
  31. * http://www.dompdf.com/
  32. *
  33. * @link http://www.dompdf.com/
  34. * @copyright 2004 Benj Carson
  35. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  36. * @package dompdf
  37. */
  38. /* $Id: block_renderer.cls.php 216 2010-03-11 22:49:18Z ryan.masten $ */
  39. /**
  40. * Renders block frames
  41. *
  42. * @access private
  43. * @package dompdf
  44. */
  45. class Block_Renderer extends Abstract_Renderer {
  46. //........................................................................
  47. function render(Frame $frame) {
  48. $style = $frame->get_style();
  49. list($x, $y, $w, $h) = $frame->get_padding_box();
  50. // Draw our background, border and content
  51. if ( ($bg = $style->background_color) !== "transparent" ) {
  52. $this->_canvas->filled_rectangle( $x, $y, $w, $h, $style->background_color );
  53. }
  54. if ( ($url = $style->background_image) && $url !== "none" )
  55. $this->_background_image($url, $x, $y, $w, $h, $style);
  56. $this->_render_border($frame);
  57. }
  58. protected function _render_border(Frame_Decorator $frame, $corner_style = "bevel") {
  59. $cb = $frame->get_containing_block();
  60. $style = $frame->get_style();
  61. $bbox = $frame->get_border_box();
  62. $bp = $frame->get_style()->get_border_properties();
  63. $widths = array($style->length_in_pt($bp["top"]["width"]),
  64. $style->length_in_pt($bp["right"]["width"]),
  65. $style->length_in_pt($bp["bottom"]["width"]),
  66. $style->length_in_pt($bp["left"]["width"]));
  67. foreach ($bp as $side => $props) {
  68. list($x, $y, $w, $h) = $bbox;
  69. if ( !$props["style"] || $props["style"] === "none" || $props["width"] <= 0 )
  70. continue;
  71. switch($side) {
  72. case "top":
  73. $length = $w;
  74. break;
  75. case "bottom":
  76. $length = $w;
  77. $y += $h;
  78. break;
  79. case "left":
  80. $length = $h;
  81. break;
  82. case "right":
  83. $length = $h;
  84. $x += $w;
  85. break;
  86. default:
  87. break;
  88. }
  89. $method = "_border_" . $props["style"];
  90. $this->$method($x, $y, $length, $props["color"], $widths, $side, $corner_style);
  91. }
  92. }
  93. }