mergeFontStyles($mergedStyle, $style, $baseStyle); $this->mergeOtherFontProperties($mergedStyle, $style, $baseStyle); $this->mergeCellProperties($mergedStyle, $style, $baseStyle); return $mergedStyle; } /** * @param Style $styleToUpdate (passed as reference) * @param Style $style * @param Style $baseStyle * @return void */ private function mergeFontStyles(Style $styleToUpdate, Style $style, Style $baseStyle) { if (!$style->hasSetFontBold() && $baseStyle->isFontBold()) { $styleToUpdate->setFontBold(); } if (!$style->hasSetFontItalic() && $baseStyle->isFontItalic()) { $styleToUpdate->setFontItalic(); } if (!$style->hasSetFontUnderline() && $baseStyle->isFontUnderline()) { $styleToUpdate->setFontUnderline(); } if (!$style->hasSetFontStrikethrough() && $baseStyle->isFontStrikethrough()) { $styleToUpdate->setFontStrikethrough(); } } /** * @param Style $styleToUpdate Style to update (passed as reference) * @param Style $style * @param Style $baseStyle * @return void */ private function mergeOtherFontProperties(Style $styleToUpdate, Style $style, Style $baseStyle) { if (!$style->hasSetFontSize() && $baseStyle->getFontSize() !== Style::DEFAULT_FONT_SIZE) { $styleToUpdate->setFontSize($baseStyle->getFontSize()); } if (!$style->hasSetFontColor() && $baseStyle->getFontColor() !== Style::DEFAULT_FONT_COLOR) { $styleToUpdate->setFontColor($baseStyle->getFontColor()); } if (!$style->hasSetFontName() && $baseStyle->getFontName() !== Style::DEFAULT_FONT_NAME) { $styleToUpdate->setFontName($baseStyle->getFontName()); } } /** * @param Style $styleToUpdate Style to update (passed as reference) * @param Style $style * @param Style $baseStyle * @return void */ private function mergeCellProperties(Style $styleToUpdate, Style $style, Style $baseStyle) { if (!$style->hasSetWrapText() && $baseStyle->hasSetWrapText()) { $styleToUpdate->setShouldWrapText($baseStyle->shouldWrapText()); } if (!$style->hasSetCellAlignment() && $baseStyle->shouldApplyCellAlignment()) { $styleToUpdate->setCellAlignment($baseStyle->getCellAlignment()); } if (!$style->hasSetCellVerticalAlignment() && $baseStyle->shouldApplyCellVerticalAlignment()) { $styleToUpdate->setCellVerticalAlignment($baseStyle->getCellVerticalAlignment()); } if ($style->getBorder() === null && $baseStyle->shouldApplyBorder()) { $styleToUpdate->setBorder($baseStyle->getBorder()); } if ($style->getFormat() === null && $baseStyle->shouldApplyFormat()) { $styleToUpdate->setFormat($baseStyle->getFormat()); } if (!$style->shouldApplyBackgroundColor() && $baseStyle->shouldApplyBackgroundColor()) { $styleToUpdate->setBackgroundColor($baseStyle->getBackgroundColor()); } } }