PHRAS-376 Fix pdf print aspect ratio

This commit is contained in:
Nicolas Le Goff
2015-01-19 15:06:12 +01:00
parent 1b33daf863
commit d58170739e

View File

@@ -243,19 +243,24 @@ class PDF
$wimg = $himg = 50; $wimg = $himg = 50;
// 1px = 3.77952 mm // 1px = 3.77952 mm
$finalWidth = round($subdef->get_width() / 3.779528, 2); $finalWidth = round($subdef->get_width() / 3.779528, 2);
$finalheight = round($subdef->get_height() / 3.779528, 2); $finalHeight = round($subdef->get_height() / 3.779528, 2);
if ($finalWidth > 0 && $finalheight > 0) { $aspectH = $finalWidth/$finalHeight;
if ($finalWidth > $finalheight && ($wimg < $finalWidth)) $aspectW = $finalHeight/$finalWidth;
$finalheight = $wimg * $finalheight / $finalWidth;
else if ($finalheight > $finalWidth && $himg < $finalheight) if ($finalWidth > 0 && $finalHeight > 0) {
$finalWidth = $himg * $finalWidth / $finalheight; if ($finalWidth > $finalHeight && $finalWidth > $wimg) {
else if ($finalheight == $finalWidth && $himg < $finalheight) { $finalWidth = $wimg;
$finalheight = $wimg * $finalheight / $finalWidth; $finalHeight = $wimg * $aspectW;
$finalWidth = $himg * $finalWidth / $finalheight; } else if ($finalHeight > $finalWidth && $finalHeight > $himg) {
$finalHeight = $himg;
$finalWidth = $himg * $aspectH;
} else if ($finalHeight == $finalWidth & $finalWidth > $wimg) {
$finalHeight = $wimg;
$finalWidth = $himg;
} }
} }
if ($this->pdf->GetY() > $this->pdf->getPageHeight() - (6 + $finalheight + 20)) if ($this->pdf->GetY() > $this->pdf->getPageHeight() - (6 + $finalHeight + 20))
$this->pdf->AddPage(); $this->pdf->AddPage();
$title = "record : " . $rec->get_title(); $title = "record : " . $rec->get_title();
@@ -292,7 +297,7 @@ class PDF
if ($fimg) { if ($fimg) {
$y = $this->pdf->GetY(); $y = $this->pdf->GetY();
$this->pdf->Image($fimg, $lmargin, $y, $finalWidth, $finalheight); $this->pdf->Image($fimg, $lmargin, $y, $finalWidth, $finalHeight);
$this->pdf->SetY($y + 3); $this->pdf->SetY($y + 3);
} }
@@ -312,8 +317,8 @@ class PDF
$this->pdf->Write(6, "\n"); $this->pdf->Write(6, "\n");
$nf++; $nf++;
} }
if ($this->pdf->PageNo() == $p0 && ($this->pdf->GetY() - $y0) < $finalheight) if ($this->pdf->PageNo() == $p0 && ($this->pdf->GetY() - $y0) < $finalHeight)
$this->pdf->SetY($y0 + $finalheight); $this->pdf->SetY($y0 + $finalHeight);
$ndoc++; $ndoc++;
} }
$this->pdf->SetLeftMargin($lmargin); $this->pdf->SetLeftMargin($lmargin);
@@ -447,28 +452,34 @@ class PDF
&& $subdef->get_type() == \media_subdef::TYPE_IMAGE) && $subdef->get_type() == \media_subdef::TYPE_IMAGE)
$f = \recordutils_image::watermark($this->app, $subdef); $f = \recordutils_image::watermark($this->app, $subdef);
// original height / original width x new width = new height
$wimg = $himg = 150; // preview dans un carre de 150 mm $wimg = $himg = 150; // preview dans un carre de 150 mm
// 1px = 3.77952 mm // 1px = 3.77952 mm
$finalWidth = round($subdef->get_width() / 3.779528, 2); $finalWidth = round($subdef->get_width() / 3.779528, 2);
$finalheight = round($subdef->get_height() / 3.779528, 2); $finalHeight = round($subdef->get_height() / 3.779528, 2);
if ($finalWidth > 0 && $finalheight > 0) { $aspectH = $finalWidth/$finalHeight;
if ($finalWidth > $finalheight && ($wimg < $finalWidth)) $aspectW = $finalHeight/$finalWidth;
$finalheight = $wimg * $finalheight / $finalWidth;
else if ($finalheight > $finalWidth && $himg < $finalheight) if ($finalWidth > 0 && $finalHeight > 0) {
$finalWidth = $himg * $finalWidth / $finalheight; if ($finalWidth > $finalHeight && $finalWidth > $wimg) {
else if ($finalheight == $finalWidth && $himg < $finalheight) { $finalWidth = $wimg;
$finalheight = $wimg * $finalheight / $finalWidth; $finalHeight = $wimg * $aspectW;
$finalWidth = $himg * $finalWidth / $finalheight; } else if ($finalHeight > $finalWidth && $finalHeight > $himg) {
$finalHeight = $himg;
$finalWidth = $himg * $aspectH;
} else if ($finalHeight == $finalWidth & $finalWidth > $wimg) {
$finalHeight = $wimg;
$finalWidth = $himg;
} }
} }
$this->pdf->Image($f, (210 - $finalWidth) / 2, $y, $finalWidth, $finalheight); $this->pdf->Image($f, (210 - $finalWidth) / 2, $y, $finalWidth, $finalHeight);
if ($miniConv != NULL) { if ($miniConv != NULL) {
foreach ($miniConv as $oneF) foreach ($miniConv as $oneF)
unlink($oneF); unlink($oneF);
} }
$this->pdf->SetXY($lmargin, $y += ( $finalheight + 5)); $this->pdf->SetXY($lmargin, $y += ( $finalHeight + 5));
$nf = 0; $nf = 0;
if ($write_caption) { if ($write_caption) {