4 // PDF functions taken from FPDF http://www.fpdf.org
6 require_once('lib/pdf.php');
8 class PDF_Japanese extends PDF {
13 var $SJIS_widths = array(' '=>278,'!'=>299,'"'=>353,'#'=>614,'$'=>614,'%'=>721,'&'=>735,'\''=>216,
14 '('=>323,')'=>323,'*'=>449,'+'=>529,','=>219,'-'=>306,'.'=>219,'/'=>453,'0'=>614,'1'=>614,
15 '2'=>614,'3'=>614,'4'=>614,'5'=>614,'6'=>614,'7'=>614,'8'=>614,'9'=>614,':'=>219,';'=>219,
16 '<'=>529,'='=>529,'>'=>529,'?'=>486,'@'=>744,'A'=>646,'B'=>604,'C'=>617,'D'=>681,'E'=>567,
17 'F'=>537,'G'=>647,'H'=>738,'I'=>320,'J'=>433,'K'=>637,'L'=>566,'M'=>904,'N'=>710,'O'=>716,
18 'P'=>605,'Q'=>716,'R'=>623,'S'=>517,'T'=>601,'U'=>690,'V'=>668,'W'=>990,'X'=>681,'Y'=>634,
19 'Z'=>578,'['=>316,'\\'=>614,']'=>316,'^'=>529,'_'=>500,'`'=>387,'a'=>509,'b'=>566,'c'=>478,
20 'd'=>565,'e'=>503,'f'=>337,'g'=>549,'h'=>580,'i'=>275,'j'=>266,'k'=>544,'l'=>276,'m'=>854,
21 'n'=>579,'o'=>550,'p'=>578,'q'=>566,'r'=>410,'s'=>444,'t'=>340,'u'=>575,'v'=>512,'w'=>760,
22 'x'=>503,'y'=>529,'z'=>453,'{'=>326,'|'=>380,'}'=>326,'~'=>387);
24 function AddCIDFont($family,$style,$name,$cw,$CMap,$registry)
26 $fontkey=strtolower($family).strtoupper($style);
27 if(isset($this->fonts[$fontkey]))
28 $this->Error("CID font already added: $family $style");
29 $i=count($this->fonts)+1;
30 $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>-120,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry);
33 function AddCIDFonts($family,$name,$cw,$CMap,$registry)
35 $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry);
36 $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry);
37 $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry);
38 $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry);
41 function AddSJISFont($family='SJIS')
43 //Add SJIS font with proportional Latin
44 $name='KozMinPro-Regular-Acro';
45 $cw=$this->SJIS_widths;
47 $registry=array('ordering'=>'Japan1','supplement'=>2);
48 $this->AddCIDFonts($family,$name,$cw,$CMap,$registry);
51 function AddSJIShwFont($family='SJIS-hw')
53 //Add SJIS font with half-width Latin
54 $name='KozMinPro-Regular-Acro';
55 for($i=32;$i<=126;$i++)
58 $registry=array('ordering'=>'Japan1','supplement'=>2);
59 $this->AddCIDFonts($family,$name,$cw,$CMap,$registry);
62 function GetStringWidth($s)
64 if($this->CurrentFont['type']=='Type0')
65 return $this->GetSJISStringWidth($s);
67 return parent::GetStringWidth($s);
70 function GetSJISStringWidth($s)
72 //SJIS version of GetStringWidth()
74 $cw=&$this->CurrentFont['cw'];
84 elseif($o>=161 and $o<=223) {
89 //Full-width character
94 return $l*$this->FontSize/1000;
97 function MultiCell($w,$h,$txt,$border=0,$align='L',$fill=0)
99 if($this->CurrentFont['type']=='Type0')
100 $this->SJISMultiCell($w,$h,$txt,$border,$align,$fill);
102 parent::MultiCell($w,$h,$txt,$border,$align,$fill);
105 function SJISMultiCell($w,$h,$txt,$border=0,$align='L',$fill=0)
107 //Output text with automatic or explicit line breaks
108 $cw=&$this->CurrentFont['cw'];
110 $w=$this->w-$this->rMargin-$this->x;
111 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
112 $s=str_replace("\r",'',$txt);
114 if($nb>0 and $s{$nb-1}=="\n")
124 if(is_int(strpos($border,'L')))
126 if(is_int(strpos($border,'R')))
128 $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
141 //Explicit line break
142 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
148 if($border and $nl==2)
158 } elseif($o>=161 and $o<=223) {
159 //Half-width katakana
164 //Full-width character
170 //Automatic line break
171 if($sep==-1 or $i==$j) {
174 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
176 $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
177 $i=($s[$sep]==' ') ? $sep+1 : $sep;
183 if($border and $nl==2)
192 if($border and is_int(strpos($border,'B')))
194 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
195 $this->x=$this->lMargin;
198 function Write($h,$txt,$link='')
200 if($this->CurrentFont['type']=='Type0')
201 $this->SJISWrite($h,$txt,$link);
203 parent::Write($h,$txt,$link);
206 function SJISWrite($h,$txt,$link)
208 //SJIS version of Write()
209 $cw=&$this->CurrentFont['cw'];
210 $w=$this->w-$this->rMargin-$this->x;
211 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
212 $s=str_replace("\r",'',$txt);
224 //Explicit line break
225 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
232 $this->x=$this->lMargin;
233 $w=$this->w-$this->rMargin-$this->x;
234 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
245 } elseif($o>=161 and $o<=223) {
246 //Half-width katakana
251 //Full-width character
257 //Automatic line break
258 if($sep==-1 or $i==$j) {
259 if($this->x>$this->lMargin) {
261 $this->x=$this->lMargin;
263 $w=$this->w-$this->rMargin-$this->x;
264 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
271 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
273 $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link);
274 $i=($s[$sep]==' ') ? $sep+1 : $sep;
280 $this->x=$this->lMargin;
281 $w=$this->w-$this->rMargin-$this->x;
282 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
293 $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link);
299 foreach($this->diffs as $diff) {
302 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
303 $this->_out('endobj');
305 if (!check_php_version(5,3)) {
306 $mqr=get_magic_quotes_runtime();
307 set_magic_quotes_runtime(0);
309 foreach($this->FontFiles as $file=>$info) {
310 //Font file embedding
312 $this->FontFiles[$file]['n']=$this->n;
313 if(defined('FPDF_FONTPATH'))
314 $file=FPDF_FONTPATH.$file;
315 $size=filesize($file);
317 $this->Error('Font file not found');
318 $this->_out('<</Length '.$size);
319 if(substr($file,-2)=='.z')
320 $this->_out('/Filter /FlateDecode');
321 $this->_out('/Length1 '.$info['length1']);
322 if(isset($info['length2']))
323 $this->_out('/Length2 '.$info['length2'].' /Length3 0');
325 $f=fopen($file,'rb');
326 $this->_putstream(fread($f,$size));
328 $this->_out('endobj');
330 if (!check_php_version(5,3)) {
331 set_magic_quotes_runtime($mqr);
333 foreach($this->fonts as $k=>$font) {
336 $this->fonts[$k]['n']=$this->n;
337 $this->_out('<</Type /Font');
338 if($font['type']=='Type0')
339 $this->_putType0($font);
342 $this->_out('/BaseFont /'.$name);
343 if($font['type']=='core') {
345 $this->_out('/Subtype /Type1');
346 if($name!='Symbol' and $name!='ZapfDingbats')
347 $this->_out('/Encoding /WinAnsiEncoding');
350 $this->_out('/Subtype /'.$font['type']);
351 $this->_out('/FirstChar 32');
352 $this->_out('/LastChar 255');
353 $this->_out('/Widths '.($this->n+1).' 0 R');
354 $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
356 if(isset($font['diff']))
357 $this->_out('/Encoding '.($nf+$font['diff']).' 0 R');
359 $this->_out('/Encoding /WinAnsiEncoding');
363 $this->_out('endobj');
364 if($font['type']!='core') {
369 for($i=32;$i<=255;$i++)
370 $s.=$cw[chr($i)].' ';
372 $this->_out('endobj');
375 $s='<</Type /FontDescriptor /FontName /'.$name;
376 foreach($font['desc'] as $k=>$v)
380 $s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
381 $this->_out($s.'>>');
382 $this->_out('endobj');
388 function _putType0($font)
391 $this->_out('/Subtype /Type0');
392 $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']);
393 $this->_out('/Encoding /'.$font['CMap']);
394 $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]');
396 $this->_out('endobj');
399 $this->_out('<</Type /Font');
400 $this->_out('/Subtype /CIDFontType0');
401 $this->_out('/BaseFont /'.$font['name']);
402 $this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('.$font['registry']['ordering'].') /Supplement '.$font['registry']['supplement'].'>>');
403 $this->_out('/FontDescriptor '.($this->n+1).' 0 R');
405 foreach($font['cw'] as $w)
407 $this->_out($W.'] 231 325 500 631 [500] 326 389 500]');
409 $this->_out('endobj');
412 $this->_out('<</Type /FontDescriptor');
413 $this->_out('/FontName /'.$font['name']);
414 $this->_out('/Flags 6');
415 $this->_out('/FontBBox [0 -200 1000 900]');
416 $this->_out('/ItalicAngle 0');
417 $this->_out('/Ascent 800');
418 $this->_out('/Descent -200');
419 $this->_out('/CapHeight 800');
420 $this->_out('/StemV 60');
422 $this->_out('endobj');
430 // c-hanging-comment-ender-p: nil
431 // indent-tabs-mode: nil