1 | <?php |
---|
2 | /** |
---|
3 | * DOMPDF - PHP5 HTML to PDF renderer |
---|
4 | * |
---|
5 | * File: $RCSfile: image_frame_reflower.cls.php,v $ |
---|
6 | * Created on: 2004-08-08 |
---|
7 | * |
---|
8 | * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca> |
---|
9 | * |
---|
10 | * This library is free software; you can redistribute it and/or |
---|
11 | * modify it under the terms of the GNU Lesser General Public |
---|
12 | * License as published by the Free Software Foundation; either |
---|
13 | * version 2.1 of the License, or (at your option) any later version. |
---|
14 | * |
---|
15 | * This library is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * Lesser General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU Lesser General Public License |
---|
21 | * along with this library in the file LICENSE.LGPL; if not, write to the |
---|
22 | * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
---|
23 | * 02111-1307 USA |
---|
24 | * |
---|
25 | * Alternatively, you may distribute this software under the terms of the |
---|
26 | * PHP License, version 3.0 or later. A copy of this license should have |
---|
27 | * been distributed with this file in the file LICENSE.PHP . If this is not |
---|
28 | * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. |
---|
29 | * |
---|
30 | * The latest version of DOMPDF might be available at: |
---|
31 | * http://www.digitaljunkies.ca/dompdf |
---|
32 | * |
---|
33 | * @link http://www.digitaljunkies.ca/dompdf |
---|
34 | * @copyright 2004 Benj Carson |
---|
35 | * @author Benj Carson <benjcarson@digitaljunkies.ca> |
---|
36 | * @package dompdf |
---|
37 | * @version 0.5.1 |
---|
38 | */ |
---|
39 | |
---|
40 | /* $Id: image_frame_reflower.cls.php,v 1.9 2006/07/07 21:31:03 benjcarson Exp $ */ |
---|
41 | |
---|
42 | /** |
---|
43 | * Image reflower class |
---|
44 | * |
---|
45 | * @access private |
---|
46 | * @package dompdf |
---|
47 | */ |
---|
48 | class Image_Frame_Reflower extends Frame_Reflower { |
---|
49 | |
---|
50 | function __construct(Image_Frame_Decorator $frame) { |
---|
51 | parent::__construct($frame); |
---|
52 | } |
---|
53 | |
---|
54 | function reflow() { |
---|
55 | |
---|
56 | // Set the frame's width |
---|
57 | $this->get_min_max_width(); |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | function get_min_max_width() { |
---|
62 | |
---|
63 | // We need to grab our *parent's* style because images are wrapped... |
---|
64 | $style = $this->_frame->get_parent()->get_style(); |
---|
65 | |
---|
66 | $width = $style->width; |
---|
67 | $height = $style->height; |
---|
68 | |
---|
69 | // Determine the image's size |
---|
70 | list($img_width, $img_height, $type) = getimagesize($this->_frame->get_image_url()); |
---|
71 | |
---|
72 | if ( is_percent($width) ) |
---|
73 | $width = ((float)rtrim($width,"%")) * $img_width / 100; |
---|
74 | |
---|
75 | if ( is_percent($height) ) |
---|
76 | $height = ((float)rtrim($height,"%")) * $img_height / 100; |
---|
77 | |
---|
78 | $width = $style->length_in_pt($width); |
---|
79 | $height = $style->length_in_pt($height); |
---|
80 | |
---|
81 | if ( $width === "auto" && $height === "auto" ) { |
---|
82 | $width = $img_width; |
---|
83 | $height = $img_height; |
---|
84 | |
---|
85 | } else if ( $width === "auto" && $height !== "auto" ) { |
---|
86 | $width = (float)$height / $img_height * $img_width; |
---|
87 | |
---|
88 | } else if ( $width !== "auto" && $height === "auto" ) { |
---|
89 | $height = (float)$width / $img_width * $img_height; |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | // Resample images if the sizes were auto |
---|
94 | if ( $style->width === "auto" && $style->height === "auto" ) { |
---|
95 | $width = ((float)rtrim($width, "px")) * 72 / DOMPDF_DPI; |
---|
96 | $height = ((float)rtrim($height, "px")) * 72 / DOMPDF_DPI; |
---|
97 | } |
---|
98 | |
---|
99 | // Synchronize the styles |
---|
100 | $inner_style = $this->_frame->get_style(); |
---|
101 | $inner_style->width = $style->width = $width . "pt"; |
---|
102 | $inner_style->height = $style->height = $height . "pt"; |
---|
103 | |
---|
104 | $inner_style->padding_top = $style->padding_top; |
---|
105 | $inner_style->padding_right = $style->padding_right; |
---|
106 | $inner_style->padding_bottom = $style->padding_bottom; |
---|
107 | $inner_style->padding_left = $style->padding_left; |
---|
108 | |
---|
109 | $inner_style->border_top_width = $style->border_top_width; |
---|
110 | $inner_style->border_right_width = $style->border_right_width; |
---|
111 | $inner_style->border_bottom_width = $style->border_bottom_width; |
---|
112 | $inner_style->border_left_width = $style->border_left_width; |
---|
113 | |
---|
114 | $inner_style->border_top_style = $style->border_top_style; |
---|
115 | $inner_style->border_right_style = $style->border_right_style; |
---|
116 | $inner_style->border_bottom_style = $style->border_bottom_style; |
---|
117 | $inner_style->border_left_style = $style->border_left_style; |
---|
118 | |
---|
119 | $inner_style->margin_top = $style->margin_top; |
---|
120 | $inner_style->margin_right = $style->margin_right; |
---|
121 | $inner_style->margin_bottom = $style->margin_bottom; |
---|
122 | $inner_style->margin_left = $style->margin_left; |
---|
123 | |
---|
124 | return array( $width, $width, "min" => $width, "max" => $width); |
---|
125 | |
---|
126 | } |
---|
127 | } |
---|
128 | ?> |
---|