1 | <?php |
---|
2 | /** |
---|
3 | * DOMPDF - PHP5 HTML to PDF renderer |
---|
4 | * |
---|
5 | * File: $RCSfile: table_cell_frame_reflower.cls.php,v $ |
---|
6 | * Created on: 2004-06-07 |
---|
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: table_cell_frame_reflower.cls.php,v 1.9 2006/07/07 21:31:04 benjcarson Exp $ */ |
---|
41 | |
---|
42 | |
---|
43 | /** |
---|
44 | * Reflows table cells |
---|
45 | * |
---|
46 | * @access private |
---|
47 | * @package dompdf |
---|
48 | */ |
---|
49 | class Table_Cell_Frame_Reflower extends Block_Frame_Reflower { |
---|
50 | |
---|
51 | //........................................................................ |
---|
52 | |
---|
53 | function __construct(Frame $frame) { |
---|
54 | parent::__construct($frame); |
---|
55 | } |
---|
56 | |
---|
57 | //........................................................................ |
---|
58 | |
---|
59 | function reflow() { |
---|
60 | |
---|
61 | $style = $this->_frame->get_style(); |
---|
62 | |
---|
63 | $table = Table_Frame_Decorator::find_parent_table($this->_frame); |
---|
64 | $cellmap = $table->get_cellmap(); |
---|
65 | |
---|
66 | list($x, $y) = $cellmap->get_frame_position($this->_frame); |
---|
67 | $this->_frame->set_position($x, $y); |
---|
68 | |
---|
69 | $cells = $cellmap->get_spanned_cells($this->_frame); |
---|
70 | |
---|
71 | $w = 0; |
---|
72 | foreach ( $cells["columns"] as $i ) { |
---|
73 | $col = $cellmap->get_column( $i ); |
---|
74 | $w += $col["used-width"]; |
---|
75 | } |
---|
76 | |
---|
77 | //FIXME? |
---|
78 | $h = $this->_frame->get_containing_block("h"); |
---|
79 | |
---|
80 | $left_space = $style->length_in_pt(array($style->margin_left, |
---|
81 | $style->padding_left, |
---|
82 | $style->border_left_width), |
---|
83 | $w); |
---|
84 | |
---|
85 | $right_space = $style->length_in_pt(array($style->padding_right, |
---|
86 | $style->margin_right, |
---|
87 | $style->border_right_width), |
---|
88 | $w); |
---|
89 | |
---|
90 | $top_space = $style->length_in_pt(array($style->margin_top, |
---|
91 | $style->padding_top, |
---|
92 | $style->border_top_width), |
---|
93 | $w); |
---|
94 | $bottom_space = $style->length_in_pt(array($style->margin_bottom, |
---|
95 | $style->padding_bottom, |
---|
96 | $style->border_bottom_width), |
---|
97 | $w); |
---|
98 | |
---|
99 | $style->width = $cb_w = $w - $left_space - $right_space; |
---|
100 | |
---|
101 | $content_x = $x + $left_space; |
---|
102 | $content_y = $line_y = $y + $top_space; |
---|
103 | |
---|
104 | // Adjust the first line based on the text-indent property |
---|
105 | $indent = $style->length_in_pt($style->text_indent, $w); |
---|
106 | $this->_frame->increase_line_width($indent); |
---|
107 | |
---|
108 | // Set the y position of the first line in the cell |
---|
109 | $this->_frame->set_current_line($line_y); |
---|
110 | |
---|
111 | // Set the containing blocks and reflow each child |
---|
112 | foreach ( $this->_frame->get_children() as $child ) { |
---|
113 | |
---|
114 | $child->set_containing_block($content_x, $content_y, $cb_w, $h); |
---|
115 | $child->reflow(); |
---|
116 | |
---|
117 | $this->_frame->add_frame_to_line( $child ); |
---|
118 | } |
---|
119 | |
---|
120 | // Determine our height |
---|
121 | $height = $style->length_in_pt($style->height, $w); |
---|
122 | |
---|
123 | $this->_frame->set_content_height($this->_calculate_content_height()); |
---|
124 | |
---|
125 | $height = max($height, $this->_frame->get_content_height()); |
---|
126 | |
---|
127 | // Let the cellmap know our height |
---|
128 | $cell_height = $height / count($cells["rows"]) + $top_space + $bottom_space; |
---|
129 | |
---|
130 | foreach ($cells["rows"] as $i) |
---|
131 | $cellmap->set_row_height($i, $cell_height); |
---|
132 | |
---|
133 | $style->height = $height; |
---|
134 | |
---|
135 | $this->_text_align(); |
---|
136 | |
---|
137 | $this->vertical_align(); |
---|
138 | |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|
142 | ?> |
---|