Skip to content

Commit

Permalink
Merge pull request #17 from crealoz/dev
Browse files Browse the repository at this point in the history
fix title display bug
  • Loading branch information
ChristopheFerreboeuf authored Nov 14, 2024
2 parents 02fa24d + 4781a14 commit 77f23ee
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions Service/PDFWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,25 @@ private function manageSubResult(array $subResults): void
*/
private function displaySection(string $title, array $section): void
{
$translatedTitle = $this->cliTranslator->translate($title);
if ($this->columnCount !== 1) {
$this->setColumnCount(1);
}
$this->currentPage->drawText($translatedTitle, 44, $this->y);
foreach ($section as $type => $entries) {
if ($this->shouldDisplaySectionTitle($section)) {
$translatedTitle = $this->cliTranslator->translate($title);
$this->currentPage->drawText($translatedTitle, 44, $this->y);
} else {
return;
}
foreach ($section as $entries) {
if (isset($entries['specificSections'])) {
$sectionName = $entries['specificSections'];
unset($entries['specificSections']);
if (!isset($this->specificSections[$sectionName]) || !$this->specificSections[$sectionName] instanceof SectionInterface) {
throw new \InvalidArgumentException("Specific section $sectionName is not valid");
}
if ($entries['files'] === []) {
continue;
}
$numberOfPages = $this->specificSections[$sectionName]->calculateSize($entries) / 800;
if ($numberOfPages > 10) {
$this->delegateToAnnex($numberOfPages, $entries, $title, $sectionName);
Expand All @@ -253,6 +260,18 @@ private function displaySection(string $title, array $section): void
}
}

private function shouldDisplaySectionTitle(array $section): bool
{
$shouldDisplay = false;
foreach ($section as $entries) {
if (!empty($entries['files'])) {
$shouldDisplay = true;
break;
}
}
return $shouldDisplay;
}

/**
* The generic function to write subsections. It displays the title, the explanation and the files.
*
Expand Down

0 comments on commit 77f23ee

Please sign in to comment.