[] Map whose keys contain all the fonts used */ protected $usedFontsSet = []; /** * Registers the given style as a used style. * Duplicate styles won't be registered more than once. * * @param \Box\Spout\Writer\Style\Style $style The style to be registered * @return \Box\Spout\Writer\Style\Style The registered style, updated with an internal ID. */ public function registerStyle($style) { $this->usedFontsSet[$style->getFontName()] = true; return parent::registerStyle($style); } /** * @return string[] List of used fonts name */ protected function getUsedFonts() { return array_keys($this->usedFontsSet); } /** * Returns the content of the "styles.xml" file, given a list of styles. * * @param int $numWorksheets Number of worksheets created * @return string */ public function getStylesXMLFileContent($numWorksheets) { $content = << EOD; $content .= $this->getFontFaceSectionContent(); $content .= $this->getStylesSectionContent(); $content .= $this->getAutomaticStylesSectionContent($numWorksheets); $content .= $this->getMasterStylesSectionContent($numWorksheets); $content .= << EOD; return $content; } /** * Returns the content of the "" section, inside "styles.xml" file. * * @return string */ protected function getFontFaceSectionContent() { $content = ''; foreach ($this->getUsedFonts() as $fontName) { $content .= ''; } $content .= ''; return $content; } /** * Returns the content of the "" section, inside "styles.xml" file. * * @return string */ protected function getStylesSectionContent() { $defaultStyle = $this->getDefaultStyle(); return << EOD; } /** * Returns the content of the "" section, inside "styles.xml" file. * * @param int $numWorksheets Number of worksheets created * @return string */ protected function getAutomaticStylesSectionContent($numWorksheets) { $content = ''; for ($i = 1; $i <= $numWorksheets; $i++) { $content .= << EOD; } $content .= ''; return $content; } /** * Returns the content of the "" section, inside "styles.xml" file. * * @param int $numWorksheets Number of worksheets created * @return string */ protected function getMasterStylesSectionContent($numWorksheets) { $content = ''; for ($i = 1; $i <= $numWorksheets; $i++) { $content .= << EOD; } $content .= ''; return $content; } /** * Returns the contents of the "" section, inside "content.xml" file. * * @return string */ public function getContentXmlFontFaceSectionContent() { $content = ''; foreach ($this->getUsedFonts() as $fontName) { $content .= ''; } $content .= ''; return $content; } /** * Returns the contents of the "" section, inside "content.xml" file. * * @param int $numWorksheets Number of worksheets created * @return string */ public function getContentXmlAutomaticStylesSectionContent($numWorksheets) { $content = ''; foreach ($this->getRegisteredStyles() as $style) { $content .= $this->getStyleSectionContent($style); } $content .= << EOD; for ($i = 1; $i <= $numWorksheets; $i++) { $content .= << EOD; } $content .= ''; return $content; } /** * Returns the contents of the "" section, inside "" section * * @param \Box\Spout\Writer\Style\Style $style * @return string */ protected function getStyleSectionContent($style) { $defaultStyle = $this->getDefaultStyle(); $styleIndex = $style->getId() + 1; // 1-based $content = ''; if ($style->shouldApplyFont()) { $content .= 'getFontColor(); if ($fontColor !== $defaultStyle->getFontColor()) { $content .= ' fo:color="#' . $fontColor . '"'; } $fontName = $style->getFontName(); if ($fontName !== $defaultStyle->getFontName()) { $content .= ' style:font-name="' . $fontName . '" style:font-name-asian="' . $fontName . '" style:font-name-complex="' . $fontName . '"'; } $fontSize = $style->getFontSize(); if ($fontSize !== $defaultStyle->getFontSize()) { $content .= ' fo:font-size="' . $fontSize . 'pt" style:font-size-asian="' . $fontSize . 'pt" style:font-size-complex="' . $fontSize . 'pt"'; } if ($style->isFontBold()) { $content .= ' fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"'; } if ($style->isFontItalic()) { $content .= ' fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"'; } if ($style->isFontUnderline()) { $content .= ' style:text-underline-style="solid" style:text-underline-type="single"'; } if ($style->isFontStrikethrough()) { $content .= ' style:text-line-through-style="solid"'; } $content .= '/>'; } if ($style->shouldWrapText()) { $content .= ''; } $content .= ''; return $content; } }