| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package dompdf |
| 4 |
* @link https://github.com/dompdf/dompdf |
| 5 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 6 |
*/ |
| 7 |
namespace Dompdf\Renderer; |
| 8 |
|
| 9 |
use Dompdf\Frame; |
| 10 |
use Dompdf\FrameDecorator\Image as ImageFrameDecorator; |
| 11 |
use Dompdf\Image\Cache; |
| 12 |
|
| 13 |
/** |
| 14 |
* Image renderer |
| 15 |
* |
| 16 |
* @package dompdf |
| 17 |
*/ |
| 18 |
class Image extends Block |
| 19 |
{ |
| 20 |
/** |
| 21 |
* @param ImageFrameDecorator $frame |
| 22 |
*/ |
| 23 |
function render(Frame $frame) |
| 24 |
{ |
| 25 |
$style = $frame->get_style(); |
| 26 |
$border_box = $frame->get_border_box(); |
| 27 |
|
| 28 |
$this->_set_opacity($frame->get_opacity($style->opacity)); |
| 29 |
|
| 30 |
// Render background & borders |
| 31 |
$this->_render_background($frame, $border_box); |
| 32 |
$this->_render_border($frame, $border_box); |
| 33 |
$this->_render_outline($frame, $border_box); |
| 34 |
|
| 35 |
$content_box = $frame->get_content_box(); |
| 36 |
[$x, $y, $w, $h] = $content_box; |
| 37 |
|
| 38 |
$src = $frame->get_image_url(); |
| 39 |
$alt = null; |
| 40 |
|
| 41 |
if (Cache::is_broken($src) && |
| 42 |
$alt = $frame->get_node()->getAttribute("alt") |
| 43 |
) { |
| 44 |
$font = $style->font_family; |
| 45 |
$size = $style->font_size; |
| 46 |
$word_spacing = $style->word_spacing; |
| 47 |
$letter_spacing = $style->letter_spacing; |
| 48 |
|
| 49 |
$this->_canvas->text( |
| 50 |
$x, |
| 51 |
$y, |
| 52 |
$alt, |
| 53 |
$font, |
| 54 |
$size, |
| 55 |
$style->color, |
| 56 |
$word_spacing, |
| 57 |
$letter_spacing |
| 58 |
); |
| 59 |
} elseif ($w > 0 && $h > 0) { |
| 60 |
if ($style->has_border_radius()) { |
| 61 |
[$tl, $tr, $br, $bl] = $style->resolve_border_radius($border_box, $content_box); |
| 62 |
$this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl); |
| 63 |
} |
| 64 |
|
| 65 |
$this->_canvas->image($src, $x, $y, $w, $h, $style->image_resolution); |
| 66 |
|
| 67 |
if ($style->has_border_radius()) { |
| 68 |
$this->_canvas->clipping_end(); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
if ($msg = $frame->get_image_msg()) { |
| 73 |
$parts = preg_split("/\s*\n\s*/", $msg); |
| 74 |
$font = $style->font_family; |
| 75 |
$height = 10; |
| 76 |
$_y = $alt ? $y + $h - count($parts) * $height : $y; |
| 77 |
|
| 78 |
foreach ($parts as $i => $_part) { |
| 79 |
$this->_canvas->text($x, $_y + $i * $height, $_part, $font, $height * 0.8, [0.5, 0.5, 0.5]); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
$id = $frame->get_node()->getAttribute("id"); |
| 84 |
if (strlen($id) > 0) { |
| 85 |
$this->_canvas->add_named_dest($id); |
| 86 |
} |
| 87 |
|
| 88 |
$this->debugBlockLayout($frame, "blue"); |
| 89 |
} |
| 90 |
} |
| 91 |
|