| 1 |
<?php |
| 2 |
//require('fpdf.php'); |
| 3 |
require(USCES_PLUGIN_DIR.'/classes/fpdf/mbfpdi.php'); |
| 4 |
|
| 5 |
$SJIS_widths=array(' '=>278,'!'=>299,'"'=>353,'#'=>614,'$'=>614,'%'=>721,'&'=>735,'\''=>216, |
| 6 |
'('=>323,')'=>323,'*'=>449,'+'=>529,','=>219,'-'=>306,'.'=>219,'/'=>453,'0'=>614,'1'=>614, |
| 7 |
'2'=>614,'3'=>614,'4'=>614,'5'=>614,'6'=>614,'7'=>614,'8'=>614,'9'=>614,':'=>219,';'=>219, |
| 8 |
'<'=>529,'='=>529,'>'=>529,'?'=>486,'@'=>744,'A'=>646,'B'=>604,'C'=>617,'D'=>681,'E'=>567, |
| 9 |
'F'=>537,'G'=>647,'H'=>738,'I'=>320,'J'=>433,'K'=>637,'L'=>566,'M'=>904,'N'=>710,'O'=>716, |
| 10 |
'P'=>605,'Q'=>716,'R'=>623,'S'=>517,'T'=>601,'U'=>690,'V'=>668,'W'=>990,'X'=>681,'Y'=>634, |
| 11 |
'Z'=>578,'['=>316,'\\'=>614,']'=>316,'^'=>529,'_'=>500,'`'=>387,'a'=>509,'b'=>566,'c'=>478, |
| 12 |
'd'=>565,'e'=>503,'f'=>337,'g'=>549,'h'=>580,'i'=>275,'j'=>266,'k'=>544,'l'=>276,'m'=>854, |
| 13 |
'n'=>579,'o'=>550,'p'=>578,'q'=>566,'r'=>410,'s'=>444,'t'=>340,'u'=>575,'v'=>512,'w'=>760, |
| 14 |
'x'=>503,'y'=>529,'z'=>453,'{'=>326,'|'=>380,'}'=>326,'~'=>387); |
| 15 |
|
| 16 |
//class PDF_Japanese extends FPDF |
| 17 |
class PDF_Japanese extends MBfpdi |
| 18 |
{ |
| 19 |
function AddCIDFont($family,$style,$name,$cw,$CMap,$registry) |
| 20 |
{ |
| 21 |
$fontkey=strtolower($family).strtoupper($style); |
| 22 |
if(isset($this->fonts[$fontkey])) |
| 23 |
$this->Error("CID font already added: $family $style"); |
| 24 |
$i=count($this->fonts)+1; |
| 25 |
$this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>-120,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry); |
| 26 |
} |
| 27 |
|
| 28 |
function AddCIDFonts($family,$name,$cw,$CMap,$registry) |
| 29 |
{ |
| 30 |
$this->AddCIDFont($family,'',$name,$cw,$CMap,$registry); |
| 31 |
$this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry); |
| 32 |
$this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry); |
| 33 |
$this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry); |
| 34 |
} |
| 35 |
|
| 36 |
function AddSJISFont($family='SJIS') |
| 37 |
{ |
| 38 |
//Add SJIS font with proportional Latin |
| 39 |
$name='KozMinPro-Regular-Acro'; |
| 40 |
$cw=$GLOBALS['SJIS_widths']; |
| 41 |
$CMap='90msp-RKSJ-H'; |
| 42 |
$registry=array('ordering'=>'Japan1','supplement'=>2); |
| 43 |
$this->AddCIDFonts($family,$name,$cw,$CMap,$registry); |
| 44 |
} |
| 45 |
|
| 46 |
function AddSJIShwFont($family='SJIS-hw') |
| 47 |
{ |
| 48 |
//Add SJIS font with half-width Latin |
| 49 |
$name='KozMinPro-Regular-Acro'; |
| 50 |
for($i=32;$i<=126;$i++) |
| 51 |
$cw[chr($i)]=500; |
| 52 |
$CMap='90ms-RKSJ-H'; |
| 53 |
$registry=array('ordering'=>'Japan1','supplement'=>2); |
| 54 |
$this->AddCIDFonts($family,$name,$cw,$CMap,$registry); |
| 55 |
} |
| 56 |
|
| 57 |
function GetStringWidth($s) |
| 58 |
{ |
| 59 |
if($this->CurrentFont['type']=='Type0') |
| 60 |
return $this->GetSJISStringWidth($s); |
| 61 |
else |
| 62 |
return parent::GetStringWidth($s); |
| 63 |
} |
| 64 |
|
| 65 |
function GetSJISStringWidth($s) |
| 66 |
{ |
| 67 |
//SJIS version of GetStringWidth() |
| 68 |
$l=0; |
| 69 |
$cw=&$this->CurrentFont['cw']; |
| 70 |
$nb=strlen($s); |
| 71 |
$i=0; |
| 72 |
while($i<$nb) |
| 73 |
{ |
| 74 |
$o=ord($s{$i}); |
| 75 |
if($o<128) |
| 76 |
{ |
| 77 |
//ASCII |
| 78 |
$l+=$cw[$s{$i}]; |
| 79 |
$i++; |
| 80 |
} |
| 81 |
elseif($o>=161 and $o<=223) |
| 82 |
{ |
| 83 |
//Half-width katakana |
| 84 |
$l+=500; |
| 85 |
$i++; |
| 86 |
} |
| 87 |
else |
| 88 |
{ |
| 89 |
//Full-width character |
| 90 |
$l+=1000; |
| 91 |
$i+=2; |
| 92 |
} |
| 93 |
} |
| 94 |
return $l*$this->FontSize/1000; |
| 95 |
} |
| 96 |
|
| 97 |
function MultiCell($w,$h,$txt,$border=0,$align='L',$fill=0) |
| 98 |
{ |
| 99 |
if($this->CurrentFont['type']=='Type0') |
| 100 |
$this->SJISMultiCell($w,$h,$txt,$border,$align,$fill); |
| 101 |
else |
| 102 |
parent::MultiCell($w,$h,$txt,$border,$align,$fill); |
| 103 |
} |
| 104 |
|
| 105 |
function SJISMultiCell($w,$h,$txt,$border=0,$align='L',$fill=0) |
| 106 |
{ |
| 107 |
//Output text with automatic or explicit line breaks |
| 108 |
$cw=&$this->CurrentFont['cw']; |
| 109 |
if($w==0) |
| 110 |
$w=$this->w-$this->rMargin-$this->x; |
| 111 |
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
| 112 |
$s=str_replace("\r",'',$txt); |
| 113 |
$nb=strlen($s); |
| 114 |
if($nb>0 and $s{$nb-1}=="\n") |
| 115 |
$nb--; |
| 116 |
$b=0; |
| 117 |
if($border) |
| 118 |
{ |
| 119 |
if($border==1) |
| 120 |
{ |
| 121 |
$border='LTRB'; |
| 122 |
$b='LRT'; |
| 123 |
$b2='LR'; |
| 124 |
} |
| 125 |
else |
| 126 |
{ |
| 127 |
$b2=''; |
| 128 |
if(is_int(strpos($border,'L'))) |
| 129 |
$b2.='L'; |
| 130 |
if(is_int(strpos($border,'R'))) |
| 131 |
$b2.='R'; |
| 132 |
$b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; |
| 133 |
} |
| 134 |
} |
| 135 |
$sep=-1; |
| 136 |
$i=0; |
| 137 |
$j=0; |
| 138 |
$l=0; |
| 139 |
$nl=1; |
| 140 |
while($i<$nb) |
| 141 |
{ |
| 142 |
//Get next character |
| 143 |
$c=$s{$i}; |
| 144 |
$o=ord($c); |
| 145 |
if($o==10) |
| 146 |
{ |
| 147 |
//Explicit line break |
| 148 |
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
| 149 |
$i++; |
| 150 |
$sep=-1; |
| 151 |
$j=$i; |
| 152 |
$l=0; |
| 153 |
$nl++; |
| 154 |
if($border and $nl==2) |
| 155 |
$b=$b2; |
| 156 |
continue; |
| 157 |
} |
| 158 |
if($o<128) |
| 159 |
{ |
| 160 |
//ASCII |
| 161 |
$l+=$cw[$c]; |
| 162 |
$n=1; |
| 163 |
if($o==32) |
| 164 |
$sep=$i; |
| 165 |
} |
| 166 |
elseif($o>=161 and $o<=223) |
| 167 |
{ |
| 168 |
//Half-width katakana |
| 169 |
$l+=500; |
| 170 |
$n=1; |
| 171 |
$sep=$i; |
| 172 |
} |
| 173 |
else |
| 174 |
{ |
| 175 |
//Full-width character |
| 176 |
$l+=1000; |
| 177 |
$n=2; |
| 178 |
$sep=$i; |
| 179 |
} |
| 180 |
if($l>$wmax) |
| 181 |
{ |
| 182 |
//Automatic line break |
| 183 |
if($sep==-1 or $i==$j) |
| 184 |
{ |
| 185 |
if($i==$j) |
| 186 |
$i+=$n; |
| 187 |
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
| 188 |
} |
| 189 |
else |
| 190 |
{ |
| 191 |
$this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
| 192 |
$i=($s[$sep]==' ') ? $sep+1 : $sep; |
| 193 |
} |
| 194 |
$sep=-1; |
| 195 |
$j=$i; |
| 196 |
$l=0; |
| 197 |
$nl++; |
| 198 |
if($border and $nl==2) |
| 199 |
$b=$b2; |
| 200 |
} |
| 201 |
else |
| 202 |
{ |
| 203 |
$i+=$n; |
| 204 |
if($o>=128) |
| 205 |
$sep=$i; |
| 206 |
} |
| 207 |
} |
| 208 |
//Last chunk |
| 209 |
if($border and is_int(strpos($border,'B'))) |
| 210 |
$b.='B'; |
| 211 |
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
| 212 |
$this->x=$this->lMargin; |
| 213 |
} |
| 214 |
|
| 215 |
function Write($h,$txt,$link='') |
| 216 |
{ |
| 217 |
if($this->CurrentFont['type']=='Type0') |
| 218 |
$this->SJISWrite($h,$txt,$link); |
| 219 |
else |
| 220 |
parent::Write($h,$txt,$link); |
| 221 |
} |
| 222 |
|
| 223 |
function SJISWrite($h,$txt,$link) |
| 224 |
{ |
| 225 |
//SJIS version of Write() |
| 226 |
$cw=&$this->CurrentFont['cw']; |
| 227 |
$w=$this->w-$this->rMargin-$this->x; |
| 228 |
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
| 229 |
$s=str_replace("\r",'',$txt); |
| 230 |
$nb=strlen($s); |
| 231 |
$sep=-1; |
| 232 |
$i=0; |
| 233 |
$j=0; |
| 234 |
$l=0; |
| 235 |
$nl=1; |
| 236 |
while($i<$nb) |
| 237 |
{ |
| 238 |
//Get next character |
| 239 |
$c=$s{$i}; |
| 240 |
$o=ord($c); |
| 241 |
if($o==10) |
| 242 |
{ |
| 243 |
//Explicit line break |
| 244 |
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); |
| 245 |
$i++; |
| 246 |
$sep=-1; |
| 247 |
$j=$i; |
| 248 |
$l=0; |
| 249 |
if($nl==1) |
| 250 |
{ |
| 251 |
//Go to left margin |
| 252 |
$this->x=$this->lMargin; |
| 253 |
$w=$this->w-$this->rMargin-$this->x; |
| 254 |
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
| 255 |
} |
| 256 |
$nl++; |
| 257 |
continue; |
| 258 |
} |
| 259 |
if($o<128) |
| 260 |
{ |
| 261 |
//ASCII |
| 262 |
$l+=$cw[$c]; |
| 263 |
$n=1; |
| 264 |
if($o==32) |
| 265 |
$sep=$i; |
| 266 |
} |
| 267 |
elseif($o>=161 and $o<=223) |
| 268 |
{ |
| 269 |
//Half-width katakana |
| 270 |
$l+=500; |
| 271 |
$n=1; |
| 272 |
$sep=$i; |
| 273 |
} |
| 274 |
else |
| 275 |
{ |
| 276 |
//Full-width character |
| 277 |
$l+=1000; |
| 278 |
$n=2; |
| 279 |
$sep=$i; |
| 280 |
} |
| 281 |
if($l>$wmax) |
| 282 |
{ |
| 283 |
//Automatic line break |
| 284 |
if($sep==-1 or $i==$j) |
| 285 |
{ |
| 286 |
if($this->x>$this->lMargin) |
| 287 |
{ |
| 288 |
//Move to next line |
| 289 |
$this->x=$this->lMargin; |
| 290 |
$this->y+=$h; |
| 291 |
$w=$this->w-$this->rMargin-$this->x; |
| 292 |
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
| 293 |
$i+=$n; |
| 294 |
$nl++; |
| 295 |
continue; |
| 296 |
} |
| 297 |
if($i==$j) |
| 298 |
$i+=$n; |
| 299 |
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); |
| 300 |
} |
| 301 |
else |
| 302 |
{ |
| 303 |
$this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); |
| 304 |
$i=($s[$sep]==' ') ? $sep+1 : $sep; |
| 305 |
} |
| 306 |
$sep=-1; |
| 307 |
$j=$i; |
| 308 |
$l=0; |
| 309 |
if($nl==1) |
| 310 |
{ |
| 311 |
$this->x=$this->lMargin; |
| 312 |
$w=$this->w-$this->rMargin-$this->x; |
| 313 |
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
| 314 |
} |
| 315 |
$nl++; |
| 316 |
} |
| 317 |
else |
| 318 |
{ |
| 319 |
$i+=$n; |
| 320 |
if($o>=128) |
| 321 |
$sep=$i; |
| 322 |
} |
| 323 |
} |
| 324 |
//Last chunk |
| 325 |
if($i!=$j) |
| 326 |
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link); |
| 327 |
} |
| 328 |
|
| 329 |
function _putfonts() |
| 330 |
{ |
| 331 |
$nf=$this->n; |
| 332 |
foreach($this->diffs as $diff) |
| 333 |
{ |
| 334 |
//Encodings |
| 335 |
$this->_newobj(); |
| 336 |
$this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); |
| 337 |
$this->_out('endobj'); |
| 338 |
} |
| 339 |
// $mqr=get_magic_quotes_runtime(); |
| 340 |
// set_magic_quotes_runtime(0); |
| 341 |
foreach($this->FontFiles as $file=>$info) |
| 342 |
{ |
| 343 |
//Font file embedding |
| 344 |
$this->_newobj(); |
| 345 |
$this->FontFiles[$file]['n']=$this->n; |
| 346 |
if(defined('FPDF_FONTPATH')) |
| 347 |
$file=FPDF_FONTPATH.$file; |
| 348 |
$size=filesize($file); |
| 349 |
if(!$size) |
| 350 |
$this->Error('Font file not found'); |
| 351 |
$this->_out('<</Length '.$size); |
| 352 |
if(substr($file,-2)=='.z') |
| 353 |
$this->_out('/Filter /FlateDecode'); |
| 354 |
$this->_out('/Length1 '.$info['length1']); |
| 355 |
if(isset($info['length2'])) |
| 356 |
$this->_out('/Length2 '.$info['length2'].' /Length3 0'); |
| 357 |
$this->_out('>>'); |
| 358 |
$f=fopen($file,'rb'); |
| 359 |
$this->_putstream(fread($f,$size)); |
| 360 |
fclose($f); |
| 361 |
$this->_out('endobj'); |
| 362 |
} |
| 363 |
// set_magic_quotes_runtime($mqr); |
| 364 |
foreach($this->fonts as $k=>$font) |
| 365 |
{ |
| 366 |
//Font objects |
| 367 |
$this->_newobj(); |
| 368 |
$this->fonts[$k]['n']=$this->n; |
| 369 |
$this->_out('<</Type /Font'); |
| 370 |
if($font['type']=='Type0') |
| 371 |
$this->_putType0($font); |
| 372 |
else |
| 373 |
{ |
| 374 |
$name=$font['name']; |
| 375 |
$this->_out('/BaseFont /'.$name); |
| 376 |
if($font['type']=='core') |
| 377 |
{ |
| 378 |
//Standard font |
| 379 |
$this->_out('/Subtype /Type1'); |
| 380 |
if($name!='Symbol' and $name!='ZapfDingbats') |
| 381 |
$this->_out('/Encoding /WinAnsiEncoding'); |
| 382 |
} |
| 383 |
else |
| 384 |
{ |
| 385 |
//Additional font |
| 386 |
$this->_out('/Subtype /'.$font['type']); |
| 387 |
$this->_out('/FirstChar 32'); |
| 388 |
$this->_out('/LastChar 255'); |
| 389 |
$this->_out('/Widths '.($this->n+1).' 0 R'); |
| 390 |
$this->_out('/FontDescriptor '.($this->n+2).' 0 R'); |
| 391 |
if($font['enc']) |
| 392 |
{ |
| 393 |
if(isset($font['diff'])) |
| 394 |
$this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); |
| 395 |
else |
| 396 |
$this->_out('/Encoding /WinAnsiEncoding'); |
| 397 |
} |
| 398 |
} |
| 399 |
$this->_out('>>'); |
| 400 |
$this->_out('endobj'); |
| 401 |
if($font['type']!='core') |
| 402 |
{ |
| 403 |
//Widths |
| 404 |
$this->_newobj(); |
| 405 |
$cw=&$font['cw']; |
| 406 |
$s='['; |
| 407 |
for($i=32;$i<=255;$i++) |
| 408 |
$s.=$cw[chr($i)].' '; |
| 409 |
$this->_out($s.']'); |
| 410 |
$this->_out('endobj'); |
| 411 |
//Descriptor |
| 412 |
$this->_newobj(); |
| 413 |
$s='<</Type /FontDescriptor /FontName /'.$name; |
| 414 |
foreach($font['desc'] as $k=>$v) |
| 415 |
$s.=' /'.$k.' '.$v; |
| 416 |
$file=$font['file']; |
| 417 |
if($file) |
| 418 |
$s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; |
| 419 |
$this->_out($s.'>>'); |
| 420 |
$this->_out('endobj'); |
| 421 |
} |
| 422 |
} |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
function _putType0($font) |
| 427 |
{ |
| 428 |
//Type0 |
| 429 |
$this->_out('/Subtype /Type0'); |
| 430 |
$this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); |
| 431 |
$this->_out('/Encoding /'.$font['CMap']); |
| 432 |
$this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); |
| 433 |
$this->_out('>>'); |
| 434 |
$this->_out('endobj'); |
| 435 |
//CIDFont |
| 436 |
$this->_newobj(); |
| 437 |
$this->_out('<</Type /Font'); |
| 438 |
$this->_out('/Subtype /CIDFontType0'); |
| 439 |
$this->_out('/BaseFont /'.$font['name']); |
| 440 |
$this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('.$font['registry']['ordering'].') /Supplement '.$font['registry']['supplement'].'>>'); |
| 441 |
$this->_out('/FontDescriptor '.($this->n+1).' 0 R'); |
| 442 |
$W='/W [1 ['; |
| 443 |
foreach($font['cw'] as $w) |
| 444 |
$W.=$w.' '; |
| 445 |
$this->_out($W.'] 231 325 500 631 [500] 326 389 500]'); |
| 446 |
$this->_out('>>'); |
| 447 |
$this->_out('endobj'); |
| 448 |
//Font descriptor |
| 449 |
$this->_newobj(); |
| 450 |
$this->_out('<</Type /FontDescriptor'); |
| 451 |
$this->_out('/FontName /'.$font['name']); |
| 452 |
$this->_out('/Flags 6'); |
| 453 |
$this->_out('/FontBBox [0 -200 1000 900]'); |
| 454 |
$this->_out('/ItalicAngle 0'); |
| 455 |
$this->_out('/Ascent 800'); |
| 456 |
$this->_out('/Descent -200'); |
| 457 |
$this->_out('/CapHeight 800'); |
| 458 |
$this->_out('/StemV 60'); |
| 459 |
$this->_out('>>'); |
| 460 |
$this->_out('endobj'); |
| 461 |
} |
| 462 |
} |
| 463 |
?> |
| 464 |
|