frame.cls.php
来自「国外很不错的一个开源OA系统Group-Office」· PHP 代码 · 共 774 行 · 第 1/2 页
PHP
774 行
<?php/** * DOMPDF - PHP5 HTML to PDF renderer * * File: $RCSfile: frame.cls.php,v $ * Created on: 2004-06-02 * * 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: frame.cls.php,v 1.2 2006/07/21 10:46:18 mschering Exp $ *//** * The main Frame class * * This class represents a single HTML element. This class stores * positioning information as well as containing block location and * dimensions. Style information for the element is stored in a {@link * Style} object. Tree structure is maintained via the parent & children * links. * * @access protected * @package dompdf */class Frame { /** * The DOMNode object this frame represents * * @var DOMNode */ protected $_node; /** * Unique identifier for this frame. Used to reference this frame * via the node. * * @var string */ protected $_id; /** * This frame's calculated style * * @var Style */ protected $_style; /** * This frame's original style. Needed for cases where frames are * split across pages. * * @var Style */ protected $_original_style; /** * This frame's parent in the document tree. * * @var Frame */ protected $_parent; /** * This frame's first child. All children are handled as a * doubly-linked list. * * @var Frame */ protected $_first_child; /** * This frame's last child. * * @var Frame */ protected $_last_child; /** * This frame's previous sibling in the document tree. * * @var Frame */ protected $_prev_sibling; /** * This frame's next sibling in the document tree. * * @var Frame */ protected $_next_sibling; /** * This frame's containing block (used in layout): array(x, y, w, h) * * @var array */ protected $_containing_block; /** * Position on the page of the top-left corner of the margin box of * this frame: array(x,y) * * @var array */ protected $_position; /** * This frame's decorator * * @var Frame_Decorator */ protected $_decorator; /** * Class constructor * * @param DOMNode $node the DOMNode this frame represents */ function __construct(DomNode $node) { $this->_node = $node; $this->_parent = null; $this->_first_child = null; $this->_last_child = null; $this->_prev_sibling = $this->_next_sibling = null; $this->_style = null; $this->_original_style = null; $this->_containing_block = array("x" => null, "y" => null, "w" => null, "h" => null); $this->_position = array("x" => null, "y" => null); $this->_decorator = null; //$this->set_id( uniqid(rand()) ); if(!isset($GLOBALS['dompdfuniqueid'])) { $GLOBALS['dompdfuniqueid']=1; }else { $GLOBALS['dompdfuniqueid']++; } $this->set_id('frm_'.$GLOBALS['dompdfuniqueid']); } /** * "Destructor": forcibly free all references held by this frame * * @param bool $recursive if true, call dispose on all children */ function dispose($recursive = false) { if ( $recursive ) { while ( $child = $this->_first_child ) $child->dispose(true); } // Remove this frame from the tree if ( $this->_prev_sibling ) { $this->_prev_sibling->_next_sibling = $this->_next_sibling; } if ( $this->_next_sibling ) { $this->_next_sibling->_prev_sibling = $this->_prev_sibling; } if ( $this->_parent && $this->_parent->_first_child === $this ) { $this->_parent->_first_child = $this->_next_sibling; } if ( $this->_parent && $this->_parent->_last_child === $this ) { $this->_parent->_last_child = $this->_prev_sibling; } if ( $this->_parent ) { $this->_parent->get_node()->removeChild($this->_node); } $this->_style->dispose(); unset($this->_style); $this->_original_style->dispose(); unset($this->_original_style); } // Re-initialize the frame function reset() { $this->_position = array("x" => null, "y" => null); $this->_containing_block = array("x" => null, "y" => null, "w" => null, "h" => null); unset($this->_style); $this->_style = clone $this->_original_style; } //........................................................................ // Accessor methods function get_node() { return $this->_node; } function get_id() { return $this->_id; } function get_style() { return $this->_style; } function get_original_style() { return $this->_original_style; } function get_parent() { return $this->_parent; } function get_decorator() { return $this->_decorator; } function get_first_child() { return $this->_first_child; } function get_last_child() { return $this->_last_child; } function get_prev_sibling() { return $this->_prev_sibling; } function get_next_sibling() { return $this->_next_sibling; } function get_children() { return new FrameList($this); } // Layout property accessors function get_containing_block($i = null) { if ( isset($i) ) return $this->_containing_block[$i]; return $this->_containing_block; } function get_position($i = null) { if ( isset($i) ) return $this->_position[$i]; return array($this->_position["x"], $this->_position["y"], "x"=>$this->_position["x"], "y"=>$this->_position["y"]); } //........................................................................ // Return the height of the margin box of the frame, in pt. Meaningless // unless the height has been calculated properly. function get_margin_height() { return $this->_style->length_in_pt(array($this->_style->height, $this->_style->margin_top, $this->_style->margin_bottom, $this->_style->border_top_width, $this->_style->border_bottom_width, $this->_style->padding_top, $this->_style->padding_bottom), $this->_containing_block["w"]); } // Return the width of the margin box of the frame, in pt. Meaningless // unless the width has been calculted properly. function get_margin_width() { return $this->_style->length_in_pt(array($this->_style->width, $this->_style->margin_left, $this->_style->margin_right, $this->_style->border_left_width, $this->_style->border_right_width, $this->_style->padding_left, $this->_style->padding_right), $this->_containing_block["w"]); } // Return the padding box (x,y,w,h) of the frame function get_padding_box() { $x = $this->_position["x"] + $this->_style->length_in_pt(array($this->_style->margin_left, $this->_style->border_left_width), $this->_containing_block["w"]); $y = $this->_position["y"] + $this->_style->length_in_pt(array($this->_style->margin_top, $this->_style->border_top_width), $this->_containing_block["w"]); $w = $this->_style->length_in_pt(array($this->_style->padding_left, $this->_style->width, $this->_style->padding_right), $this->_containing_block["w"]); $h = $this->_style->length_in_pt(array($this->_style->padding_top, $this->_style->height, $this->_style->padding_bottom), $this->_containing_block["w"]); return array(0 => $x, "x" => $x, 1 => $y, "y" => $y, 2 => $w, "w" => $w, 3 => $h, "h" => $h); } // Return the border box of the frame function get_border_box() { $x = $this->_position["x"] + $this->_style->length_in_pt($this->_style->margin_left, $this->_containing_block["w"]); $y = $this->_position["y"] + $this->_style->length_in_pt($this->_style->margin_top, $this->_containing_block["w"]); $w = $this->_style->length_in_pt(array($this->_style->border_left_width, $this->_style->padding_left, $this->_style->width, $this->_style->padding_right, $this->_style->border_right_width), $this->_containing_block["w"]); $h = $this->_style->length_in_pt(array($this->_style->border_top_width, $this->_style->padding_top, $this->_style->height, $this->_style->padding_bottom, $this->_style->border_bottom_width), $this->_containing_block["w"]); return array(0 => $x, "x" => $x, 1 => $y, "y" => $y, 2 => $w, "w" => $w, 3 => $h, "h" => $h); } //........................................................................ // Set methods function set_id($id) { $this->_id = $id; // We can only set attributes of DOMElement objects (nodeType == 1). // Since these are the only objects that we can assign CSS rules to, // this shortcoming is okay. if ( $this->_node->nodeType == 1) $this->_node->setAttribute("frame_id", $id); } function set_style(Style $style) { if ( is_null($this->_style) ) $this->_original_style = clone $style; $this->_style = $style; } function set_decorator(Frame_Decorator $decorator) { $this->_decorator = $decorator; } function set_containing_block($x = null, $y = null, $w = null, $h = null) { if ( is_array($x) ) extract($x); if (is_numeric($x)) { $this->_containing_block[0] = $x; $this->_containing_block["x"] = $x; } if (is_numeric($y)) { $this->_containing_block[1] = $y; $this->_containing_block["y"] = $y;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?