[3019] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * DOMPDF - PHP5 HTML to PDF renderer |
---|
| 4 | * |
---|
| 5 | * File: $RCSfile: page_frame_reflower.cls.php,v $ |
---|
| 6 | * Created on: 2004-06-16 |
---|
| 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: page_frame_reflower.cls.php 186 2009-10-19 22:42:06Z eclecticgeek@gmail.com $ */ |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * Reflows pages |
---|
| 44 | * |
---|
| 45 | * @access private |
---|
| 46 | * @package dompdf |
---|
| 47 | */ |
---|
| 48 | class Page_Frame_Reflower extends Frame_Reflower { |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * Cache of the callbacks array |
---|
| 52 | * |
---|
| 53 | * @var array |
---|
| 54 | */ |
---|
| 55 | private $_callbacks; |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * Cache of the canvas |
---|
| 59 | * |
---|
| 60 | * @var Canvas |
---|
| 61 | */ |
---|
| 62 | private $_canvas; |
---|
| 63 | |
---|
| 64 | function __construct(Page_Frame_Decorator $frame) { parent::__construct($frame); } |
---|
| 65 | |
---|
| 66 | //........................................................................ |
---|
| 67 | |
---|
| 68 | function reflow() { |
---|
| 69 | $style = $this->_frame->get_style(); |
---|
| 70 | |
---|
| 71 | // Paged layout: |
---|
| 72 | // http://www.w3.org/TR/CSS21/page.html |
---|
| 73 | |
---|
| 74 | // Pages are only concerned with margins |
---|
| 75 | $cb = $this->_frame->get_containing_block(); |
---|
| 76 | $left = $style->length_in_pt($style->margin_left, $cb["w"]); |
---|
| 77 | $right = $style->length_in_pt($style->margin_right, $cb["w"]); |
---|
| 78 | $top = $style->length_in_pt($style->margin_top, $cb["w"]); |
---|
| 79 | $bottom = $style->length_in_pt($style->margin_bottom, $cb["w"]); |
---|
| 80 | |
---|
| 81 | $content_x = $cb["x"] + $left; |
---|
| 82 | $content_y = $cb["y"] + $top; |
---|
| 83 | $content_width = $cb["w"] - $left - $right; |
---|
| 84 | $content_height = $cb["h"] - $top - $bottom; |
---|
| 85 | |
---|
| 86 | $prev_child = null; |
---|
| 87 | $child = $this->_frame->get_first_child(); |
---|
| 88 | |
---|
| 89 | while ($child) { |
---|
| 90 | |
---|
| 91 | $child->set_containing_block($content_x, $content_y, $content_width, $content_height); |
---|
| 92 | |
---|
| 93 | // Check for begin reflow callback |
---|
| 94 | $this->_check_callbacks("begin_page_reflow", $child); |
---|
| 95 | |
---|
| 96 | $child->reflow(); |
---|
| 97 | $next_child = $child->get_next_sibling(); |
---|
| 98 | |
---|
| 99 | // Check for begin render callback |
---|
| 100 | $this->_check_callbacks("begin_page_render", $child); |
---|
| 101 | |
---|
| 102 | // Render the page |
---|
| 103 | $this->_frame->get_renderer()->render($child); |
---|
| 104 | |
---|
| 105 | // Check for end render callback |
---|
| 106 | $this->_check_callbacks("end_page_render", $child); |
---|
| 107 | |
---|
| 108 | if ( $next_child ) |
---|
| 109 | { |
---|
| 110 | $this->_frame->next_page(); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | // Wait to dispose of all frames on the previous page |
---|
| 114 | // so callback will have access to them |
---|
| 115 | if ( $prev_child ) |
---|
| 116 | { |
---|
| 117 | $prev_child->dispose(true); |
---|
| 118 | } |
---|
| 119 | $prev_child = $child; |
---|
| 120 | $child = $next_child; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | // Dispose of previous page if it still exists |
---|
| 124 | if ( $prev_child ) |
---|
| 125 | { |
---|
| 126 | $prev_child->dispose(true); |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | //........................................................................ |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | * Check for callbacks that need to be performed when a given event |
---|
| 134 | * gets triggered on a page |
---|
| 135 | * |
---|
| 136 | * @param string $event the type of event |
---|
| 137 | * @param Frame $frame the frame that event is triggered on |
---|
| 138 | */ |
---|
| 139 | protected function _check_callbacks($event, $frame) { |
---|
| 140 | if (!isset($this->_callbacks)) { |
---|
| 141 | $dompdf = $this->_frame->get_dompdf(); |
---|
| 142 | $this->_callbacks = $dompdf->get_callbacks(); |
---|
| 143 | $this->_canvas = $dompdf->get_canvas(); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | if (is_array($this->_callbacks) && isset($this->_callbacks[$event])) { |
---|
| 147 | $info = array(0 => $this->_canvas, "canvas" => $this->_canvas, |
---|
| 148 | 1 => $frame, "frame" => $frame); |
---|
| 149 | $fs = $this->_callbacks[$event]; |
---|
| 150 | foreach ($fs as $f) { |
---|
| 151 | if (is_callable($f)) { |
---|
| 152 | if (is_array($f)) { |
---|
| 153 | $f[0]->$f[1]($info); |
---|
| 154 | } else { |
---|
| 155 | $f($info); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | ?> |
---|