PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Style / ConditionalFormatting / StyleMerger.php

StyleMerger.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php

91 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Style\Border;
6 use TablePress\PhpOffice\PhpSpreadsheet\Style\Borders;
7 use TablePress\PhpOffice\PhpSpreadsheet\Style\Fill;
8 use TablePress\PhpOffice\PhpSpreadsheet\Style\Font;
9 use TablePress\PhpOffice\PhpSpreadsheet\Style\Style;
10
11 class StyleMerger
12 {
13 protected Style $baseStyle;
14
15 public function __construct(Style $baseStyle)
16 {
17 // Setting to $baseStyle sometimes causes problems later on.
18 $array = $baseStyle->exportArray();
19 $this->baseStyle = new Style();
20 $this->baseStyle->applyFromArray($array);
21 }
22
23 public function getStyle(): Style
24 {
25 return $this->baseStyle;
26 }
27
28 public function mergeStyle(Style $style): void
29 {
30 if ($style->getNumberFormat()->getFormatCode() !== null) {
31 $this->baseStyle->getNumberFormat()->setFormatCode($style->getNumberFormat()->getFormatCode());
32 }
33 $this->mergeFontStyle($this->baseStyle->getFont(), $style->getFont());
34 $this->mergeFillStyle($this->baseStyle->getFill(), $style->getFill());
35 $this->mergeBordersStyle($this->baseStyle->getBorders(), $style->getBorders());
36 }
37
38 protected function mergeFontStyle(Font $baseFontStyle, Font $fontStyle): void
39 {
40 if ($fontStyle->getBold() !== null) {
41 $baseFontStyle->setBold($fontStyle->getBold());
42 }
43 if ($fontStyle->getItalic() !== null) {
44 $baseFontStyle->setItalic($fontStyle->getItalic());
45 }
46 if ($fontStyle->getStrikethrough() !== null) {
47 $baseFontStyle->setStrikethrough($fontStyle->getStrikethrough());
48 }
49 if ($fontStyle->getUnderline() !== null) {
50 $baseFontStyle->setUnderline($fontStyle->getUnderline());
51 }
52 if ($fontStyle->getColor()->getARGB() !== null) {
53 $baseFontStyle->setColor($fontStyle->getColor());
54 }
55 }
56
57 protected function mergeFillStyle(Fill $baseFillStyle, Fill $fillStyle): void
58 {
59 if ($fillStyle->getFillType() !== null) {
60 $baseFillStyle->setFillType($fillStyle->getFillType());
61 }
62 $baseFillStyle->setRotation($fillStyle->getRotation());
63 if ($fillStyle->getStartColor()->getARGB() !== null) {
64 $baseFillStyle->setStartColor($fillStyle->getStartColor());
65 }
66 if ($fillStyle->getEndColor()->getARGB() !== null) {
67 $baseFillStyle->setEndColor($fillStyle->getEndColor());
68 }
69 }
70
71 protected function mergeBordersStyle(Borders $baseBordersStyle, Borders $bordersStyle): void
72 {
73 $this->mergeBorderStyle($baseBordersStyle->getTop(), $bordersStyle->getTop());
74 $this->mergeBorderStyle($baseBordersStyle->getBottom(), $bordersStyle->getBottom());
75 $this->mergeBorderStyle($baseBordersStyle->getLeft(), $bordersStyle->getLeft());
76 $this->mergeBorderStyle($baseBordersStyle->getRight(), $bordersStyle->getRight());
77 }
78
79 protected function mergeBorderStyle(Border $baseBorderStyle, Border $borderStyle): void
80 {
81 if ($borderStyle->getBorderStyle() !== Border::BORDER_OMIT) {
82 $baseBorderStyle->setBorderStyle(
83 $borderStyle->getBorderStyle()
84 );
85 }
86 if ($borderStyle->getColor()->getARGB() !== null) {
87 $baseBorderStyle->setColor($borderStyle->getColor());
88 }
89 }
90 }
91