composer package updates
[openemr.git] / vendor / dompdf / dompdf / src / Renderer / Image.php
blob87333af71e3755cdff87ded2dd805e3a75bbe593
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;
11 use Dompdf\Frame;
12 use Dompdf\Image\Cache;
14 /**
15 * Image renderer
17 * @access private
18 * @package dompdf
20 class Image extends Block
23 /**
24 * @param Frame $frame
26 function render(Frame $frame)
28 // Render background & borders
29 $style = $frame->get_style();
30 $cb = $frame->get_containing_block();
31 list($x, $y, $w, $h) = $frame->get_border_box();
33 $this->_set_opacity($frame->get_opacity($style->opacity));
35 list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);
37 $has_border_radius = $tl + $tr + $br + $bl > 0;
39 if ($has_border_radius) {
40 $this->_canvas->clipping_roundrectangle($x, $y, (float)$w, (float)$h, $tl, $tr, $br, $bl);
43 if (($bg = $style->background_color) !== "transparent") {
44 $this->_canvas->filled_rectangle($x, $y, (float)$w, (float)$h, $bg);
47 if (($url = $style->background_image) && $url !== "none") {
48 $this->_background_image($url, $x, $y, $w, $h, $style);
51 if ($has_border_radius) {
52 $this->_canvas->clipping_end();
55 $this->_render_border($frame);
56 $this->_render_outline($frame);
58 list($x, $y) = $frame->get_padding_box();
60 $x += (float)$style->length_in_pt($style->padding_left, $cb["w"]);
61 $y += (float)$style->length_in_pt($style->padding_top, $cb["h"]);
63 $w = (float)$style->length_in_pt($style->width, $cb["w"]);
64 $h = (float)$style->length_in_pt($style->height, $cb["h"]);
66 if ($has_border_radius) {
67 list($wt, $wr, $wb, $wl) = array(
68 $style->border_top_width,
69 $style->border_right_width,
70 $style->border_bottom_width,
71 $style->border_left_width,
74 // we have to get the "inner" radius
75 if ($tl > 0) {
76 $tl -= ($wt + $wl) / 2;
78 if ($tr > 0) {
79 $tr -= ($wt + $wr) / 2;
81 if ($br > 0) {
82 $br -= ($wb + $wr) / 2;
84 if ($bl > 0) {
85 $bl -= ($wb + $wl) / 2;
88 $this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
91 $src = $frame->get_image_url();
92 $alt = null;
94 if (Cache::is_broken($src) &&
95 $alt = $frame->get_node()->getAttribute("alt")
96 ) {
97 $font = $style->font_family;
98 $size = $style->font_size;
99 $spacing = $style->word_spacing;
100 $this->_canvas->text(
103 $alt,
104 $font,
105 $size,
106 $style->color,
107 $spacing
109 } else {
110 $this->_canvas->image($src, $x, $y, $w, $h, $style->image_resolution);
113 if ($has_border_radius) {
114 $this->_canvas->clipping_end();
117 if ($msg = $frame->get_image_msg()) {
118 $parts = preg_split("/\s*\n\s*/", $msg);
119 $height = 10;
120 $_y = $alt ? $y + $h - count($parts) * $height : $y;
122 foreach ($parts as $i => $_part) {
123 $this->_canvas->text($x, $_y + $i * $height, $_part, "times", $height * 0.8, array(0.5, 0.5, 0.5));
127 if ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutBlocks()) {
128 $this->_debug_layout($frame->get_border_box(), "blue");
129 if ($this->_dompdf->getOptions()->getDebugLayoutPaddingBox()) {
130 $this->_debug_layout($frame->get_padding_box(), "blue", array(0.5, 0.5));
134 $id = $frame->get_node()->getAttribute("id");
135 if (strlen($id) > 0) {
136 $this->_canvas->add_named_dest($id);