From 29914281e72586a3fa25ac08e61cb5990ecfdd89 Mon Sep 17 00:00:00 2001 From: takeuji <8424850+takeuji@users.noreply.github.com> Date: Wed, 31 Aug 2022 16:53:49 +0900 Subject: [PATCH] =?UTF-8?q?PDF=E3=81=AE=E7=BD=AB=E7=B7=9A=E3=81=AE?= =?UTF-8?q?=E9=AB=98=E3=81=95=E3=81=8C=E3=81=9D=E3=82=8D=E3=82=8F=E3=81=AA?= =?UTF-8?q?=E3=81=84=E4=B8=8D=E5=85=B7=E5=90=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/OrderPdfService.php | 44 +++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/Eccube/Service/OrderPdfService.php b/src/Eccube/Service/OrderPdfService.php index a9130c3d034..d0df4c0a85c 100644 --- a/src/Eccube/Service/OrderPdfService.php +++ b/src/Eccube/Service/OrderPdfService.php @@ -651,8 +651,6 @@ protected function lfText($x, $y, $text, $size = 0, $style = '') /** * Colored table. * - * TODO: 後の列の高さが大きい場合、表示が乱れる。 - * * @param array $header 出力するラベル名一覧 * @param array $data 出力するデータ * @param array $w 出力するセル幅一覧 @@ -687,18 +685,9 @@ protected function setFancyTable($header, $data, $w) $this->SetFont(''); // Data $fill = 0; - $h = 4; - foreach ($data as $row) { - // 行のの処理 + $writeRow = function($row, $cellHeight, $fill, $isBorder) use($w) { $i = 0; - $h = 4; - $this->Cell(5, $h, '', 0, 0, '', 0, ''); - if ((277 - $this->getY()) < ($h * 4)) { - $this->checkPageBreak($this->PageBreakTrigger + 1); - } - - // Cellの高さを保持 - $cellHeight = 0; + $h = 0; foreach ($row as $col) { // 列の処理 // TODO: 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。 @@ -708,8 +697,6 @@ protected function setFancyTable($header, $data, $w) // セル高さが最大値を保持する if ($h >= $cellHeight) { $cellHeight = $h; - } else { - $this->checkPageBreak($this->PageBreakTrigger + 1); } // 最終列の場合は次の行へ移動 @@ -719,18 +706,37 @@ protected function setFancyTable($header, $data, $w) $this->MultiCell( $w[$i], // セル幅 $cellHeight, // セルの最小の高さ - $col, // 文字列 - 1, // 境界線の描画方法を指定 + !$isBorder ? $col : '', // 文字列 + $isBorder ? 1 : 0, // 境界線の描画方法を指定 $align, // テキストの整列 $fill, // 背景の塗つぶし指定 - $ln // 出力後のカーソルの移動方法 + $ln // 出力後のカーソルの移動方法 ); $h = $this->getLastH(); + $i++; + } + return $cellHeight; + }; - ++$i; + foreach ($data as $row) { + // 行の処理 + $h = 4; + $this->Cell(5, $h, '', 0, 0, '', 0, ''); + if ((277 - $this->getY()) < ($h * 4)) { + $this->checkPageBreak($this->PageBreakTrigger + 1); } + + $x = $this->getX(); + $y = $this->getY(); + // 1度目は文字だけ出力し、行の高さ最大を取得 + $h = $writeRow($row, $h, $fill, false); + $this->setXY($x, $y); + // 2度目に最大の高さに合わせて、境界線を描画 + $writeRow($row, $h, $fill, true); + $fill = !$fill; } + $h = 4; $this->Cell(5, $h, '', 0, 0, '', 0, ''); $this->Cell(array_sum($w), 0, '', 'T'); $this->SetFillColor(255);