📄 table_frame_reflower.cls.php
字号:
$used_width += $w; } 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; } } else { // we are over constrained // Each column gets its minimum width foreach (array_keys($columns) as $i) $cellmap->set_column_width($i, $columns[$i]["min-width"]); } } //........................................................................ // Determine the frame's height based on min/max height protected function _calculate_height() { $style = $this->_frame->get_style(); $height = $style->height; $cellmap = $this->_frame->get_cellmap(); $cellmap->assign_frame_heights(); $rows = $cellmap->get_rows(); // Determine our content height $content_height = 0; foreach ( $rows as $r ) $content_height += $r["height"]; $cb = $this->_frame->get_containing_block(); if ( !($style->overflow === "visible" || ($style->overflow === "hidden" && $height === "auto")) ) { // Only handle min/max height if the height is independent of the frame's content $min_height = $style->min_height; $max_height = $style->max_height; if ( isset($cb["h"]) ) { $min_height = $style->length_in_pt($min_height, $cb["h"]); $max_height = $style->length_in_pt($max_height, $cb["h"]); } else if ( isset($cb["w"]) ) { if ( mb_strpos($min_height, "%") !== false ) $min_height = 0; else $min_height = $style->length_in_pt($min_height, $cb["w"]); if ( mb_strpos($max_height, "%") !== false ) $max_height = "none"; else $max_height = $style->length_in_pt($max_height, $cb["w"]); } if ( $max_height !== "none" && $min_height > $max_height ) // Swap 'em list($max_height, $min_height) = array($min_height, $max_height); if ( $max_height !== "none" && $height > $max_height ) $height = $max_height; if ( $height < $min_height ) $height = $min_height; } else { // Use the content height or the height value, whichever is greater if ( $height !== "auto" ) { $height = $style->length_in_pt($height, $cb["h"]); if ( $height <= $content_height ) $height = $content_height; else $cellmap->set_frame_heights($height,$content_height); } else $height = $content_height; } return $height; } //........................................................................ function reflow() { // Check if a page break is forced $page = $this->_frame->get_root(); $page->check_forced_page_break($this->_frame); // Bail if the page is full if ( $page->is_full() ) return; // Let the page know that we're reflowing a table so that splits // are suppressed (simply setting page-break-inside: avoid won't // work because we may have an arbitrary number of block elements // inside tds.) $page->table_reflow_start(); // Collapse vertical margins, if required $this->_collapse_margins(); $this->_frame->position(); // Table layout algorithm: // http://www.w3.org/TR/CSS21/tables.html#auto-table-layout if ( is_null($this->_state) ) $this->get_min_max_width(); $cb = $this->_frame->get_containing_block(); $style = $this->_frame->get_style(); // This is slightly inexact, but should be okay. Add half the // border-spacing to the table as padding. The other half is added to // the cells themselves. if ( $style->border_collapse === "separate" ) { list($h, $v) = $style->border_spacing; $v = $style->length_in_pt($v) / 2; $h = $style->length_in_pt($h) / 2; $style->padding_left = $style->length_in_pt($style->padding_left, $cb["w"]) + $h; $style->padding_right = $style->length_in_pt($style->padding_right, $cb["w"]) + $h; $style->padding_top = $style->length_in_pt($style->padding_top, $cb["w"]) + $v; $style->padding_bottom = $style->length_in_pt($style->padding_bottom, $cb["w"]) + $v; } $this->_assign_widths(); // Adjust left & right margins, if they are auto $width = $style->width; $left = $style->margin_left; $right = $style->margin_right; $diff = $cb["w"] - $width; if ( $left === "auto" && $right === "auto" && $diff > 0 ) { $left = $right = $diff / 2; $style->margin_left = "$left pt"; $style->margin_right = "$right pt"; } else { $left = $style->length_in_pt($left, $cb["w"]); $right = $style->length_in_pt($right, $cb["w"]); } list($x, $y) = $this->_frame->get_position(); // Determine the content edge $content_x = $x + $left + $style->length_in_pt(array($style->padding_left, $style->border_left_width), $cb["w"]); $content_y = $y + $style->length_in_pt(array($style->margin_top, $style->border_top_width, $style->padding_top), $cb["w"]); if ( isset($cb["h"]) ) $h = $cb["h"]; else $h = null; $cellmap = $this->_frame->get_cellmap(); $col =& $cellmap->get_column(0); $col["x"] = $content_x; $row =& $cellmap->get_row(0); $row["y"] = $content_y; $cellmap->assign_x_positions(); // Set the containing block of each child & reflow foreach ( $this->_frame->get_children() as $child ) { // Bail if the page is full if ( $page->is_full() ) break; $child->set_containing_block($content_x, $content_y, $width, $h); $child->reflow(); // Check if a split has occured $page->check_page_break($child); } // Assign heights to our cells: $style->height = $this->_calculate_height(); if ( $style->border_collapse === "collapse" ) { // Unset our borders because our cells are now using them $style->border_style = "none"; } $page->table_reflow_end(); // Debugging: //echo ($this->_frame->get_cellmap()); } //........................................................................ function get_min_max_width() { $style = $this->_frame->get_style(); $this->_frame->normalise(); // Add the cells to the cellmap (this will calcluate column widths as // frames are added) $this->_frame->get_cellmap()->add_frame($this->_frame); // Find the min/max width of the table and sort the columns into // absolute/percent/auto arrays $this->_state = array(); $this->_state["min_width"] = 0; $this->_state["max_width"] = 0; $this->_state["percent_used"] = 0; $this->_state["absolute_used"] = 0; $this->_state["auto_min"] = 0; $this->_state["absolute"] = array(); $this->_state["percent"] = array(); $this->_state["auto"] = array(); $columns =& $this->_frame->get_cellmap()->get_columns(); foreach (array_keys($columns) as $i) { $this->_state["min_width"] += $columns[$i]["min-width"]; $this->_state["max_width"] += $columns[$i]["max-width"]; if ( $columns[$i]["absolute"] > 0 ) { $this->_state["absolute"][] = $i; $this->_state["absolute_used"] += $columns[$i]["absolute"]; } else if ( $columns[$i]["percent"] > 0 ) { $this->_state["percent"][] = $i; $this->_state["percent_used"] += $columns[$i]["percent"]; } else { $this->_state["auto"][] = $i; $this->_state["auto_min"] += $columns[$i]["min-width"]; } } return array($this->_state["min_width"], $this->_state["max_width"], "min" => $this->_state["min_width"], "max" => $this->_state["max_width"]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -