- Timestamp:
- 2013/04/06 15:29:51 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/class/helper/SC_Helper_FPDI.php
r22567 r22778 6 6 $GLOBALS[SJIS_widths] = $SJIS_widths; 7 7 8 class SC_Helper_FPDI extends PDF_Japanese 8 class SC_Helper_FPDI extends PDF_Japanese 9 9 { 10 /** SJIS 変換を有効とするか */ 11 var $enable_conv_sjis = true; 12 10 13 /** 11 14 * PDF_Japanese の明朝フォントに加えゴシックフォントを追加定義 … … 22 25 } 23 26 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() 30 28 { 31 $ y = $this->y;29 $arrArg = func_get_args(); 32 30 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]); 68 33 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; 141 36 142 return $rise_h; 37 call_user_func_array(array(parent, 'SJISMultiCell'), $arrArg); 38 39 $this->enable_conv_sjis = $bak; 143 40 } 144 41 … … 150 47 function FancyTable($header, $data, $w) 151 48 { 49 $base_x = $this->x; 152 50 // Colors, line width and bold font 153 51 $this->SetFillColor(216, 216, 216); … … 166 64 $this->SetFont(''); 167 65 // Data 168 $fill = 0;66 $fill = false; 169 67 $h = 4; 170 68 foreach ($data as $row) { 69 $x = $base_x; 171 70 $h = 4; 172 71 $i = 0; 173 $this->Cell(5, $h, '', 0, 0, '', 0, ''); 72 // XXX この処理を消すと2ページ目以降でセルごとに改ページされる。 73 $this->Cell(0, $h, '', 0, 0, '', 0, ''); 174 74 foreach ($row as $col) { 75 // 列位置 76 $this->x = $x; 175 77 // FIXME 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。 176 78 if ($i == 0) { … … 179 81 $align = 'R'; 180 82 } 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]; 182 88 $i++; 183 89 } … … 185 91 $fill = !$fill; 186 92 } 187 $this->Cell(5, $h, '', 0, 0, '', 0, '');188 $this->Cell(array_sum($w), 0, '', 'T');189 93 $this->SetFillColor(255); 94 $this->x = $base_x; 190 95 } 191 96 … … 203 108 function lfConvSjis($conv_str) 204 109 { 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; 206 115 } 207 116 }
Note: See TracChangeset
for help on using the changeset viewer.