📄 table_frame_reflower.cls.php
字号:
<?php/** * DOMPDF - PHP5 HTML to PDF renderer * * File: $RCSfile: table_frame_reflower.cls.php,v $ * Created on: 2004-06-17 * * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library in the file LICENSE.LGPL; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA * * Alternatively, you may distribute this software under the terms of the * PHP License, version 3.0 or later. A copy of this license should have * been distributed with this file in the file LICENSE.PHP . If this is not * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. * * The latest version of DOMPDF might be available at: * http://www.digitaljunkies.ca/dompdf * * @link http://www.digitaljunkies.ca/dompdf * @copyright 2004 Benj Carson * @author Benj Carson <benjcarson@digitaljunkies.ca> * @package dompdf * @version 0.5.1 *//* $Id: table_frame_reflower.cls.php,v 1.2 2006/07/21 10:46:20 mschering Exp $ *//** * Reflows tables * * @access private * @package dompdf */class Table_Frame_Reflower extends Frame_Reflower { /** * Cache of results between call to get_min_max_width and assign_widths * * @var array */ protected $_state; function __construct(Table_Frame_Decorator $frame) { $this->_state = null; parent::__construct($frame); } /** * State is held here so it needs to be reset along with the decorator */ function reset() { $this->_state = null; } //........................................................................ protected function _assign_widths() { $style = $this->_frame->get_style(); // Find the min/max width of the table and sort the columns into // absolute/percent/auto arrays $min_width = $this->_state["min_width"]; $max_width = $this->_state["max_width"]; $percent_used = $this->_state["percent_used"]; $absolute_used = $this->_state["absolute_used"]; $auto_min = $this->_state["auto_min"]; $absolute =& $this->_state["absolute"]; $percent =& $this->_state["percent"]; $auto =& $this->_state["auto"]; // Determine the actual width of the table $cb = $this->_frame->get_containing_block(); $columns =& $this->_frame->get_cellmap()->get_columns(); $width = $style->width; // Calcluate padding & border fudge factor $left = $style->margin_left; $right = $style->margin_right; $left = $left == "auto" ? 0 : $style->length_in_pt($left, $cb["w"]); $right = $right == "auto" ? 0 : $style->length_in_pt($right, $cb["w"]); $delta = $left + $right + $style->length_in_pt(array($style->padding_left, $style->border_left_width, $style->border_right_width, $style->padding_right), $cb["w"]); $min_table_width = $style->length_in_pt( $style->min_width, $cb["w"] - $delta ); if ( $width !== "auto" ) { $preferred_width = $style->length_in_pt($width, $cb["w"]) - $delta; if ( $preferred_width < $min_table_width ) $preferred_width = $min_table_width; if ( $preferred_width > $min_width ) $width = $preferred_width; else $width = $min_width; } else { if ( $max_width + $delta < $cb["w"] ) $width = $max_width; else if ( $cb["w"] - $delta > $min_width ) $width = $cb["w"] - $delta; else $width = $min_width; if ( $width < $min_table_width ) $width = $min_table_width; } // Store our resolved width $style->width = $width; $cellmap = $this->_frame->get_cellmap(); // If the whole table fits on the page, then assign each column it's max width if ( $width == $max_width ) { foreach (array_keys($columns) as $i) $cellmap->set_column_width($i, $columns[$i]["max-width"]); return; } // Determine leftover and assign it evenly to all columns if ( $width > $min_width ) { // We have four cases to deal with: // // 1. All columns are auto--no widths have been specified. In this // case we distribute extra space across all columns weighted by max-width. // // 2. Only absolute widths have been specified. In this case we // distribute any extra space equally among 'width: auto' columns. // // 3. Only percentage widths have been specified. In this case we // normalize the percentage values and distribute any remaining % to // width: auto columns. We then proceed to assign widths as fractions // of the table width. // // 4. Both absolute and percentage widths have been specified. This // is annoying. // Case 1: if ( $absolute_used == 0 && $percent_used == 0 ) { $increment = $width - $min_width; foreach (array_keys($columns) as $i) $cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment * ($columns[$i]["max-width"] / $max_width)); return; } // Case 2 if ( $absolute_used > 0 && $percent_used == 0 ) { if ( count($auto) > 0 ) $increment = ($width - $auto_min - $absolute_used) / count($auto); else $increment = 0; // Use the absolutely specified width or the increment foreach (array_keys($columns) as $i) { if ( $columns[$i]["absolute"] > 0 ) $cellmap->set_column_width($i, $columns[$i]["min-width"]); else $cellmap->set_column_width($i,$columns[$i]["min-width"] + $increment); } return; } // Case 3: if ( $absolute_used == 0 && $percent_used > 0 ) { $scale = null; $remaining = null; // Scale percent values if the total percentage is > 100, or if all // values are specified as percentages. if ( $percent_used > 100 || count($auto) == 0) $scale = 100 / $percent_used; else $scale = 1; // Account for the minimum space used by the unassigned auto columns $used_width = $auto_min; foreach ($percent as $i) { $columns[$i]["percent"] *= $scale; $slack = $width - $used_width; $w = min($columns[$i]["percent"] * $width/100, $slack); if ( $w < $columns[$i]["min-width"] ) $w = $columns[$i]["min-width"]; $cellmap->set_column_width($i, $w); $used_width += $w; } // This works because $used_width includes the min-width of each // unassigned column if ( count($auto) > 0 ) { $increment = ($width - $used_width) / count($auto); foreach ($auto as $i) $cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment); } return; } // Case 4: // First-come, first served if ( $absolute_used > 0 && $percent_used > 0 ) { $used_width = $auto_min; foreach ($absolute as $i) { $cellmap->set_column_width($i, $columns[$i]["min-width"]); $used_width += $columns[$i]["min-width"]; } // Scale percent values if the total percentage is > 100 or there // are no auto values to take up slack if ( $percent_used > 100 || count($auto) == 0 ) $scale = 100 / $percent_used; else $scale = 1; $remaining_width = $width - $used_width; foreach ($percent as $i) { $slack = $remaining_width - $used_width; $columns[$i]["percent"] *= $scale; $w = min($columns[$i]["percent"] * $remaining_width / 100, $slack); if ( $w < $columns[$i]["min-width"] ) $w = $columns[$i]["min-width"]; $columns[$i]["used-width"] = $w;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -