commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / vendor / dompdf / dompdf / src / Renderer / Image.php
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
11 use Dompdf\Frame;
12 use Dompdf\Image\Cache;
13
14 /**
15 * Image renderer
16 *
17 * @access private
18 * @package dompdf
19 */
20 class Image extends Block
21 {
22
23 function render(Frame $frame)
24 {
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();
29
30 $this->_set_opacity($frame->get_opacity($style->opacity));
31
32 list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);
33
34 $has_border_radius = $tl + $tr + $br + $bl > 0;
35
36 if ($has_border_radius) {
37 $this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
38 }
39
40 if (($bg = $style->background_color) !== "transparent") {
41 $this->_canvas->filled_rectangle($x, $y, $w, $h, $bg);
42 }
43
44 if (($url = $style->background_image) && $url !== "none") {
45 $this->_background_image($url, $x, $y, $w, $h, $style);
46 }
47
48 if ($has_border_radius) {
49 $this->_canvas->clipping_end();
50 }
51
52 $this->_render_border($frame);
53 $this->_render_outline($frame);
54
55 list($x, $y) = $frame->get_padding_box();
56
57 $x += $style->length_in_pt($style->padding_left, $cb["w"]);
58 $y += $style->length_in_pt($style->padding_top, $cb["h"]);
59
60 $w = $style->length_in_pt($style->width, $cb["w"]);
61 $h = $style->length_in_pt($style->height, $cb["h"]);
62
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,
69 );
70
71 // we have to get the "inner" radius
72 if ($tl > 0) {
73 $tl -= ($wt + $wl) / 2;
74 }
75 if ($tr > 0) {
76 $tr -= ($wt + $wr) / 2;
77 }
78 if ($br > 0) {
79 $br -= ($wb + $wr) / 2;
80 }
81 if ($bl > 0) {
82 $bl -= ($wb + $wl) / 2;
83 }
84
85 $this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
86 }
87
88 $src = $frame->get_image_url();
89 $alt = null;
90
91 if (Cache::is_broken($src) &&
92 $alt = $frame->get_node()->getAttribute("alt")
93 ) {
94 $font = $style->font_family;
95 $size = $style->font_size;
96 $spacing = $style->word_spacing;
97 $this->_canvas->text($x, $y, $alt,
98 $font, $size,
99 $style->color, $spacing);
100 } else {
101 $this->_canvas->image($src, $x, $y, $w, $h, $style->image_resolution);
102 }
103
104 if ($has_border_radius) {
105 $this->_canvas->clipping_end();
106 }
107
108 if ($msg = $frame->get_image_msg()) {
109 $parts = preg_split("/\s*\n\s*/", $msg);
110 $height = 10;
111 $_y = $alt ? $y + $h - count($parts) * $height : $y;
112
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));
115 }
116 }
117
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));
122 }
123 }
124 }
125 }