Skripty : Thajská podpora

Popis

Toto rozšíření opraví umístění některých thajských diakritická znamének.

Zdrojový kód


<?php
/*******************************************************************************
* Software: FPDF Thai Positioning Improve * * Version: 1.0 * * Date: 2005-04-30 * * Advisor: Mr. Wittawas Puntumchinda * * Coding: Mr. Sirichai Fuangfoo * * License: Freeware * * * * You may use, modify and redistribute this software as you wish. * *******************************************************************************/
require('fpdf.php'); class FPDF_Thai extends FPDF{ var $txt_error; var $s_error; var $string_th; var $s_th; var $pointX; var $pointY; var $curPointX; var $checkFill; var $array_th; /****************************************************************************************
* »ÃÐàÀ·: Function ¢Í§ Class FPDF_TH * ÍéÒ§ÍÔ§: Function MultiCell ¢Í§ Class FPDF * ¡Ò÷ӧҹ: ãªé㹡ÒþÔÁ¾ì¢éͤÇÒÁËÅÒºÃ÷Ѵ¢Í§àÍ¡ÊÒà PDF * ÃٺẺ: MultiCell ( $w = ¤ÇÒÁ¡ÇéÒ§¢Í§Cell, * $h = ¤ÇÒÁÊÙ§¢Í§Cell, * $txt = ¢éͤÇÒÁ·Õè¨Ð¾ÔÁ¾ì, * $border = ¡Ó˹´¡ÒÃáÊ´§àÊ鹡Ãͺ(0 = äÁèáÊ´§, 1= áÊ´§) , * $align = µÓá˹觢éͤÇÒÁ(L = «éÒÂ, R = ¢ÇÒ, C = ¡Ö觡ÅÒ§, J = ¡ÃШÒÂ), * $fill = ¡Ó˹´¡ÒÃáÊ´§ÊբͧCell(0 = äÁèáÊ´§, 1 = áÊ´§) * )
*****************************************************************************************/
function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) { //Output text with automatic or explicit line breaks
$cw=&$this->CurrentFont['cw']; if($w==0) $w=$this->w-$this->rMargin-$this->x; $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; $s=str_replace("\r",'',$txt); $nb=strlen($s); if($nb>0 && $s[$nb-1]=="\n") $nb--; $b=0; if($border) { if($border==1) { $border='LTRB'; $b='LRT'; $b2='LR'; } else { $b2=''; if(strpos($border,'L')!==false) $b2.='L'; if(strpos($border,'R')!==false) $b2.='R'; $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2; } } $sep=-1; $i=0; $j=0; $l=0; $ns=0; $nl=1; while($i<$nb) { //Get next character $c=$s{$i}; if($c=="\n") { //Explicit line break if($this->ws>0) { $this->ws=0; $this->_out('0 Tw'); } $this->MCell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); $i++; $sep=-1; $j=$i; $l=0; $ns=0; $nl++; if($border && $nl==2) $b=$b2; continue; } if($c==' ') { $sep=$i; $ls=$l; $ns++; } $l+=$cw[$c]; if($l>$wmax) { //Automatic line break if($sep==-1) { if($i==$j) $i++; if($this->ws>0) {
$this->ws=0; $this->_out('0 Tw'); }
$this->MCell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); } else { if($align=='J') {
$this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; $this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); }
$this->MCell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); $i=$sep+1; } $sep=-1; $j=$i; $l=0; $ns=0; $nl++; if($border && $nl==2) $b=$b2; } else $i++; } //Last chunk if($this->ws>0) { $this->ws=0; $this->_out('0 Tw'); } if($border && strpos($border,'B')!==false) $b.='B'; $this->MCell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); $this->x=$this->lMargin; } /****************************************************************************************
* »ÃÐàÀ· : Function ¢Í§ Class FPDF_TH
* ÍéÒ§ÍÔ§ : Function Cell ¢Í§ Class FPDF
* ¡Ò÷ӧҹ : ãªé㹡ÒþÔÁ¾ì¢éͤÇÒÁ·ÕÅкÃ÷Ѵ¢Í§àÍ¡ÊÒà PDF
* ÃٺẺ : Cell ( $w = ¤ÇÒÁ¡ÇéÒ§¢Í§Cell, * $h = ¤ÇÒÁÊÙ§¢Í§Cell, * $txt = ¢éͤÇÒÁ·Õè¨Ð¾ÔÁ¾ì, * $border = ¡Ó˹´¡ÒÃáÊ´§àÊ鹡Ãͺ(0 = äÁèáÊ´§, 1= áÊ´§), * $ln = µÓá˹觷ÕèÍÂÙè¶Ñ´ä»¨Ò¡à«ÅÅì(0 = ¢ÇÒ, 1 = ºÃ÷Ѵ¶Ñ´ä», 2 = ´éÒ¹ÅèÒ§), * $align = µÓá˹觢éͤÇÒÁ(L = «éÒÂ, R = ¢ÇÒ, C = ¡Ö觡ÅÒ§, T = º¹, B = ÅèÒ§), * $fill = ¡Ó˹´¡ÒÃáÊ´§ÊբͧCell(0 = äÁèáÊ´§, 1 = áÊ´§), * $link = URL ·Õèµéͧ¡ÒÃãËé¢éͤÇÒÁàª×èÍÁâ§件֧ * )
*****************************************************************************************/
function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') { $this->checkFill=""; $k=$this->k; if($this->y+$h>$this->PageBreakTrigger && !$this->InFooter && $this->AcceptPageBreak()) { //¢Öé¹Ë¹éÒãËÁèÍѵâ¹Áѵ $x=$this->x; $ws=$this->ws; if($ws>0) { $this->ws=0; $this->_out('0 Tw'); } $this->AddPage($this->CurOrientation); $this->x=$x; if($ws>0) { $this->ws=$ws; $this->_out(sprintf('%.3f Tw',$ws*$k)); } } //¡Ó˹´¤ÇÒÁ¡ÇéÒ§à«ÅÅìà·èҡѺ˹éÒ¡ÃдÒÉ if($w==0) $w=$this->w-$this->rMargin-$this->x; $this->s_th=''; //¡Ó˹´¡ÒÃáÊ´§àÊ鹡Ãͺ 4 ´éÒ¹ áÅÐÊÕ¡Ãͺ if($fill==1 || $border==1) { if($fill==1) $op=($border==1) ? 'B' : 'f'; else $op='S'; $this->s_th=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); if($op=='f') $this->checkFill=$op; } //¡Ó˹´¡ÒÃáÊ´§àÊ鹡Ãͺ·ÕÅÐàÊé¹ if(is_string($border)) { $x=$this->x; $y=$this->y; if(strpos($border,'L')!==false) $this->s_th.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); if(strpos($border,'T')!==false) $this->s_th.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); if(strpos($border,'R')!==false) $this->s_th.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); if(strpos($border,'B')!==false) $this->s_th.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); } if($txt!=='') { $x=$this->x; $y=$this->y; //¡Ó˹´¡ÒèѴ¢éͤÇÒÁã¹à«ÅÅìµÒÁá¹ÇÃдѺ if(strpos($align,'R')!==false) $dx=$w-$this->cMargin-$this->GetStringWidth($txt); elseif(strpos($align,'C')!==false) $dx=($w-$this->GetStringWidth($txt))/2; else $dx=$this->cMargin; //¡Ó˹´¡ÒèѴ¢éͤÇÒÁã¹à«ÅÅìµÒÁá¹Ç´Ôè§ if(strpos($align,'T')!==false) $dy=$h-(.7*$this->k*$this->FontSize); elseif(strpos($align,'B')!==false) $dy=$h-(.3*$this->k*$this->FontSize); else $dy=.5*$h; //¡Ó˹´¡ÒâմàÊé¹ãµé¢éͤÇÒÁ if($this->underline) { //¡Ó˹´ºÑ¹·Ö¡¡ÃÒ¿Ô¡ if($this->ColorFlag) $this->s_th.=' q '.$this->TextColor.' '; //¢Õ´àÊé¹ãµé¢éͤÇÒÁ0 $this->s_th.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); //¡Ó˹´¤×¹¤èÒ¡ÃÒ¿Ô¡ if($this->ColorFlag) $this->s_th.=' Q '; } //¡Ó˹´¢éͤÇÒÁàª×èÍÁâ§件֧ if($link) $this->Link($this->x,$this->y,$this->GetStringWidth($txt),$this->FontSize,$link); /*if($s) $this->_out($s);
$s='';*/ //µÑ´ÍÑ¡ÉÃÍÍ¡¨Ò¡¢éͤÇÒÁ ·ÕÅеÑÇà¡çºÅ§ÍÐàÃÂì
$this->array_th=substr($txt,0); $i=0; $this->pointY=($this->h-($y+$dy+.3*$this->FontSize))*$k; $this->curPointX=($x+$dx)*$k; $this->string_th=''; $this->txt_error=0; while($i<=strlen($txt)) { //¡Ó˹´µÓá˹觷Õè¨Ð¾ÔÁ¾ìÍÑ¡ÉÃã¹à«ÅÅì $this->pointX=($x+$dx+.02*$this->GetStringWidth($this->array_th[$i-1]))*$k; if(($this->array_th[$i]=='è')||($this->array_th[$i]=='é')||($this->array_th[$i]=='ê')||($this->array_th[$i]=='ë')||($this->array_th[$i]=='ì')||($this->array_th[$i]=='Ô')||($this->array_th[$i]=='Õ')||($this->array_th[$i]=='Ö')||($this->array_th[$i]=='×')||($this->array_th[$i]=='ç')||($this->array_th[$i]=='Ñ')||($this->array_th[$i]=='Ó')||($this->array_th[$i]=='Ø')||($this->array_th[$i]=='Ù')) { //µÃǨÊͺÍÑ¡Éà »ÃѺµÓá˹è§áÅзӡÒþÔÁ¾ì $this->_checkT($i); if($this->txt_error==0) $this->string_th.=$this->array_th[$i]; else
{
$this->txt_error=0; }
} else
$this->string_th.=$this->array_th[$i]; //àÅ×è͹µÓáË¹è§ x ä»·ÕèµÑÇ·Õè¨Ð¾ÔÁ¾ì¶Ñ´ä» $x=$x+$this->GetStringWidth($this->array_th[$i]); $i++; } $this->TText($this->curPointX,$this->pointY,$this->string_th); /*$this->s_th.=$this->s_hidden.$this->s_error;*/ //$this->s_th.=$this->s_error; if($this->s_th) $this->_out($this->s_th); } else //¹Ó¤èÒä»áÊ´§àÁ×èÍäÁèÁÕ¢éͤÇÒÁ $this->_out($this->s_th); $this->lasth=$h; //µÃǨÊͺ¡ÒÃÇÒ§µÓá˹觢ͧà«ÅÅì¶Ñ´ä» if($ln>0) { //¢Ö鹺Ã÷ѴãËÁè $this->y+=$h; if($ln==1) $this->x=$this->lMargin; } else $this->x+=$w; } /********************************************************************************
* ãªé§Ò¹: Function Cell ¢Í§ Class FPDF_TH
* ¡Ò÷ӧҹ: ãªé㹡ÒõÃǨÊͺÍÑ¡Éà áÅлÃѺµÓá˹觡è͹·Õè¨Ð·Ó¡ÒþÔÁ¾ì
* ¤ÇÒÁµéͧ¡ÒÃ: $this->array_th = ÍÐàÃÂì¢Í§ÍÑ¡É÷ÕèµÑ´ÍÍ¡¨Ò¡¢éͤÇÒÁ * $i = ÅӴѺ»Ñ¨¨ØºÑ¹ã¹ÍÐàÃÂì·Õè¨Ð·Ó¡ÒõÃǨÊͺ * $s = ÊÒÂÍÑ¡¢ÃТͧ⤴ PDF *********************************************************************************/
function _checkT($i) { $pointY=$this->pointY; $pointX=$this->pointX; //µÇ¨Êͺ¡ÒÃáÊ´§¼Å¢Í§µÑÇÍÑ¡ÉÃà˹×ÍÊÃк¹ if($this->_errorTh($this->array_th[$i])==1) { //µÃǨÊͺµÑÇÍÑ¡Éáè͹˹éÒ¹Ñé¹äÁèãªèÊÃк¹ »ÃѺµÓá˹è§Å§
if(($this->_errorTh($this->array_th[$i-1])!=2)&&($this->array_th[$i+1]!="Ó")) { //¶éÒµÑǹÑé¹à»ç¹äÁéàÍ¡ËÃ×ÍäÁé¨ÑµÇÒ if($this->array_th[$i]=="è"||$this->array_th[$i]=="ë") { $pointY=$this->pointY-.2*$this->FontSize*$this->k; $this->txt_error=1; } //¶éÒµÑǹÑé¹à»ç¹äÁéâ·ËÃ×ÍäÁéµÃÕ elseif($this->array_th[$i]=='é'||$this->array_th[$i]=='ê') { $pointY=$this->pointY-.23*$this->FontSize*$this->k; $this->txt_error=1; } //¶éÒµÑǹÑé¹à»ç¹¡ÒÃѹµì else { $pointY=$this->pointY-.17*$this->FontSize*$this->k; $this->txt_error=1; } } //µÃǨÊͺµÑÇÍÑ¡ÉõÑÇ¡è͹˹éÒ¹Ñé¹à»ç¹µÑÇÍÑ¡ÉÃËÒ§ÂÒǺ¹ if($this->_errorTh($this->array_th[$i-1])==3) { //¶éÒµÑǹÑé¹à»ç¹äÁéàÍ¡ËÃ×ÍäÁé¨ÑµÇÒ if($this->array_th[$i]=="è"||$this->array_th[$i]=="ë") { $pointX=$this->pointX-.17*$this->GetStringWidth($this->array_th[$i-1])*$this->k; $this->txt_error=1; } //¶éÒµÑǹÑé¹à»ç¹äÁ�â·ËÃ×ÍäÁéµÃÕ elseif($this->array_th[$i]=='é'||$this->array_th[$i]=='ê') { $pointX=$this->pointX-.25*$this->GetStringWidth($this->array_th[$i-1])*$this->k; $this->txt_error=1; } //¶éÒµÑǹÑé¹à»ç¹¡ÒÃѹµì else { $pointX=$this->pointX-.4*$this->GetStringWidth($this->array_th[$i-1])*$this->k; $this->txt_error=1; } } //µÃǨÊͺµÑÇÍÑ¡ÉõÑÇ¡è͹˹éÒ¹Ñé¹ä»ÍÕ¡à»ç¹µÑÇÍÑ¡ÉÃËÒ§ÂÒǺ¹
if($this->_errorTh($this->array_th[$i-2])==3) {
//¶éÒµÑǹÑé¹à»ç¹äÁéàÍ¡ËÃ×ÍäÁé¨ÑµÇÒ if($this->array_th[$i]=="è"||$this->array_th[$i]=="ë") { $pointX=$this->pointX-.17*$this->GetStringWidth($this->array_th[$i-2])*$this->k; $this->txt_error=1; } //¶éÒµÑǹÑé¹à»ç¹äÁéâ·ËÃ×ÍäÁéµÃÕ elseif($this->array_th[$i]=='é'||$this->array_th[$i]=='ê') {
$pointX=$this->pointX-.25*$this->GetStringWidth($this->array_th[$i-2])*$this->k; $this->txt_error=1; } //¶éÒµÑǹÑé¹à»ç¹¡ÒÃѹµì else { $pointX=$this->pointX-.4*$this->GetStringWidth($this->array_th[$i-2])*$this->k;
$this->txt_error=1; } } } //¨º¡ÒõÃǨÊͺµÑÇÍÑ¡ÉÃà˹×ÍÊÃк¹ //µÇ¨Êͺ¡ÒÃáÊ´§¼Å¢Í§µÑÇÍÑ¡ÉÃÊÃк¹ elseif($this->_errorTh($this->array_th[$i])==2) { //µÃǨÊͺµÑÇÍÑ¡ÉõÑÇ¡è͹˹éÒ¹Ñé¹à»ç¹µÑÇÍÑ¡ÉÃËÒ§ÂÒǺ¹ if($this->_errorTh($this->array_th[$i-1])==3) { $pointX=$this->pointX-.17*$this->GetStringWidth($this->array_th[$i-1])*$this->k; $this->txt_error=1; } //¶éÒµÑǹÑé¹à»ç¹ÊÃÐÍÓ if($this->array_th[$i]=="Ó") //µÃǨÊͺµÑÇÍÑ¡ÉõÑÇ¡è͹˹éÒ¹Ñé¹à»ç¹µÑÇÍÑ¡ÉÃËÒ§ÂÒǺ¹ if($this->_errorTh($this->array_th[$i-2])==3) { $pointX=$this->pointX-.17*$this->GetStringWidth($this->array_th[$i-2])*$this->k; $this->txt_error=1; } }
//¨º¡ÒõÃǨÊͺµÑÇÍÑ¡ÉÃÊÃк¹ //µÇ¨Êͺ¡ÒÃáÊ´§¼Å¢Í§µÑÇÍÑ¡ÉÃÊÃÐÅèÒ§ elseif($this->_errorTh($this->array_th[$i])==6) { //µÃǨÊͺµÑÇÍÑ¡ÉõÑÇ¡è͹˹éÒ¹Ñé¹à»ç¹µÑÇÍÑ¡Éà ­. ¡Ñº °. if($this->_errorTh($this->array_th[$i-1])==5)
{
//$this->string_th $this->curPointX
$this->TText($this->curPointX,$this->pointY,$this->string_th); $this->string_th=''; $this->curPointX=$this->pointX; if($this->checkFill=='f') $this->s_th.=' q '; else $this->s_th.=' q 1 g '; //ÊÃéÒ§ÊÕèàËÅÕèÂÁä»»Ô´·Õè°Ò¹ÅèÒ§¢Í§µÑÇÍÑ¡Éà ­. ¡Ñº °. $s. $this->s_th.=sprintf('%.2f %.2f %.2f %.2f re f ',$this->pointX-$this->GetStringWidth($this->array_th[$i-1])*$this->k,$this->pointY-.27*$this->FontSize*$this->k,.9*$this->GetStringWidth($this->array_th[$i-1])*$this->k,.25*$this->FontSize*$this->k); $this->s_th.=' Q '; $this->txt_error=1; } //µÃǨÊͺµÑÇÍÑ¡ÉõÑÇ¡è͹˹éÒ¹Ñé¹à»ç¹ÍÑ¡¢ÃÐ ¯. ¡Ñº ®. elseif($this->_errorTh($this->array_th[$i-1])==4)
{
$pointY=$this->pointY-.25*$this->FontSize*$this->k; $this->txt_error=1; } //¨º¡ÒõÃǨÊͺµÑÇÍÑ¡ÉÃÊÃÐÅèÒ§ }
//¨º¡ÒõÃǨÊͺµÑÇÍÑ¡ÉÃÐÊÃÐÅèÒ§ if($this->txt_error==1) $this->TText($pointX,$pointY,$this->array_th[$i]); } /********************************************************************************
* ãªé§Ò¹: Function _checkT ¢Í§ Class FPDF_TH
* ¡Ò÷ӧҹ: ãªé㹡ÒõÃǨÊͺÍÑ¡É÷ÕèÍÒ¨¨Ð·ÓãËéà¡Ô´¡ÒþÔÁ¾ì·Õè¼Ô´¾ÅÒ´
* ¤ÇÒÁµéͧ¡ÒÃ: $char_th = µÑÇÍÑ¡É÷Õè¨Ðãªé㹡ÒÃà»ÃÕºà·Õº *********************************************************************************/
function _errorTh($char_th) { $txt_error=0; //µÑÇÍÑ¡Éú¹-º¹ if(($char_th=='è')||($char_th=='é')||($char_th=='ê')||($char_th=='ë')||($char_th=='ì')) $txt_error=1; //µÑÇÍÑ¡Éú¹ elseif(($char_th=='Ô')||($char_th=='Õ')||($char_th=='Ö')||($char_th=='×')||($char_th=='ç')||($char_th=='Ñ')||($char_th=='Ó')) $txt_error=2; //µÑÇÍÑ¡ÉáÅÒ§-º¹ elseif(($char_th=='»')||($char_th=='¿')||($char_th=='½')) $txt_error=3; //µÑÇÍÑ¡ÉáÅÒ§-ÅèÒ§ elseif(($char_th=='®')||($char_th=='¯')) $txt_error=4; //µÑÇÍÑ¡ÉáÅÒ§-ÅèÒ§ elseif(($char_th=='­')||($char_th=='°')) $txt_error=5; //µÑÇÍÑ¡ÉÃÊÃÐÅèÒ§ elseif(($char_th=='Ø')||($char_th=='Ù')) $txt_error=6; else $txt_error=0; return $txt_error; } /********************************************************************************
* ãªé§Ò¹: Function _checkT ¢Í§ Class FPDF_TH *
* ¡Ò÷ӧҹ: ãªéã¹¾ÔÁ¾ìµÑÇÍÑ¡É÷ÕèµÃǨÊͺáÅéÇ *
* ¤ÇÒÁµéͧ¡ÒÃ: $txt_th = µÑÇÍÑ¡Éà 1 µÑÇ ·ÕèµÃǨÊͺáÅéÇ * * $s = ÊÒÂÍÑ¡¢ÃТͧ⤴ PDF * *********************************************************************************/
function TText($pX,$pY,$txt_th) { //µÇ¨Êͺ¡ÒÃãÊèÊÕà«ÅÅì if($this->ColorFlag) $this->s_th.=' q '.$this->TextColor.' '; $txt_th2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt_th))); //ÃкصÓáË¹è§ áÅоÔÁ¾ìµÑÇÍÑ¡Éà $this->s_th.=sprintf(' BT %.2f %.2f Td (%s) Tj ET ',$pX,$pY,$txt_th2); if($this->ColorFlag) $this->s_th.=' Q '; } /****************************************************************************************
* ãªé§Ò¹: called by function MultiCell within this class
* ÍéÒ§ÍÔ§: Function Cell ¢Í§ Class FPDF
* ¡Ò÷ӧҹ: ãªé㹡ÒþÔÁ¾ì¢éͤÇÒÁ·ÕÅкÃ÷Ѵ¢Í§àÍ¡ÊÒà PDF
* ÃٺẺ: MCell ( $w = ¤ÇÒÁ¡ÇéÒ§¢Í§Cell, * $h = ¤ÇÒÁÊÙ§¢Í§Cell, * $txt = ¢éͤÇÒÁ·Õè¨Ð¾ÔÁ¾ì, * $border = ¡Ó˹´¡ÒÃáÊ´§àÊ鹡Ãͺ(0 = äÁèáÊ´§, 1= áÊ´§), * $ln = µÓá˹觷ÕèÍÂÙè¶Ñ´ä»¨Ò¡à«ÅÅì(0 = ¢ÇÒ, 1 = ºÃ÷Ѵ¶Ñ´ä», 2 = ´éÒ¹ÅèÒ§), * $align = µÓá˹觢éͤÇÒÁ(L = «éÒÂ, R = ¢ÇÒ, C = ¡Ö觡ÅÒ§, T = º¹, B = ÅèÒ§), * $fill = ¡Ó˹´¡ÒÃáÊ´§ÊբͧCell(0 = äÁèáÊ´§, 1 = áÊ´§) * $link = URL ·Õèµéͧ¡ÒÃãËé¢éͤÇÒÁàª×èÍÁâ§件֧ * )
*****************************************************************************************/
function MCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') { $this->checkFill=""; $k=$this->k; if($this->y+$h>$this->PageBreakTrigger && !$this->InFooter && $this->AcceptPageBreak()) { //¢Öé¹Ë¹éÒãËÁèÍѵâ¹Áѵ $x=$this->x; $ws=$this->ws; if($ws>0) { $this->ws=0; $this->_out('0 Tw'); } $this->AddPage($this->CurOrientation); $this->x=$x; if($ws>0) { $this->ws=$ws; $this->_out(sprintf('%.3f Tw',$ws*$k)); } } //¡Ó˹´¤ÇÒÁ¡ÇéÒ§à«ÅÅìà·èҡѺ˹éÒ¡ÃдÒÉ if($w==0) $w=$this->w-$this->rMargin-$this->x; $this->s_th=''; //¡Ó˹´¡ÒÃáÊ´§àÊ鹡Ãͺ 4 ´éÒ¹ áÅÐÊÕ¡Ãͺ if($fill==1 || $border==1) { if($fill==1) $op=($border==1) ? 'B' : 'f'; else $op='S'; $this->s_th=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); if($op=='f') $this->checkFill=$op; } //¡Ó˹´¡ÒÃáÊ´§àÊ鹡Ãͺ·ÕÅÐàÊé¹ if(is_string($border)) { $x=$this->x; $y=$this->y; if(strpos($border,'L')!==false) $this->s_th.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); if(strpos($border,'T')!==false) $this->s_th.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); if(strpos($border,'R')!==false) $this->s_th.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); if(strpos($border,'B')!==false) $this->s_th.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); } if($txt!=='') { $x=$this->x; $y=$this->y; //¡Ó˹´¡ÒèѴ¢éͤÇÒÁã¹à«ÅÅìµÒÁá¹ÇÃдѺ if(strpos($align,'R')!==false) $dx=$w-$this->cMargin-$this->GetStringWidth($txt); elseif(strpos($align,'C')!==false) $dx=($w-$this->GetStringWidth($txt))/2; else $dx=$this->cMargin; //¡Ó˹´¡ÒèѴ¢éͤÇÒÁã¹à«ÅÅìµÒÁá¹Ç´Ôè§ if(strpos($align,'T')!==false) $dy=$h-(.7*$this->k*$this->FontSize); elseif(strpos($align,'B')!==false) $dy=$h-(.3*$this->k*$this->FontSize); else $dy=.5*$h; //¡Ó˹´¡ÒâմàÊé¹ãµé¢éͤÇÒÁ if($this->underline) { //¡Ó˹´ºÑ¹·Ö¡¡ÃÒ¿Ô¡ if($this->ColorFlag) $this->s_th.='q '.$this->TextColor.' '; //¢Õ´àÊé¹ãµé¢éͤÇÒÁ0 $this->s_th.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); //¡Ó˹´¤×¹¤èÒ¡ÃÒ¿Ô¡ if($this->ColorFlag) $this->s_th.=' Q'; } //¡Ó˹´¢éͤÇÒÁàª×èÍÁâ§件֧ if($link) $this->Link($this->x,$this->y,$this->GetStringWidth($txt),$this->FontSize,$link); if($this->s_th) $this->_out($this->s_th); $this->s_th=''; //µÑ´ÍÑ¡ÉÃÍÍ¡¨Ò¡¢éͤÇÒÁ ·ÕÅеÑÇà¡çºÅ§ÍÐàÃÂì $this->array_th=substr($txt,0); $i=0; while($i<=strlen($txt)) { //¡Ó˹´µÓá˹觷Õè¨Ð¾ÔÁ¾ìÍÑ¡ÉÃã¹à«ÅÅì $this->pointX=($x+$dx+.02*$this->GetStringWidth($this->array_th[$i-1]))*$k; $this->pointY=($this->h-($y+$dy+.3*$this->FontSize))*$k; //µÃǨÊͺÍÑ¡Éà »ÃѺµÓá˹è§áÅзӡÒþÔÁ¾ì $this->_checkT($i); if($this->txt_error==0) $this->TText($this->pointX,$this->pointY,$this->array_th[$i]); else { $this->txt_error=0; } //µÃǨÊͺ¡ÒÃãÊèàŢ˹éÒ if($this->array_th[$i]=='{'&&$this->array_th[$i+1]=='n'&&$this->array_th[$i+2]=='b'&&$this->array_th[$i+3]=='}') $i=$i+3; //àÅ×è͹µÓáË¹è§ x ä»·ÕèµÑÇ·Õè¨Ð¾ÔÁ¾ì¶Ñ´ä» $x=$x+$this->GetStringWidth($this->array_th[$i]); $i++; } $this->_out($this->s_th); } else //¹Ó¤èÒä»áÊ´§àÁ×èÍäÁèÁÕ¢éͤÇÒÁ $this->_out($this->s_th); $this->lasth=$h; //µÃǨÊͺ¡ÒÃÇÒ§µÓá˹觢ͧà«ÅÅì¶Ñ´ä» if($ln>0) { //¢Ö鹺Ã÷ѴãËÁè $this->y+=$h; if($ln==1) $this->x=$this->lMargin; } else $this->x+=$w; } //End of class } ?>


Příklad


<?php
require('fpdf_thai.php');

class PDF extends FPDF_Thai{
function Header()
{
    $this->SetFont('AngsanaNew','BU',40);

    $this->Cell(190,10,'ÁËÒÇÔ·ÂÒÅѺÙþÒ',0,0,'C');

    $this->Ln(20);
}

function ColorTable($header,$data)

{
    //Colors, line width and bold font
    $this->SetFillColor(255,0,0);

    $this->SetTextColor(255);
    $this->SetDrawColor(128,0,0);

    $this->SetLineWidth(.3);
    $this->SetFont('','B');
    //Header

    $w=array(40,35,40,45);
    for($i=0;$i<count($header);$i++)

        $this->Cell($w[$i],7,$header[$i],1,0,'C',1);

    $this->Ln();
    //Color and font restoration
    $this->SetFillColor(224,235,255);

    $this->SetTextColor(0);
    $this->SetFont('');
    //Data
    $fill=0;

    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);

        $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);

        $this->Cell($w[2],6,$row[2],'LR',0,'C',$fill);

        $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);

        $this->Ln();
        $fill=!$fill;
    }
    $this->Cell(array_sum($w),0,'','T');

}
}

$pdf=new PDF();
$pdf->AddFont('AngsanaNew','','angsa.php');

$pdf->AddFont('AngsanaNew','B','angsab.php');
$pdf->AddPage();
$pdf->SetFont('AngsanaNew','',12);

//Column titles
$header=array('ª×èÍ','¹ÒÁÊ¡ØÅ','ÃËÑʹÔÊÔµ','¤èÒãªé¨èÒÂ/à´×͹');
//Read file lines

$lines=file('student.txt');
$data=array();
foreach($lines as $line)
    $data[]=explode(';',chop($line));

//Output table
$pdf->ColorTable($header,$data);

$pdf->Output();

?>


Ukázka

fpdf-thaiska-podpora.pdf

Download

fpdf-thaiska-podpora.zip

Informace

Author: Wittawas Puntumchinda
License: FPDF