2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
13 This class is an extension to the tcpdf class using a syntax that the original reports were written in
14 (the R &OS pdf.php class) - due to easily portation this wrapper class
15 was written to allow the same code base to use the more functional tcpdf.class by Nicola Asuni
17 * Wrapper for use R&OSpdf API with tcpdf.org class
18 * Joe Hunt <joe.hunt.consulting@gmail.com> and Janusz Dobrowolski <janusz@iron.from.pl>
21 define("K_RE_PATTERN_RTL", "/(
23 | \xD7[\x80\x83\x86\x90-\xAA\xB0-\xB4] # R
24 | \xDF[\x80-\xAA\xB4\xB5\xBA] # R
26 | \xEF\xAC[\x9D\x9F\xA0-\xA8\xAA-\xB6\xB8-\xBC\xBE] # R
27 | \xEF\xAD[\x80\x81\x83\x84\x86-\x8F] # R
28 | \xF0\x90\xA0[\x80-\x85\x88\x8A-\xB5\xB7\xB8\xBC\xBF] # R
29 | \xF0\x90\xA4[\x80-\x99] # R
30 | \xF0\x90\xA8[\x80\x90-\x93\x95-\x97\x99-\xB3] # R
31 | \xF0\x90\xA9[\x80-\x87\x90-\x98] # R
32 | \xE2\x80[\xAB\xAE] # RLE & RLO
36 * Pattern to test Arabic strings using regular expressions.
37 * source: http://www.w3.org/International/questions/qa-forms-utf-8
39 define("K_RE_PATTERN_ARABIC", "/(
40 \xD8[\x80-\x83\x8B\x8D\x9B\x9E\x9F\xA1-\xBA] # AL
41 | \xD9[\x80-\x8A\xAD-\xAF\xB1-\xBF] # AL
42 | \xDA[\x80-\xBF] # AL
43 | \xDB[\x80-\x95\x9D\xA5\xA6\xAE\xAF\xBA-\xBF] # AL
44 | \xDC[\x80-\x8D\x90\x92-\xAF] # AL
45 | \xDD[\x8D-\xAD] # AL
46 | \xDE[\x80-\xA5\xB1] # AL
47 | \xEF\xAD[\x90-\xBF] # AL
48 | \xEF\xAE[\x80-\xB1] # AL
49 | \xEF\xAF[\x93-\xBF] # AL
50 | \xEF[\xB0-\xB3][\x80-\xBF] # AL
51 | \xEF\xB4[\x80-\xBD] # AL
52 | \xEF\xB5[\x90-\xBF] # AL
53 | \xEF\xB6[\x80-\x8F\x92-\xBF] # AL
54 | \xEF\xB7[\x80-\x87\xB0-\xBC] # AL
55 | \xEF\xB9[\xB0-\xB4\xB6-\xBF] # AL
56 | \xEF\xBA[\x80-\xBF] # AL
57 | \xEF\xBB[\x80-\xBC] # AL
58 | \xD9[\xA0-\xA9\xAB\xAC] # AN
61 include_once (dirname(__FILE__).'/tcpdf.php');
63 class Cpdf extends TCPDF {
65 function Cpdf($pageSize='A4', $l=array())
67 if (!isset($l['a_meta_charset']))
68 $l = array('a_meta_charset' => 'ISO-8859-1', 'a_meta_dir' => 'ltr', 'a_meta_language' => 'en_GB', 'w_page' => 'page');
69 $enc = $l['a_meta_charset'];
70 $uni = ($enc == 'UTF-8' || $enc == 'GB2312' ? true : false);
72 ini_set("memory_limit", "48M");
73 $this->TCPDF('P', 'pt', $pageSize, $uni, $enc);
74 $this->setLanguageArray($l);
75 $this->setPrintHeader(false);
76 $this->setPrintFooter(false);
77 $this->setPDFVersion("1.3");
78 $this->setAutoPageBreak(0);
81 $this->SetLineWidth(1);
85 function selectFont($fontname, $style='')
88 $fontname = basename($fontname);
89 if ($style == 'italic')
91 elseif ($style == 'bold')
99 switch ($this->l['a_meta_language'])
101 case "ar_EG" : $fontname = "ae_tholoth"; break;
102 case "zh_CN" : $fontname = "gbsn00lp"; break;
103 case "zh_TW" : $fontname = "chinese_traditional_cid0"; break;
104 default : $fontname = "dejavu"; break;
107 elseif ($this->encoding === "ISO-8859-2")
109 switch ($this->l['a_meta_language'])
111 default : $fontname = "freesans"; break;
114 elseif ($this->encoding === "ISO-8859-5")
116 switch ($this->l['a_meta_language'])
118 default : $fontname = "freesans5"; break;
121 // else use built-in adobe fonts helvetica.
123 $this->SetFont($fontname, $type);
139 function line($x1,$y1,$x2,$y2)
141 TCPDF::line($x1, $this->h-$y1, $x2, $this->h-$y2);
144 function rectangle($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array())
146 TCPDF::Rect($x, $this->h-$y, $w, $h, $style, $border_style, $fill_color);
150 function addText($xb,$yb,$size,$txt)//,$angle=0,$wordSpaceAdjust=0)
152 if ($this->isunicode && $this->encoding != "UTF-8")
153 $txt = iconv($this->encoding, "UTF-8", $txt);
154 $this->SetFontSize($size);
155 $this->Text($xb, $this->h-$yb, $txt);
158 function addInfo($label,$value)
162 $this->SetTitle($value);
164 if ($label=='Subject')
166 $this->SetSubject($value);
168 if($label=='Creator')
170 // The Creator info in source is not exactly it should be ;)
171 $value = str_replace( "ros.co.nz", "tcpdf.org", $value );
172 $value = str_replace( "R&OS", "", $value );
173 $this->SetCreator( $value );
177 $this->SetAuthor($value);
181 function addJpegFromFile($img,$x,$y,$w=0,$h=0)
183 $this->Image($img, $x, $this->h-$y-$h, $w, $h);
186 function addPngFromFile($img,$x,$y,$w=0,$h=0)
188 $this->Image($img, $x, $this->h-$y-$h, $w, $h);
191 * Next Two functions are adopted from R&OS pdf class
195 * draw a part of an ellipse
197 function partEllipse($x0,$y0,$astart,$afinish,$r1,$r2=0,$angle=0,$nSeg=8)
199 $this->ellipse($x0,$y0,$r1,$r2,$angle,$nSeg,$astart,$afinish,0);
204 * note that the part and filled ellipse are just special cases of this function
206 * draws an ellipse in the current line style
207 * centered at $x0,$y0, radii $r1,$r2
208 * if $r2 is not set, then a circle is drawn
209 * nSeg is not allowed to be less than 2, as this will simply draw a line (and will even draw a
210 * pretty crappy shape at 2, as we are approximating with bezier curves.
212 function ellipse($x0,$y0,$r1,$r2=0,$angle=0,$nSeg=8,$astart=0,$afinish=360,$close=1,$fill=0)
214 TCPDF::Ellipse($x0, $y0, $r1, $r2, $angle, $astart. $afinish, ($close?'C':''), "", "", $nSeg);
219 TCPDF::Output('', 'I');
222 function calcTextWrap($txt, $width, $spacebreak=false)
226 $w = $this->GetStringWidth($txt);
227 if ($w > $width && $w > 0 && $width != 0)
230 $k = intval($n * $width / $w);
231 if ($k > 0 && $k < $n)
233 $txt2 = substr($txt, 0, $k);
234 if ($spacebreak && (($pos = strrpos($txt2, " ")) !== false))
236 $txt2 = substr($txt2, 0, $pos);
237 $ret = substr($txt, $pos+1);
240 $ret = substr($txt, $k);
243 return array($txt2, $ret);
246 function addTextWrap($xb, $yb, $w, $h, $txt, $align='left', $border=0, $fill=0, $spacebreak=false)
251 if ($align == 'right')
253 elseif ($align == 'left')
258 $txt = $this->calcTextWrap($txt, $w, $spacebreak);
261 $this->SetXY($xb, $this->h - $yb - $h);
262 $txt = TCPDF::unhtmlentities($txt);
263 if ($this->isunicode && $this->encoding != "UTF-8")
264 $txt = iconv($this->encoding, "UTF-8", $txt);
265 $this->Cell($w, $h, $txt, $border, 0, $align, $fill);
269 * sets the colour for stroke operations
271 function setStrokeColor($r,$g,$b,$force=0)
273 TCPDF::SetDrawColor($r,$g,$b);
276 * this sets the line drawing style.
277 * width, is the thickness of the line in user units
278 * cap is the type of cap to put on the line, values can be 'butt','round','square'
279 * where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
281 * join can be 'miter', 'round', 'bevel'
282 * dash is an array which sets the dash pattern, is a series of length values, which are the lengths of the
284 * (2) represents 2 on, 2 off, 2 on , 2 off ...
285 * (2,1) is 2 on, 1 off, 2 on, 1 off.. etc
286 * phase is a modifier on the dash pattern which is used to shift the point at which the pattern starts.
288 function setLineStyle($width=1,$cap='',$join='',$dash='',$phase=0)
290 $this->SetLineWidth($width);
293 function Text($x, $y, $txt, $stroke=0, $clip=false)
295 TCPDF::Text($x,$y, TCPDF::unhtmlentities($txt), $stroke, $clip);