image_renderer.cls.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @author Fabien Ménager <fabien.menager@gmail.com>
  7. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  8. */
  9. /**
  10. * Image renderer
  11. *
  12. * @access private
  13. * @package dompdf
  14. */
  15. class Image_Renderer extends Block_Renderer {
  16. function render(Frame $frame) {
  17. // Render background & borders
  18. $style = $frame->get_style();
  19. $cb = $frame->get_containing_block();
  20. list($x, $y, $w, $h) = $frame->get_border_box();
  21. $this->_set_opacity( $frame->get_opacity( $style->opacity ) );
  22. list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);
  23. $has_border_radius = $tl + $tr + $br + $bl > 0;
  24. if ( $has_border_radius ) {
  25. $this->_canvas->clipping_roundrectangle( $x, $y, $w, $h, $tl, $tr, $br, $bl );
  26. }
  27. if ( ($bg = $style->background_color) !== "transparent" ) {
  28. $this->_canvas->filled_rectangle($x, $y, $w, $h, $bg);
  29. }
  30. if ( ($url = $style->background_image) && $url !== "none" ) {
  31. $this->_background_image($url, $x, $y, $w, $h, $style);
  32. }
  33. if ( $has_border_radius ) {
  34. $this->_canvas->clipping_end();
  35. }
  36. $this->_render_border($frame);
  37. $this->_render_outline($frame);
  38. list($x, $y) = $frame->get_padding_box();
  39. $x += $style->length_in_pt($style->padding_left, $cb["w"]);
  40. $y += $style->length_in_pt($style->padding_top, $cb["h"]);
  41. $w = $style->length_in_pt($style->width, $cb["w"]);
  42. $h = $style->length_in_pt($style->height, $cb["h"]);
  43. if ( $has_border_radius ) {
  44. list($wt, $wr, $wb, $wl) = array(
  45. $style->border_top_width,
  46. $style->border_right_width,
  47. $style->border_bottom_width,
  48. $style->border_left_width,
  49. );
  50. // we have to get the "inner" radius
  51. if ( $tl > 0 ) {
  52. $tl -= ($wt + $wl) / 2;
  53. }
  54. if ( $tr > 0 ) {
  55. $tr -= ($wt + $wr) / 2;
  56. }
  57. if ( $br > 0 ) {
  58. $br -= ($wb + $wr) / 2;
  59. }
  60. if ( $bl > 0 ) {
  61. $bl -= ($wb + $wl) / 2;
  62. }
  63. $this->_canvas->clipping_roundrectangle( $x, $y, $w, $h, $tl, $tr, $br, $bl );
  64. }
  65. $src = $frame->get_image_url();
  66. $alt = null;
  67. if ( Image_Cache::is_broken($src) &&
  68. $alt = $frame->get_node()->getAttribute("alt") ) {
  69. $font = $style->font_family;
  70. $size = $style->font_size;
  71. $spacing = $style->word_spacing;
  72. $this->_canvas->text($x, $y, $alt,
  73. $font, $size,
  74. $style->color, $spacing);
  75. }
  76. else {
  77. $this->_canvas->image( $src, $x, $y, $w, $h, $style->image_resolution);
  78. }
  79. if ( $has_border_radius ) {
  80. $this->_canvas->clipping_end();
  81. }
  82. if ( $msg = $frame->get_image_msg() ) {
  83. $parts = preg_split("/\s*\n\s*/", $msg);
  84. $height = 10;
  85. $_y = $alt ? $y+$h-count($parts)*$height : $y;
  86. foreach($parts as $i => $_part) {
  87. $this->_canvas->text($x, $_y + $i*$height, $_part, "times", $height*0.8, array(0.5, 0.5, 0.5));
  88. }
  89. }
  90. if (DEBUG_LAYOUT && DEBUG_LAYOUT_BLOCKS) {
  91. $this->_debug_layout($frame->get_border_box(), "blue");
  92. if (DEBUG_LAYOUT_PADDINGBOX) {
  93. $this->_debug_layout($frame->get_padding_box(), "blue", array(0.5, 0.5));
  94. }
  95. }
  96. }
  97. }