wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.PDF.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.PDF.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/3rdparty/fpdf/fpdi.php");
20 require_once(BASE."wcmf/lib/util/class.Message.php");
21 
22 /**
23  * @class PDF
24  * @ingroup Output
25  * @brief PDF extends FPDF/FPDI.
26  *
27  * @author ingo herwig <ingo@wemove.com>
28  */
29 class PDF extends FPDI
30 {
31  var $_pageStarted = false;
32  var $_pageEnded = false;
33 
34  /**
35  * Overriden to set the template on the page
36  */
37  function Header()
38  {
39  parent::Header();
40  $this->useTemplate($this->tpl);
41  }
42  /**
43  * Call this method when rendering a new page
44  */
45  function startPage()
46  {
47  $this->_pageStarted = true;
48  $this->_pageEnded = false;
49  }
50  /**
51  * Call this method when rendering a page finished
52  */
53  function endPage()
54  {
55  $this->_pageEnded = true;
56  $this->_pageStarted = false;
57  }
58  /**
59  * Determine if a new page started
60  * @return True/False
61  */
62  function isPageStarted()
63  {
64  return $this->_pageStarted;
65  }
66  /**
67  * Determine if a page finished
68  * @return True/False
69  */
70  function isPageEnded()
71  {
72  return $this->_pageEnded;
73  }
74  /**
75  * Move the render position down by given units
76  * @param units The number of units to move
77  */
78  function moveDown($units)
79  {
80  $this->SetY($units+$this->GetY());
81  }
82  /**
83  * Move the render position right by given units
84  * @param units The number of units to move
85  */
86  function moveRight($units)
87  {
88  $this->SetX($units+$this->GetX());
89  }
90  /**
91  * Computes the number of lines a MultiCell of width w will take
92  * instead of NbLines it correctly handles linebreaks
93  * @param width The width
94  * @param text The text
95  */
96  function numberOfLines($width, $text)
97  {
98  $nbLines = 0;
99  $lines = split("\n", $text);
100  foreach ($lines as $line)
101  $nbLines += $this->NbLines($width, $line);
102  return $nbLines;
103  }
104 
105  /**
106  * The following code is taken from FPDF Add-On 'Table with MultiCells'
107  * @see http://www.fpdf.de/downloads/addons/3/
108  */
109 
110  /**
111  * If the height h would cause an overflow, add a new page immediately
112  * @param h The height
113  * @return True/False wether a new page was inserted or not
114  */
115  function CheckPageBreak($h)
116  {
117  if($this->GetY()+$h>$this->PageBreakTrigger)
118  {
119  $this->AddPage($this->CurOrientation);
120  return true;
121  }
122  return false;
123  }
124  /**
125  * Computes the number of lines a MultiCell of width w will take
126  * @param w The width
127  * @param txt The text
128  */
129  function NbLines($w, $txt)
130  {
131  $cw=&$this->CurrentFont['cw'];
132  if($w==0)
133  $w=$this->w-$this->rMargin-$this->x;
134  $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
135  $s=str_replace("\r",'',$txt);
136  $nb=strlen($s);
137  if($nb>0 and $s[$nb-1]=="\n")
138  $nb--;
139  $sep=-1;
140  $i=0;
141  $j=0;
142  $l=0;
143  $nl=1;
144  while($i<$nb)
145  {
146  $c=$s[$i];
147  if($c=="\n")
148  {
149  $i++;
150  $sep=-1;
151  $j=$i;
152  $l=0;
153  $nl++;
154  continue;
155  }
156  if($c==' ')
157  $sep=$i;
158  $l+=$cw[$c];
159  if($l>$wmax)
160  {
161  if($sep==-1)
162  {
163  if($i==$j)
164  $i++;
165  }
166  else
167  $i=$sep+1;
168  $sep=-1;
169  $j=$i;
170  $l=0;
171  $nl++;
172  }
173  else
174  $i++;
175  }
176  return $nl;
177  }
178 }
179 ?>
NbLines($w, $txt)
Definition: class.PDF.php:129
startPage()
Definition: class.PDF.php:45
CheckPageBreak($h)
Definition: class.PDF.php:115
isPageEnded()
Definition: class.PDF.php:70
moveDown($units)
Definition: class.PDF.php:78
isPageStarted()
Definition: class.PDF.php:62
endPage()
Definition: class.PDF.php:53
PDF extends FPDF/FPDI.
Definition: class.PDF.php:29
moveRight($units)
Definition: class.PDF.php:86
numberOfLines($width, $text)
Definition: class.PDF.php:96
Header()
Definition: class.PDF.php:37
$_pageEnded
Definition: class.PDF.php:32
$_pageStarted
Definition: class.PDF.php:31