fpdf.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  1. <?php
  2. /*******************************************************************************
  3. * Software: FPDF *
  4. * Version: 1.53 *
  5. * Date: 2004-12-31 *
  6. * Author: Olivier PLATHEY *
  7. * License: Freeware *
  8. * *
  9. * You may use and modify this software as you wish. *
  10. *******************************************************************************/
  11. if(!class_exists('FPDF'))
  12. {
  13. define('FPDF_VERSION','1.53');
  14. class FPDF
  15. {
  16. //Private properties
  17. var $page; //current page number
  18. var $n; //current object number
  19. var $offsets; //array of object offsets
  20. var $buffer; //buffer holding in-memory PDF
  21. var $pages; //array containing pages
  22. var $state; //current document state
  23. var $compress; //compression flag
  24. var $DefOrientation; //default orientation
  25. var $CurOrientation; //current orientation
  26. var $OrientationChanges; //array indicating orientation changes
  27. var $k; //scale factor (number of points in user unit)
  28. var $fwPt,$fhPt; //dimensions of page format in points
  29. var $fw,$fh; //dimensions of page format in user unit
  30. var $wPt,$hPt; //current dimensions of page in points
  31. var $w,$h; //current dimensions of page in user unit
  32. var $lMargin; //left margin
  33. var $tMargin; //top margin
  34. var $rMargin; //right margin
  35. var $bMargin; //page break margin
  36. var $cMargin; //cell margin
  37. var $x,$y; //current position in user unit for cell positioning
  38. var $lasth; //height of last cell printed
  39. var $LineWidth; //line width in user unit
  40. var $CoreFonts; //array of standard font names
  41. var $fonts; //array of used fonts
  42. var $FontFiles; //array of font files
  43. var $diffs; //array of encoding differences
  44. var $images; //array of used images
  45. var $PageLinks; //array of links in pages
  46. var $links; //array of internal links
  47. var $FontFamily; //current font family
  48. var $FontStyle; //current font style
  49. var $underline; //underlining flag
  50. var $CurrentFont; //current font info
  51. var $FontSizePt; //current font size in points
  52. var $FontSize; //current font size in user unit
  53. var $DrawColor; //commands for drawing color
  54. var $FillColor; //commands for filling color
  55. var $TextColor; //commands for text color
  56. var $ColorFlag; //indicates whether fill and text colors are different
  57. var $ws; //word spacing
  58. var $AutoPageBreak; //automatic page breaking
  59. var $PageBreakTrigger; //threshold used to trigger page breaks
  60. var $InFooter; //flag set when processing footer
  61. var $ZoomMode; //zoom display mode
  62. var $LayoutMode; //layout display mode
  63. var $title; //title
  64. var $subject; //subject
  65. var $author; //author
  66. var $keywords; //keywords
  67. var $creator; //creator
  68. var $AliasNbPages; //alias for total number of pages
  69. var $PDFVersion; //PDF version number
  70. //From pdf_table
  71. var $tb_columns; //number of columns of the table
  72. var $tb_header_type; //array which contains the header characteristics and texts
  73. var $tb_data_type; //array which contains the data characteristics (only the characteristics)
  74. var $tb_table_type; //array which contains the table charactersitics
  75. var $table_startx, $table_starty; //the X and Y position where the table starts
  76. /*******************************************************************************
  77. * *
  78. * Public methods *
  79. * *
  80. *******************************************************************************/
  81. function FPDF($orientation='P',$unit='mm',$format='A4')
  82. {
  83. //Some checks
  84. $this->_dochecks();
  85. //Initialization of properties
  86. $this->page=0;
  87. $this->n=2;
  88. $this->buffer='';
  89. $this->pages=array();
  90. $this->OrientationChanges=array();
  91. $this->state=0;
  92. $this->fonts=array();
  93. $this->FontFiles=array();
  94. $this->diffs=array();
  95. $this->images=array();
  96. $this->links=array();
  97. $this->InFooter=false;
  98. $this->lasth=0;
  99. $this->FontFamily='';
  100. $this->FontStyle='';
  101. $this->FontSizePt=12;
  102. $this->underline=false;
  103. $this->DrawColor='0 G';
  104. $this->FillColor='0 g';
  105. $this->TextColor='0 g';
  106. $this->ColorFlag=false;
  107. $this->ws=0;
  108. //Standard fonts
  109. $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique',
  110. 'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique',
  111. 'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic',
  112. 'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats');
  113. //Scale factor
  114. if($unit=='pt')
  115. $this->k=1;
  116. elseif($unit=='mm')
  117. $this->k=72/25.4;
  118. elseif($unit=='cm')
  119. $this->k=72/2.54;
  120. elseif($unit=='in')
  121. $this->k=72;
  122. else
  123. $this->Error('Incorrect unit: '.$unit);
  124. //Page format
  125. if(is_string($format))
  126. {
  127. $format=strtolower($format);
  128. if($format=='a3')
  129. $format=array(841.89,1190.55);
  130. elseif($format=='a4')
  131. $format=array(595.28,841.89);
  132. elseif($format=='a5')
  133. $format=array(420.94,595.28);
  134. elseif($format=='letter')
  135. $format=array(612,792);
  136. elseif($format=='legal')
  137. $format=array(612,1008);
  138. else
  139. $this->Error('Unknown page format: '.$format);
  140. $this->fwPt=$format[0];
  141. $this->fhPt=$format[1];
  142. }
  143. else
  144. {
  145. $this->fwPt=$format[0]*$this->k;
  146. $this->fhPt=$format[1]*$this->k;
  147. }
  148. $this->fw=$this->fwPt/$this->k;
  149. $this->fh=$this->fhPt/$this->k;
  150. //Page orientation
  151. $orientation=strtolower($orientation);
  152. if($orientation=='p' || $orientation=='portrait')
  153. {
  154. $this->DefOrientation='P';
  155. $this->wPt=$this->fwPt;
  156. $this->hPt=$this->fhPt;
  157. }
  158. elseif($orientation=='l' || $orientation=='landscape')
  159. {
  160. $this->DefOrientation='L';
  161. $this->wPt=$this->fhPt;
  162. $this->hPt=$this->fwPt;
  163. }
  164. else
  165. $this->Error('Incorrect orientation: '.$orientation);
  166. $this->CurOrientation=$this->DefOrientation;
  167. $this->w=$this->wPt/$this->k;
  168. $this->h=$this->hPt/$this->k;
  169. //Page margins (1 cm)
  170. $margin=28.35/$this->k;
  171. $this->SetMargins($margin,$margin);
  172. //Interior cell margin (1 mm)
  173. $this->cMargin=$margin/10;
  174. //Line width (0.2 mm)
  175. $this->LineWidth=.567/$this->k;
  176. //Automatic page break
  177. $this->SetAutoPageBreak(true,2*$margin);
  178. //Full width display mode
  179. $this->SetDisplayMode('fullwidth');
  180. //Enable compression
  181. $this->SetCompression(true);
  182. //Set default PDF version number
  183. $this->PDFVersion='1.3';
  184. }
  185. function SetMargins($left,$top,$right=-1)
  186. {
  187. //Set left, top and right margins
  188. $this->lMargin=$left;
  189. $this->tMargin=$top;
  190. if($right==-1)
  191. $right=$left;
  192. $this->rMargin=$right;
  193. }
  194. function SetLeftMargin($margin)
  195. {
  196. //Set left margin
  197. $this->lMargin=$margin;
  198. if($this->page>0 && $this->x<$margin)
  199. $this->x=$margin;
  200. }
  201. function SetTopMargin($margin)
  202. {
  203. //Set top margin
  204. $this->tMargin=$margin;
  205. }
  206. function SetRightMargin($margin)
  207. {
  208. //Set right margin
  209. $this->rMargin=$margin;
  210. }
  211. function SetAutoPageBreak($auto,$margin=0)
  212. {
  213. //Set auto page break mode and triggering margin
  214. $this->AutoPageBreak=$auto;
  215. $this->bMargin=$margin;
  216. $this->PageBreakTrigger=$this->h-$margin;
  217. }
  218. function SetDisplayMode($zoom,$layout='continuous')
  219. {
  220. //Set display mode in viewer
  221. if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom))
  222. $this->ZoomMode=$zoom;
  223. else
  224. $this->Error('Incorrect zoom display mode: '.$zoom);
  225. if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default')
  226. $this->LayoutMode=$layout;
  227. else
  228. $this->Error('Incorrect layout display mode: '.$layout);
  229. }
  230. function SetCompression($compress)
  231. {
  232. //Set page compression
  233. if(function_exists('gzcompress'))
  234. $this->compress=$compress;
  235. else
  236. $this->compress=false;
  237. }
  238. function SetTitle($title)
  239. {
  240. //Title of document
  241. $this->title=$title;
  242. }
  243. function SetSubject($subject)
  244. {
  245. //Subject of document
  246. $this->subject=$subject;
  247. }
  248. function SetAuthor($author)
  249. {
  250. //Author of document
  251. $this->author=$author;
  252. }
  253. function SetKeywords($keywords)
  254. {
  255. //Keywords of document
  256. $this->keywords=$keywords;
  257. }
  258. function SetCreator($creator)
  259. {
  260. //Creator of document
  261. $this->creator=$creator;
  262. }
  263. function AliasNbPages($alias='{nb}')
  264. {
  265. //Define an alias for total number of pages
  266. $this->AliasNbPages=$alias;
  267. }
  268. function Error($msg)
  269. {
  270. //Fatal error
  271. die('<B>FPDF error: </B>'.$msg);
  272. }
  273. function Open()
  274. {
  275. //Begin document
  276. $this->state=1;
  277. }
  278. function Close()
  279. {
  280. //Terminate document
  281. if($this->state==3)
  282. return;
  283. if($this->page==0)
  284. $this->AddPage();
  285. //Page footer
  286. $this->InFooter=true;
  287. $this->Footer();
  288. $this->InFooter=false;
  289. //Close page
  290. $this->_endpage();
  291. //Close document
  292. $this->_enddoc();
  293. }
  294. function AddPage($orientation='')
  295. {
  296. //Start a new page
  297. if($this->state==0)
  298. $this->Open();
  299. $family=$this->FontFamily;
  300. $style=$this->FontStyle.($this->underline ? 'U' : '');
  301. $size=$this->FontSizePt;
  302. $lw=$this->LineWidth;
  303. $dc=$this->DrawColor;
  304. $fc=$this->FillColor;
  305. $tc=$this->TextColor;
  306. $cf=$this->ColorFlag;
  307. if($this->page>0)
  308. {
  309. //Page footer
  310. $this->InFooter=true;
  311. $this->Footer();
  312. $this->InFooter=false;
  313. //Close page
  314. $this->_endpage();
  315. }
  316. //Start new page
  317. $this->_beginpage($orientation);
  318. //Set line cap style to square
  319. $this->_out('2 J');
  320. //Set line width
  321. $this->LineWidth=$lw;
  322. $this->_out(sprintf('%.2f w',$lw*$this->k));
  323. //Set font
  324. if($family)
  325. $this->SetFont($family,$style,$size);
  326. //Set colors
  327. $this->DrawColor=$dc;
  328. if($dc!='0 G')
  329. $this->_out($dc);
  330. $this->FillColor=$fc;
  331. if($fc!='0 g')
  332. $this->_out($fc);
  333. $this->TextColor=$tc;
  334. $this->ColorFlag=$cf;
  335. //Page header
  336. $this->Header();
  337. //Restore line width
  338. if($this->LineWidth!=$lw)
  339. {
  340. $this->LineWidth=$lw;
  341. $this->_out(sprintf('%.2f w',$lw*$this->k));
  342. }
  343. //Restore font
  344. if($family)
  345. $this->SetFont($family,$style,$size);
  346. //Restore colors
  347. if($this->DrawColor!=$dc)
  348. {
  349. $this->DrawColor=$dc;
  350. $this->_out($dc);
  351. }
  352. if($this->FillColor!=$fc)
  353. {
  354. $this->FillColor=$fc;
  355. $this->_out($fc);
  356. }
  357. $this->TextColor=$tc;
  358. $this->ColorFlag=$cf;
  359. }
  360. function Header()
  361. {
  362. //To be implemented in your own inherited class
  363. }
  364. function Footer()
  365. {
  366. //To be implemented in your own inherited class
  367. }
  368. function PageNo()
  369. {
  370. //Get current page number
  371. return $this->page;
  372. }
  373. function SetDrawColor($r,$g=-1,$b=-1)
  374. {
  375. //Set color for all stroking operations
  376. if(($r==0 && $g==0 && $b==0) || $g==-1)
  377. $this->DrawColor=sprintf('%.3f G',$r/255);
  378. else
  379. $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
  380. if($this->page>0)
  381. $this->_out($this->DrawColor);
  382. }
  383. function SetFillColor($r,$g=-1,$b=-1)
  384. {
  385. //Set color for all filling operations
  386. if(($r==0 && $g==0 && $b==0) || $g==-1)
  387. $this->FillColor=sprintf('%.3f g',$r/255);
  388. else
  389. $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  390. $this->ColorFlag=($this->FillColor!=$this->TextColor);
  391. if($this->page>0)
  392. $this->_out($this->FillColor);
  393. }
  394. function SetTextColor($r,$g=-1,$b=-1)
  395. {
  396. //Set color for text
  397. if(($r==0 && $g==0 && $b==0) || $g==-1)
  398. $this->TextColor=sprintf('%.3f g',$r/255);
  399. else
  400. $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  401. $this->ColorFlag=($this->FillColor!=$this->TextColor);
  402. }
  403. function GetStringWidth($s)
  404. {
  405. //Get width of a string in the current font
  406. $s=(string)$s;
  407. $cw=&$this->CurrentFont['cw'];
  408. $w=0;
  409. $l=strlen($s);
  410. for($i=0;$i<$l;$i++)
  411. $w+=$cw[$s{$i}];
  412. return $w*$this->FontSize/1000;
  413. }
  414. function SetLineWidth($width)
  415. {
  416. //Set line width
  417. $this->LineWidth=$width;
  418. if($this->page>0)
  419. $this->_out(sprintf('%.2f w',$width*$this->k));
  420. }
  421. function Line($x1,$y1,$x2,$y2)
  422. {
  423. //Draw a line
  424. $this->_out(sprintf('%.2f %.2f m %.2f %.2f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));
  425. }
  426. function Rect($x,$y,$w,$h,$style='')
  427. {
  428. //Draw a rectangle
  429. if($style=='F')
  430. $op='f';
  431. elseif($style=='FD' || $style=='DF')
  432. $op='B';
  433. else
  434. $op='S';
  435. $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
  436. }
  437. function AddFont($family,$style='',$file='')
  438. {
  439. //Add a TrueType or Type1 font
  440. $family=strtolower($family);
  441. if($file=='')
  442. $file=str_replace(' ','',$family).strtolower($style).'.php';
  443. if($family=='arial')
  444. $family='helvetica';
  445. $style=strtoupper($style);
  446. if($style=='IB')
  447. $style='BI';
  448. $fontkey=$family.$style;
  449. if(isset($this->fonts[$fontkey]))
  450. $this->Error('Font already added: '.$family.' '.$style);
  451. include($this->_getfontpath().$file);
  452. if(!isset($name))
  453. $this->Error('Could not include font definition file');
  454. $i=count($this->fonts)+1;
  455. $this->fonts[$fontkey]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file);
  456. if($diff)
  457. {
  458. //Search existing encodings
  459. $d=0;
  460. $nb=count($this->diffs);
  461. for($i=1;$i<=$nb;$i++)
  462. {
  463. if($this->diffs[$i]==$diff)
  464. {
  465. $d=$i;
  466. break;
  467. }
  468. }
  469. if($d==0)
  470. {
  471. $d=$nb+1;
  472. $this->diffs[$d]=$diff;
  473. }
  474. $this->fonts[$fontkey]['diff']=$d;
  475. }
  476. if($file)
  477. {
  478. if($type=='TrueType')
  479. $this->FontFiles[$file]=array('length1'=>$originalsize);
  480. else
  481. $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
  482. }
  483. }
  484. function SetFont($family,$style='',$size=0)
  485. {
  486. //Select a font; size given in points
  487. global $fpdf_charwidths;
  488. $family=strtolower($family);
  489. if($family=='')
  490. $family=$this->FontFamily;
  491. if($family=='arial')
  492. $family='helvetica';
  493. elseif($family=='symbol' || $family=='zapfdingbats')
  494. $style='';
  495. $style=strtoupper($style);
  496. if(strpos($style,'U')!==false)
  497. {
  498. $this->underline=true;
  499. $style=str_replace('U','',$style);
  500. }
  501. else
  502. $this->underline=false;
  503. if($style=='IB')
  504. $style='BI';
  505. if($size==0)
  506. $size=$this->FontSizePt;
  507. //Test if font is already selected
  508. if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size)
  509. return;
  510. //Test if used for the first time
  511. $fontkey=$family.$style;
  512. if(!isset($this->fonts[$fontkey]))
  513. {
  514. //Check if one of the standard fonts
  515. if(isset($this->CoreFonts[$fontkey]))
  516. {
  517. if(!isset($fpdf_charwidths[$fontkey]))
  518. {
  519. //Load metric file
  520. $file=$family;
  521. if($family=='times' || $family=='helvetica')
  522. $file.=strtolower($style);
  523. include($this->_getfontpath().$file.'.php');
  524. if(!isset($fpdf_charwidths[$fontkey]))
  525. $this->Error('Could not include font metric file');
  526. }
  527. $i=count($this->fonts)+1;
  528. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]);
  529. }
  530. else
  531. $this->Error('Undefined font: '.$family.' '.$style);
  532. }
  533. //Select it
  534. $this->FontFamily=$family;
  535. $this->FontStyle=$style;
  536. $this->FontSizePt=$size;
  537. $this->FontSize=$size/$this->k;
  538. $this->CurrentFont=&$this->fonts[$fontkey];
  539. if($this->page>0)
  540. $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
  541. }
  542. function SetFontSize($size)
  543. {
  544. //Set font size in points
  545. if($this->FontSizePt==$size)
  546. return;
  547. $this->FontSizePt=$size;
  548. $this->FontSize=$size/$this->k;
  549. if($this->page>0)
  550. $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
  551. }
  552. function AddLink()
  553. {
  554. //Create a new internal link
  555. $n=count($this->links)+1;
  556. $this->links[$n]=array(0,0);
  557. return $n;
  558. }
  559. function SetLink($link,$y=0,$page=-1)
  560. {
  561. //Set destination of internal link
  562. if($y==-1)
  563. $y=$this->y;
  564. if($page==-1)
  565. $page=$this->page;
  566. $this->links[$link]=array($page,$y);
  567. }
  568. function Link($x,$y,$w,$h,$link)
  569. {
  570. //Put a link on the page
  571. $this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  572. }
  573. function Text($x,$y,$txt)
  574. {
  575. //Output a string
  576. $s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
  577. if($this->underline && $txt!='')
  578. $s.=' '.$this->_dounderline($x,$y,$txt);
  579. if($this->ColorFlag)
  580. $s='q '.$this->TextColor.' '.$s.' Q';
  581. $this->_out($s);
  582. }
  583. function AcceptPageBreak()
  584. {
  585. //Accept automatic page break or not
  586. return $this->AutoPageBreak;
  587. }
  588. function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='')
  589. {
  590. //Output a cell
  591. $k=$this->k;
  592. if($this->y+$h>$this->PageBreakTrigger && !$this->InFooter && $this->AcceptPageBreak())
  593. {
  594. //Automatic page break
  595. $x=$this->x;
  596. $ws=$this->ws;
  597. if($ws>0)
  598. {
  599. $this->ws=0;
  600. $this->_out('0 Tw');
  601. }
  602. $this->AddPage($this->CurOrientation);
  603. $this->x=$x;
  604. if($ws>0)
  605. {
  606. $this->ws=$ws;
  607. $this->_out(sprintf('%.3f Tw',$ws*$k));
  608. }
  609. }
  610. if($w==0)
  611. $w=$this->w-$this->rMargin-$this->x;
  612. $s='';
  613. if($fill==1 || $border==1)
  614. {
  615. if($fill==1)
  616. $op=($border==1) ? 'B' : 'f';
  617. else
  618. $op='S';
  619. $s=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
  620. }
  621. if(is_string($border))
  622. {
  623. $x=$this->x;
  624. $y=$this->y;
  625. if(strpos($border,'L')!==false)
  626. $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
  627. if(strpos($border,'T')!==false)
  628. $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
  629. if(strpos($border,'R')!==false)
  630. $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
  631. if(strpos($border,'B')!==false)
  632. $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
  633. }
  634. if($txt!=='')
  635. {
  636. if($align=='R')
  637. $dx=$w-$this->cMargin-$this->GetStringWidth($txt);
  638. elseif($align=='C')
  639. $dx=($w-$this->GetStringWidth($txt))/2;
  640. else
  641. $dx=$this->cMargin;
  642. if($this->ColorFlag)
  643. $s.='q '.$this->TextColor.' ';
  644. $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
  645. $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2);
  646. if($this->underline)
  647. $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
  648. if($this->ColorFlag)
  649. $s.=' Q';
  650. if($link)
  651. $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link);
  652. }
  653. if($s)
  654. $this->_out($s);
  655. $this->lasth=$h;
  656. if($ln>0)
  657. {
  658. //Go to next line
  659. $this->y+=$h;
  660. if($ln==1)
  661. $this->x=$this->lMargin;
  662. }
  663. else
  664. $this->x+=$w;
  665. }
  666. function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0)
  667. {
  668. //Output text with automatic or explicit line breaks
  669. $cw=&$this->CurrentFont['cw'];
  670. if($w==0)
  671. $w=$this->w-$this->rMargin-$this->x;
  672. $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  673. $s=str_replace("\r",'',$txt);
  674. $nb=strlen($s);
  675. if($nb>0 && $s[$nb-1]=="\n")
  676. $nb--;
  677. $b=0;
  678. if($border)
  679. {
  680. if($border==1)
  681. {
  682. $border='LTRB';
  683. $b='LRT';
  684. $b2='LR';
  685. }
  686. else
  687. {
  688. $b2='';
  689. if(strpos($border,'L')!==false)
  690. $b2.='L';
  691. if(strpos($border,'R')!==false)
  692. $b2.='R';
  693. $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2;
  694. }
  695. }
  696. $sep=-1;
  697. $i=0;
  698. $j=0;
  699. $l=0;
  700. $ns=0;
  701. $nl=1;
  702. while($i<$nb)
  703. {
  704. //Get next character
  705. $c=$s{$i};
  706. if($c=="\n")
  707. {
  708. //Explicit line break
  709. if($this->ws>0)
  710. {
  711. $this->ws=0;
  712. $this->_out('0 Tw');
  713. }
  714. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
  715. $i++;
  716. $sep=-1;
  717. $j=$i;
  718. $l=0;
  719. $ns=0;
  720. $nl++;
  721. if($border && $nl==2)
  722. $b=$b2;
  723. continue;
  724. }
  725. if($c==' ')
  726. {
  727. $sep=$i;
  728. $ls=$l;
  729. $ns++;
  730. }
  731. $l+=$cw[$c];
  732. if($l>$wmax)
  733. {
  734. //Automatic line break
  735. if($sep==-1)
  736. {
  737. if($i==$j)
  738. $i++;
  739. if($this->ws>0)
  740. {
  741. $this->ws=0;
  742. $this->_out('0 Tw');
  743. }
  744. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
  745. }
  746. else
  747. {
  748. if($align=='J')
  749. {
  750. $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
  751. $this->_out(sprintf('%.3f Tw',$this->ws*$this->k));
  752. }
  753. $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
  754. $i=$sep+1;
  755. }
  756. $sep=-1;
  757. $j=$i;
  758. $l=0;
  759. $ns=0;
  760. $nl++;
  761. if($border && $nl==2)
  762. $b=$b2;
  763. }
  764. else
  765. $i++;
  766. }
  767. //Last chunk
  768. if($this->ws>0)
  769. {
  770. $this->ws=0;
  771. $this->_out('0 Tw');
  772. }
  773. if($border && strpos($border,'B')!==false)
  774. $b.='B';
  775. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
  776. $this->x=$this->lMargin;
  777. }
  778. function Write($h,$txt,$link='')
  779. {
  780. //Output text in flowing mode
  781. $cw=&$this->CurrentFont['cw'];
  782. $w=$this->w-$this->rMargin-$this->x;
  783. $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  784. $s=str_replace("\r",'',$txt);
  785. $nb=strlen($s);
  786. $sep=-1;
  787. $i=0;
  788. $j=0;
  789. $l=0;
  790. $nl=1;
  791. while($i<$nb)
  792. {
  793. //Get next character
  794. $c=$s{$i};
  795. if($c=="\n")
  796. {
  797. //Explicit line break
  798. $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
  799. $i++;
  800. $sep=-1;
  801. $j=$i;
  802. $l=0;
  803. if($nl==1)
  804. {
  805. $this->x=$this->lMargin;
  806. $w=$this->w-$this->rMargin-$this->x;
  807. $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  808. }
  809. $nl++;
  810. continue;
  811. }
  812. if($c==' ')
  813. $sep=$i;
  814. $l+=$cw[$c];
  815. if($l>$wmax)
  816. {
  817. //Automatic line break
  818. if($sep==-1)
  819. {
  820. if($this->x>$this->lMargin)
  821. {
  822. //Move to next line
  823. $this->x=$this->lMargin;
  824. $this->y+=$h;
  825. $w=$this->w-$this->rMargin-$this->x;
  826. $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  827. $i++;
  828. $nl++;
  829. continue;
  830. }
  831. if($i==$j)
  832. $i++;
  833. $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
  834. }
  835. else
  836. {
  837. $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link);
  838. $i=$sep+1;
  839. }
  840. $sep=-1;
  841. $j=$i;
  842. $l=0;
  843. if($nl==1)
  844. {
  845. $this->x=$this->lMargin;
  846. $w=$this->w-$this->rMargin-$this->x;
  847. $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  848. }
  849. $nl++;
  850. }
  851. else
  852. $i++;
  853. }
  854. //Last chunk
  855. if($i!=$j)
  856. $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link);
  857. }
  858. function Image($file,$x,$y,$w=0,$h=0,$type='',$link='')
  859. {
  860. //Put an image on the page
  861. if(!isset($this->images[$file]))
  862. {
  863. //First use of image, get info
  864. if($type=='')
  865. {
  866. $pos=strrpos($file,'.');
  867. if(!$pos)
  868. $this->Error('Image file has no extension and no type was specified: '.$file);
  869. $type=substr($file,$pos+1);
  870. }
  871. $type=strtolower($type);
  872. $mqr=get_magic_quotes_runtime();
  873. set_magic_quotes_runtime(0);
  874. if($type=='jpg' || $type=='jpeg')
  875. $info=$this->_parsejpg($file);
  876. elseif($type=='png')
  877. $info=$this->_parsepng($file);
  878. else
  879. {
  880. //Allow for additional formats
  881. $mtd='_parse'.$type;
  882. if(!method_exists($this,$mtd))
  883. $this->Error('Unsupported image type: '.$type);
  884. $info=$this->$mtd($file);
  885. }
  886. set_magic_quotes_runtime($mqr);
  887. $info['i']=count($this->images)+1;
  888. $this->images[$file]=$info;
  889. }
  890. else
  891. $info=$this->images[$file];
  892. //Automatic width and height calculation if needed
  893. if($w==0 && $h==0)
  894. {
  895. //Put image at 72 dpi
  896. $w=$info['w']/$this->k;
  897. $h=$info['h']/$this->k;
  898. }
  899. if($w==0)
  900. $w=$h*$info['w']/$info['h'];
  901. if($h==0)
  902. $h=$w*$info['h']/$info['w'];
  903. $this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']));
  904. if($link)
  905. $this->Link($x,$y,$w,$h,$link);
  906. }
  907. function Ln($h='')
  908. {
  909. //Line feed; default value is last cell height
  910. $this->x=$this->lMargin;
  911. if(is_string($h))
  912. $this->y+=$this->lasth;
  913. else
  914. $this->y+=$h;
  915. }
  916. function GetX()
  917. {
  918. //Get x position
  919. return $this->x;
  920. }
  921. function SetX($x)
  922. {
  923. //Set x position
  924. if($x>=0)
  925. $this->x=$x;
  926. else
  927. $this->x=$this->w+$x;
  928. }
  929. function GetY()
  930. {
  931. //Get y position
  932. return $this->y;
  933. }
  934. function SetY($y)
  935. {
  936. //Set y position and reset x
  937. $this->x=$this->lMargin;
  938. if($y>=0)
  939. $this->y=$y;
  940. else
  941. $this->y=$this->h+$y;
  942. }
  943. function SetXY($x,$y)
  944. {
  945. //Set x and y positions
  946. $this->SetY($y);
  947. $this->SetX($x);
  948. }
  949. function Output($name='',$dest='')
  950. {
  951. //Output PDF to some destination
  952. //Finish document if necessary
  953. if($this->state<3)
  954. $this->Close();
  955. //Normalize parameters
  956. if(is_bool($dest))
  957. $dest=$dest ? 'D' : 'F';
  958. $dest=strtoupper($dest);
  959. if($dest=='')
  960. {
  961. if($name=='')
  962. {
  963. $name='doc.pdf';
  964. $dest='I';
  965. }
  966. else
  967. $dest='F';
  968. }
  969. switch($dest)
  970. {
  971. case 'I':
  972. //Send to standard output
  973. if(ob_get_contents())
  974. $this->Error('Some data has already been output, can\'t send PDF file');
  975. if(php_sapi_name()!='cli')
  976. {
  977. //We send to a browser
  978. header('Content-Type: application/pdf');
  979. if(headers_sent())
  980. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  981. header('Content-Length: '.strlen($this->buffer));
  982. header('Content-disposition: inline; filename="'.$name.'"');
  983. }
  984. echo $this->buffer;
  985. break;
  986. case 'D':
  987. //Download file
  988. if(ob_get_contents())
  989. $this->Error('Some data has already been output, can\'t send PDF file');
  990. if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  991. header('Content-Type: application/force-download');
  992. else
  993. header('Content-Type: application/octet-stream');
  994. if(headers_sent())
  995. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  996. header('Content-Length: '.strlen($this->buffer));
  997. header('Content-disposition: attachment; filename="'.$name.'"');
  998. echo $this->buffer;
  999. break;
  1000. case 'F':
  1001. //Save to local file
  1002. $f=fopen($name,'wb');
  1003. if(!$f)
  1004. $this->Error('Unable to create output file: '.$name);
  1005. fwrite($f,$this->buffer,strlen($this->buffer));
  1006. fclose($f);
  1007. break;
  1008. case 'S':
  1009. //Return as a string
  1010. return $this->buffer;
  1011. default:
  1012. $this->Error('Incorrect output destination: '.$dest);
  1013. }
  1014. return '';
  1015. }
  1016. /*******************************************************************************
  1017. * *
  1018. * Protected methods *
  1019. * *
  1020. *******************************************************************************/
  1021. function _dochecks()
  1022. {
  1023. //Check for locale-related bug
  1024. if(1.1==1)
  1025. $this->Error('Don\'t alter the locale before including class file');
  1026. //Check for decimal separator
  1027. if(sprintf('%.1f',1.0)!='1.0')
  1028. setlocale(LC_NUMERIC,'C');
  1029. }
  1030. function _getfontpath()
  1031. {
  1032. if(!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'/font'))
  1033. define('FPDF_FONTPATH',dirname(__FILE__).'/font/');
  1034. return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : '';
  1035. }
  1036. function _putpages()
  1037. {
  1038. $nb=$this->page;
  1039. if(!empty($this->AliasNbPages))
  1040. {
  1041. //Replace number of pages
  1042. for($n=1;$n<=$nb;$n++)
  1043. $this->pages[$n]=str_replace($this->AliasNbPages,$nb,$this->pages[$n]);
  1044. }
  1045. if($this->DefOrientation=='P')
  1046. {
  1047. $wPt=$this->fwPt;
  1048. $hPt=$this->fhPt;
  1049. }
  1050. else
  1051. {
  1052. $wPt=$this->fhPt;
  1053. $hPt=$this->fwPt;
  1054. }
  1055. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  1056. for($n=1;$n<=$nb;$n++)
  1057. {
  1058. //Page
  1059. $this->_newobj();
  1060. $this->_out('<</Type /Page');
  1061. $this->_out('/Parent 1 0 R');
  1062. if(isset($this->OrientationChanges[$n]))
  1063. $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt));
  1064. $this->_out('/Resources 2 0 R');
  1065. if(isset($this->PageLinks[$n]))
  1066. {
  1067. //Links
  1068. $annots='/Annots [';
  1069. foreach($this->PageLinks[$n] as $pl)
  1070. {
  1071. $rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
  1072. $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
  1073. if(is_string($pl[4]))
  1074. $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>';
  1075. else
  1076. {
  1077. $l=$this->links[$pl[4]];
  1078. $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt;
  1079. $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k);
  1080. }
  1081. }
  1082. $this->_out($annots.']');
  1083. }
  1084. $this->_out('/Contents '.($this->n+1).' 0 R>>');
  1085. $this->_out('endobj');
  1086. //Page content
  1087. $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n];
  1088. $this->_newobj();
  1089. $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  1090. $this->_putstream($p);
  1091. $this->_out('endobj');
  1092. }
  1093. //Pages root
  1094. $this->offsets[1]=strlen($this->buffer);
  1095. $this->_out('1 0 obj');
  1096. $this->_out('<</Type /Pages');
  1097. $kids='/Kids [';
  1098. for($i=0;$i<$nb;$i++)
  1099. $kids.=(3+2*$i).' 0 R ';
  1100. $this->_out($kids.']');
  1101. $this->_out('/Count '.$nb);
  1102. $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt));
  1103. $this->_out('>>');
  1104. $this->_out('endobj');
  1105. }
  1106. function _putfonts()
  1107. {
  1108. $nf=$this->n;
  1109. foreach($this->diffs as $diff)
  1110. {
  1111. //Encodings
  1112. $this->_newobj();
  1113. $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  1114. $this->_out('endobj');
  1115. }
  1116. $mqr=get_magic_quotes_runtime();
  1117. set_magic_quotes_runtime(0);
  1118. foreach($this->FontFiles as $file=>$info)
  1119. {
  1120. //Font file embedding
  1121. $this->_newobj();
  1122. $this->FontFiles[$file]['n']=$this->n;
  1123. $font='';
  1124. $f=fopen($this->_getfontpath().$file,'rb',1);
  1125. if(!$f)
  1126. $this->Error('Font file not found');
  1127. while(!feof($f))
  1128. $font.=fread($f,8192);
  1129. fclose($f);
  1130. $compressed=(substr($file,-2)=='.z');
  1131. if(!$compressed && isset($info['length2']))
  1132. {
  1133. $header=(ord($font{0})==128);
  1134. if($header)
  1135. {
  1136. //Strip first binary header
  1137. $font=substr($font,6);
  1138. }
  1139. if($header && ord($font{$info['length1']})==128)
  1140. {
  1141. //Strip second binary header
  1142. $font=substr($font,0,$info['length1']).substr($font,$info['length1']+6);
  1143. }
  1144. }
  1145. $this->_out('<</Length '.strlen($font));
  1146. if($compressed)
  1147. $this->_out('/Filter /FlateDecode');
  1148. $this->_out('/Length1 '.$info['length1']);
  1149. if(isset($info['length2']))
  1150. $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  1151. $this->_out('>>');
  1152. $this->_putstream($font);
  1153. $this->_out('endobj');
  1154. }
  1155. set_magic_quotes_runtime($mqr);
  1156. foreach($this->fonts as $k=>$font)
  1157. {
  1158. //Font objects
  1159. $this->fonts[$k]['n']=$this->n+1;
  1160. $type=$font['type'];
  1161. $name=$font['name'];
  1162. if($type=='core')
  1163. {
  1164. //Standard font
  1165. $this->_newobj();
  1166. $this->_out('<</Type /Font');
  1167. $this->_out('/BaseFont /'.$name);
  1168. $this->_out('/Subtype /Type1');
  1169. if($name!='Symbol' && $name!='ZapfDingbats')
  1170. $this->_out('/Encoding /WinAnsiEncoding');
  1171. $this->_out('>>');
  1172. $this->_out('endobj');
  1173. }
  1174. elseif($type=='Type1' || $type=='TrueType')
  1175. {
  1176. //Additional Type1 or TrueType font
  1177. $this->_newobj();
  1178. $this->_out('<</Type /Font');
  1179. $this->_out('/BaseFont /'.$name);
  1180. $this->_out('/Subtype /'.$type);
  1181. $this->_out('/FirstChar 32 /LastChar 255');
  1182. $this->_out('/Widths '.($this->n+1).' 0 R');
  1183. $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  1184. if($font['enc'])
  1185. {
  1186. if(isset($font['diff']))
  1187. $this->_out('/Encoding '.($nf+$font['diff']).' 0 R');
  1188. else
  1189. $this->_out('/Encoding /WinAnsiEncoding');
  1190. }
  1191. $this->_out('>>');
  1192. $this->_out('endobj');
  1193. //Widths
  1194. $this->_newobj();
  1195. $cw=&$font['cw'];
  1196. $s='[';
  1197. for($i=32;$i<=255;$i++)
  1198. $s.=$cw[chr($i)].' ';
  1199. $this->_out($s.']');
  1200. $this->_out('endobj');
  1201. //Descriptor
  1202. $this->_newobj();
  1203. $s='<</Type /FontDescriptor /FontName /'.$name;
  1204. foreach($font['desc'] as $k=>$v)
  1205. $s.=' /'.$k.' '.$v;
  1206. $file=$font['file'];
  1207. if($file)
  1208. $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
  1209. $this->_out($s.'>>');
  1210. $this->_out('endobj');
  1211. }
  1212. else
  1213. {
  1214. //Allow for additional types
  1215. $mtd='_put'.strtolower($type);
  1216. if(!method_exists($this,$mtd))
  1217. $this->Error('Unsupported font type: '.$type);
  1218. $this->$mtd($font);
  1219. }
  1220. }
  1221. }
  1222. function _putimages()
  1223. {
  1224. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  1225. reset($this->images);
  1226. while(list($file,$info)=each($this->images))
  1227. {
  1228. $this->_newobj();
  1229. $this->images[$file]['n']=$this->n;
  1230. $this->_out('<</Type /XObject');
  1231. $this->_out('/Subtype /Image');
  1232. $this->_out('/Width '.$info['w']);
  1233. $this->_out('/Height '.$info['h']);
  1234. if($info['cs']=='Indexed')
  1235. $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
  1236. else
  1237. {
  1238. $this->_out('/ColorSpace /'.$info['cs']);
  1239. if($info['cs']=='DeviceCMYK')
  1240. $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  1241. }
  1242. $this->_out('/BitsPerComponent '.$info['bpc']);
  1243. if(isset($info['f']))
  1244. $this->_out('/Filter /'.$info['f']);
  1245. if(isset($info['parms']))
  1246. $this->_out($info['parms']);
  1247. if(isset($info['trns']) && is_array($info['trns']))
  1248. {
  1249. $trns='';
  1250. for($i=0;$i<count($info['trns']);$i++)
  1251. $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  1252. $this->_out('/Mask ['.$trns.']');
  1253. }
  1254. $this->_out('/Length '.strlen($info['data']).'>>');
  1255. $this->_putstream($info['data']);
  1256. unset($this->images[$file]['data']);
  1257. $this->_out('endobj');
  1258. //Palette
  1259. if($info['cs']=='Indexed')
  1260. {
  1261. $this->_newobj();
  1262. $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  1263. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  1264. $this->_putstream($pal);
  1265. $this->_out('endobj');
  1266. }
  1267. }
  1268. }
  1269. function _putxobjectdict()
  1270. {
  1271. foreach($this->images as $image)
  1272. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  1273. }
  1274. function _putresourcedict()
  1275. {
  1276. $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  1277. $this->_out('/Font <<');
  1278. foreach($this->fonts as $font)
  1279. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  1280. $this->_out('>>');
  1281. $this->_out('/XObject <<');
  1282. $this->_putxobjectdict();
  1283. $this->_out('>>');
  1284. }
  1285. function _putresources()
  1286. {
  1287. $this->_putfonts();
  1288. $this->_putimages();
  1289. //Resource dictionary
  1290. $this->offsets[2]=strlen($this->buffer);
  1291. $this->_out('2 0 obj');
  1292. $this->_out('<<');
  1293. $this->_putresourcedict();
  1294. $this->_out('>>');
  1295. $this->_out('endobj');
  1296. }
  1297. function _putinfo()
  1298. {
  1299. $this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION));
  1300. if(!empty($this->title))
  1301. $this->_out('/Title '.$this->_textstring($this->title));
  1302. if(!empty($this->subject))
  1303. $this->_out('/Subject '.$this->_textstring($this->subject));
  1304. if(!empty($this->author))
  1305. $this->_out('/Author '.$this->_textstring($this->author));
  1306. if(!empty($this->keywords))
  1307. $this->_out('/Keywords '.$this->_textstring($this->keywords));
  1308. if(!empty($this->creator))
  1309. $this->_out('/Creator '.$this->_textstring($this->creator));
  1310. $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis')));
  1311. }
  1312. function _putcatalog()
  1313. {
  1314. $this->_out('/Type /Catalog');
  1315. $this->_out('/Pages 1 0 R');
  1316. if($this->ZoomMode=='fullpage')
  1317. $this->_out('/OpenAction [3 0 R /Fit]');
  1318. elseif($this->ZoomMode=='fullwidth')
  1319. $this->_out('/OpenAction [3 0 R /FitH null]');
  1320. elseif($this->ZoomMode=='real')
  1321. $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  1322. elseif(!is_string($this->ZoomMode))
  1323. $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
  1324. if($this->LayoutMode=='single')
  1325. $this->_out('/PageLayout /SinglePage');
  1326. elseif($this->LayoutMode=='continuous')
  1327. $this->_out('/PageLayout /OneColumn');
  1328. elseif($this->LayoutMode=='two')
  1329. $this->_out('/PageLayout /TwoColumnLeft');
  1330. }
  1331. function _putheader()
  1332. {
  1333. $this->_out('%PDF-'.$this->PDFVersion);
  1334. }
  1335. function _puttrailer()
  1336. {
  1337. $this->_out('/Size '.($this->n+1));
  1338. $this->_out('/Root '.$this->n.' 0 R');
  1339. $this->_out('/Info '.($this->n-1).' 0 R');
  1340. }
  1341. function _enddoc()
  1342. {
  1343. $this->_putheader();
  1344. $this->_putpages();
  1345. $this->_putresources();
  1346. //Info
  1347. $this->_newobj();
  1348. $this->_out('<<');
  1349. $this->_putinfo();
  1350. $this->_out('>>');
  1351. $this->_out('endobj');
  1352. //Catalog
  1353. $this->_newobj();
  1354. $this->_out('<<');
  1355. $this->_putcatalog();
  1356. $this->_out('>>');
  1357. $this->_out('endobj');
  1358. //Cross-ref
  1359. $o=strlen($this->buffer);
  1360. $this->_out('xref');
  1361. $this->_out('0 '.($this->n+1));
  1362. $this->_out('0000000000 65535 f ');
  1363. for($i=1;$i<=$this->n;$i++)
  1364. $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  1365. //Trailer
  1366. $this->_out('trailer');
  1367. $this->_out('<<');
  1368. $this->_puttrailer();
  1369. $this->_out('>>');
  1370. $this->_out('startxref');
  1371. $this->_out($o);
  1372. $this->_out('%%EOF');
  1373. $this->state=3;
  1374. }
  1375. function _beginpage($orientation)
  1376. {
  1377. $this->page++;
  1378. $this->pages[$this->page]='';
  1379. $this->state=2;
  1380. $this->x=$this->lMargin;
  1381. $this->y=$this->tMargin;
  1382. $this->FontFamily='';
  1383. //Page orientation
  1384. if(!$orientation)
  1385. $orientation=$this->DefOrientation;
  1386. else
  1387. {
  1388. $orientation=strtoupper($orientation{0});
  1389. if($orientation!=$this->DefOrientation)
  1390. $this->OrientationChanges[$this->page]=true;
  1391. }
  1392. if($orientation!=$this->CurOrientation)
  1393. {
  1394. //Change orientation
  1395. if($orientation=='P')
  1396. {
  1397. $this->wPt=$this->fwPt;
  1398. $this->hPt=$this->fhPt;
  1399. $this->w=$this->fw;
  1400. $this->h=$this->fh;
  1401. }
  1402. else
  1403. {
  1404. $this->wPt=$this->fhPt;
  1405. $this->hPt=$this->fwPt;
  1406. $this->w=$this->fh;
  1407. $this->h=$this->fw;
  1408. }
  1409. $this->PageBreakTrigger=$this->h-$this->bMargin;
  1410. $this->CurOrientation=$orientation;
  1411. }
  1412. }
  1413. function _endpage()
  1414. {
  1415. //End of page contents
  1416. $this->state=1;
  1417. }
  1418. function _newobj()
  1419. {
  1420. //Begin a new object
  1421. $this->n++;
  1422. $this->offsets[$this->n]=strlen($this->buffer);
  1423. $this->_out($this->n.' 0 obj');
  1424. }
  1425. function _dounderline($x,$y,$txt)
  1426. {
  1427. //Underline text
  1428. $up=$this->CurrentFont['up'];
  1429. $ut=$this->CurrentFont['ut'];
  1430. $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' ');
  1431. return sprintf('%.2f %.2f %.2f %.2f re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt);
  1432. }
  1433. function _parsejpg($file)
  1434. {
  1435. //Extract info from a JPEG file
  1436. $a=GetImageSize($file);
  1437. if(!$a)
  1438. $this->Error('Missing or incorrect image file: '.$file);
  1439. if($a[2]!=2)
  1440. $this->Error('Not a JPEG file: '.$file);
  1441. if(!isset($a['channels']) || $a['channels']==3)
  1442. $colspace='DeviceRGB';
  1443. elseif($a['channels']==4)
  1444. $colspace='DeviceCMYK';
  1445. else
  1446. $colspace='DeviceGray';
  1447. $bpc=isset($a['bits']) ? $a['bits'] : 8;
  1448. //Read whole file
  1449. $f=fopen($file,'rb');
  1450. $data='';
  1451. while(!feof($f))
  1452. $data.=fread($f,4096);
  1453. fclose($f);
  1454. return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
  1455. }
  1456. function _parsepng($file)
  1457. {
  1458. //Extract info from a PNG file
  1459. $f=fopen($file,'rb');
  1460. if(!$f)
  1461. $this->Error('Can\'t open image file: '.$file);
  1462. //Check signature
  1463. if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10))
  1464. $this->Error('Not a PNG file: '.$file);
  1465. //Read header chunk
  1466. fread($f,4);
  1467. if(fread($f,4)!='IHDR')
  1468. $this->Error('Incorrect PNG file: '.$file);
  1469. $w=$this->_freadint($f);
  1470. $h=$this->_freadint($f);
  1471. $bpc=ord(fread($f,1));
  1472. if($bpc>8)
  1473. $this->Error('16-bit depth not supported: '.$file);
  1474. $ct=ord(fread($f,1));
  1475. if($ct==0)
  1476. $colspace='DeviceGray';
  1477. elseif($ct==2)
  1478. $colspace='DeviceRGB';
  1479. elseif($ct==3)
  1480. $colspace='Indexed';
  1481. else
  1482. $this->Error('Alpha channel not supported: '.$file);
  1483. if(ord(fread($f,1))!=0)
  1484. $this->Error('Unknown compression method: '.$file);
  1485. if(ord(fread($f,1))!=0)
  1486. $this->Error('Unknown filter method: '.$file);
  1487. if(ord(fread($f,1))!=0)
  1488. $this->Error('Interlacing not supported: '.$file);
  1489. fread($f,4);
  1490. $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  1491. //Scan chunks looking for palette, transparency and image data
  1492. $pal='';
  1493. $trns='';
  1494. $data='';
  1495. do
  1496. {
  1497. $n=$this->_freadint($f);
  1498. $type=fread($f,4);
  1499. if($type=='PLTE')
  1500. {
  1501. //Read palette
  1502. $pal=fread($f,$n);
  1503. fread($f,4);
  1504. }
  1505. elseif($type=='tRNS')
  1506. {
  1507. //Read transparency info
  1508. $t=fread($f,$n);
  1509. if($ct==0)
  1510. $trns=array(ord(substr($t,1,1)));
  1511. elseif($ct==2)
  1512. $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  1513. else
  1514. {
  1515. $pos=strpos($t,chr(0));
  1516. if($pos!==false)
  1517. $trns=array($pos);
  1518. }
  1519. fread($f,4);
  1520. }
  1521. elseif($type=='IDAT')
  1522. {
  1523. //Read image data block
  1524. $data.=fread($f,$n);
  1525. fread($f,4);
  1526. }
  1527. elseif($type=='IEND')
  1528. break;
  1529. else
  1530. fread($f,$n+4);
  1531. }
  1532. while($n);
  1533. if($colspace=='Indexed' && empty($pal))
  1534. $this->Error('Missing palette in '.$file);
  1535. fclose($f);
  1536. return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data);
  1537. }
  1538. function _freadint($f)
  1539. {
  1540. //Read a 4-byte integer from file
  1541. $a=unpack('Ni',fread($f,4));
  1542. return $a['i'];
  1543. }
  1544. function _textstring($s)
  1545. {
  1546. //Format a text string
  1547. return '('.$this->_escape($s).')';
  1548. }
  1549. function _escape($s)
  1550. {
  1551. //Add \ before \, ( and )
  1552. return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s)));
  1553. }
  1554. function _putstream($s)
  1555. {
  1556. $this->_out('stream');
  1557. $this->_out($s);
  1558. $this->_out('endstream');
  1559. }
  1560. function _out($s)
  1561. {
  1562. //Add a line to the document
  1563. if($this->state==2)
  1564. $this->pages[$this->page].=$s."\n";
  1565. else
  1566. $this->buffer.=$s."\n";
  1567. }
  1568. // - Edit by Global Cube -
  1569. //returns the width of the page in user units
  1570. function PageWidth(){
  1571. return (int) $this->w-$this->rMargin-$this->lMargin;
  1572. }
  1573. //initialize all the variables that we use
  1574. function Table_Init($col_no = 0){
  1575. $this->tb_columns = $col_no;
  1576. $this->tb_header_type = Array();
  1577. $this->tb_data_type = Array();
  1578. $this->tb_type = Array();
  1579. $this->table_startx = 0;
  1580. $this->table_starty = 0;
  1581. }
  1582. //Sets the number of columns of the table
  1583. function Set_Table_Columns($nr){
  1584. $this->tb_columns = $nr;
  1585. }
  1586. /*
  1587. Characteristics constants for Header Type:
  1588. EVERY CELL FROM THE TABLE IS A MULTICELL
  1589. WIDTH - header width
  1590. TEXT - header text
  1591. T_COLOR - text color = array(r,g,b);
  1592. T_SIZE - text size
  1593. T_FONT - text font - font type = "Arial", "Times"
  1594. T_ALIGN - text align - "RLCJ"
  1595. T_TYPE - text type (Bold Italic etc)
  1596. LN_SPACE - space between lines
  1597. BG_COLOR - background color = array(r,g,b);
  1598. BRD_COLOR - border color = array(r,g,b);
  1599. BRD_SIZE - border size
  1600. BRD_TYPE - border type - up down, with border, without
  1601. all these setting conform to the settings from the MultiCell function
  1602. */
  1603. /*
  1604. Function: Set_Header_Type($type_arr) -- sets the array for the header type
  1605. type array =
  1606. array(
  1607. 0=>array(
  1608. "WIDTH" => 10,
  1609. "T_COLOR" => array(120,120,120),
  1610. "T_SIZE" => 5,
  1611. ...
  1612. "TEXT" => "Header text 1"
  1613. ),
  1614. 1=>array(
  1615. ...
  1616. ),
  1617. );
  1618. where 0,1... are the column number
  1619. */
  1620. function Set_Header_Type($type_arr){
  1621. $this->tb_header_type = $type_arr;
  1622. }
  1623. /*
  1624. Characteristics constants for Data Type:
  1625. EVERY CELL FROM THE TABLE IS A MULTICELL
  1626. T_COLOR - text color = array(r,g,b);
  1627. T_SIZE - text size
  1628. T_FONT - text font - font type = "Arial", "Times"
  1629. T_ALIGN - text align - "RLCJ"
  1630. T_TYPE - text type (Bold Italic etc)
  1631. LN_SPACE - space between lines
  1632. BG_COLOR - background color = array(r,g,b);
  1633. BRD_COLOR - border color = array(r,g,b);
  1634. BRD_SIZE - border size
  1635. BRD_TYPE - border type - up down, with border, without
  1636. all these settings conform to the settings from the MultiCell function
  1637. */
  1638. /*
  1639. Function: Set_data_Type($type_arr) -- sets the array for the header type
  1640. type array =
  1641. array(
  1642. 0=>array(
  1643. "T_COLOR" => array(120,120,120),
  1644. "T_SIZE" => 5,
  1645. ...
  1646. "BRD_TYPE" => 1
  1647. ),
  1648. 1=>array(
  1649. ...
  1650. ),
  1651. );
  1652. where 0,1... are the column number
  1653. */
  1654. function Set_Data_Type($type_arr){
  1655. $this->tb_data_type = $type_arr;
  1656. }
  1657. /*
  1658. Function Set_Table_Type
  1659. $type_arr = array(
  1660. "BRD_COLOR"=> array (120,120,120), //border color
  1661. "BRD_SIZE"=>5), //border line width
  1662. "TB_COLUMNS"=>5), //the number of columns
  1663. "TB_ALIGN"=>"L"), //the align of the table, possible values = L, R, C equivalent to Left, Right, Center
  1664. )
  1665. */
  1666. function Set_Table_Type($type_arr){
  1667. $this->tb_table_type = $type_arr;
  1668. if (isset($type_arr['TB_COLUMNS']))
  1669. $this->tb_columns = $type_arr['TB_COLUMNS'];
  1670. }
  1671. //this function draws the exterior table border
  1672. function Draw_Table_Border(){
  1673. /* "BRD_COLOR"=> array (120,120,120), //border color
  1674. "BRD_SIZE"=>5), //border line width
  1675. "TB_COLUMNS"=>5), //the number of columns
  1676. "TB_ALIGN"=>"L"), //the align of the table, possible values = L, R, C equivalent to Left, Right, Center
  1677. */
  1678. //set the colors
  1679. list($r, $g, $b) = $this->tb_table_type['BRD_COLOR'];
  1680. $this->SetDrawColor($r, $g, $b);
  1681. //set the line width
  1682. $this->SetLineWidth($this->tb_table_type['BRD_SIZE']);
  1683. //draw the border
  1684. $this->Rect(
  1685. $this->table_startx,
  1686. $this->table_starty,
  1687. $this->Get_Table_Width(),
  1688. $this->GetY()-$this->table_starty);
  1689. }
  1690. //returns the table width in user units
  1691. function Get_Table_Width()
  1692. {
  1693. //calculate the table width
  1694. $tb_width = 0;
  1695. for ($i=0; $i < $this->tb_columns; $i++){
  1696. $tb_width += $this->tb_header_type[$i]['WIDTH'];
  1697. }
  1698. return $tb_width;
  1699. }
  1700. //aligns the table to C, L or R (default is L)
  1701. function Table_Align(){
  1702. //check if the table is aligned
  1703. if (isset($this->tb_table_type['TB_ALIGN']))
  1704. $tb_align = $this->tb_table_type['TB_ALIGN'];
  1705. else
  1706. $tb_align='';
  1707. //set the table align
  1708. switch($tb_align){
  1709. case 'C':
  1710. $this->SetX($this->lMargin + ($this->PageWidth() - $this->Get_Table_Width())/2);
  1711. break;
  1712. case 'R':
  1713. $this->SetX($this->lMargin + ($this->PageWidth() - $this->Get_Table_Width()));
  1714. break;
  1715. default:
  1716. $this->SetX($this->lMargin);
  1717. break;
  1718. }
  1719. }
  1720. //Draws the Header
  1721. function Draw_Header(){
  1722. $this->Table_Align();
  1723. $this->table_startx = $this->GetX();
  1724. $this->table_starty = $this->GetY();
  1725. $nb = 0;
  1726. $ln = 0;
  1727. $xx = Array();
  1728. //calculate the maximum height of the cells
  1729. for($i=0;$i<$this->tb_columns;$i++)
  1730. {
  1731. #print_r($this->tb_header_type[$i]);
  1732. $this->SetFont( $this->tb_header_type[$i]['T_FONT'],
  1733. $this->tb_header_type[$i]['T_TYPE'],
  1734. $this->tb_header_type[$i]['T_SIZE']);
  1735. $xx[$i] = $this->NbLines($this->tb_header_type[$i]['WIDTH'],$this->tb_header_type[$i]['TEXT']);
  1736. $ln = max($ln, $this->tb_header_type[$i]['LN_SIZE']);
  1737. $nb = max($nb,$xx[$i]);
  1738. }
  1739. //this is the maximum cell height
  1740. $h = $ln * $nb;
  1741. //Draw the cells of the row
  1742. for($i=0;$i<$this->tb_columns;$i++)
  1743. {
  1744. //border size BRD_SIZE
  1745. $this->SetLineWidth($this->tb_header_type[$i]['BRD_SIZE']);
  1746. //fill color = BG_COLOR
  1747. list($r, $g, $b) = $this->tb_header_type[$i]['BG_COLOR'];
  1748. $this->SetFillColor($r, $g, $b);
  1749. //Draw Color = BRD_COLOR
  1750. list($r, $g, $b) = $this->tb_header_type[$i]['BRD_COLOR'];
  1751. $this->SetDrawColor($r, $g, $b);
  1752. //Text Color = T_COLOR
  1753. list($r, $g, $b) = $this->tb_header_type[$i]['T_COLOR'];
  1754. $this->SetTextColor($r, $g, $b);
  1755. //Set the font, font type and size
  1756. $this->SetFont( $this->tb_header_type[$i]['T_FONT'],
  1757. $this->tb_header_type[$i]['T_TYPE'],
  1758. $this->tb_header_type[$i]['T_SIZE']);
  1759. $w=$this->tb_header_type[$i]['WIDTH'];
  1760. //Save the current position
  1761. $x=$this->GetX();
  1762. $y=$this->GetY();
  1763. //Print the text
  1764. $this->MultiCell(
  1765. $w, $h / $xx[$i],
  1766. $this->tb_header_type[$i]['TEXT'],
  1767. $this->tb_header_type[$i]['BRD_TYPE'],
  1768. $this->tb_header_type[$i]['T_ALIGN'],
  1769. 1);
  1770. //Put the position to the right of the cell
  1771. $this->SetXY($x+$w,$y);
  1772. }
  1773. //Go to the next line
  1774. $this->Ln($ln*$nb);
  1775. }
  1776. //this function Draws the data's from the table
  1777. //have to call this function after the table initialization, after the table, header and data
  1778. //types are set and after the header is drawn
  1779. function Draw_Data($data){
  1780. $nb = 0;
  1781. $ln = 0;
  1782. $xx = Array();
  1783. $tt = Array();
  1784. $this->SetX($this->table_startx);
  1785. //calculate the maximum height of the cells
  1786. for($i=0;$i<$this->tb_columns;$i++)
  1787. {
  1788. if (!isset($data[$i]['T_FONT']))
  1789. $data[$i]['T_FONT'] = $this->tb_data_type[$i]['T_FONT'];
  1790. if (!isset($data[$i]['T_TYPE']))
  1791. $data[$i]['T_TYPE'] = $this->tb_data_type[$i]['T_TYPE'];
  1792. if (!isset($data[$i]['T_SIZE']))
  1793. $data[$i]['T_SIZE'] = $this->tb_data_type[$i]['T_SIZE'];
  1794. if (!isset($data[$i]['T_COLOR']))
  1795. $data[$i]['T_COLOR'] = $this->tb_data_type[$i]['T_COLOR'];
  1796. if (!isset($data[$i]['T_ALIGN']))
  1797. $data[$i]['T_ALIGN'] = $this->tb_data_type[$i]['T_ALIGN'];
  1798. if (!isset($data[$i]['LN_SIZE']))
  1799. $data[$i]['LN_SIZE'] = $this->tb_data_type[$i]['LN_SIZE'];
  1800. if (!isset($data[$i]['BRD_SIZE']))
  1801. $data[$i]['BRD_SIZE'] = $this->tb_data_type[$i]['BRD_SIZE'];
  1802. if (!isset($data[$i]['BRD_COLOR']))
  1803. $data[$i]['BRD_COLOR'] = $this->tb_data_type[$i]['BRD_COLOR'];
  1804. if (!isset($data[$i]['BRD_TYPE']))
  1805. $data[$i]['BRD_TYPE'] = $this->tb_data_type[$i]['BRD_TYPE'];
  1806. if (!isset($data[$i]['BG_COLOR']))
  1807. $data[$i]['BG_COLOR'] = $this->tb_data_type[$i]['BG_COLOR'];
  1808. $this->SetFont( $data[$i]['T_FONT'],
  1809. $data[$i]['T_TYPE'],
  1810. $data[$i]['T_SIZE']);
  1811. $xx[$i] = $this->NbLines($this->tb_header_type[$i]['WIDTH'],$data[$i]['TEXT']);
  1812. $ln = max($ln, $data[$i]['LN_SIZE']);
  1813. $nb = max($nb,$xx[$i]);
  1814. }
  1815. //this is the maximum cell height
  1816. $h = $ln * $nb;
  1817. $this->CheckPageBreak($h);
  1818. //Draw the cells of the row
  1819. for($i=0;$i<$this->tb_columns;$i++)
  1820. {
  1821. //border size = BRD_SIZE
  1822. $this->SetLineWidth($data[$i]['BRD_SIZE']);
  1823. //fill color = BG_COLOR
  1824. list($r, $g, $b) = $data[$i]['BG_COLOR'];
  1825. $this->SetFillColor($r, $g, $b);
  1826. //Draw Color = BRD_COLOR
  1827. list($r, $g, $b) = $data[$i]['BRD_COLOR'];
  1828. $this->SetDrawColor($r, $g, $b);
  1829. //Text Color = T_COLOR
  1830. list($r, $g, $b) = $data[$i]['T_COLOR'];
  1831. $this->SetTextColor($r, $g, $b);
  1832. //Set the font, font type and size
  1833. $this->SetFont( $data[$i]['T_FONT'],
  1834. $data[$i]['T_TYPE'],
  1835. $data[$i]['T_SIZE']);
  1836. $w=$this->tb_header_type[$i]['WIDTH'];
  1837. //Save the current position
  1838. $x=$this->GetX();
  1839. $y=$this->GetY();
  1840. //Print the text
  1841. $this->MultiCell(
  1842. $w, $h / $xx[$i],
  1843. $data[$i]['TEXT'],
  1844. $data[$i]['BRD_TYPE'],
  1845. $data[$i]['T_ALIGN'],
  1846. 1);
  1847. //Put the position to the right of the cell
  1848. $this->SetXY($x+$w,$y);
  1849. }
  1850. //Go to the next line
  1851. $this->Ln($ln*$nb);
  1852. }
  1853. //if the table is bigger than a page then it jumps to next page and draws the header
  1854. function CheckPageBreak($h)
  1855. {
  1856. //If the height h would cause an overflow, add a new page immediately
  1857. if($this->GetY()+$h>$this->PageBreakTrigger){
  1858. $this->Draw_Table_Border();
  1859. $this->AddPage($this->CurOrientation);
  1860. $table_startx = $this->GetX();
  1861. $table_starty = $this->GetY();
  1862. $this->Draw_Header();
  1863. }
  1864. //align the table
  1865. $this->Table_Align();
  1866. }
  1867. function NbLines($w,$txt)
  1868. {
  1869. //Computes the number of lines a MultiCell of width w will take
  1870. $cw=&$this->CurrentFont['cw'];
  1871. if($w==0)
  1872. $w=$this->w-$this->rMargin-$this->x;
  1873. $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  1874. $s=str_replace("\r",'',$txt);
  1875. $nb=strlen($s);
  1876. if($nb>0 and $s[$nb-1]=="\n")
  1877. $nb--;
  1878. $sep=-1;
  1879. $i=0;
  1880. $j=0;
  1881. $l=0;
  1882. $nl=1;
  1883. while($i<$nb)
  1884. {
  1885. $c=$s[$i];
  1886. if($c=="\n")
  1887. {
  1888. $i++;
  1889. $sep=-1;
  1890. $j=$i;
  1891. $l=0;
  1892. $nl++;
  1893. continue;
  1894. }
  1895. if($c==' ')
  1896. $sep=$i;
  1897. $l+=$cw[$c];
  1898. if($l>$wmax)
  1899. {
  1900. if($sep==-1)
  1901. {
  1902. if($i==$j)
  1903. $i++;
  1904. }
  1905. else
  1906. $i=$sep+1;
  1907. $sep=-1;
  1908. $j=$i;
  1909. $l=0;
  1910. $nl++;
  1911. }
  1912. else
  1913. $i++;
  1914. }
  1915. return $nl;
  1916. }
  1917. //End of - Edit by Global Cube -
  1918. //End of class
  1919. }
  1920. //Handle special IE contype request
  1921. if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype')
  1922. {
  1923. header('Content-Type: application/pdf');
  1924. exit;
  1925. }
  1926. }
  1927. ?>