Ignore:
Timestamp:
2012/05/14 00:32:52 (12 years ago)
Author:
Seasoft
Message:

#1794 (data/module/fpdi/japanese.php のカスタマイズを分離する)
#1802 (PDF 納品書の備考欄に背景色が塗られる場合がある)

Location:
branches/version-2_12-dev/data/class
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/SC_Fpdf.php

    r21767 r21826  
    2222 */ 
    2323 
    24 /*---------------------------------------------------------------------- 
    25  * [名称] SC_Fpdf 
    26  * [概要] pdfファイルを表示する。 
    27  *---------------------------------------------------------------------- 
     24/** 
     25 * PDF 納品書を出力する 
     26 * 
     27 * TODO ページクラスとすべき要素を多々含んでいるように感じる。 
    2828 */ 
    2929 
    30 require DATA_REALDIR . 'module/fpdf/fpdf.php'; 
    31 require DATA_REALDIR . 'module/fpdi/japanese.php'; 
    3230define('PDF_TEMPLATE_REALDIR', TEMPLATE_ADMIN_REALDIR . 'pdf/'); 
    3331 
    34 class SC_Fpdf extends PDF_Japanese { 
     32class SC_Fpdf extends SC_Helper_FPDI { 
    3533    function __construct($download, $title, $tpl_pdf = 'nouhinsyo1.pdf') { 
    3634        $this->FPDF(); 
     
    4442        $this->width_cell = array(110.3,12,21.7,24.5); 
    4543 
    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[] = '金額(税込)'; 
    5048 
    5149        $this->arrMessage = array( 
     
    5452            'ご確認くださいますよう、お願いいたします。' 
    5553        ); 
    56  
    57         $this->lfAddGothicFont(); 
    5854 
    5955        // SJISフォント 
     
    163159 
    164160        $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, '');  //文書タイトル(納品書・請求書) 
    166162        $this->Cell(0, 66, '', 0, 2, 'R', 0, ''); 
    167163        $this->Cell(5, 0, '', 0, 0, 'R', 0, ''); 
    168164        $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, ''); 
    170166        $this->Cell(0, 45, '', 0, 2, '', 0, ''); 
    171167 
    172168        $this->SetFont('SJIS', '', 8); 
    173169 
    174         $monetary_unit = $this->lfConvSjis('円'); 
    175         $point_unit = $this->lfConvSjis('Pt'); 
     170        $monetary_unit = '円'; 
     171        $point_unit = 'Pt'; 
    176172 
    177173        // 購入商品情報 
     
    187183            $data[2] = $data[0] * $data[1]; 
    188184 
    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].' / '; 
    191187            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]; 
    193189                if ($this->arrDisp['classcategory_name2'][$i] == '') { 
    194190                    $arrOrder[$i][0] .= ' ]'; 
    195191                } else { 
    196                     $arrOrder[$i][0] .= $this->lfConvSjis(' * '.$this->arrDisp['classcategory_name2'][$i].' ]'); 
     192                    $arrOrder[$i][0] .= ' * '.$this->arrDisp['classcategory_name2'][$i].' ]'; 
    197193                } 
    198194            } 
     
    211207        $arrOrder[$i][0] = ''; 
    212208        $arrOrder[$i][1] = ''; 
    213         $arrOrder[$i][2] = $this->lfConvSjis('商品合計'); 
     209        $arrOrder[$i][2] = '商品合計'; 
    214210        $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit; 
    215211 
     
    217213        $arrOrder[$i][0] = ''; 
    218214        $arrOrder[$i][1] = ''; 
    219         $arrOrder[$i][2] = $this->lfConvSjis('送料'); 
     215        $arrOrder[$i][2] = '送料'; 
    220216        $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit; 
    221217 
     
    223219        $arrOrder[$i][0] = ''; 
    224220        $arrOrder[$i][1] = ''; 
    225         $arrOrder[$i][2] = $this->lfConvSjis('手数料'); 
     221        $arrOrder[$i][2] = '手数料'; 
    226222        $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit; 
    227223 
     
    229225        $arrOrder[$i][0] = ''; 
    230226        $arrOrder[$i][1] = ''; 
    231         $arrOrder[$i][2] = $this->lfConvSjis('値引き'); 
     227        $arrOrder[$i][2] = '値引き'; 
    232228        $arrOrder[$i][3] = '- '.number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit; 
    233229 
     
    235231        $arrOrder[$i][0] = ''; 
    236232        $arrOrder[$i][1] = ''; 
    237         $arrOrder[$i][2] = $this->lfConvSjis('請求金額'); 
     233        $arrOrder[$i][2] = '請求金額'; 
    238234        $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit; 
    239235 
     
    249245            $arrOrder[$i][0] = ''; 
    250246            $arrOrder[$i][1] = ''; 
    251             $arrOrder[$i][2] = $this->lfConvSjis('利用ポイント'); 
     247            $arrOrder[$i][2] = '利用ポイント'; 
    252248            $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit; 
    253249 
     
    255251            $arrOrder[$i][0] = ''; 
    256252            $arrOrder[$i][1] = ''; 
    257             $arrOrder[$i][2] = $this->lfConvSjis('加算ポイント'); 
     253            $arrOrder[$i][2] = '加算ポイント'; 
    258254            $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit; 
    259255        } 
     
    265261        $this->Cell(0, 10, '', 0, 1, 'C', 0, ''); 
    266262        $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, '');  //備考 
    268264        $this->Ln(); 
    269265        $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, '');  //備考 
    271267    } 
    272268 
     
    296292 
    297293        $this->SetFont('', $style, $size); 
    298         $this->Text($x, $y, $this->lfConvSjis($text)); 
     294        $this->Text($x, $y, $text); 
    299295 
    300296        // 復元 
     
    335331        return $arrRet; 
    336332    } 
    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 void 
    347      */ 
    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 void 
    361      */ 
    362     function Footer() { 
    363     } 
    364333} 
  • branches/version-2_12-dev/data/class/helper/SC_Helper_FPDI.php

    r21814 r21826  
    11<?php 
    22require 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 
     3require DATA_REALDIR . 'module/fpdi/japanese.php'; 
     4 
     5// japanese.php のバグ回避 
     6$GLOBALS[SJIS_widths] = $SJIS_widths; 
     7 
     8class 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 
    10933        $cw =& $this->CurrentFont['cw']; 
    11034        if ($w == 0) { 
     
    13862        $l = 0; 
    13963        $nl = 1; 
    140         $this->rise_h = 0; //‚‚³ŒvŽZ—p 
     64        $rise_h = $h; // 高さ計算用 
    14165 
    14266        while ($i < $nb) { 
    143             //Get next character 
     67            // Get next character 
    14468            $c = $s{$i}; 
    14569            $o = ord($c); 
    14670            if ($o == 10) { 
    147                 //Explicit line break 
    148                 $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); 
    14973                $i++; 
    15074                $sep = -1; 
     
    15276                $l = 0; 
    15377                $nl++; 
    154                 $this->rise_h += $h; //‚‚³ŒvŽZ—p 
     78                $rise_h += $h; // 高さ計算用 
    15579                if ($border && $nl == 2) { 
    15680                    $b=$b2; 
     
    15983            } 
    16084            if ($o < 128) { 
    161                 //ASCII 
     85                // ASCII 
    16286                $l += $cw[$c]; 
    16387                $n = 1; 
     
    16791            } 
    16892            elseif($o >= 161 && $o <= 223) { 
    169                 //Half-width katakana 
     93                // Half-width katakana 
    17094                $l += 500; 
    17195                $n = 1; 
     
    17397            } 
    17498            else { 
    175                 //Full-width character 
     99                // Full-width character 
    176100                $l += 1000; 
    177101                $n = 2; 
     
    179103            } 
    180104            if ($l > $wmax) { 
    181                 //Automatic line break 
     105                // Automatic line break 
    182106                if ($sep == -1 || $i == $j) { 
    183107                    if ($i == $j) { 
    184108                        $i += $n; 
    185109                    } 
    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); 
    187111                } 
    188112                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); 
    190114                    $i = ($s[$sep] == ' ') ? $sep + 1 : $sep; 
    191115                } 
    192                 $this->rise_h += $h; //‚‚³ŒvŽZ—p 
     116                $rise_h += $h; // 高さ計算用 
    193117                $sep = -1; 
    194118                $j = $i; 
     
    206130            } 
    207131        } 
    208         //Last chunk 
     132        // Last chunk 
    209133        if ($border && is_int(strpos($border, 'B'))) { 
    210134            $b .= 'B'; 
    211135        } 
    212         $this->Cell($w, $h, substr($s, $j, $i - $j), $b, $ln, $align, $fill); 
    213         $this->rise_h += $h; //‘‰Á•ª‚̍‚‚³‚ðŒvŽZ 
    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     */ 
    473148    function FancyTable($header, $data, $w) { 
    474         //Colors, line width and bold font 
     149        // Colors, line width and bold font 
    475150        $this->SetFillColor(216, 216, 216); 
    476151        $this->SetTextColor(0); 
     
    478153        $this->SetLineWidth(.3); 
    479154        $this->SetFont('', 'B'); 
    480         //Header 
     155        // Header 
    481156        for ($i = 0; $i < count($header); $i++) { 
    482157            $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1); 
    483158        } 
    484159        $this->Ln(); 
    485         //Color and font restoration 
     160        // Color and font restoration 
    486161        $this->SetFillColor(235, 235, 235); 
    487162        $this->SetTextColor(0); 
    488163        $this->SetFont(''); 
    489         //Data 
     164        // Data 
    490165        $fill = 0; 
    491166        foreach ($data as $row) { 
    492167            $h = 4; 
    493168            $i = 0; 
     169            $y = $this->y; 
    494170            $this->Cell(5, $h, '', 0, 0, '', 0, ''); 
    495171            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'; 
    502176                } 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); 
    506180                $i++; 
    507181            } 
    508182            $this->Ln(); 
    509             $fill =! $fill; 
    510  
     183            $fill = !$fill; 
    511184        } 
    512185        $this->Cell(5, $h, '', 0, 0, '', 0, ''); 
    513186        $this->Cell(array_sum($w), 0, '', 'T'); 
    514     } 
    515  
    516     function Footer() { 
    517         //‰º’[‚©‚ç1.5 cm ‚Ɉړ® 
    518         $this->SetY(-15); 
    519         //ƒtƒHƒ“ƒg‚ðÝ’è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    } 
    525202} 
Note: See TracChangeset for help on using the changeset viewer.