/vendor/dompdf/dompdf/src/Renderer/Image.php

https://gitlab.com/dae.nuli/toko · PHP · 125 lines · 87 code · 23 blank · 15 comment · 17 complexity · 8dcbb053107b2d989fac5bdf89a7bfc3 MD5 · raw file

  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. namespace Dompdf\Renderer;
  10. use Dompdf\Frame;
  11. use Dompdf\Image\Cache;
  12. /**
  13. * Image renderer
  14. *
  15. * @access private
  16. * @package dompdf
  17. */
  18. class Image extends Block
  19. {
  20. function render(Frame $frame)
  21. {
  22. // Render background & borders
  23. $style = $frame->get_style();
  24. $cb = $frame->get_containing_block();
  25. list($x, $y, $w, $h) = $frame->get_border_box();
  26. $this->_set_opacity($frame->get_opacity($style->opacity));
  27. list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);
  28. $has_border_radius = $tl + $tr + $br + $bl > 0;
  29. if ($has_border_radius) {
  30. $this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
  31. }
  32. if (($bg = $style->background_color) !== "transparent") {
  33. $this->_canvas->filled_rectangle($x, $y, $w, $h, $bg);
  34. }
  35. if (($url = $style->background_image) && $url !== "none") {
  36. $this->_background_image($url, $x, $y, $w, $h, $style);
  37. }
  38. if ($has_border_radius) {
  39. $this->_canvas->clipping_end();
  40. }
  41. $this->_render_border($frame);
  42. $this->_render_outline($frame);
  43. list($x, $y) = $frame->get_padding_box();
  44. $x += $style->length_in_pt($style->padding_left, $cb["w"]);
  45. $y += $style->length_in_pt($style->padding_top, $cb["h"]);
  46. $w = $style->length_in_pt($style->width, $cb["w"]);
  47. $h = $style->length_in_pt($style->height, $cb["h"]);
  48. if ($has_border_radius) {
  49. list($wt, $wr, $wb, $wl) = array(
  50. $style->border_top_width,
  51. $style->border_right_width,
  52. $style->border_bottom_width,
  53. $style->border_left_width,
  54. );
  55. // we have to get the "inner" radius
  56. if ($tl > 0) {
  57. $tl -= ($wt + $wl) / 2;
  58. }
  59. if ($tr > 0) {
  60. $tr -= ($wt + $wr) / 2;
  61. }
  62. if ($br > 0) {
  63. $br -= ($wb + $wr) / 2;
  64. }
  65. if ($bl > 0) {
  66. $bl -= ($wb + $wl) / 2;
  67. }
  68. $this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
  69. }
  70. $src = $frame->get_image_url();
  71. $alt = null;
  72. if (Cache::is_broken($src) &&
  73. $alt = $frame->get_node()->getAttribute("alt")
  74. ) {
  75. $font = $style->font_family;
  76. $size = $style->font_size;
  77. $spacing = $style->word_spacing;
  78. $this->_canvas->text($x, $y, $alt,
  79. $font, $size,
  80. $style->color, $spacing);
  81. } else {
  82. $this->_canvas->image($src, $x, $y, $w, $h, $style->image_resolution);
  83. }
  84. if ($has_border_radius) {
  85. $this->_canvas->clipping_end();
  86. }
  87. if ($msg = $frame->get_image_msg()) {
  88. $parts = preg_split("/\s*\n\s*/", $msg);
  89. $height = 10;
  90. $_y = $alt ? $y + $h - count($parts) * $height : $y;
  91. foreach ($parts as $i => $_part) {
  92. $this->_canvas->text($x, $_y + $i * $height, $_part, "times", $height * 0.8, array(0.5, 0.5, 0.5));
  93. }
  94. }
  95. if ($this->_dompdf->get_option("debugLayout") && $this->_dompdf->get_option("debugLayoutBlocks")) {
  96. $this->_debug_layout($frame->get_border_box(), "blue");
  97. if ($this->_dompdf->get_option("debugLayoutPaddingBox")) {
  98. $this->_debug_layout($frame->get_padding_box(), "blue", array(0.5, 0.5));
  99. }
  100. }
  101. }
  102. }