Changeset 21826 for branches/version-2_12-dev/data
- Timestamp:
- 2012/05/14 00:32:52 (12 years ago)
- Location:
- branches/version-2_12-dev/data
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/SC_Fpdf.php
r21767 r21826 22 22 */ 23 23 24 /* ----------------------------------------------------------------------25 * [名称] SC_Fpdf26 * [概要] pdfファイルを表示する。27 * ----------------------------------------------------------------------24 /** 25 * PDF 納品書を出力する 26 * 27 * TODO ページクラスとすべき要素を多々含んでいるように感じる。 28 28 */ 29 29 30 require DATA_REALDIR . 'module/fpdf/fpdf.php';31 require DATA_REALDIR . 'module/fpdi/japanese.php';32 30 define('PDF_TEMPLATE_REALDIR', TEMPLATE_ADMIN_REALDIR . 'pdf/'); 33 31 34 class SC_Fpdf extends PDF_Japanese{32 class SC_Fpdf extends SC_Helper_FPDI { 35 33 function __construct($download, $title, $tpl_pdf = 'nouhinsyo1.pdf') { 36 34 $this->FPDF(); … … 44 42 $this->width_cell = array(110.3,12,21.7,24.5); 45 43 46 $this->label_cell[] = $this->lfConvSjis('商品名 / 商品コード / [ 規格 ]');47 $this->label_cell[] = $this->lfConvSjis('数量');48 $this->label_cell[] = $this->lfConvSjis('単価');49 $this->label_cell[] = $this->lfConvSjis('金額(税込)');44 $this->label_cell[] = '商品名 / 商品コード / [ 規格 ]'; 45 $this->label_cell[] = '数量'; 46 $this->label_cell[] = '単価'; 47 $this->label_cell[] = '金額(税込)'; 50 48 51 49 $this->arrMessage = array( … … 54 52 'ご確認くださいますよう、お願いいたします。' 55 53 ); 56 57 $this->lfAddGothicFont();58 54 59 55 // SJISフォント … … 163 159 164 160 $this->SetFont('Gothic', 'B', 15); 165 $this->Cell(0, 10, $this-> lfConvSjis($this->tpl_title), 0, 2, 'C', 0, ''); //文書タイトル(納品書・請求書)161 $this->Cell(0, 10, $this->tpl_title, 0, 2, 'C', 0, ''); //文書タイトル(納品書・請求書) 166 162 $this->Cell(0, 66, '', 0, 2, 'R', 0, ''); 167 163 $this->Cell(5, 0, '', 0, 0, 'R', 0, ''); 168 164 $this->SetFont('SJIS', 'B', 15); 169 $this->Cell(67, 8, $this->lfConvSjis(number_format($this->arrDisp['payment_total']).' 円'), 0, 2, 'R', 0, '');165 $this->Cell(67, 8, number_format($this->arrDisp['payment_total']).' 円', 0, 2, 'R', 0, ''); 170 166 $this->Cell(0, 45, '', 0, 2, '', 0, ''); 171 167 172 168 $this->SetFont('SJIS', '', 8); 173 169 174 $monetary_unit = $this->lfConvSjis('円');175 $point_unit = $this->lfConvSjis('Pt');170 $monetary_unit = '円'; 171 $point_unit = 'Pt'; 176 172 177 173 // 購入商品情報 … … 187 183 $data[2] = $data[0] * $data[1]; 188 184 189 $arrOrder[$i][0] = $this-> lfConvSjis($this->arrDisp['product_name'][$i].' / ');190 $arrOrder[$i][0] .= $this-> lfConvSjis($this->arrDisp['product_code'][$i].' / ');185 $arrOrder[$i][0] = $this->arrDisp['product_name'][$i].' / '; 186 $arrOrder[$i][0] .= $this->arrDisp['product_code'][$i].' / '; 191 187 if ($this->arrDisp['classcategory_name1'][$i]) { 192 $arrOrder[$i][0] .= $this->lfConvSjis(' [ '.$this->arrDisp['classcategory_name1'][$i]);188 $arrOrder[$i][0] .= ' [ '.$this->arrDisp['classcategory_name1'][$i]; 193 189 if ($this->arrDisp['classcategory_name2'][$i] == '') { 194 190 $arrOrder[$i][0] .= ' ]'; 195 191 } else { 196 $arrOrder[$i][0] .= $this->lfConvSjis(' * '.$this->arrDisp['classcategory_name2'][$i].' ]');192 $arrOrder[$i][0] .= ' * '.$this->arrDisp['classcategory_name2'][$i].' ]'; 197 193 } 198 194 } … … 211 207 $arrOrder[$i][0] = ''; 212 208 $arrOrder[$i][1] = ''; 213 $arrOrder[$i][2] = $this->lfConvSjis('商品合計');209 $arrOrder[$i][2] = '商品合計'; 214 210 $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit; 215 211 … … 217 213 $arrOrder[$i][0] = ''; 218 214 $arrOrder[$i][1] = ''; 219 $arrOrder[$i][2] = $this->lfConvSjis('送料');215 $arrOrder[$i][2] = '送料'; 220 216 $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit; 221 217 … … 223 219 $arrOrder[$i][0] = ''; 224 220 $arrOrder[$i][1] = ''; 225 $arrOrder[$i][2] = $this->lfConvSjis('手数料');221 $arrOrder[$i][2] = '手数料'; 226 222 $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit; 227 223 … … 229 225 $arrOrder[$i][0] = ''; 230 226 $arrOrder[$i][1] = ''; 231 $arrOrder[$i][2] = $this->lfConvSjis('値引き');227 $arrOrder[$i][2] = '値引き'; 232 228 $arrOrder[$i][3] = '- '.number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit; 233 229 … … 235 231 $arrOrder[$i][0] = ''; 236 232 $arrOrder[$i][1] = ''; 237 $arrOrder[$i][2] = $this->lfConvSjis('請求金額');233 $arrOrder[$i][2] = '請求金額'; 238 234 $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit; 239 235 … … 249 245 $arrOrder[$i][0] = ''; 250 246 $arrOrder[$i][1] = ''; 251 $arrOrder[$i][2] = $this->lfConvSjis('利用ポイント');247 $arrOrder[$i][2] = '利用ポイント'; 252 248 $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit; 253 249 … … 255 251 $arrOrder[$i][0] = ''; 256 252 $arrOrder[$i][1] = ''; 257 $arrOrder[$i][2] = $this->lfConvSjis('加算ポイント');253 $arrOrder[$i][2] = '加算ポイント'; 258 254 $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit; 259 255 } … … 265 261 $this->Cell(0, 10, '', 0, 1, 'C', 0, ''); 266 262 $this->SetFont('Gothic', 'B', 9); 267 $this->MultiCell(0, 6, $this->lfConvSjis('< 備 考 >'), 'T', 2, 'L', 0, ''); //備考263 $this->MultiCell(0, 6, '< 備 考 >', 'T', 2, 'L', 0, ''); //備考 268 264 $this->Ln(); 269 265 $this->SetFont('SJIS', '', 8); 270 $this->MultiCell(0, 4, $this-> lfConvSjis($this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3']), '', 2, 'L', 0, ''); //備考266 $this->MultiCell(0, 4, $this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3'], '', 2, 'L', 0, ''); //備考 271 267 } 272 268 … … 296 292 297 293 $this->SetFont('', $style, $size); 298 $this->Text($x, $y, $t his->lfConvSjis($text));294 $this->Text($x, $y, $text); 299 295 300 296 // 復元 … … 335 331 return $arrRet; 336 332 } 337 338 // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJIS-winのみ339 function lfConvSjis($conv_str) {340 return mb_convert_encoding($conv_str, 'SJIS-win', CHAR_CODE);341 }342 343 /**344 * ゴシックフォントを定義345 *346 * @return void347 */348 function lfAddGothicFont() {349 $cw = $GLOBALS['SJIS_widths'];350 $c_map = '90msp-RKSJ-H';351 $registry = array('ordering'=>'Japan1','supplement'=>2);352 $this->AddCIDFonts('Gothic', 'KozGoPro-Medium-Acro,MS-PGothic,Osaka', $cw, $c_map, $registry);353 }354 355 /**356 * フッター357 *358 * 現状の PDF_Japanese#Footer の動作によって、生成される PDF がエラーとなるケースがあり、359 * そのエラーを抑える意図。360 * @return void361 */362 function Footer() {363 }364 333 } -
branches/version-2_12-dev/data/class/helper/SC_Helper_FPDI.php
r21814 r21826 1 1 <?php 2 2 require DATA_REALDIR . 'module/fpdf/fpdf.php'; 3 require DATA_REALDIR . 'module/fpdi/fpdi.php'; 4 5 class SC_Helper_FPDI extends FPDI { 6 public static $SJIS_widths = array( 7 ' ' => 278, '!' => 299, '"' => 353, '#' => 614, '$' => 614, '%' => 721, '&' => 735, '\'' => 216, 8 '(' => 323, ')' => 323, '*' => 449, '+' => 529, ',' => 219, '-' => 306, '.' => 219, '/' => 453, '0' => 614, '1' => 614, 9 '2' => 614, '3' => 614, '4' => 614, '5' => 614, '6' => 614, '7' => 614, '8' => 614, '9' => 614, ':' => 219, ';' => 219, 10 '<' => 529, '=' => 529, '>' => 529, '?' => 486, '@' => 744, 'A' => 646, 'B' => 604, 'C' => 617, 'D' => 681, 'E' => 567, 11 'F' => 537, 'G' => 647, 'H' => 738, 'I' => 320, 'J' => 433, 'K' => 637, 'L' => 566, 'M' => 904, 'N' => 710, 'O' => 716, 12 'P' => 605, 'Q' => 716, 'R' => 623, 'S' => 517, 'T' => 601, 'U' => 690, 'V' => 668, 'W' => 990, 'X' => 681, 'Y' => 634, 13 'Z' => 578, '[' => 316, '\\' => 614, ']' => 316, '^' => 529, '_' => 500, '`' => 387, 'a' => 509, 'b' => 566, 'c' => 478, 14 'd' => 565, 'e' => 503, 'f' => 337, 'g' => 549, 'h' => 580, 'i' => 275, 'j' => 266, 'k' => 544, 'l' => 276, 'm' => 854, 15 'n' => 579, 'o' => 550, 'p' => 578, 'q' => 566, 'r' => 410, 's' => 444, 't' => 340, 'u' => 575, 'v' => 512, 'w' => 760, 16 'x' => 503, 'y' => 529, 'z' => 453, '{' => 326, '|' => 380, '}' => 326, '~' => 387, 17 ); 18 19 function AddCIDFont($family, $style, $name, $cw, $CMap, $registry) { 20 $fontkey = strtolower($family).strtoupper($style); 21 if (isset($this->fonts[$fontkey])) { 22 $this->Error("CID font already added: $family $style"); 23 } 24 $i = count($this->fonts) + 1; 25 $this->fonts[$fontkey] = array( 26 'i' => $i, 27 'type' => 'Type0', 28 'name' => $name, 29 'up' => -120, 30 'ut' => 40, 31 'cw' => $cw, 32 'CMap' => $CMap, 33 'registry' => $registry, 34 ); 35 } 36 37 function AddCIDFonts($family, $name, $cw, $CMap, $registry) { 38 $this->AddCIDFont($family, '', $name, $cw, $CMap, $registry); 39 $this->AddCIDFont($family, 'B', $name . ',Bold', $cw, $CMap, $registry); 40 $this->AddCIDFont($family, 'I', $name . ',Italic', $cw, $CMap, $registry); 41 $this->AddCIDFont($family, 'BI', $name . ',BoldItalic', $cw, $CMap, $registry); 42 } 43 44 function AddSJISFont($family = 'SJIS') { 45 //Add SJIS font with proportional Latin 46 $name = 'KozMinPro-Regular-Acro'; 47 $cw = SC_Helper_FPDI_Ex::$SJIS_widths; 48 $CMap = '90msp-RKSJ-H'; 49 $registry = array('ordering' => 'Japan1', 'supplement' => 2); 50 $this->AddCIDFonts($family, $name, $cw, $CMap, $registry); 51 } 52 53 function AddSJIShwFont($family = 'SJIS-hw') { 54 //Add SJIS font with half-width Latin 55 $name = 'KozMinPro-Regular-Acro'; 56 for ($i = 32; $i <= 126; $i++) { 57 $cw[chr($i)] = 500; 58 } 59 $CMap = '90ms-RKSJ-H'; 60 $registry = array('ordering' => 'Japan1', 'supplement' => 2); 61 $this->AddCIDFonts($family, $name, $cw, $CMap, $registry); 62 } 63 64 function GetStringWidth($s) { 65 if ($this->CurrentFont['type']=='Type0') { 66 return $this->GetSJISStringWidth($s); 67 } else { 68 return parent::GetStringWidth($s); 69 } 70 } 71 72 function GetSJISStringWidth($s) { 73 //SJIS version of GetStringWidth() 74 $l = 0; 75 $cw =& $this->CurrentFont['cw']; 76 $nb = strlen($s); 77 $i = 0; 78 while ($i<$nb) { 79 $o = ord($s{$i}); 80 if ($o < 128) { 81 //ASCII 82 $l += $cw[$s{$i}]; 83 $i++; 84 } 85 elseif($o >= 161 && $o <= 223) { 86 //Half-width katakana 87 $l += 500; 88 $i++; 89 } 90 else { 91 //Full-width character 92 $l += 1000; 93 $i += 2; 94 } 95 } 96 return $l * $this->FontSize / 1000; 97 } 98 99 function MultiCell($w, $h, $txt, $border = 0, $align = 'L', $fill = 0, $ln = 2) { 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 } 105 } 106 107 function SJISMultiCell($w, $h, $txt, $border = 0, $align = 'L', $fill = 0, $ln = 2) { 108 //Output text with automatic or explicit line breaks 3 require DATA_REALDIR . 'module/fpdi/japanese.php'; 4 5 // japanese.php のバグ回避 6 $GLOBALS[SJIS_widths] = $SJIS_widths; 7 8 class SC_Helper_FPDI extends PDF_Japanese { 9 /** 10 * PDF_Japanese の明朝フォントに加えゴシックフォントを追加定義 11 * 12 * @return void 13 */ 14 function AddSJISFont() { 15 parent::AddSJISFont(); 16 $cw = $GLOBALS['SJIS_widths']; 17 $c_map = '90msp-RKSJ-H'; 18 $registry = array('ordering'=>'Japan1','supplement'=>2); 19 $this->AddCIDFonts('Gothic', 'KozGoPro-Medium-Acro,MS-PGothic,Osaka', $cw, $c_map, $registry); 20 } 21 22 /** 23 * FancyTable から利用するための SJISMultiCell 24 * 25 * PDF_Japanese#SJISMultiCell をベースにカスタマイズ。 26 */ 27 function SJISMultiCellForFancyTable($w, $h, $txt, $border = 0, $align = 'L', $fill = 0) { 28 $y = $this->y; 29 30 // ここで SJIS に変換する。そのため、このメソッドの中では、PDF_Japanese#Cell を直接呼ぶ。 31 $txt = $this->lfConvSjis($txt); 32 // Output text with automatic or explicit line breaks 109 33 $cw =& $this->CurrentFont['cw']; 110 34 if ($w == 0) { … … 138 62 $l = 0; 139 63 $nl = 1; 140 $ this->rise_h = 0; //³vZp64 $rise_h = $h; // 高さ計算用 141 65 142 66 while ($i < $nb) { 143 // Get next character67 // Get next character 144 68 $c = $s{$i}; 145 69 $o = ord($c); 146 70 if ($o == 10) { 147 // Explicit line break148 $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);71 // Explicit line break 72 parent::Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); 149 73 $i++; 150 74 $sep = -1; … … 152 76 $l = 0; 153 77 $nl++; 154 $ this->rise_h += $h; //³vZp78 $rise_h += $h; // 高さ計算用 155 79 if ($border && $nl == 2) { 156 80 $b=$b2; … … 159 83 } 160 84 if ($o < 128) { 161 // ASCII85 // ASCII 162 86 $l += $cw[$c]; 163 87 $n = 1; … … 167 91 } 168 92 elseif($o >= 161 && $o <= 223) { 169 // Half-width katakana93 // Half-width katakana 170 94 $l += 500; 171 95 $n = 1; … … 173 97 } 174 98 else { 175 // Full-width character99 // Full-width character 176 100 $l += 1000; 177 101 $n = 2; … … 179 103 } 180 104 if ($l > $wmax) { 181 // Automatic line break105 // Automatic line break 182 106 if ($sep == -1 || $i == $j) { 183 107 if ($i == $j) { 184 108 $i += $n; 185 109 } 186 $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);110 parent::Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); 187 111 } 188 112 else { 189 $this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill);113 parent::Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill); 190 114 $i = ($s[$sep] == ' ') ? $sep + 1 : $sep; 191 115 } 192 $ this->rise_h += $h; //³vZp116 $rise_h += $h; // 高さ計算用 193 117 $sep = -1; 194 118 $j = $i; … … 206 130 } 207 131 } 208 // Last chunk132 // Last chunk 209 133 if ($border && is_int(strpos($border, 'B'))) { 210 134 $b .= 'B'; 211 135 } 212 $this->Cell($w, $h, substr($s, $j, $i - $j), $b, $ln, $align, $fill); 213 $this->rise_h += $h; //ÁªÌ³ðvZ 214 //üsȵÝè©ÂA³ªKè̳ÈãÅ êÎY²ðÝèµÈ¨·B 215 if ($ln == 0 && $h < $this->rise_h) { 216 $this->y = $this->y - $this->rise_h + $h; 217 } 218 219 //$this->x = $this->lMargin; 220 } 221 222 function Write($h, $txt, $link = '') { 223 if ($this->CurrentFont['type'] == 'Type0') { 224 $this->SJISWrite($h, $txt, $link); 225 } 226 else { 227 parent::Write($h, $txt, $link); 228 } 229 } 230 231 function SJISWrite($h, $txt, $link) { 232 //SJIS version of Write() 233 $cw =& $this->CurrentFont['cw']; 234 $w = $this->w - $this->rMargin - $this->x; 235 $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; 236 $s = str_replace("\r", '', $txt); 237 $nb = strlen($s); 238 $sep = -1; 239 $i = 0; 240 $j = 0; 241 $l = 0; 242 $nl = 1; 243 while($i < $nb) { 244 //Get next character 245 $c = $s[$i]; 246 $o = ord($c); 247 if ($o == 10) { 248 //Explicit line break 249 $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); 250 $i++; 251 $sep = -1; 252 $j = $i; 253 $l = 0; 254 if ($nl == 1) { 255 //Go to left margin 256 $this->x = $this->lMargin; 257 $w = $this->w - $this->rMargin - $this->x; 258 $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; 259 } 260 $nl++; 261 continue; 262 } 263 if ($o < 128) { 264 //ASCII 265 $l += $cw[$c]; 266 $n = 1; 267 if ($o == 32) { 268 $sep = $i; 269 } 270 } 271 elseif($o >= 161 && $o <= 223) { 272 //Half-width katakana 273 $l += 500; 274 $n = 1; 275 $sep = $i; 276 } 277 else { 278 //Full-width character 279 $l += 1000; 280 $n = 2; 281 $sep = $i; 282 } 283 if ($l > $wmax) { 284 //Automatic line break 285 if ($sep == -1 || $i == $j) { 286 if ($this->x > $this->lMargin) { 287 //Move to next line 288 $this->x = $this->lMargin; 289 $this->y += $h; 290 $w = $this->w - $this->rMargin - $this->x; 291 $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; 292 $i += $n; 293 $nl++; 294 continue; 295 } 296 if($i == $j) 297 $i += $n; 298 $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); 299 } 300 else { 301 $this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', 0, $link); 302 $i = ($s[$sep] == ' ') ? $sep + 1 : $sep; 303 } 304 $sep =- 1; 305 $j = $i; 306 $l = 0; 307 if ($nl == 1) { 308 $this->x = $this->lMargin; 309 $w = $this->w - $this->rMargin - $this->x; 310 $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; 311 } 312 $nl++; 313 } 314 else { 315 $i += $n; 316 if ($o >= 128) { 317 $sep = $i; 318 } 319 } 320 } 321 //Last chunk 322 if ($i != $j) { 323 $this->Cell($l / 1000 * $this->FontSize, $h, substr($s, $j, $i - $j), 0, 0, '', 0, $link); 324 } 325 } 326 327 function _putfonts() { 328 $nf = $this->n; 329 foreach ($this->diffs as $diff) { 330 //Encodings 331 $this->_newobj(); 332 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); 333 $this->_out('endobj'); 334 } 335 $mqr = get_magic_quotes_runtime(); 336 set_magic_quotes_runtime(0); 337 foreach ($this->FontFiles as $file => $info) { 338 //Font file embedding 339 $this->_newobj(); 340 $this->FontFiles[$file]['n'] = $this->n; 341 if (defined('FPDF_FONTPATH')) { 342 $file = FPDF_FONTPATH . $file; 343 } 344 $size = filesize($file); 345 if (!$size) { 346 $this->Error('Font file not found'); 347 } 348 $this->_out('<</Length '.$size); 349 if (substr($file, -2) == '.z') { 350 $this->_out('/Filter /FlateDecode'); 351 } 352 $this->_out('/Length1 '.$info['length1']); 353 if (isset($info['length2'])) { 354 $this->_out('/Length2 '.$info['length2'].' /Length3 0'); 355 } 356 $this->_out('>>'); 357 $f = fopen($file, 'rb'); 358 $this->_putstream(fread($f, $size)); 359 fclose($f); 360 $this->_out('endobj'); 361 } 362 set_magic_quotes_runtime($mqr); 363 foreach ($this->fonts as $k => $font) { 364 //Font objects 365 $this->_newobj(); 366 $this->fonts[$k]['n'] = $this->n; 367 $this->_out('<</Type /Font'); 368 if ($font['type'] == 'Type0') { 369 $this->_putType0($font); 370 } else { 371 $name = $font['name']; 372 $this->_out('/BaseFont /'.$name); 373 if ($font['type'] == 'core') { 374 //Standard font 375 $this->_out('/Subtype /Type1'); 376 if ($name!='Symbol' && $name!='ZapfDingbats') { 377 $this->_out('/Encoding /WinAnsiEncoding'); 378 } 379 } 380 else { 381 //Additional font 382 $this->_out('/Subtype /'.$font['type']); 383 $this->_out('/FirstChar 32'); 384 $this->_out('/LastChar 255'); 385 $this->_out('/Widths '.($this->n+1).' 0 R'); 386 $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); 387 if ($font['enc']) { 388 if (isset($font['diff'])) { 389 $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); 390 } 391 else { 392 $this->_out('/Encoding /WinAnsiEncoding'); 393 } 394 } 395 } 396 $this->_out('>>'); 397 $this->_out('endobj'); 398 if ($font['type'] != 'core') { 399 //Widths 400 $this->_newobj(); 401 $cw =& $font['cw']; 402 $s = '['; 403 for ($i = 32; $i <= 255 ; $i++) { 404 $s .= $cw[chr($i)] . ' '; 405 } 406 $this->_out($s . ']'); 407 $this->_out('endobj'); 408 //Descriptor 409 $this->_newobj(); 410 $s = '<</Type /FontDescriptor /FontName /' . $name; 411 foreach ($font['desc'] as $k => $v) { 412 $s .= ' /' . $k . ' ' . $v; 413 } 414 $file = $font['file']; 415 if ($file) { 416 $s .= ' /FontFile' . ($font['type'] == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$file]['n'] . ' 0 R'; 417 } 418 $this->_out($s . '>>'); 419 $this->_out('endobj'); 420 } 421 } 422 } 423 } 424 425 function _putType0($font) { 426 //Type0 427 $this->_out('/Subtype /Type0'); 428 $this->_out('/BaseFont /' . $font['name'] . '-' . $font['CMap']); 429 $this->_out('/Encoding /' . $font['CMap']); 430 $this->_out('/DescendantFonts [' . ($this->n + 1) . ' 0 R]'); 431 $this->_out('>>'); 432 $this->_out('endobj'); 433 //CIDFont 434 $this->_newobj(); 435 $this->_out('<</Type /Font'); 436 $this->_out('/Subtype /CIDFontType0'); 437 $this->_out('/BaseFont /' . $font['name']); 438 $this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering (' . $font['registry']['ordering'] . ') /Supplement ' . $font['registry']['supplement'] . '>>'); 439 $this->_out('/FontDescriptor ' . ($this->n + 1) . ' 0 R'); 440 $W = '/W [1 ['; 441 foreach ($font['cw'] as $w) { 442 $W .= $w . ' '; 443 } 444 $this->_out($W . '] 231 325 500 631 [500] 326 389 500]'); 445 $this->_out('>>'); 446 $this->_out('endobj'); 447 //Font descriptor 448 $this->_newobj(); 449 $this->_out('<</Type /FontDescriptor'); 450 $this->_out('/FontName /' . $font['name']); 451 $this->_out('/Flags 6'); 452 $this->_out('/FontBBox [0 -200 1000 900]'); 453 $this->_out('/ItalicAngle 0'); 454 $this->_out('/Ascent 800'); 455 $this->_out('/Descent -200'); 456 $this->_out('/CapHeight 800'); 457 $this->_out('/StemV 60'); 458 $this->_out('>>'); 459 $this->_out('endobj'); 460 } 461 462 //Load data 463 function LoadData($file) { 464 //Read file lines 465 $lines = file($file); 466 $data = array(); 467 foreach ($lines as $line) 468 $data[] = explode(';', chop($line)); 469 return $data; 470 } 471 472 //Colored table 136 parent::Cell($w, $h, substr($s, $j, $i - $j), $b, 0, $align, $fill); 137 // メソッド内でY軸を増す操作を行う場合があるので戻す。 138 $this->y = $y; 139 140 return $rise_h; 141 } 142 143 /** 144 * Colored table 145 * 146 * FIXME: 後の列の高さが大きい場合、表示が乱れる。 147 */ 473 148 function FancyTable($header, $data, $w) { 474 // Colors, line width and bold font149 // Colors, line width and bold font 475 150 $this->SetFillColor(216, 216, 216); 476 151 $this->SetTextColor(0); … … 478 153 $this->SetLineWidth(.3); 479 154 $this->SetFont('', 'B'); 480 // Header155 // Header 481 156 for ($i = 0; $i < count($header); $i++) { 482 157 $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1); 483 158 } 484 159 $this->Ln(); 485 // Color and font restoration160 // Color and font restoration 486 161 $this->SetFillColor(235, 235, 235); 487 162 $this->SetTextColor(0); 488 163 $this->SetFont(''); 489 // Data164 // Data 490 165 $fill = 0; 491 166 foreach ($data as $row) { 492 167 $h = 4; 493 168 $i = 0; 169 $y = $this->y; 494 170 $this->Cell(5, $h, '', 0, 0, '', 0, ''); 495 171 foreach ($row as $col) { 496 if ($i > 3) { 497 $i = 0; 498 } 499 if ($i != 0) { 500 //$this->MultiCell($w[$i], $h, number_format($col), 1, 'R', $fill, 0); 501 $this->MultiCell($w[$i], $h, $col, 1, 'R', $fill, 0); 172 $this->y = $y; 173 // FIXME 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。 174 if ($i == 0) { 175 $align = 'L'; 502 176 } else { 503 $ this->MultiCell($w[$i], $h, $col, 1, 'L', $fill, 0);504 } 505 $h = $this-> rise_h;177 $align = 'R'; 178 } 179 $h = $this->SJISMultiCellForFancyTable($w[$i], $h, $col, 1, $align, $fill, 0); 506 180 $i++; 507 181 } 508 182 $this->Ln(); 509 $fill =! $fill; 510 183 $fill = !$fill; 511 184 } 512 185 $this->Cell(5, $h, '', 0, 0, '', 0, ''); 513 186 $this->Cell(array_sum($w), 0, '', 'T'); 514 } 515 516 function Footer() { 517 //º[©ç1.5 cm ÉÚ® 518 $this->SetY(-15); 519 //tHgðÝèB Arial italic 8 520 $this->SetFont('Arial', 'I', 8); 521 //»ÝÌy[WÔÆy[WðoÍ 522 #$this->Cell(0, 10, ''.$this->PageNo().' / {nb}', 0, 0, 'C'); 523 } 524 187 $this->SetFillColor(255); 188 } 189 190 function Text($x, $y, $txt) { 191 parent::Text($x, $y, $this->lfConvSjis($txt)); 192 } 193 194 function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') { 195 parent::Cell($w, $h, $this->lfConvSjis($txt), $border, $ln, $align, $fill, $link); 196 } 197 198 // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJIS-winのみ 199 function lfConvSjis($conv_str) { 200 return mb_convert_encoding($conv_str, 'SJIS-win', CHAR_CODE); 201 } 525 202 } -
branches/version-2_12-dev/data/module/fpdi/japanese.php
r20993 r21826 2 2 require('fpdi.php'); 3 3 4 $SJIS_widths =array(' '=>278,'!'=>299,'"'=>353,'#'=>614,'$'=>614,'%'=>721,'&'=>735,'\''=>216,5 6 7 8 9 10 11 12 13 4 $SJIS_widths = array(' '=>278,'!'=>299,'"'=>353,'#'=>614,'$'=>614,'%'=>721,'&'=>735,'\''=>216, 5 '('=>323,')'=>323,'*'=>449,'+'=>529,','=>219,'-'=>306,'.'=>219,'/'=>453,'0'=>614,'1'=>614, 6 '2'=>614,'3'=>614,'4'=>614,'5'=>614,'6'=>614,'7'=>614,'8'=>614,'9'=>614,':'=>219,';'=>219, 7 '<'=>529,'='=>529,'>'=>529,'?'=>486,'@'=>744,'A'=>646,'B'=>604,'C'=>617,'D'=>681,'E'=>567, 8 'F'=>537,'G'=>647,'H'=>738,'I'=>320,'J'=>433,'K'=>637,'L'=>566,'M'=>904,'N'=>710,'O'=>716, 9 'P'=>605,'Q'=>716,'R'=>623,'S'=>517,'T'=>601,'U'=>690,'V'=>668,'W'=>990,'X'=>681,'Y'=>634, 10 'Z'=>578,'['=>316,'\\'=>614,']'=>316,'^'=>529,'_'=>500,'`'=>387,'a'=>509,'b'=>566,'c'=>478, 11 'd'=>565,'e'=>503,'f'=>337,'g'=>549,'h'=>580,'i'=>275,'j'=>266,'k'=>544,'l'=>276,'m'=>854, 12 'n'=>579,'o'=>550,'p'=>578,'q'=>566,'r'=>410,'s'=>444,'t'=>340,'u'=>575,'v'=>512,'w'=>760, 13 'x'=>503,'y'=>529,'z'=>453,'{'=>326,'|'=>380,'}'=>326,'~'=>387); 14 14 15 15 class PDF_Japanese extends FPDI 16 16 { 17 function AddCIDFont($family, $style,$name,$cw,$CMap,$registry)18 { 19 20 21 22 23 24 } 25 26 function AddCIDFonts($family, $name,$cw,$CMap,$registry)27 { 28 29 30 31 17 function AddCIDFont($family, $style, $name, $cw, $CMap, $registry) 18 { 19 $fontkey=strtolower($family).strtoupper($style); 20 if(isset($this->fonts[$fontkey])) 21 $this->Error("CID font already added: $family $style"); 22 $i=count($this->fonts)+1; 23 $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>-120,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry); 24 } 25 26 function AddCIDFonts($family, $name, $cw, $CMap, $registry) 27 { 28 $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry); 29 $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry); 30 $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry); 31 $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry); 32 32 } 33 33 34 34 function AddSJISFont($family='SJIS') 35 35 { 36 //Add SJIS font with proportional Latin 37 $name='KozMinPro-Regular-Acro'; 38 //$name='Gothic'; // ÏX 39 $cw=$GLOBALS['SJIS_widths']; 40 $CMap='90msp-RKSJ-H'; 41 $registry=array('ordering'=>'Japan1','supplement'=>2); 42 $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); 36 // Add SJIS font with proportional Latin 37 $name='KozMinPro-Regular-Acro'; 38 $cw=$GLOBALS['SJIS_widths']; 39 $CMap='90msp-RKSJ-H'; 40 $registry=array('ordering'=>'Japan1','supplement'=>2); 41 $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); 43 42 } 44 43 45 44 function AddSJIShwFont($family='SJIS-hw') 46 45 { 47 //Add SJIS font with half-width Latin48 49 50 51 52 53 46 // Add SJIS font with half-width Latin 47 $name='KozMinPro-Regular-Acro'; 48 for($i=32;$i<=126;$i++) 49 $cw[chr($i)]=500; 50 $CMap='90ms-RKSJ-H'; 51 $registry=array('ordering'=>'Japan1','supplement'=>2); 52 $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); 54 53 } 55 54 56 55 function GetStringWidth($s) 57 56 { 58 59 60 61 57 if($this->CurrentFont['type']=='Type0') 58 return $this->GetSJISStringWidth($s); 59 else 60 return parent::GetStringWidth($s); 62 61 } 63 62 64 63 function GetSJISStringWidth($s) 65 64 { 66 //SJIS version of GetStringWidth() 67 $l=0; 68 $cw=&$this->CurrentFont['cw']; 69 $nb=strlen($s); 70 $i=0; 71 while($i<$nb) 72 { 73 $o=ord($s{$i}); 74 if($o<128) 75 { 76 //ASCII 77 $l+=$cw[$s{$i}]; 78 $i++; 79 } 80 elseif($o>=161 and $o<=223) 81 { 82 //Half-width katakana 83 $l+=500; 84 $i++; 85 } 86 else 87 { 88 //Full-width character 89 $l+=1000; 90 $i+=2; 91 } 92 } 93 return $l*$this->FontSize/1000; 94 } 95 96 function MultiCell($w,$h,$txt,$border=0,$align='L',$fill=0,$ln=2) 97 { 98 if($this->CurrentFont['type']=='Type0') 99 $this->SJISMultiCell($w,$h,$txt,$border,$align,$fill,$ln); 100 else 101 parent::MultiCell($w,$h,$txt,$border,$align,$fill,$ln); 102 } 103 104 function SJISMultiCell($w,$h,$txt,$border=0,$align='L',$fill=0,$ln=2) 105 { 106 //Output text with automatic or explicit line breaks 107 $cw=&$this->CurrentFont['cw']; 108 if($w==0) 109 $w=$this->w-$this->rMargin-$this->x; 110 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 111 $s=str_replace("\r",'',$txt); 112 $nb=strlen($s); 113 if($nb>0 and $s{$nb-1}=="\n") 114 $nb--; 115 $b=0; 116 if($border) 117 { 118 if($border==1) 119 { 120 $border='LTRB'; 121 $b='LRT'; 122 $b2='LR'; 123 } 124 else 125 { 126 $b2=''; 127 if(is_int(strpos($border,'L'))) 128 $b2.='L'; 129 if(is_int(strpos($border,'R'))) 130 $b2.='R'; 131 $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; 132 } 133 } 134 $sep=-1; 135 $i=0; 136 $j=0; 137 $l=0; 138 $nl=1; 139 $this->rise_h = 0; //³vZp 140 141 while($i<$nb) 142 { 143 //Get next character 144 $c=$s{$i}; 145 $o=ord($c); 146 if($o==10) 147 { 148 //Explicit line break 149 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 150 $i++; 151 $sep=-1; 152 $j=$i; 153 $l=0; 154 $nl++; 155 $this->rise_h += $h; //³vZp 156 if($border and $nl==2) 157 $b=$b2; 158 continue; 159 } 160 if($o<128) 161 { 162 //ASCII 163 $l+=$cw[$c]; 164 $n=1; 165 if($o==32) 166 $sep=$i; 167 } 168 elseif($o>=161 and $o<=223) 169 { 170 //Half-width katakana 171 $l+=500; 172 $n=1; 173 $sep=$i; 174 } 175 else 176 { 177 //Full-width character 178 $l+=1000; 179 $n=2; 180 $sep=$i; 181 } 182 if($l>$wmax) 183 { 184 //Automatic line break 185 if($sep==-1 or $i==$j) 186 { 187 if($i==$j) 188 $i+=$n; 189 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 190 } 191 else 192 { 193 $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 194 $i=($s[$sep]==' ') ? $sep+1 : $sep; 195 } 196 $this->rise_h += $h; //³vZp 197 $sep=-1; 198 $j=$i; 199 $l=0; 200 $nl++; 201 if($border and $nl==2) 202 $b=$b2; 203 } 204 else 205 { 206 $i+=$n; 207 if($o>=128) 208 $sep=$i; 209 } 210 } 211 //Last chunk 212 if($border and is_int(strpos($border,'B'))) 213 $b.='B'; 214 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,$ln,$align,$fill); 215 $this->rise_h += $h; //ÁªÌ³ðvZ 216 //üsȵÝè©ÂA³ªKè̳ÈãÅ êÎY²ðÝèµÈ¨·B 217 if($ln == 0 and $h < $this->rise_h) { 218 $this->y = $this->y - $this->rise_h + $h; 219 } 220 221 //$this->x=$this->lMargin; 222 } 223 224 function Write($h,$txt,$link='') 225 { 226 if($this->CurrentFont['type']=='Type0') 227 $this->SJISWrite($h,$txt,$link); 228 else 229 parent::Write($h,$txt,$link); 230 } 231 232 function SJISWrite($h,$txt,$link) 233 { 234 //SJIS version of Write() 235 $cw=&$this->CurrentFont['cw']; 236 $w=$this->w-$this->rMargin-$this->x; 237 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 238 $s=str_replace("\r",'',$txt); 239 $nb=strlen($s); 240 $sep=-1; 241 $i=0; 242 $j=0; 243 $l=0; 244 $nl=1; 245 while($i<$nb) 246 { 247 //Get next character 248 $c=$s{$i}; 249 $o=ord($c); 250 if($o==10) 251 { 252 //Explicit line break 253 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 254 $i++; 255 $sep=-1; 256 $j=$i; 257 $l=0; 258 if($nl==1) 259 { 260 //Go to left margin 261 $this->x=$this->lMargin; 262 $w=$this->w-$this->rMargin-$this->x; 263 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 264 } 265 $nl++; 266 continue; 267 } 268 if($o<128) 269 { 270 //ASCII 271 $l+=$cw[$c]; 272 $n=1; 273 if($o==32) 274 $sep=$i; 275 } 276 elseif($o>=161 and $o<=223) 277 { 278 //Half-width katakana 279 $l+=500; 280 $n=1; 281 $sep=$i; 282 } 283 else 284 { 285 //Full-width character 286 $l+=1000; 287 $n=2; 288 $sep=$i; 289 } 290 if($l>$wmax) 291 { 292 //Automatic line break 293 if($sep==-1 or $i==$j) 294 { 295 if($this->x>$this->lMargin) 296 { 297 //Move to next line 298 $this->x=$this->lMargin; 299 $this->y+=$h; 300 $w=$this->w-$this->rMargin-$this->x; 301 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 302 $i+=$n; 303 $nl++; 304 continue; 305 } 306 if($i==$j) 307 $i+=$n; 308 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 309 } 310 else 311 { 312 $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); 313 $i=($s[$sep]==' ') ? $sep+1 : $sep; 314 } 315 $sep=-1; 316 $j=$i; 317 $l=0; 318 if($nl==1) 319 { 320 $this->x=$this->lMargin; 321 $w=$this->w-$this->rMargin-$this->x; 322 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 323 } 324 $nl++; 325 } 326 else 327 { 328 $i+=$n; 329 if($o>=128) 330 $sep=$i; 331 } 332 } 333 //Last chunk 334 if($i!=$j) 335 $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link); 336 } 337 338 function _putfonts() 339 { 340 $nf=$this->n; 341 foreach($this->diffs as $diff) 342 { 343 //Encodings 344 $this->_newobj(); 345 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); 346 $this->_out('endobj'); 347 } 348 $mqr=get_magic_quotes_runtime(); 349 set_magic_quotes_runtime(0); 350 foreach($this->FontFiles as $file=>$info) 351 { 352 //Font file embedding 353 $this->_newobj(); 354 $this->FontFiles[$file]['n']=$this->n; 355 if(defined('FPDF_FONTPATH')) 356 $file=FPDF_FONTPATH.$file; 357 $size=filesize($file); 358 if(!$size) 359 $this->Error('Font file not found'); 360 $this->_out('<</Length '.$size); 361 if(substr($file,-2)=='.z') 362 $this->_out('/Filter /FlateDecode'); 363 $this->_out('/Length1 '.$info['length1']); 364 if(isset($info['length2'])) 365 $this->_out('/Length2 '.$info['length2'].' /Length3 0'); 366 $this->_out('>>'); 367 $f=fopen($file,'rb'); 368 $this->_putstream(fread($f,$size)); 369 fclose($f); 370 $this->_out('endobj'); 371 } 372 set_magic_quotes_runtime($mqr); 373 foreach($this->fonts as $k=>$font) 374 { 375 //Font objects 376 $this->_newobj(); 377 $this->fonts[$k]['n']=$this->n; 378 $this->_out('<</Type /Font'); 379 if($font['type']=='Type0') 380 $this->_putType0($font); 381 else 382 { 383 $name=$font['name']; 384 $this->_out('/BaseFont /'.$name); 385 if($font['type']=='core') 386 { 387 //Standard font 388 $this->_out('/Subtype /Type1'); 389 if($name!='Symbol' and $name!='ZapfDingbats') 390 $this->_out('/Encoding /WinAnsiEncoding'); 391 } 392 else 393 { 394 //Additional font 395 $this->_out('/Subtype /'.$font['type']); 396 $this->_out('/FirstChar 32'); 397 $this->_out('/LastChar 255'); 398 $this->_out('/Widths '.($this->n+1).' 0 R'); 399 $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); 400 if($font['enc']) 401 { 402 if(isset($font['diff'])) 403 $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); 404 else 405 $this->_out('/Encoding /WinAnsiEncoding'); 406 } 407 } 408 $this->_out('>>'); 409 $this->_out('endobj'); 410 if($font['type']!='core') 411 { 412 //Widths 413 $this->_newobj(); 414 $cw=&$font['cw']; 415 $s='['; 416 for($i=32;$i<=255;$i++) 417 $s.=$cw[chr($i)].' '; 418 $this->_out($s.']'); 419 $this->_out('endobj'); 420 //Descriptor 421 $this->_newobj(); 422 $s='<</Type /FontDescriptor /FontName /'.$name; 423 foreach($font['desc'] as $k=>$v) 424 $s.=' /'.$k.' '.$v; 425 $file=$font['file']; 426 if($file) 427 $s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; 428 $this->_out($s.'>>'); 429 $this->_out('endobj'); 430 } 431 } 432 } 65 // SJIS version of GetStringWidth() 66 $l=0; 67 $cw=&$this->CurrentFont['cw']; 68 $nb=strlen($s); 69 $i=0; 70 while($i<$nb) 71 { 72 $o=ord($s[$i]); 73 if($o<128) 74 { 75 // ASCII 76 $l+=$cw[$s[$i]]; 77 $i++; 78 } 79 elseif($o>=161 && $o<=223) 80 { 81 // Half-width katakana 82 $l+=500; 83 $i++; 84 } 85 else 86 { 87 // Full-width character 88 $l+=1000; 89 $i+=2; 90 } 91 } 92 return $l*$this->FontSize/1000; 93 } 94 95 function MultiCell($w, $h, $txt, $border=0, $align='L', $fill=false) 96 { 97 if($this->CurrentFont['type']=='Type0') 98 $this->SJISMultiCell($w,$h,$txt,$border,$align,$fill); 99 else 100 parent::MultiCell($w,$h,$txt,$border,$align,$fill); 101 } 102 103 function SJISMultiCell($w, $h, $txt, $border=0, $align='L', $fill=false) 104 { 105 // Output text with automatic or explicit line breaks 106 $cw=&$this->CurrentFont['cw']; 107 if($w==0) 108 $w=$this->w-$this->rMargin-$this->x; 109 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 110 $s=str_replace("\r",'',$txt); 111 $nb=strlen($s); 112 if($nb>0 && $s[$nb-1]=="\n") 113 $nb--; 114 $b=0; 115 if($border) 116 { 117 if($border==1) 118 { 119 $border='LTRB'; 120 $b='LRT'; 121 $b2='LR'; 122 } 123 else 124 { 125 $b2=''; 126 if(is_int(strpos($border,'L'))) 127 $b2.='L'; 128 if(is_int(strpos($border,'R'))) 129 $b2.='R'; 130 $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; 131 } 132 } 133 $sep=-1; 134 $i=0; 135 $j=0; 136 $l=0; 137 $nl=1; 138 while($i<$nb) 139 { 140 // Get next character 141 $c=$s[$i]; 142 $o=ord($c); 143 if($o==10) 144 { 145 // Explicit line break 146 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 147 $i++; 148 $sep=-1; 149 $j=$i; 150 $l=0; 151 $nl++; 152 if($border && $nl==2) 153 $b=$b2; 154 continue; 155 } 156 if($o<128) 157 { 158 // ASCII 159 $l+=$cw[$c]; 160 $n=1; 161 if($o==32) 162 $sep=$i; 163 } 164 elseif($o>=161 && $o<=223) 165 { 166 // Half-width katakana 167 $l+=500; 168 $n=1; 169 $sep=$i; 170 } 171 else 172 { 173 // Full-width character 174 $l+=1000; 175 $n=2; 176 $sep=$i; 177 } 178 if($l>$wmax) 179 { 180 // Automatic line break 181 if($sep==-1 || $i==$j) 182 { 183 if($i==$j) 184 $i+=$n; 185 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 186 } 187 else 188 { 189 $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 190 $i=($s[$sep]==' ') ? $sep+1 : $sep; 191 } 192 $sep=-1; 193 $j=$i; 194 $l=0; 195 $nl++; 196 if($border && $nl==2) 197 $b=$b2; 198 } 199 else 200 { 201 $i+=$n; 202 if($o>=128) 203 $sep=$i; 204 } 205 } 206 // Last chunk 207 if($border && is_int(strpos($border,'B'))) 208 $b.='B'; 209 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 210 $this->x=$this->lMargin; 211 } 212 213 function Write($h, $txt, $link='') 214 { 215 if($this->CurrentFont['type']=='Type0') 216 $this->SJISWrite($h,$txt,$link); 217 else 218 parent::Write($h,$txt,$link); 219 } 220 221 function SJISWrite($h, $txt, $link) 222 { 223 // SJIS version of Write() 224 $cw=&$this->CurrentFont['cw']; 225 $w=$this->w-$this->rMargin-$this->x; 226 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 227 $s=str_replace("\r",'',$txt); 228 $nb=strlen($s); 229 $sep=-1; 230 $i=0; 231 $j=0; 232 $l=0; 233 $nl=1; 234 while($i<$nb) 235 { 236 // Get next character 237 $c=$s[$i]; 238 $o=ord($c); 239 if($o==10) 240 { 241 // Explicit line break 242 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 243 $i++; 244 $sep=-1; 245 $j=$i; 246 $l=0; 247 if($nl==1) 248 { 249 // Go to left margin 250 $this->x=$this->lMargin; 251 $w=$this->w-$this->rMargin-$this->x; 252 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 253 } 254 $nl++; 255 continue; 256 } 257 if($o<128) 258 { 259 // ASCII 260 $l+=$cw[$c]; 261 $n=1; 262 if($o==32) 263 $sep=$i; 264 } 265 elseif($o>=161 && $o<=223) 266 { 267 // Half-width katakana 268 $l+=500; 269 $n=1; 270 $sep=$i; 271 } 272 else 273 { 274 // Full-width character 275 $l+=1000; 276 $n=2; 277 $sep=$i; 278 } 279 if($l>$wmax) 280 { 281 // Automatic line break 282 if($sep==-1 || $i==$j) 283 { 284 if($this->x>$this->lMargin) 285 { 286 // Move to next line 287 $this->x=$this->lMargin; 288 $this->y+=$h; 289 $w=$this->w-$this->rMargin-$this->x; 290 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 291 $i+=$n; 292 $nl++; 293 continue; 294 } 295 if($i==$j) 296 $i+=$n; 297 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 298 } 299 else 300 { 301 $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); 302 $i=($s[$sep]==' ') ? $sep+1 : $sep; 303 } 304 $sep=-1; 305 $j=$i; 306 $l=0; 307 if($nl==1) 308 { 309 $this->x=$this->lMargin; 310 $w=$this->w-$this->rMargin-$this->x; 311 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 312 } 313 $nl++; 314 } 315 else 316 { 317 $i+=$n; 318 if($o>=128) 319 $sep=$i; 320 } 321 } 322 // Last chunk 323 if($i!=$j) 324 $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link); 433 325 } 434 326 435 327 function _putType0($font) 436 328 { 437 //Type0 438 $this->_out('/Subtype /Type0'); 439 $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); 440 $this->_out('/Encoding /'.$font['CMap']); 441 $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); 442 $this->_out('>>'); 443 $this->_out('endobj'); 444 //CIDFont 445 $this->_newobj(); 446 $this->_out('<</Type /Font'); 447 $this->_out('/Subtype /CIDFontType0'); 448 $this->_out('/BaseFont /'.$font['name']); 449 $this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('.$font['registry']['ordering'].') /Supplement '.$font['registry']['supplement'].'>>'); 450 $this->_out('/FontDescriptor '.($this->n+1).' 0 R'); 451 $W='/W [1 ['; 452 foreach($font['cw'] as $w) 453 $W.=$w.' '; 454 $this->_out($W.'] 231 325 500 631 [500] 326 389 500]'); 455 $this->_out('>>'); 456 $this->_out('endobj'); 457 //Font descriptor 458 $this->_newobj(); 459 $this->_out('<</Type /FontDescriptor'); 460 $this->_out('/FontName /'.$font['name']); 461 $this->_out('/Flags 6'); 462 $this->_out('/FontBBox [0 -200 1000 900]'); 463 $this->_out('/ItalicAngle 0'); 464 $this->_out('/Ascent 800'); 465 $this->_out('/Descent -200'); 466 $this->_out('/CapHeight 800'); 467 $this->_out('/StemV 60'); 468 $this->_out('>>'); 469 $this->_out('endobj'); 470 } 471 472 //Load data 473 function LoadData($file) 474 { 475 //Read file lines 476 $lines=file($file); 477 $data=array(); 478 foreach($lines as $line) 479 $data[]=explode(';',chop($line)); 480 return $data; 481 } 482 483 //Colored table 484 function FancyTable($header,$data,$w) 485 { 486 //Colors, line width and bold font 487 $this->SetFillColor(216,216,216); 488 $this->SetTextColor(0); 489 $this->SetDrawColor(0,0,0); 490 $this->SetLineWidth(.3); 491 $this->SetFont('','B'); 492 //Header 493 for($i=0;$i<count($header);$i++) 494 $this->Cell($w[$i],7,$header[$i],1,0,'C',1); 495 $this->Ln(); 496 //Color and font restoration 497 $this->SetFillColor(235,235,235); 498 $this->SetTextColor(0); 499 $this->SetFont(''); 500 //Data 501 $fill=0; 502 foreach($data as $row) 503 { 504 $h = 4; 505 $i = 0; 506 $this->Cell(5, $h, '', 0, 0, '', 0, ''); 507 foreach($row as $col) { 508 if($i > 3) { $i = 0; } 509 if ($i != 0) { 510 //$this->MultiCell($w[$i],$h,number_format($col),1,'R',$fill, 0); 511 $this->MultiCell($w[$i],$h,$col,1,'R',$fill, 0); 512 } else { 513 $this->MultiCell($w[$i],$h,$col,1,'L',$fill, 0); 514 } 515 $h = $this->rise_h; 516 $i++; 517 } 518 $this->Ln(); 519 $fill=!$fill; 520 521 } 522 $this->Cell(5, $h, '', 0, 0, '', 0, ''); 523 $this->Cell(array_sum($w),0,'','T'); 524 } 525 526 function Footer() 527 { 528 //º[©ç1.5 cm ÉÚ® 529 $this->SetY(-15); 530 //tHgðÝèB Arial italic 8 531 $this->SetFont('Arial','I',8); 532 //»ÝÌy[WÔÆy[WðoÍ 533 #$this->Cell(0,10,''.$this->PageNo().' / {nb}',0,0,'C'); 534 } 535 329 // Type0 330 $this->_newobj(); 331 $this->_out('<</Type /Font'); 332 $this->_out('/Subtype /Type0'); 333 $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); 334 $this->_out('/Encoding /'.$font['CMap']); 335 $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); 336 $this->_out('>>'); 337 $this->_out('endobj'); 338 // CIDFont 339 $this->_newobj(); 340 $this->_out('<</Type /Font'); 341 $this->_out('/Subtype /CIDFontType0'); 342 $this->_out('/BaseFont /'.$font['name']); 343 $this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('.$font['registry']['ordering'].') /Supplement '.$font['registry']['supplement'].'>>'); 344 $this->_out('/FontDescriptor '.($this->n+1).' 0 R'); 345 $W='/W [1 ['; 346 foreach($font['cw'] as $w) 347 $W.=$w.' '; 348 $this->_out($W.'] 231 325 500 631 [500] 326 389 500]'); 349 $this->_out('>>'); 350 $this->_out('endobj'); 351 // Font descriptor 352 $this->_newobj(); 353 $this->_out('<</Type /FontDescriptor'); 354 $this->_out('/FontName /'.$font['name']); 355 $this->_out('/Flags 6'); 356 $this->_out('/FontBBox [0 -200 1000 900]'); 357 $this->_out('/ItalicAngle 0'); 358 $this->_out('/Ascent 800'); 359 $this->_out('/Descent -200'); 360 $this->_out('/CapHeight 800'); 361 $this->_out('/StemV 60'); 362 $this->_out('>>'); 363 $this->_out('endobj'); 364 } 536 365 } 537 366 ?>
Note: See TracChangeset
for help on using the changeset viewer.