cellmap.cls.php

来自「国外很不错的一个开源OA系统Group-Office」· PHP 代码 · 共 696 行 · 第 1/2 页

PHP
696
字号
<?php/** * DOMPDF - PHP5 HTML to PDF renderer * * File: $RCSfile: cellmap.cls.php,v $ * Created on: 2004-07-28 * * 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: cellmap.cls.php,v 1.2 2006/07/21 10:46:18 mschering Exp $ *//** * Maps table cells to the table grid. * * This class resolves borders in tables with collapsed borders and helps * place row & column spanned table cells. * * @access private * @package dompdf */class Cellmap {  /**   * Border style weight lookup for collapsed border resolution.   *   * @var array   */  static protected $_BORDER_STYLE_SCORE = array("inset"  => 1,                                                "groove" => 2,                                                "outset" => 3,                                                "ridge"  => 4,                                                "dotted" => 5,                                                "dashed" => 6,                                                "solid"  => 7,                                                "double" => 8,                                                "none"   => 0);  /**   * The table object this cellmap is attached to.   *   * @var Table_Frame_Decorator   */  protected $_table;    /**   * The total number of rows in the table   *   * @var int   */  protected $_num_rows;  /**   * The total number of columns in the table   *   * @var int   */  protected $_num_cols;  /**   * 2D array mapping <row,column> to frames   *   * @var array   */  protected $_cells;  /**   * 1D array of column dimensions   *   * @var array   */  protected $_columns;  /**   * 1D array of row dimensions   *   * @var array   */  protected $_rows;  /**   * 2D array of border specs   *   * @var array   */  protected $_borders;  /**   * 1D Array mapping frames to (multiple) <row, col> pairs, keyed on   * frame_id.   *   * @var array   */  protected $_frames;  /**   * Current column when adding cells, 0-based   *   * @var int   */  private $__col;  /**   * Current row when adding cells, 0-based   *   * @var int   */  private $__row;    //........................................................................  function __construct(Table_Frame_Decorator $table) {    $this->_table = $table;    $this->reset();  }  //........................................................................  function reset() {        $this->_num_rows = 0;    $this->_num_cols = 0;    $this->_cells  = array();    $this->_frames = array();    $this->_columns = array();    $this->_rows = array();       $this->_borders = array();        $this->__col = $this->__row = 0;  }    //........................................................................  function get_num_rows() { return $this->_num_rows; }  function get_num_cols() { return $this->_num_cols; }  function &get_columns() {    return $this->_columns;  }    function &get_column($i) {    if ( !isset($this->_columns[$i]) )      $this->_columns[$i] = array("x" => 0,                                  "min-width" => 0,                                  "max-width" => 0,                                  "used-width" => null,                                  "absolute" => 0,                                  "percent" => 0,                                  "auto" => true);    return $this->_columns[$i];  }  function &get_rows() {    return $this->_rows;  }    function &get_row($j) {    if ( !isset($this->_rows[$j]) )      $this->_rows[$j] = array("y" => 0,                               "first-column" => 0,                               "height" => null);    return $this->_rows[$j];  }  function get_border($i, $j, $h_v, $prop = null) {    if ( !isset($this->_borders[$i][$j][$h_v]) )      $this->_borders[$i][$j][$h_v] = array("width" => 0,                                           "style" => "solid",                                           "color" => "black");    if ( isset($prop) )      return $this->_borders[$i][$j][$h_v][$prop];        return $this->_borders[$i][$j][$h_v];  }    function get_border_properties($i, $j) {        $left = $this->get_border($i, $j, "vertical");    $right = $this->get_border($i, $j+1, "vertical");    $top = $this->get_border($i, $j, "horizontal");    $bottom = $this->get_border($i+1, $j, "horizontal");        return compact("top", "bottom", "left", "right");  }    //........................................................................  function get_spanned_cells($frame) {    $key = $frame->get_id();    if ( !isset($this->_frames[$key]) ) {      throw new DOMPDF_Internal_Exception("Frame not found in cellmap");    }          return $this->_frames[$key];      }  function get_frame_position($frame) {    global $_dompdf_warnings;        $key = $frame->get_id();    if ( !isset($this->_frames[$key]) ) {      throw new DOMPDF_Internal_Exception("Frame not found in cellmap");    }    $col = $this->_frames[$key]["columns"][0];    $row = $this->_frames[$key]["rows"][0];    if ( !isset($this->_columns[$col])) {      $_dompdf_warnings[] = "Frame not found in columns array.  Check your table layout for missing or extra TDs.";      $x = 0;    } else       $x = $this->_columns[$col]["x"];        if ( !isset($this->_rows[$row])) {      $_dompdf_warnings[] = "Frame not found in row array.  Check your table layout for missing or extra TDs.";      $y = 0;    } else       $y = $this->_rows[$row]["y"];    return array($x, $y, "x" => $x, "y" => $y);  }    function get_frame_width($frame) {    $key = $frame->get_id();    if ( !isset($this->_frames[$key]) ) {      throw new DOMPDF_Internal_Exception("Frame not found in cellmap");    }    $cols = $this->_frames[$key]["columns"];    $w = 0;    foreach ($cols as $i)      $w += $this->_columns[$i]["used-width"];    return $w;      }    function get_frame_height($frame) {    $key = $frame->get_id();    if ( !isset($this->_frames[$key]) )       throw new DOMPDF_Internal_Exception("Frame not found in cellmap");    $rows = $this->_frames[$key]["rows"];    $h = 0;    foreach ($rows as $i) {      if ( !isset($this->_rows[$i]) )  {        throw new Exception("foo");      }      $h += $this->_rows[$i]["height"];    }    return $h;      }    //........................................................................  function set_column_width($j, $width) {    $col =& $this->get_column($j);    $col["used-width"] = $width;    $next_col =& $this->get_column($j+1);    $next_col["x"] = $next_col["x"] + $width;      }    function set_row_height($i, $height) {    $row =& $this->get_row($i);        if ( $height <= $row["height"] )      return;        $row["height"] = $height;    $next_row =& $this->get_row($i+1);    $next_row["y"] = $row["y"] + $height;  }  //........................................................................  protected function _resolve_border($i, $j, $h_v, $border_spec) {    $n_width = $border_spec["width"];    $n_style = $border_spec["style"];    $n_color = $border_spec["color"];        if ( !isset($this->_borders[$i][$j][$h_v]) ) {      $this->_borders[$i][$j][$h_v] = $border_spec;      return $this->_borders[$i][$j][$h_v]["width"];    }        $o_width = $this->_borders[$i][$j][$h_v]["width"];    $o_style = $this->_borders[$i][$j][$h_v]["style"];    $o_color = $this->_borders[$i][$j][$h_v]["color"];    if ( ($n_style === "hidden" ||          $n_width  >  $o_width ||          $o_style === "none")         or         ($o_width == $n_width &&          in_array($n_style, self::$_BORDER_STYLE_SCORE) &&          self::$_BORDER_STYLE_SCORE[ $n_style ] > self::$_BORDER_STYLE_SCORE[ $o_style ]) )      $this->_borders[$i][$j][$h_v] = $border_spec;    return $this->_borders[$i][$j][$h_v]["width"];  }    //........................................................................  function add_frame(Frame $frame) {    $style = $frame->get_style();        $display = $style->display;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?