Image_Renderer

Image renderer.

Defined (1)

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

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