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
9 namespace Dompdf\Renderer
;
12 use Dompdf\Image\Cache
;
20 class Image
extends Block
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
76 $tl -= ($wt +
$wl) / 2;
79 $tr -= ($wt +
$wr) / 2;
82 $br -= ($wb +
$wr) / 2;
85 $bl -= ($wb +
$wl) / 2;
88 $this->_canvas
->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
91 $src = $frame->get_image_url();
94 if (Cache
::is_broken($src) &&
95 $alt = $frame->get_node()->getAttribute("alt")
97 $font = $style->font_family
;
98 $size = $style->font_size
;
99 $spacing = $style->word_spacing
;
100 $this->_canvas
->text(
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);
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);