/** * Returns the contents of the "<style:style>" section, inside "<office:automatic-styles>" section * * @param \Box\Spout\Writer\Style\Style $style * @return string */ protected function getStyleSectionContent($style) { $defaultStyle = $this->getDefaultStyle(); $styleIndex = $style->getId() + 1; // 1-based $content = '<style:style style:data-style-name="N0" style:family="table-cell" style:name="ce' . $styleIndex . '" style:parent-style-name="Default">'; if ($style->shouldApplyFont()) { $content .= '<style:text-properties'; $fontColor = $style->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 .= '<style:table-cell-properties fo:wrap-option="wrap" style:vertical-align="automatic"/>'; } if ($style->shouldApplyBorder()) { $borderProperty = '<style:table-cell-properties %s />'; $borders = array_map(function (BorderPart $borderPart) { return BorderHelper::serializeBorderPart($borderPart); }, $style->getBorder()->getParts()); $content .= sprintf($borderProperty, implode(' ', $borders)); } if ($style->shouldApplyBackgroundColor()) { $content .= sprintf(' <style:table-cell-properties fo:background-color="#%s"/>', $style->getBackgroundColor()); } $content .= '</style:style>'; return $content; }
/** * Returns the contents of the borders definition for the "<style:table-cell-properties>" section * * @param \Box\Spout\Writer\Style\Style $style * @return string */ private function getBorderXMLContent($style) { $borderProperty = '<style:table-cell-properties %s />'; $borders = array_map(function (BorderPart $borderPart) { return BorderHelper::serializeBorderPart($borderPart); }, $style->getBorder()->getParts()); return sprintf($borderProperty, implode(' ', $borders)); }