source: trunk/filemanager/tp/dompdf/include/cached_pdf_decorator.cls.php @ 2000

Revision 2000, 6.7 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implementação do módulo gerenciador de arquivos

Line 
1<?php
2/**
3 * DOMPDF - PHP5 HTML to PDF renderer
4 *
5 * File: $RCSfile: cached_pdf_decorator.cls.php,v $
6 * Created on: 2004-07-23
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: cached_pdf_decorator.cls.php 186 2009-10-19 22:42:06Z eclecticgeek@gmail.com $ */
41
42/**
43 * Caching canvas implementation
44 *
45 * Each rendered page is serialized and stored in the {@link Page_Cache}.
46 * This is useful for static forms/pages that do not need to be re-rendered
47 * all the time.
48 *
49 * This class decorates normal CPDF_Adapters.  It is currently completely
50 * experimental.
51 *
52 * @access private
53 * @package dompdf
54 */
55class Cached_PDF_Decorator extends CPDF_Adapter implements Canvas {
56  protected $_pdf;
57  protected $_cache_id;
58  protected $_current_page_id;
59  protected $_fonts;  // fonts used in this document
60 
61  function __construct($cache_id, CPDF_Adapter $pdf) {
62    $this->_pdf = $pdf;
63    $this->_cache_id = $cache_id;
64    $this->_fonts = array();
65   
66    $this->_current_page_id = $this->_pdf->open_object();
67  }
68
69  //........................................................................
70
71  function get_cpdf() { return $this->_pdf->get_cpdf(); }
72
73  function open_object() { $this->_pdf->open_object(); }
74  function reopen_object() { return $this->_pdf->reopen_object(); }
75 
76  function close_object() { $this->_pdf->close_object(); }
77
78  function add_object($object, $where = 'all') { $this->_pdf->add_object($object, $where); }
79
80  function serialize_object($id) { $this->_pdf->serialize_object($id); }
81
82  function reopen_serialized_object($obj) { $this->_pdf->reopen_serialized_object($obj); }
83   
84  //........................................................................
85
86  function get_width() { return $this->_pdf->get_width(); }
87  function get_height() {  return $this->_pdf->get_height(); }
88  function get_page_number() { return $this->_pdf->get_page_number(); }
89  function get_page_count() { return $this->_pdf->get_page_count(); }
90
91  function set_page_number($num) { $this->_pdf->set_page_number($num); }
92  function set_page_count($count) { $this->_pdf->set_page_count($count); }
93
94  function line($x1, $y1, $x2, $y2, $color, $width, $style = array()) {
95    $this->_pdf->line($x1, $y1, $x2, $y2, $color, $width, $style);
96  }
97                             
98  function rectangle($x1, $y1, $w, $h, $color, $width, $style = array()) {
99    $this->_pdf->rectangle($x1, $y1, $w, $h, $color, $width, $style);
100  }
101 
102  function filled_rectangle($x1, $y1, $w, $h, $color) {
103    $this->_pdf->filled_rectangle($x1, $y1, $w, $h, $color);
104  }
105   
106  function polygon($points, $color, $width = null, $style = array(), $fill = false) {
107    $this->_pdf->polygon($points, $color, $width, $style, $fill);
108  }
109
110  function circle($x, $y, $r1, $color, $width = null, $style = null, $fill = false) {
111    $this->_pdf->circle($x, $y, $r1, $color, $width, $style, $fill);
112  }
113
114  function image($img_url, $x, $y, $w = null, $h = null) {
115    $this->_pdf->image($img_url, $x, $y, $w, $h);
116  }
117 
118  function text($x, $y, $text, $font, $size, $color = array(0,0,0), $adjust = 0, $angle = 0) {
119    $this->_fonts[$font] = true;
120    $this->_pdf->text($x, $y, $text, $font, $size, $color, $adjust, $angle);
121  }
122
123  function page_text($x, $y, $text, $font, $size, $color = array(0,0,0), $adjust = 0, $angle = 0) {
124   
125    // We want to remove this from cached pages since it may not be correct
126    $this->_pdf->close_object();
127    $this->_pdf->page_text($x, $y, $text, $font, $size, $color, $adjust, $angle);
128    $this->_pdf->reopen_object($this->_current_page_id);
129  }
130 
131  function page_script($script, $type = 'text/php') {
132   
133    // We want to remove this from cached pages since it may not be correct
134    $this->_pdf->close_object();
135    $this->_pdf->page_script($script, $type);
136    $this->_pdf->reopen_object($this->_current_page_id);
137  }
138 
139  function new_page() {
140    $this->_pdf->close_object();
141
142    // Add the object to the current page
143    $this->_pdf->add_object($this->_current_page_id, "add");
144    $this->_pdf->new_page();   
145
146    Page_Cache::store_page($this->_cache_id,
147                           $this->_pdf->get_page_number() - 1,
148                           $this->_pdf->serialize_object($this->_current_page_id));
149
150    $this->_current_page_id = $this->_pdf->open_object();
151    return $this->_current_page_id;
152  }
153 
154  function stream($filename) {
155    // Store the last page in the page cache
156    if ( !is_null($this->_current_page_id) ) {
157      $this->_pdf->close_object();
158      $this->_pdf->add_object($this->_current_page_id, "add");
159      Page_Cache::store_page($this->_cache_id,
160                             $this->_pdf->get_page_number(),
161                             $this->_pdf->serialize_object($this->_current_page_id));
162      Page_Cache::store_fonts($this->_cache_id, $this->_fonts);
163      $this->_current_page_id = null;
164    }
165   
166    $this->_pdf->stream($filename);
167   
168  }
169 
170  function &output() {
171    // Store the last page in the page cache
172    if ( !is_null($this->_current_page_id) ) {
173      $this->_pdf->close_object();
174      $this->_pdf->add_object($this->_current_page_id, "add");
175      Page_Cache::store_page($this->_cache_id,
176                             $this->_pdf->get_page_number(),
177                             $this->_pdf->serialize_object($this->_current_page_id));
178      $this->_current_page_id = null;
179    }
180   
181    return $this->_pdf->output();
182  }
183 
184  function get_messages() { return $this->_pdf->get_messages(); }
185 
186}
187
188?>
Note: See TracBrowser for help on using the repository browser.