From 75160b12821f7f4299cce7f0b69c83c1502ae071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 27 May 2024 13:08:29 +0200 Subject: 2024-02-19 upstream --- .../src/PhpSpreadsheet/Style/Fill.php | 314 +++++++++++++++++++++ 1 file changed, 314 insertions(+) create mode 100644 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/Fill.php (limited to 'vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/Fill.php') diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/Fill.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/Fill.php new file mode 100644 index 0000000..9ddcf83 --- /dev/null +++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/Fill.php @@ -0,0 +1,314 @@ +fillType = null; + } + $this->startColor = new Color(Color::COLOR_WHITE, $isSupervisor, $isConditional); + $this->endColor = new Color(Color::COLOR_BLACK, $isSupervisor, $isConditional); + + // bind parent if we are a supervisor + if ($isSupervisor) { + $this->startColor->bindParent($this, 'startColor'); + $this->endColor->bindParent($this, 'endColor'); + } + } + + /** + * Get the shared style component for the currently active cell in currently active sheet. + * Only used for style supervisor. + * + * @return Fill + */ + public function getSharedComponent() + { + return $this->parent->getSharedComponent()->getFill(); + } + + /** + * Build style array from subcomponents. + * + * @param array $array + * + * @return array + */ + public function getStyleArray($array) + { + return ['fill' => $array]; + } + + /** + * Apply styles from array. + * + * + * $spreadsheet->getActiveSheet()->getStyle('B2')->getFill()->applyFromArray( + * [ + * 'fillType' => Fill::FILL_GRADIENT_LINEAR, + * 'rotation' => 0, + * 'startColor' => [ + * 'rgb' => '000000' + * ], + * 'endColor' => [ + * 'argb' => 'FFFFFFFF' + * ] + * ] + * ); + * + * + * @param array $pStyles Array containing style information + * + * @return $this + */ + public function applyFromArray(array $pStyles) + { + if ($this->isSupervisor) { + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); + } else { + if (isset($pStyles['fillType'])) { + $this->setFillType($pStyles['fillType']); + } + if (isset($pStyles['rotation'])) { + $this->setRotation($pStyles['rotation']); + } + if (isset($pStyles['startColor'])) { + $this->getStartColor()->applyFromArray($pStyles['startColor']); + } + if (isset($pStyles['endColor'])) { + $this->getEndColor()->applyFromArray($pStyles['endColor']); + } + if (isset($pStyles['color'])) { + $this->getStartColor()->applyFromArray($pStyles['color']); + $this->getEndColor()->applyFromArray($pStyles['color']); + } + } + + return $this; + } + + /** + * Get Fill Type. + * + * @return string + */ + public function getFillType() + { + if ($this->isSupervisor) { + return $this->getSharedComponent()->getFillType(); + } + + return $this->fillType; + } + + /** + * Set Fill Type. + * + * @param string $pValue Fill type, see self::FILL_* + * + * @return $this + */ + public function setFillType($pValue) + { + if ($this->isSupervisor) { + $styleArray = $this->getStyleArray(['fillType' => $pValue]); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); + } else { + $this->fillType = $pValue; + } + + return $this; + } + + /** + * Get Rotation. + * + * @return float + */ + public function getRotation() + { + if ($this->isSupervisor) { + return $this->getSharedComponent()->getRotation(); + } + + return $this->rotation; + } + + /** + * Set Rotation. + * + * @param float $pValue + * + * @return $this + */ + public function setRotation($pValue) + { + if ($this->isSupervisor) { + $styleArray = $this->getStyleArray(['rotation' => $pValue]); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); + } else { + $this->rotation = $pValue; + } + + return $this; + } + + /** + * Get Start Color. + * + * @return Color + */ + public function getStartColor() + { + return $this->startColor; + } + + /** + * Set Start Color. + * + * @return $this + */ + public function setStartColor(Color $pValue) + { + // make sure parameter is a real color and not a supervisor + $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; + + if ($this->isSupervisor) { + $styleArray = $this->getStartColor()->getStyleArray(['argb' => $color->getARGB()]); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); + } else { + $this->startColor = $color; + } + + return $this; + } + + /** + * Get End Color. + * + * @return Color + */ + public function getEndColor() + { + return $this->endColor; + } + + /** + * Set End Color. + * + * @return $this + */ + public function setEndColor(Color $pValue) + { + // make sure parameter is a real color and not a supervisor + $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; + + if ($this->isSupervisor) { + $styleArray = $this->getEndColor()->getStyleArray(['argb' => $color->getARGB()]); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); + } else { + $this->endColor = $color; + } + + return $this; + } + + /** + * Get hash code. + * + * @return string Hash code + */ + public function getHashCode() + { + if ($this->isSupervisor) { + return $this->getSharedComponent()->getHashCode(); + } + // Note that we don't care about colours for fill type NONE, but could have duplicate NONEs with + // different hashes if we don't explicitly prevent this + return md5( + $this->getFillType() . + $this->getRotation() . + ($this->getFillType() !== self::FILL_NONE ? $this->getStartColor()->getHashCode() : '') . + ($this->getFillType() !== self::FILL_NONE ? $this->getEndColor()->getHashCode() : '') . + __CLASS__ + ); + } +} -- cgit v1.2.3