1 | <?php |
||
11 | class TcpdfWrapper |
||
12 | { |
||
13 | private $__pdf; |
||
14 | private $__fonts = []; |
||
15 | private $__tcpdfFonts; |
||
16 | |||
17 | /** |
||
18 | * __construct |
||
19 | * |
||
20 | * @author hagiwara |
||
21 | */ |
||
22 | public function __construct() |
||
27 | |||
28 | /** |
||
29 | * setPrintHeader |
||
30 | * |
||
31 | * @param boolean $print 出力フラグ |
||
32 | * @author hagiwara |
||
33 | */ |
||
34 | public function setPrintHeader($print) |
||
38 | |||
39 | /** |
||
40 | * setPrintFooter |
||
41 | * |
||
42 | * @param boolean $print 出力フラグ |
||
43 | * @author hagiwara |
||
44 | */ |
||
45 | public function setPrintFooter($print) |
||
49 | |||
50 | /** |
||
51 | * setFont |
||
52 | * |
||
53 | * @param string $name フォント名 |
||
54 | * @param string $path フォントパス nullでデフォルトセット |
||
55 | * @author hagiwara |
||
56 | */ |
||
57 | public function setFont($name, $path) |
||
61 | |||
62 | /** |
||
63 | * addPage |
||
64 | * |
||
65 | * @param string $template テンプレートパス |
||
66 | * @param integer $templateIndex テンプレートページ |
||
67 | * @author hagiwara |
||
68 | */ |
||
69 | public function addPage($template, $templateIndex) |
||
83 | |||
84 | /** |
||
85 | * setVal |
||
86 | * |
||
87 | * @param string $text テキスト |
||
88 | * @param array $option オプション |
||
89 | * @author hagiwara |
||
90 | */ |
||
91 | public function setVal($text, $option) |
||
92 | { |
||
93 | $default_option = [ |
||
94 | 'w' => 0, |
||
95 | 'h' => 0, |
||
96 | 'border' => 0, |
||
97 | 'align' => '', |
||
98 | 'fill' => false, |
||
99 | 'link' => '', |
||
100 | 'x' => 0, |
||
101 | 'y' => 0, |
||
102 | 'color' => '000000', |
||
103 | 'font' => '', |
||
104 | 'size' => 11, |
||
105 | 'stretch' => 0, |
||
106 | 'auto_size' => false, |
||
107 | ]; |
||
108 | $option = array_merge($default_option ,$option); |
||
109 | |||
110 | // 自動で枠に収めるかどうかのチェック |
||
111 | if ($option['auto_size'] == true) { |
||
|
|||
112 | $fontDefaultWidth = $this->getStringWidth($text, $option['font'], '', $option['size']); |
||
113 | if ($fontDefaultWidth > $option['w']) { |
||
114 | $option['align'] ='J'; |
||
115 | $option['stretch'] =1; |
||
116 | } |
||
117 | } |
||
118 | |||
119 | // 書き込む文字列のフォントを指定 |
||
120 | $this->__pdf->SetFont($this->getFont($option['font']), '', $option['size']); |
||
121 | // 書き込む文字列の文字色を指定 |
||
122 | $concertColor = $this->colorCodeConvert($option['color']); |
||
123 | $this->__pdf->SetTextColor($concertColor['r'], $concertColor['g'], $concertColor['b']); |
||
124 | |||
125 | $this->__pdf->SetXY($option['x'], $option['y']); |
||
126 | // 文字列を書き込む |
||
127 | $this->__pdf->Cell($option['w'], $option['h'], $text, $option['border'], 0, $option['align'], $option['fill'], $option['link'], $option['stretch']); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * getFont |
||
132 | * |
||
133 | * @param string $font フォント名 |
||
134 | * @author hagiwara |
||
135 | */ |
||
136 | private function getFont($font) |
||
144 | |||
145 | /** |
||
146 | * setImage |
||
147 | * |
||
148 | * @param string $image 画像パス |
||
149 | * @param array $option オプション |
||
150 | * @author hagiwara |
||
151 | */ |
||
152 | public function setImage($image, $option) |
||
166 | |||
167 | |||
168 | /** |
||
169 | * colorCodeConvert |
||
170 | * |
||
171 | * @param string $color カラーコード(16進数) |
||
172 | * @author hagiwara |
||
173 | */ |
||
174 | private function colorCodeConvert($color) |
||
192 | |||
193 | /** |
||
194 | * getStringWidth |
||
195 | * |
||
196 | * @param string $text テキスト |
||
197 | * @param string $font フォント名 |
||
198 | * @param string $fontstyle フォントスタイル |
||
199 | * @param integer $fontsize サイズ |
||
200 | * @param bool $getarray 結果を1文字ずつ配列で返すか |
||
201 | * @author hagiwara |
||
202 | */ |
||
203 | public function getStringWidth($text, $font, $fontstyle, $fontsize, $getarray = false) { |
||
206 | |||
207 | /** |
||
208 | * write |
||
209 | * |
||
210 | * @param string $file 出力ファイル |
||
211 | * @author hagiwara |
||
212 | */ |
||
213 | public function write($file) |
||
221 | |||
222 | } |
||
223 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.