isInline && !is_null($this->style) && is_string($this->style); if ($isStyleName) { $this->xmlWriter->startElement('w:rPr'); $this->xmlWriter->startElement('w:rStyle'); $this->xmlWriter->writeAttribute('w:val', $this->style); $this->xmlWriter->endElement(); $this->xmlWriter->endElement(); } else { $this->writeStyle(); } } /** * Write full style */ private function writeStyle() { if (!($this->style instanceof \PhpOffice\PhpWord\Style\Font)) { return; } $font = $this->style->getName(); $bold = $this->style->getBold(); $italic = $this->style->getItalic(); $color = $this->style->getColor(); $size = $this->style->getSize(); $fgColor = $this->style->getFgColor(); $bgColor = $this->style->getBgColor(); $strikethrough = $this->style->getStrikethrough(); $underline = $this->style->getUnderline(); $superscript = $this->style->getSuperScript(); $subscript = $this->style->getSubScript(); $hint = $this->style->getHint(); $this->xmlWriter->startElement('w:rPr'); // Font if ($font != PhpWord::DEFAULT_FONT_NAME) { $this->xmlWriter->startElement('w:rFonts'); $this->xmlWriter->writeAttribute('w:ascii', $font); $this->xmlWriter->writeAttribute('w:hAnsi', $font); $this->xmlWriter->writeAttribute('w:eastAsia', $font); $this->xmlWriter->writeAttribute('w:cs', $font); //Font Content Type if ($hint != PhpWord::DEFAULT_FONT_CONTENT_TYPE) { $this->xmlWriter->writeAttribute('w:hint', $hint); } $this->xmlWriter->endElement(); } // Color if ($color != PhpWord::DEFAULT_FONT_COLOR) { $this->xmlWriter->startElement('w:color'); $this->xmlWriter->writeAttribute('w:val', $color); $this->xmlWriter->endElement(); } // Size if ($size != PhpWord::DEFAULT_FONT_SIZE) { $this->xmlWriter->startElement('w:sz'); $this->xmlWriter->writeAttribute('w:val', $size * 2); $this->xmlWriter->endElement(); $this->xmlWriter->startElement('w:szCs'); $this->xmlWriter->writeAttribute('w:val', $size * 2); $this->xmlWriter->endElement(); } // Bold if ($bold) { $this->xmlWriter->writeElement('w:b', null); } // Italic if ($italic) { $this->xmlWriter->writeElement('w:i', null); $this->xmlWriter->writeElement('w:iCs', null); } // Underline if (!is_null($underline) && $underline != 'none') { $this->xmlWriter->startElement('w:u'); $this->xmlWriter->writeAttribute('w:val', $underline); $this->xmlWriter->endElement(); } // Strikethrough if ($strikethrough) { $this->xmlWriter->writeElement('w:strike', null); } // Foreground-Color if (!is_null($fgColor)) { $this->xmlWriter->startElement('w:highlight'); $this->xmlWriter->writeAttribute('w:val', $fgColor); $this->xmlWriter->endElement(); } // Background-Color if (!is_null($bgColor)) { $this->xmlWriter->startElement('w:shd'); $this->xmlWriter->writeAttribute('w:val', "clear"); $this->xmlWriter->writeAttribute('w:color', "auto"); $this->xmlWriter->writeAttribute('w:fill', $bgColor); $this->xmlWriter->endElement(); } // Superscript/subscript if ($superscript || $subscript) { $this->xmlWriter->startElement('w:vertAlign'); $this->xmlWriter->writeAttribute('w:val', $superscript ? 'superscript' : 'subscript'); $this->xmlWriter->endElement(); } $this->xmlWriter->endElement(); } /** * Set is inline * * @param bool $value */ public function setIsInline($value) { $this->isInline = $value; } }