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
23 function render(Frame
$frame)
25 // Render background & borders
26 $style = $frame->get_style();
27 $cb = $frame->get_containing_block();
28 list($x, $y, $w, $h) = $frame->get_border_box();
30 $this->_set_opacity($frame->get_opacity($style->opacity
));
32 list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);
34 $has_border_radius = $tl +
$tr +
$br +
$bl > 0;
36 if ($has_border_radius) {
37 $this->_canvas
->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
40 if (($bg = $style->background_color
) !== "transparent") {
41 $this->_canvas
->filled_rectangle($x, $y, $w, $h, $bg);
44 if (($url = $style->background_image
) && $url !== "none") {
45 $this->_background_image($url, $x, $y, $w, $h, $style);
48 if ($has_border_radius) {
49 $this->_canvas
->clipping_end();
52 $this->_render_border($frame);
53 $this->_render_outline($frame);
55 list($x, $y) = $frame->get_padding_box();
57 $x +
= $style->length_in_pt($style->padding_left
, $cb["w"]);
58 $y +
= $style->length_in_pt($style->padding_top
, $cb["h"]);
60 $w = $style->length_in_pt($style->width
, $cb["w"]);
61 $h = $style->length_in_pt($style->height
, $cb["h"]);
63 if ($has_border_radius) {
64 list($wt, $wr, $wb, $wl) = array(
65 $style->border_top_width
,
66 $style->border_right_width
,
67 $style->border_bottom_width
,
68 $style->border_left_width
,
71 // we have to get the "inner" radius
73 $tl -= ($wt +
$wl) / 2;
76 $tr -= ($wt +
$wr) / 2;
79 $br -= ($wb +
$wr) / 2;
82 $bl -= ($wb +
$wl) / 2;
85 $this->_canvas
->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
88 $src = $frame->get_image_url();
91 if (Cache
::is_broken($src) &&
92 $alt = $frame->get_node()->getAttribute("alt")
94 $font = $style->font_family
;
95 $size = $style->font_size
;
96 $spacing = $style->word_spacing
;
97 $this->_canvas
->text($x, $y, $alt,
99 $style->color
, $spacing);
101 $this->_canvas
->image($src, $x, $y, $w, $h, $style->image_resolution
);
104 if ($has_border_radius) {
105 $this->_canvas
->clipping_end();
108 if ($msg = $frame->get_image_msg()) {
109 $parts = preg_split("/\s*\n\s*/", $msg);
111 $_y = $alt ?
$y +
$h - count($parts) * $height : $y;
113 foreach ($parts as $i => $_part) {
114 $this->_canvas
->text($x, $_y +
$i * $height, $_part, "times", $height * 0.8, array(0.5, 0.5, 0.5));
118 if ($this->_dompdf
->get_option("debugLayout") && $this->_dompdf
->get_option("debugLayoutBlocks")) {
119 $this->_debug_layout($frame->get_border_box(), "blue");
120 if ($this->_dompdf
->get_option("debugLayoutPaddingBox")) {
121 $this->_debug_layout($frame->get_padding_box(), "blue", array(0.5, 0.5));