Add-On Thai support
Informations
Author:Wittawas PuntumchindaLicense: FPDF
Description
This extension fixes the positioning of some Thai diacritical marks.Source
<?php
/*******************************************************************************
* FPDF Thai Positioning Improve *
* *
* Version: 1.01 *
* Date: 2009-10-08 *
* Advisor: Mr. Wittawas Puntumchinda *
* Coding: Mr. Sirichai Fuangfoo *
* License: FPDF *
*******************************************************************************/
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(false = äÃèáô§, true = áô§)
* )
*****************************************************************************************/
function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false)
{
//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(false = äÃèáô§, true = áô§),
* $link = URL ·Ãèµéç¡ÃÃãÃé¢éäÃÃÃà ªÃèÃÃâç件ç
* )
*****************************************************************************************/
function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
{
$this->checkFill="";
$k=$this->k;
if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$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 || $border==1)
{
if($fill)
$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))
{
//¡Ãù´µÃáù觷Ãè¨Ã¾ÃþìÃáÃÃã¹à «Ã
Ã
ì
if(strpos('èéêëìÃÃÃÃçÃÃÃÃ', $this->array_th[$i])!==false)
{
$pX=$x+$dx;
if($i>0)
$pX+=.02*$this->GetStringWidth($this->array_th[$i-1]);
$this->pointX=$pX*$k;
//µÃèÃúÃáÃà »ÃúµÃáùè§áÃ
ևÃþÃþì
$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;
$nb=strlen($this->array_th);
//µÃ¨Ãú¡ÃÃáô§¼Ã
¢Ã§µÃÃÃáÃÃà ùÃÃÃÃú¹
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($i>=2 && $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(false = äÃèáô§, true = áô§)
* $link = URL ·Ãèµéç¡ÃÃãÃé¢éäÃÃÃà ªÃèÃÃâç件ç
* )
*****************************************************************************************/
function MCell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
{
$this->checkFill="";
$k=$this->k;
if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$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 || $border==1)
{
if($fill)
$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
}
?>
Example
<?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();
?>