3
3
namespace PhpOffice \PhpSpreadsheet \Style ;
4
4
5
5
use PhpOffice \PhpSpreadsheet \Chart \ChartColor ;
6
+ use PhpOffice \PhpSpreadsheet \Theme ;
6
7
7
8
class Font extends Supervisor
8
9
{
@@ -85,6 +86,8 @@ class Font extends Supervisor
85
86
*/
86
87
protected Color $ color ;
87
88
89
+ protected bool $ autoColor = false ;
90
+
88
91
public ?int $ colorIndex = null ;
89
92
90
93
protected string $ scheme = '' ;
@@ -124,6 +127,14 @@ public function __construct(bool $isSupervisor = false, bool $isConditional = fa
124
127
}
125
128
}
126
129
130
+ public function applyThemeFonts (Theme $ theme ): void
131
+ {
132
+ $ this ->setName ($ theme ->getMinorFontLatin ());
133
+ $ this ->setLatin ($ theme ->getMinorFontLatin ());
134
+ $ this ->setEastAsian ($ theme ->getMinorFontEastAsian ());
135
+ $ this ->setComplexScript ($ theme ->getMinorFontComplexScript ());
136
+ }
137
+
127
138
/**
128
139
* Get the shared style component for the currently active cell in currently active sheet.
129
140
* Only used for style supervisor.
@@ -166,7 +177,7 @@ public function getStyleArray(array $array): array
166
177
* );
167
178
* </code>
168
179
*
169
- * @param array{name?: string, latin?: string, eastAsian?: string, complexScript?: string, bold?: bool, italic?: bool, superscript?: bool, subscript?: bool, underline?: bool|string, strikethrough?: bool, color?: string[], size?: ?int, chartColor?: ChartColor, scheme?: string, cap?: string} $styleArray Array containing style information
180
+ * @param array{name?: string, latin?: string, eastAsian?: string, complexScript?: string, bold?: bool, italic?: bool, superscript?: bool, subscript?: bool, underline?: bool|string, strikethrough?: bool, color?: string[], size?: ?int, chartColor?: ChartColor, scheme?: string, cap?: string, autoColor?: bool } $styleArray Array containing style information
170
181
*
171
182
* @return $this
172
183
*/
@@ -185,7 +196,9 @@ public function applyFromArray(array $styleArray): static
185
196
$ this ->setEastAsian ($ styleArray ['eastAsian ' ]);
186
197
}
187
198
if (isset ($ styleArray ['complexScript ' ])) {
188
- $ this ->setComplexScript ($ styleArray ['complexScript ' ]);
199
+ $ this ->setComplexScript (
200
+ $ styleArray ['complexScript ' ]
201
+ );
189
202
}
190
203
if (isset ($ styleArray ['bold ' ])) {
191
204
$ this ->setBold ($ styleArray ['bold ' ]);
@@ -203,7 +216,9 @@ public function applyFromArray(array $styleArray): static
203
216
$ this ->setUnderline ($ styleArray ['underline ' ]);
204
217
}
205
218
if (isset ($ styleArray ['strikethrough ' ])) {
206
- $ this ->setStrikethrough ($ styleArray ['strikethrough ' ]);
219
+ $ this ->setStrikethrough (
220
+ $ styleArray ['strikethrough ' ]
221
+ );
207
222
}
208
223
if (isset ($ styleArray ['color ' ])) {
209
224
/** @var array{rgb?: string, argb?: string, theme?: int} */
@@ -223,6 +238,9 @@ public function applyFromArray(array $styleArray): static
223
238
if (isset ($ styleArray ['cap ' ])) {
224
239
$ this ->setCap ($ styleArray ['cap ' ]);
225
240
}
241
+ if (isset ($ styleArray ['autoColor ' ])) {
242
+ $ this ->setAutoColor ($ styleArray ['autoColor ' ]);
243
+ }
226
244
}
227
245
228
246
return $ this ;
@@ -736,6 +754,7 @@ public function getHashCode(): string
736
754
. ($ this ->subscript ? 't ' : 'f ' )
737
755
. $ this ->underline
738
756
. ($ this ->strikethrough ? 't ' : 'f ' )
757
+ . ($ this ->autoColor ? 't ' : 'f ' )
739
758
. $ this ->color ->getHashCode ()
740
759
. $ this ->scheme
741
760
. implode (
@@ -777,6 +796,7 @@ protected function exportArray1(): array
777
796
$ this ->exportArray2 ($ exportedArray , 'superscript ' , $ this ->getSuperscript ());
778
797
$ this ->exportArray2 ($ exportedArray , 'underline ' , $ this ->getUnderline ());
779
798
$ this ->exportArray2 ($ exportedArray , 'underlineColor ' , $ this ->getUnderlineColor ());
799
+ $ this ->exportArray2 ($ exportedArray , 'autoColor ' , $ this ->getAutoColor ());
780
800
781
801
return $ exportedArray ;
782
802
}
@@ -831,6 +851,29 @@ public function setHyperlinkTheme(): self
831
851
return $ this ;
832
852
}
833
853
854
+ public function setAutoColor (bool $ autoColor ): self
855
+ {
856
+ if ($ this ->isSupervisor ) {
857
+ $ styleArray = $ this ->getStyleArray (['autoColor ' => $ autoColor ]);
858
+ $ this ->getActiveSheet ()
859
+ ->getStyle ($ this ->getSelectedCells ())
860
+ ->applyFromArray ($ styleArray );
861
+ } else {
862
+ $ this ->autoColor = $ autoColor ;
863
+ }
864
+
865
+ return $ this ;
866
+ }
867
+
868
+ public function getAutoColor (): bool
869
+ {
870
+ if ($ this ->isSupervisor ) {
871
+ return $ this ->getSharedComponent ()->getAutoColor ();
872
+ }
873
+
874
+ return $ this ->autoColor ;
875
+ }
876
+
834
877
/**
835
878
* Implement PHP __clone to create a deep clone, not just a shallow copy.
836
879
*/
0 commit comments