Skip to content

Commit

Permalink
Merge pull request #5742 from takeuji/pdf-layout-fix
Browse files Browse the repository at this point in the history
PDFの罫線の高さがそろわない不具合を修正
  • Loading branch information
chihiro-adachi authored Sep 9, 2022
2 parents 67fe05b + 2991428 commit 4c27230
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/Eccube/Service/OrderPdfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,6 @@ protected function lfText($x, $y, $text, $size = 0, $style = '')
/**
* Colored table.
*
* TODO: 後の列の高さが大きい場合、表示が乱れる。
*
* @param array $header 出力するラベル名一覧
* @param array $data 出力するデータ
* @param array $w 出力するセル幅一覧
Expand Down Expand Up @@ -684,18 +682,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: 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。
Expand All @@ -705,8 +694,6 @@ protected function setFancyTable($header, $data, $w)
// セル高さが最大値を保持する
if ($h >= $cellHeight) {
$cellHeight = $h;
} else {
$this->checkPageBreak($this->PageBreakTrigger + 1);
}

// 最終列の場合は次の行へ移動
Expand All @@ -716,18 +703,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);
Expand Down

0 comments on commit 4c27230

Please sign in to comment.