Minor refactoring

This commit is contained in:
MarkBaker 2020-07-05 20:21:54 +02:00
parent f3fc321177
commit c6de56e4cf
1 changed files with 40 additions and 29 deletions

View File

@ -437,14 +437,26 @@ class Gnumeric extends BaseReader
'footer' => 0.3,
];
$marginSet = $this->buildMarginSet($sheet, $marginSet);
$this->adjustMargins($marginSet);
}
}
private function buildMarginSet(SimpleXMLElement $sheet, array $marginSet): array
{
foreach ($sheet->PrintInformation->Margins->children($this->gnm, true) as $key => $margin) {
$marginAttributes = $margin->attributes();
$marginSize = ($marginAttributes['Points']) ?? 72; // Default is 72pt
// Convert value in points to inches
$marginSize = PageMargins::fromPoints((float) $marginSize);
$marginSize = PageMargins::fromPoints((float)$marginSize);
$marginSet[$key] = $marginSize;
}
return $marginSet;
}
private function adjustMargins(array $marginSet): void
{
foreach ($marginSet as $key => $marginSize) {
// Gnumeric is quirky in the way it displays the header/footer values:
// header is actually the sum of top and header; footer is actually the sum of bottom and footer
@ -474,7 +486,6 @@ class Gnumeric extends BaseReader
}
}
}
}
private function sheetMargin(string $key, float $marginSize): void
{