commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / vendor / dompdf / dompdf / src / FrameDecorator / 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\FrameDecorator;
10
11 use Dompdf\Dompdf;
12 use Dompdf\Frame;
13 use Dompdf\FontMetrics;
14 use Dompdf\Image\Cache;
15
16 /**
17 * Decorates frames for image layout and rendering
18 *
19 * @package dompdf
20 */
21 class Image extends AbstractFrameDecorator
22 {
23
24 /**
25 * The path to the image file (note that remote images are
26 * downloaded locally to Options:tempDir).
27 *
28 * @var string
29 */
30 protected $_image_url;
31
32 /**
33 * The image's file error message
34 *
35 * @var string
36 */
37 protected $_image_msg;
38
39 /**
40 * Class constructor
41 *
42 * @param Frame $frame the frame to decorate
43 * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls)
44 */
45 function __construct(Frame $frame, Dompdf $dompdf)
46 {
47 parent::__construct($frame, $dompdf);
48 $url = $frame->get_node()->getAttribute("src");
49
50 $debug_png = $dompdf->get_option("debug_png");
51 if ($debug_png) print '[__construct ' . $url . ']';
52
53 list($this->_image_url, /*$type*/, $this->_image_msg) = Cache::resolve_url(
54 $url,
55 $dompdf->get_protocol(),
56 $dompdf->get_host(),
57 $dompdf->get_base_path(),
58 $dompdf
59 );
60
61 if (Cache::is_broken($this->_image_url) &&
62 $alt = $frame->get_node()->getAttribute("alt")
63 ) {
64 $style = $frame->get_style();
65 $style->width = (4 / 3) * $dompdf->getFontMetrics()->getTextWidth($alt, $style->font_family, $style->font_size, $style->word_spacing);
66 $style->height = $dompdf->getFontMetrics()->getFontHeight($style->font_family, $style->font_size);
67 }
68 }
69
70 /**
71 * Return the image's url
72 *
73 * @return string The url of this image
74 */
75 function get_image_url()
76 {
77 return $this->_image_url;
78 }
79
80 /**
81 * Return the image's error message
82 *
83 * @return string The image's error message
84 */
85 function get_image_msg()
86 {
87 return $this->_image_msg;
88 }
89
90 }