Changeset 22778


Ignore:
Timestamp:
2013/04/06 15:29:51 (11 years ago)
Author:
Seasoft
Message:

#2216 (PDF納品書 備考欄が過剰に折り返しされる)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13-dev/data/class/helper/SC_Helper_FPDI.php

    r22567 r22778  
    66$GLOBALS[SJIS_widths] = $SJIS_widths; 
    77 
    8 class SC_Helper_FPDI extends PDF_Japanese  
     8class SC_Helper_FPDI extends PDF_Japanese 
    99{ 
     10    /** SJIS 変換を有効とするか */ 
     11    var $enable_conv_sjis = true; 
     12 
    1013    /** 
    1114     * PDF_Japanese の明朝フォントに加えゴシックフォントを追加定義 
     
    2225    } 
    2326 
    24     /** 
    25      * FancyTable から利用するための SJISMultiCell 
    26      * 
    27      * PDF_Japanese#SJISMultiCell をベースにカスタマイズ。 
    28      */ 
    29     function SJISMultiCellForFancyTable($w, $h, $txt, $border = 0, $align = 'L', $fill = 0) 
     27    function SJISMultiCell() 
    3028    { 
    31         $y = $this->y; 
     29        $arrArg = func_get_args(); 
    3230 
    33         // ここで SJIS に変換する。そのため、このメソッドの中では、PDF_Japanese#Cell を直接呼ぶ。 
    34         $txt = $this->lfConvSjis($txt); 
    35         // Output text with automatic or explicit line breaks 
    36         $cw =& $this->CurrentFont['cw']; 
    37         if ($w == 0) { 
    38             $w = $this->w - $this->rMargin - $this->x; 
    39         } 
    40         $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; 
    41         $s = str_replace("\r", '', $txt); 
    42         $nb = strlen($s); 
    43         if ($nb > 0 && $s[$nb - 1] == "\n") { 
    44             $nb--; 
    45         } 
    46         $b = 0; 
    47         if ($border) { 
    48             if ($border == 1) { 
    49                 $border = 'LTRB'; 
    50                 $b = 'LRT'; 
    51                 $b2 = 'LR'; 
    52             } 
    53             else { 
    54                 $b2 = ''; 
    55                 if (is_int(strpos($border, 'L'))) 
    56                     $b2 .= 'L'; 
    57                 if (is_int(strpos($border, 'R'))) 
    58                     $b2 .= 'R'; 
    59                 $b = is_int(strpos($border, 'T')) ? $b2.'T' : $b2; 
    60             } 
    61         } 
    62         $sep =- 1; 
    63         $i = 0; 
    64         $j = 0; 
    65         $l = 0; 
    66         $nl = 1; 
    67         $rise_h = $h; // 高さ計算用 
     31        // $text 
     32        $arrArg[2] = $this->lfConvSjis($arrArg[2]); 
    6833 
    69         while ($i < $nb) { 
    70             // Get next character 
    71             $c = $s{$i}; 
    72             $o = ord($c); 
    73             if ($o == 10) { 
    74                 // Explicit line break 
    75                 parent::Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); 
    76                 $i++; 
    77                 $sep = -1; 
    78                 $j = $i; 
    79                 $l = 0; 
    80                 $nl++; 
    81                 $rise_h += $h; // 高さ計算用 
    82                 if ($border && $nl == 2) { 
    83                     $b=$b2; 
    84                 } 
    85                 continue; 
    86             } 
    87             if ($o < 128) { 
    88                 // ASCII 
    89                 $l += $cw[$c]; 
    90                 $n = 1; 
    91                 if ($o == 32) { 
    92                     $sep=$i; 
    93                 } 
    94             } elseif ($o >= 161 && $o <= 223) { 
    95                 // Half-width katakana 
    96                 $l += 500; 
    97                 $n = 1; 
    98                 $sep = $i; 
    99             } 
    100             else { 
    101                 // Full-width character 
    102                 $l += 1000; 
    103                 $n = 2; 
    104                 $sep = $i; 
    105             } 
    106             if ($l > $wmax) { 
    107                 // Automatic line break 
    108                 if ($sep == -1 || $i == $j) { 
    109                     if ($i == $j) { 
    110                         $i += $n; 
    111                     } 
    112                     parent::Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); 
    113                 } 
    114                 else { 
    115                     parent::Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill); 
    116                     $i = ($s[$sep] == ' ') ? $sep + 1 : $sep; 
    117                 } 
    118                 $rise_h += $h; // 高さ計算用 
    119                 $sep = -1; 
    120                 $j = $i; 
    121                 $l = 0; 
    122                 $nl++; 
    123                 if ($border && $nl == 2) { 
    124                     $b = $b2; 
    125                 } 
    126             } 
    127             else { 
    128                 $i += $n; 
    129                 if ($o >= 128) { 
    130                     $sep = $i; 
    131                 } 
    132             } 
    133         } 
    134         // Last chunk 
    135         if ($border && is_int(strpos($border, 'B'))) { 
    136             $b .= 'B'; 
    137         } 
    138         parent::Cell($w, $h, substr($s, $j, $i - $j), $b, 0, $align, $fill); 
    139         // メソッド内でY軸を増す操作を行う場合があるので戻す。 
    140         $this->y = $y; 
     34        $bak = $this->enable_conv_sjis; 
     35        $this->enable_conv_sjis = false; 
    14136 
    142         return $rise_h; 
     37        call_user_func_array(array(parent, 'SJISMultiCell'), $arrArg); 
     38 
     39        $this->enable_conv_sjis = $bak; 
    14340    } 
    14441 
     
    15047    function FancyTable($header, $data, $w) 
    15148    { 
     49        $base_x = $this->x; 
    15250        // Colors, line width and bold font 
    15351        $this->SetFillColor(216, 216, 216); 
     
    16664        $this->SetFont(''); 
    16765        // Data 
    168         $fill = 0; 
     66        $fill = false; 
    16967        $h = 4; 
    17068        foreach ($data as $row) { 
     69            $x = $base_x; 
    17170            $h = 4; 
    17271            $i = 0; 
    173             $this->Cell(5, $h, '', 0, 0, '', 0, ''); 
     72            // XXX この処理を消すと2ページ目以降でセルごとに改ページされる。 
     73            $this->Cell(0, $h, '', 0, 0, '', 0, ''); 
    17474            foreach ($row as $col) { 
     75                // 列位置 
     76                $this->x = $x; 
    17577                // FIXME 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。 
    17678                if ($i == 0) { 
     
    17981                    $align = 'R'; 
    18082                } 
    181                 $h = $this->SJISMultiCellForFancyTable($w[$i], $h, $col, 1, $align, $fill, 0); 
     83                $y_before = $this->y; 
     84                $h = $this->SJISMultiCell($w[$i], $h, $col, 1, $align, $fill, 0); 
     85                $h = $this->y - $y_before; 
     86                $this->y = $y_before; 
     87                $x += $w[$i]; 
    18288                $i++; 
    18389            } 
     
    18591            $fill = !$fill; 
    18692        } 
    187         $this->Cell(5, $h, '', 0, 0, '', 0, ''); 
    188         $this->Cell(array_sum($w), 0, '', 'T'); 
    18993        $this->SetFillColor(255); 
     94        $this->x = $base_x; 
    19095    } 
    19196 
     
    203108    function lfConvSjis($conv_str) 
    204109    { 
    205         return mb_convert_encoding($conv_str, 'SJIS-win', CHAR_CODE); 
     110        if ($this->enable_conv_sjis) { 
     111            $conv_str = mb_convert_encoding($conv_str, 'SJIS-win', CHAR_CODE); 
     112        } 
     113 
     114        return $conv_str; 
    206115    } 
    207116} 
Note: See TracChangeset for help on using the changeset viewer.