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,41 +437,52 @@ class Gnumeric extends BaseReader
'footer' => 0.3, 'footer' => 0.3,
]; ];
foreach ($sheet->PrintInformation->Margins->children($this->gnm, true) as $key => $margin) { $marginSet = $this->buildMarginSet($sheet, $marginSet);
$marginAttributes = $margin->attributes(); $this->adjustMargins($marginSet);
$marginSize = ($marginAttributes['Points']) ?? 72; // Default is 72pt }
// Convert value in points to inches }
$marginSize = PageMargins::fromPoints((float) $marginSize);
$marginSet[$key] = $marginSize;
}
foreach ($marginSet as $key => $marginSize) { private function buildMarginSet(SimpleXMLElement $sheet, array $marginSet): array
// 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 foreach ($sheet->PrintInformation->Margins->children($this->gnm, true) as $key => $margin) {
// then top is actually the header value, and bottom is actually the footer value $marginAttributes = $margin->attributes();
switch ($key) { $marginSize = ($marginAttributes['Points']) ?? 72; // Default is 72pt
case 'left': // Convert value in points to inches
case 'right': $marginSize = PageMargins::fromPoints((float)$marginSize);
$this->sheetMargin($key, $marginSize); $marginSet[$key] = $marginSize;
}
break; return $marginSet;
case 'top': }
$this->sheetMargin($key, $marginSet['header'] ?? 0);
break; private function adjustMargins(array $marginSet): void
case 'bottom': {
$this->sheetMargin($key, $marginSet['footer'] ?? 0); 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
// then top is actually the header value, and bottom is actually the footer value
switch ($key) {
case 'left':
case 'right':
$this->sheetMargin($key, $marginSize);
break; break;
case 'header': case 'top':
$this->sheetMargin($key, ($marginSet['top'] ?? 0) - $marginSize); $this->sheetMargin($key, $marginSet['header'] ?? 0);
break; break;
case 'footer': case 'bottom':
$this->sheetMargin($key, ($marginSet['bottom'] ?? 0) - $marginSize); $this->sheetMargin($key, $marginSet['footer'] ?? 0);
break; break;
} case 'header':
$this->sheetMargin($key, ($marginSet['top'] ?? 0) - $marginSize);
break;
case 'footer':
$this->sheetMargin($key, ($marginSet['bottom'] ?? 0) - $marginSize);
break;
} }
} }
} }