33namespace PhpOffice \PhpSpreadsheet \Style ;
44
55use PhpOffice \PhpSpreadsheet \Chart \ChartColor ;
6+ use PhpOffice \PhpSpreadsheet \Theme ;
67
78class Font extends Supervisor
89{
@@ -85,6 +86,8 @@ class Font extends Supervisor
8586 */
8687 protected Color $ color ;
8788
89+ protected bool $ autoColor = false ;
90+
8891 public ?int $ colorIndex = null ;
8992
9093 protected string $ scheme = '' ;
@@ -124,6 +127,14 @@ public function __construct(bool $isSupervisor = false, bool $isConditional = fa
124127 }
125128 }
126129
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+
127138 /**
128139 * Get the shared style component for the currently active cell in currently active sheet.
129140 * Only used for style supervisor.
@@ -166,7 +177,7 @@ public function getStyleArray(array $array): array
166177 * );
167178 * </code>
168179 *
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
170181 *
171182 * @return $this
172183 */
@@ -185,7 +196,9 @@ public function applyFromArray(array $styleArray): static
185196 $ this ->setEastAsian ($ styleArray ['eastAsian ' ]);
186197 }
187198 if (isset ($ styleArray ['complexScript ' ])) {
188- $ this ->setComplexScript ($ styleArray ['complexScript ' ]);
199+ $ this ->setComplexScript (
200+ $ styleArray ['complexScript ' ]
201+ );
189202 }
190203 if (isset ($ styleArray ['bold ' ])) {
191204 $ this ->setBold ($ styleArray ['bold ' ]);
@@ -203,7 +216,9 @@ public function applyFromArray(array $styleArray): static
203216 $ this ->setUnderline ($ styleArray ['underline ' ]);
204217 }
205218 if (isset ($ styleArray ['strikethrough ' ])) {
206- $ this ->setStrikethrough ($ styleArray ['strikethrough ' ]);
219+ $ this ->setStrikethrough (
220+ $ styleArray ['strikethrough ' ]
221+ );
207222 }
208223 if (isset ($ styleArray ['color ' ])) {
209224 /** @var array{rgb?: string, argb?: string, theme?: int} */
@@ -223,6 +238,9 @@ public function applyFromArray(array $styleArray): static
223238 if (isset ($ styleArray ['cap ' ])) {
224239 $ this ->setCap ($ styleArray ['cap ' ]);
225240 }
241+ if (isset ($ styleArray ['autoColor ' ])) {
242+ $ this ->setAutoColor ($ styleArray ['autoColor ' ]);
243+ }
226244 }
227245
228246 return $ this ;
@@ -736,6 +754,7 @@ public function getHashCode(): string
736754 . ($ this ->subscript ? 't ' : 'f ' )
737755 . $ this ->underline
738756 . ($ this ->strikethrough ? 't ' : 'f ' )
757+ . ($ this ->autoColor ? 't ' : 'f ' )
739758 . $ this ->color ->getHashCode ()
740759 . $ this ->scheme
741760 . implode (
@@ -777,6 +796,7 @@ protected function exportArray1(): array
777796 $ this ->exportArray2 ($ exportedArray , 'superscript ' , $ this ->getSuperscript ());
778797 $ this ->exportArray2 ($ exportedArray , 'underline ' , $ this ->getUnderline ());
779798 $ this ->exportArray2 ($ exportedArray , 'underlineColor ' , $ this ->getUnderlineColor ());
799+ $ this ->exportArray2 ($ exportedArray , 'autoColor ' , $ this ->getAutoColor ());
780800
781801 return $ exportedArray ;
782802 }
@@ -831,6 +851,29 @@ public function setHyperlinkTheme(): self
831851 return $ this ;
832852 }
833853
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+
834877 /**
835878 * Implement PHP __clone to create a deep clone, not just a shallow copy.
836879 */
0 commit comments