Skip to content

Commit

Permalink
Removed HTML margins. Updated reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Feb 5, 2025
1 parent 97c5d47 commit 173d827
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 217 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 0 additions & 137 deletions src/Pdf/Html/HtmlMargins.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Report/AbstractReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(
PdfOrientation $orientation = PdfOrientation::PORTRAIT
) {
parent::__construct($orientation);
$this->setAutoPageBreak(true, $this->bottomMargin - self::LINE_HEIGHT)
$this->setAutoPageBreak(true, $this->getBottomMargin() - self::LINE_HEIGHT)
->setLayout(PdfLayout::SINGLE_PAGE)
->setZoom(PdfZoom::FULL_PAGE);

Expand Down
2 changes: 1 addition & 1 deletion src/Report/CalculationByMonthReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private function renderChart(array $entities): void
{
$h = 100;
$newPage = \count($entities) > 12;
$top = $this->topMargin + $this->getHeader()->getHeight();
$top = $this->getTopMargin() + $this->getHeader()->getHeight();
if ($newPage) {
$h = $this->pageBreakTrigger - $top - 2.0 * self::LINE_HEIGHT;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Report/CalculationByStateReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private function renderChart(array $entities): void
{
$margin = $this->getLeftMargin();
$printableWidth = $this->getPrintableWidth();
$top = $this->topMargin + $this->getHeader()->getHeight() + self::LINE_HEIGHT;
$top = $this->getTopMargin() + $this->getHeader()->getHeight() + self::LINE_HEIGHT;
$radius = $printableWidth / 4.0;
$centerX = $margin + $printableWidth / 2.0;
$centerY = $top + $radius;
Expand Down
8 changes: 4 additions & 4 deletions src/Report/CommandsReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ private function renderOptions(array $options, float $width): void
private function renderStyledHelp(string $help): void
{
// margin
$oldMargin = $this->leftMargin;
$this->leftMargin = $this->x;
$oldMargin = $this->getLeftMargin();
$this->setLeftMargin($this->x);

// find classes
$help = \str_replace(' target="_blank" rel="noopener noreferrer"', '', $help);
if (!StringUtils::pregMatchAll(self::CLASS_PATTERN, $help, $matches, \PREG_SET_ORDER | \PREG_OFFSET_CAPTURE)) {
$this->outputHelp($help);
$this->leftMargin = $oldMargin;
$this->setLeftMargin($oldMargin);
$this->lineBreak();

return;
Expand Down Expand Up @@ -279,7 +279,7 @@ private function renderStyledHelp(string $help): void
}

// restore
$this->leftMargin = $oldMargin;
$this->setLeftMargin($oldMargin);
$this->lineBreak();
}

Expand Down
24 changes: 13 additions & 11 deletions src/Report/HtmlReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function render(): bool
*/
public function updateLeftMargin(float $leftMargin): self
{
$this->x = $this->leftMargin = $leftMargin;
$this->setLeftMargin($leftMargin);
$this->x = $leftMargin;

return $this;
}
Expand All @@ -87,7 +88,7 @@ public function updateLeftMargin(float $leftMargin): self
*/
public function updateRightMargin(float $rightMargin): self
{
$this->rightMargin = $rightMargin;
$this->setRightMargin($rightMargin);

return $this;
}
Expand All @@ -99,8 +100,8 @@ protected function beginPage(
): void {
parent::beginPage($orientation, $size, $rotation);
if (1 === $this->page) {
$this->defaultLeftMargin = $this->leftMargin;
$this->defaultRightMargin = $this->rightMargin;
$this->defaultLeftMargin = $this->getLeftMargin();
$this->defaultRightMargin = $this->getRightMargin();
}
}

Expand All @@ -111,13 +112,13 @@ protected function beginPage(
*/
private function applyDefaultMargins(): array
{
$leftMargin = $this->leftMargin;
$rightMargin = $this->rightMargin;
$leftMargin = $this->getLeftMargin();
$rightMargin = $this->getRightMargin();
if (null !== $this->defaultLeftMargin && $this->defaultLeftMargin !== $leftMargin) {
$this->x = $this->defaultLeftMargin;
}
if (null !== $this->defaultRightMargin && $this->defaultRightMargin !== $rightMargin) {
$this->rightMargin = $this->defaultRightMargin;
$this->setRightMargin($this->defaultRightMargin);
}

return [$leftMargin, $rightMargin];
Expand All @@ -130,11 +131,12 @@ private function applyDefaultMargins(): array
*/
private function applyPreviousMargins(array $previousMargins): void
{
if ($previousMargins[0] !== $this->leftMargin) {
$this->leftMargin = $this->x = $previousMargins[0];
if ($previousMargins[0] !== $this->getLeftMargin()) {
$this->setLeftMargin($previousMargins[0]);
$this->x = $previousMargins[0];
}
if ($previousMargins[1] !== $this->rightMargin) {
$this->rightMargin = $previousMargins[1];
if ($previousMargins[1] !== $this->getRightMargin()) {
$this->setRightMargin($previousMargins[1]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Report/MemoryImageReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private function renderImages(string $title, array $files, bool $color): void
$this->getLevelColor($name)?->apply($this);
}
$bounds = new PdfRectangle(
$this->leftMargin,
$this->getLeftMargin(),
$this->y,
$this->getPrintableWidth(),
self::LINE_HEIGHT,
Expand Down
56 changes: 0 additions & 56 deletions tests/Pdf/Html/HtmlMarginsTest.php

This file was deleted.

0 comments on commit 173d827

Please sign in to comment.