1 | <?php |
---|
2 | require DATA_REALDIR . 'module/fpdf/fpdf.php'; |
---|
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 | /** SJIS 変換を有効とするか */ |
---|
11 | public $enable_conv_sjis = true; |
---|
12 | |
---|
13 | /** |
---|
14 | * PDF_Japanese の明朝フォントに加えゴシックフォントを追加定義 |
---|
15 | * |
---|
16 | * @return void |
---|
17 | */ |
---|
18 | public function AddSJISFont() |
---|
19 | { |
---|
20 | parent::AddSJISFont(); |
---|
21 | $cw = $GLOBALS['SJIS_widths']; |
---|
22 | $c_map = '90msp-RKSJ-H'; |
---|
23 | $registry = array('ordering'=>'Japan1','supplement'=>2); |
---|
24 | $this->AddCIDFonts('Gothic', 'KozGoPro-Medium-Acro,MS-PGothic,Osaka', $cw, $c_map, $registry); |
---|
25 | } |
---|
26 | |
---|
27 | public function SJISMultiCell() |
---|
28 | { |
---|
29 | $arrArg = func_get_args(); |
---|
30 | |
---|
31 | // $text |
---|
32 | $arrArg[2] = $this->lfConvSjis($arrArg[2]); |
---|
33 | |
---|
34 | $bak = $this->enable_conv_sjis; |
---|
35 | $this->enable_conv_sjis = false; |
---|
36 | |
---|
37 | call_user_func_array(array(parent, 'SJISMultiCell'), $arrArg); |
---|
38 | |
---|
39 | $this->enable_conv_sjis = $bak; |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * Colored table |
---|
44 | * |
---|
45 | * FIXME: 後の列の高さが大きい場合、表示が乱れる。 |
---|
46 | */ |
---|
47 | public function FancyTable($header, $data, $w) |
---|
48 | { |
---|
49 | $base_x = $this->x; |
---|
50 | // Colors, line width and bold font |
---|
51 | $this->SetFillColor(216, 216, 216); |
---|
52 | $this->SetTextColor(0); |
---|
53 | $this->SetDrawColor(0, 0, 0); |
---|
54 | $this->SetLineWidth(.3); |
---|
55 | $this->SetFont('', 'B'); |
---|
56 | // Header |
---|
57 | for ($i = 0; $i < count($header); $i++) { |
---|
58 | $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1); |
---|
59 | } |
---|
60 | $this->Ln(); |
---|
61 | // Color and font restoration |
---|
62 | $this->SetFillColor(235, 235, 235); |
---|
63 | $this->SetTextColor(0); |
---|
64 | $this->SetFont(''); |
---|
65 | // Data |
---|
66 | $fill = false; |
---|
67 | $h = 4; |
---|
68 | foreach ($data as $row) { |
---|
69 | $x = $base_x; |
---|
70 | $h = 4; |
---|
71 | $i = 0; |
---|
72 | // XXX この処理を消すと2ページ目以降でセルごとに改ページされる。 |
---|
73 | $this->Cell(0, $h, '', 0, 0, '', 0, ''); |
---|
74 | foreach ($row as $col) { |
---|
75 | // 列位置 |
---|
76 | $this->x = $x; |
---|
77 | // FIXME 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。 |
---|
78 | if ($i == 0) { |
---|
79 | $align = 'L'; |
---|
80 | } else { |
---|
81 | $align = 'R'; |
---|
82 | } |
---|
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]; |
---|
88 | $i++; |
---|
89 | } |
---|
90 | $this->Ln(); |
---|
91 | $fill = !$fill; |
---|
92 | } |
---|
93 | $this->SetFillColor(255); |
---|
94 | $this->x = $base_x; |
---|
95 | } |
---|
96 | |
---|
97 | public function Text($x, $y, $txt) |
---|
98 | { |
---|
99 | parent::Text($x, $y, $this->lfConvSjis($txt)); |
---|
100 | } |
---|
101 | |
---|
102 | public function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') |
---|
103 | { |
---|
104 | parent::Cell($w, $h, $this->lfConvSjis($txt), $border, $ln, $align, $fill, $link); |
---|
105 | } |
---|
106 | |
---|
107 | // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJIS-winのみ |
---|
108 | public function lfConvSjis($conv_str) |
---|
109 | { |
---|
110 | if ($this->enable_conv_sjis) { |
---|
111 | $conv_str = mb_convert_encoding($conv_str, 'SJIS-win', CHAR_CODE); |
---|
112 | } |
---|
113 | |
---|
114 | return $conv_str; |
---|
115 | } |
---|
116 | } |
---|