Changeset 17718 for branches/version-2/data/pdf
- Timestamp:
- 2008/12/02 09:31:25 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2/data/pdf/japanese.php
r17232 r17718 1 1 <?php 2 require(' ../../../data/pdf/fpdf.php');3 require(' ../../../data/pdf/fpdi.php'); //ÄɲÃ2 require('fpdf.php'); 3 require('fpdi.php'); 4 4 5 5 $SJIS_widths=array(' '=>278,'!'=>299,'"'=>353,'#'=>614,'$'=>614,'%'=>721,'&'=>735,'\''=>216, 6 7 8 9 10 11 12 13 14 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 15 16 16 //class PDF_Japanese extends FPDF 17 class PDF_Japanese extends FPDI // Êѹ¹17 class PDF_Japanese extends FPDI //変更 18 18 { 19 19 function AddCIDFont($family,$style,$name,$cw,$CMap,$registry) 20 20 { 21 22 23 24 25 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 26 } 27 27 28 28 function AddCIDFonts($family,$name,$cw,$CMap,$registry) 29 29 { 30 31 32 33 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 34 } 35 35 36 36 function AddSJISFont($family='SJIS') 37 37 { 38 39 40 //$name='Gothic'; // Êѹ¹ 41 42 43 44 38 //Add SJIS font with proportional Latin 39 $name='KozMinPro-Regular-Acro'; 40 //$name='Gothic'; // 変更 41 $cw=$GLOBALS['SJIS_widths']; 42 $CMap='90msp-RKSJ-H'; 43 $registry=array('ordering'=>'Japan1','supplement'=>2); 44 $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); 45 45 } 46 46 47 47 function AddSJIShwFont($family='SJIS-hw') 48 48 { 49 50 51 52 53 54 55 49 //Add SJIS font with half-width Latin 50 $name='KozMinPro-Regular-Acro'; 51 for($i=32;$i<=126;$i++) 52 $cw[chr($i)]=500; 53 $CMap='90ms-RKSJ-H'; 54 $registry=array('ordering'=>'Japan1','supplement'=>2); 55 $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); 56 56 } 57 57 58 58 function GetStringWidth($s) 59 59 { 60 61 62 63 60 if($this->CurrentFont['type']=='Type0') 61 return $this->GetSJISStringWidth($s); 62 else 63 return parent::GetStringWidth($s); 64 64 } 65 65 66 66 function GetSJISStringWidth($s) 67 67 { 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 68 //SJIS version of GetStringWidth() 69 $l=0; 70 $cw=&$this->CurrentFont['cw']; 71 $nb=strlen($s); 72 $i=0; 73 while($i<$nb) 74 { 75 $o=ord($s{$i}); 76 if($o<128) 77 { 78 //ASCII 79 $l+=$cw[$s{$i}]; 80 $i++; 81 } 82 elseif($o>=161 and $o<=223) 83 { 84 //Half-width katakana 85 $l+=500; 86 $i++; 87 } 88 else 89 { 90 //Full-width character 91 $l+=1000; 92 $i+=2; 93 } 94 } 95 return $l*$this->FontSize/1000; 96 96 } 97 97 98 98 function MultiCell($w,$h,$txt,$border=0,$align='L',$fill=0,$ln=2) 99 99 { 100 101 102 103 100 if($this->CurrentFont['type']=='Type0') 101 $this->SJISMultiCell($w,$h,$txt,$border,$align,$fill,$ln); 102 else 103 parent::MultiCell($w,$h,$txt,$border,$align,$fill,$ln); 104 104 } 105 105 106 106 function SJISMultiCell($w,$h,$txt,$border=0,$align='L',$fill=0,$ln=2) 107 107 { 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 $this->rise_h = 0; //¹â¤µ·×»»ÍÑ 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 $this->rise_h += $h; //¹â¤µ·×»»ÍÑ 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 $this->rise_h += $h; //¹â¤µ·×»»ÍÑ 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 $this->rise_h += $h; //Áý²Ãʬ¤Î¹â¤µ¤ò·×»» 218 //²þ¹Ô¤Ê¤·ÀßÄ꤫¤Ä¡¢¹â¤µ¤¬µ¬Äê¤Î¹â¤µ°Ê¾å¤Ç¤¢¤ì¤ÐY¼´¤òÀßÄꤷ¤Ê¤ª¤¹¡£ 219 220 221 222 223 108 //Output text with automatic or explicit line breaks 109 $cw=&$this->CurrentFont['cw']; 110 if($w==0) 111 $w=$this->w-$this->rMargin-$this->x; 112 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 113 $s=str_replace("\r",'',$txt); 114 $nb=strlen($s); 115 if($nb>0 and $s{$nb-1}=="\n") 116 $nb--; 117 $b=0; 118 if($border) 119 { 120 if($border==1) 121 { 122 $border='LTRB'; 123 $b='LRT'; 124 $b2='LR'; 125 } 126 else 127 { 128 $b2=''; 129 if(is_int(strpos($border,'L'))) 130 $b2.='L'; 131 if(is_int(strpos($border,'R'))) 132 $b2.='R'; 133 $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; 134 } 135 } 136 $sep=-1; 137 $i=0; 138 $j=0; 139 $l=0; 140 $nl=1; 141 $this->rise_h = 0; //高さ計算用 142 143 while($i<$nb) 144 { 145 //Get next character 146 $c=$s{$i}; 147 $o=ord($c); 148 if($o==10) 149 { 150 //Explicit line break 151 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 152 $i++; 153 $sep=-1; 154 $j=$i; 155 $l=0; 156 $nl++; 157 $this->rise_h += $h; //高さ計算用 158 if($border and $nl==2) 159 $b=$b2; 160 continue; 161 } 162 if($o<128) 163 { 164 //ASCII 165 $l+=$cw[$c]; 166 $n=1; 167 if($o==32) 168 $sep=$i; 169 } 170 elseif($o>=161 and $o<=223) 171 { 172 //Half-width katakana 173 $l+=500; 174 $n=1; 175 $sep=$i; 176 } 177 else 178 { 179 //Full-width character 180 $l+=1000; 181 $n=2; 182 $sep=$i; 183 } 184 if($l>$wmax) 185 { 186 //Automatic line break 187 if($sep==-1 or $i==$j) 188 { 189 if($i==$j) 190 $i+=$n; 191 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 192 } 193 else 194 { 195 $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 196 $i=($s[$sep]==' ') ? $sep+1 : $sep; 197 } 198 $this->rise_h += $h; //高さ計算用 199 $sep=-1; 200 $j=$i; 201 $l=0; 202 $nl++; 203 if($border and $nl==2) 204 $b=$b2; 205 } 206 else 207 { 208 $i+=$n; 209 if($o>=128) 210 $sep=$i; 211 } 212 } 213 //Last chunk 214 if($border and is_int(strpos($border,'B'))) 215 $b.='B'; 216 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,$ln,$align,$fill); 217 $this->rise_h += $h; //増加分の高さを計算 218 //改行なし設定かつ、高さが規定の高さ以上であればY軸を設定しなおす。 219 if($ln == 0 and $h < $this->rise_h) { 220 $this->y = $this->y - $this->rise_h + $h; 221 } 222 223 //$this->x=$this->lMargin; 224 224 } 225 225 226 226 function Write($h,$txt,$link='') 227 227 { 228 229 230 231 228 if($this->CurrentFont['type']=='Type0') 229 $this->SJISWrite($h,$txt,$link); 230 else 231 parent::Write($h,$txt,$link); 232 232 } 233 233 234 234 function SJISWrite($h,$txt,$link) 235 235 { 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 236 //SJIS version of Write() 237 $cw=&$this->CurrentFont['cw']; 238 $w=$this->w-$this->rMargin-$this->x; 239 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 240 $s=str_replace("\r",'',$txt); 241 $nb=strlen($s); 242 $sep=-1; 243 $i=0; 244 $j=0; 245 $l=0; 246 $nl=1; 247 while($i<$nb) 248 { 249 //Get next character 250 $c=$s{$i}; 251 $o=ord($c); 252 if($o==10) 253 { 254 //Explicit line break 255 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 256 $i++; 257 $sep=-1; 258 $j=$i; 259 $l=0; 260 if($nl==1) 261 { 262 //Go to left margin 263 $this->x=$this->lMargin; 264 $w=$this->w-$this->rMargin-$this->x; 265 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 266 } 267 $nl++; 268 continue; 269 } 270 if($o<128) 271 { 272 //ASCII 273 $l+=$cw[$c]; 274 $n=1; 275 if($o==32) 276 $sep=$i; 277 } 278 elseif($o>=161 and $o<=223) 279 { 280 //Half-width katakana 281 $l+=500; 282 $n=1; 283 $sep=$i; 284 } 285 else 286 { 287 //Full-width character 288 $l+=1000; 289 $n=2; 290 $sep=$i; 291 } 292 if($l>$wmax) 293 { 294 //Automatic line break 295 if($sep==-1 or $i==$j) 296 { 297 if($this->x>$this->lMargin) 298 { 299 //Move to next line 300 $this->x=$this->lMargin; 301 $this->y+=$h; 302 $w=$this->w-$this->rMargin-$this->x; 303 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 304 $i+=$n; 305 $nl++; 306 continue; 307 } 308 if($i==$j) 309 $i+=$n; 310 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 311 } 312 else 313 { 314 $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); 315 $i=($s[$sep]==' ') ? $sep+1 : $sep; 316 } 317 $sep=-1; 318 $j=$i; 319 $l=0; 320 if($nl==1) 321 { 322 $this->x=$this->lMargin; 323 $w=$this->w-$this->rMargin-$this->x; 324 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 325 } 326 $nl++; 327 } 328 else 329 { 330 $i+=$n; 331 if($o>=128) 332 $sep=$i; 333 } 334 } 335 //Last chunk 336 if($i!=$j) 337 $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link); 338 338 } 339 339 340 340 function _putfonts() 341 341 { 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 342 $nf=$this->n; 343 foreach($this->diffs as $diff) 344 { 345 //Encodings 346 $this->_newobj(); 347 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); 348 $this->_out('endobj'); 349 } 350 $mqr=get_magic_quotes_runtime(); 351 set_magic_quotes_runtime(0); 352 foreach($this->FontFiles as $file=>$info) 353 { 354 //Font file embedding 355 $this->_newobj(); 356 $this->FontFiles[$file]['n']=$this->n; 357 if(defined('FPDF_FONTPATH')) 358 $file=FPDF_FONTPATH.$file; 359 $size=filesize($file); 360 if(!$size) 361 $this->Error('Font file not found'); 362 $this->_out('<</Length '.$size); 363 if(substr($file,-2)=='.z') 364 $this->_out('/Filter /FlateDecode'); 365 $this->_out('/Length1 '.$info['length1']); 366 if(isset($info['length2'])) 367 $this->_out('/Length2 '.$info['length2'].' /Length3 0'); 368 $this->_out('>>'); 369 $f=fopen($file,'rb'); 370 $this->_putstream(fread($f,$size)); 371 fclose($f); 372 $this->_out('endobj'); 373 } 374 set_magic_quotes_runtime($mqr); 375 foreach($this->fonts as $k=>$font) 376 { 377 //Font objects 378 $this->_newobj(); 379 $this->fonts[$k]['n']=$this->n; 380 $this->_out('<</Type /Font'); 381 if($font['type']=='Type0') 382 $this->_putType0($font); 383 else 384 { 385 $name=$font['name']; 386 $this->_out('/BaseFont /'.$name); 387 if($font['type']=='core') 388 { 389 //Standard font 390 $this->_out('/Subtype /Type1'); 391 if($name!='Symbol' and $name!='ZapfDingbats') 392 $this->_out('/Encoding /WinAnsiEncoding'); 393 } 394 else 395 { 396 //Additional font 397 $this->_out('/Subtype /'.$font['type']); 398 $this->_out('/FirstChar 32'); 399 $this->_out('/LastChar 255'); 400 $this->_out('/Widths '.($this->n+1).' 0 R'); 401 $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); 402 if($font['enc']) 403 { 404 if(isset($font['diff'])) 405 $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); 406 else 407 $this->_out('/Encoding /WinAnsiEncoding'); 408 } 409 } 410 $this->_out('>>'); 411 $this->_out('endobj'); 412 if($font['type']!='core') 413 { 414 //Widths 415 $this->_newobj(); 416 $cw=&$font['cw']; 417 $s='['; 418 for($i=32;$i<=255;$i++) 419 $s.=$cw[chr($i)].' '; 420 $this->_out($s.']'); 421 $this->_out('endobj'); 422 //Descriptor 423 $this->_newobj(); 424 $s='<</Type /FontDescriptor /FontName /'.$name; 425 foreach($font['desc'] as $k=>$v) 426 $s.=' /'.$k.' '.$v; 427 $file=$font['file']; 428 if($file) 429 $s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; 430 $this->_out($s.'>>'); 431 $this->_out('endobj'); 432 } 433 } 434 } 435 435 } 436 436 437 437 function _putType0($font) 438 438 { 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 439 //Type0 440 $this->_out('/Subtype /Type0'); 441 $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); 442 $this->_out('/Encoding /'.$font['CMap']); 443 $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); 444 $this->_out('>>'); 445 $this->_out('endobj'); 446 //CIDFont 447 $this->_newobj(); 448 $this->_out('<</Type /Font'); 449 $this->_out('/Subtype /CIDFontType0'); 450 $this->_out('/BaseFont /'.$font['name']); 451 $this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('.$font['registry']['ordering'].') /Supplement '.$font['registry']['supplement'].'>>'); 452 $this->_out('/FontDescriptor '.($this->n+1).' 0 R'); 453 $W='/W [1 ['; 454 foreach($font['cw'] as $w) 455 $W.=$w.' '; 456 $this->_out($W.'] 231 325 500 631 [500] 326 389 500]'); 457 $this->_out('>>'); 458 $this->_out('endobj'); 459 //Font descriptor 460 $this->_newobj(); 461 $this->_out('<</Type /FontDescriptor'); 462 $this->_out('/FontName /'.$font['name']); 463 $this->_out('/Flags 6'); 464 $this->_out('/FontBBox [0 -200 1000 900]'); 465 $this->_out('/ItalicAngle 0'); 466 $this->_out('/Ascent 800'); 467 $this->_out('/Descent -200'); 468 $this->_out('/CapHeight 800'); 469 $this->_out('/StemV 60'); 470 $this->_out('>>'); 471 $this->_out('endobj'); 472 472 } 473 473 … … 504 504 foreach($data as $row) 505 505 { 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 506 $h = 4; 507 $i = 0; 508 $this->Cell(5, $h, '', 0, 0, '', 0, ''); 509 foreach($row as $col) { 510 if($i > 3) { $i = 0; } 511 if ($i != 0) { 512 //$this->MultiCell($w[$i],$h,number_format($col),1,'R',$fill, 0); 513 $this->MultiCell($w[$i],$h,$col,1,'R',$fill, 0); 514 } else { 515 $this->MultiCell($w[$i],$h,$col,1,'L',$fill, 0); 516 } 517 $h = $this->rise_h; 518 $i++; 519 } 520 $this->Ln(); 521 521 $fill=!$fill; 522 522 … … 528 528 function Footer() 529 529 { 530 // ²¼Ã¼¤«¤é1.5 cm ¤Ë°Üư530 //下端から1.5 cm に移動 531 531 $this->SetY(-15); 532 // ¥Õ¥©¥ó¥È¤òÀßÄê¡£Arial italic 8532 //フォントを設定。 Arial italic 8 533 533 $this->SetFont('Arial','I',8); 534 // ¸½ºß¤Î¥Ú¡¼¥¸ÈÖ¹æ¤ÈÁí¥Ú¡¼¥¸¿ô¤ò½ÐÎÏ534 //現在のページ番号と総ページ数を出力 535 535 $this->Cell(0,10,''.$this->PageNo().' / {nb}',0,0,'C'); 536 536 }
Note: See TracChangeset
for help on using the changeset viewer.