/** * Test initiation for style type and paragraph style */ public function testInitiation() { $object = new Font(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), array('alignment' => Jc::BOTH)); $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $object->getStyleType()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle()); $this->assertTrue(is_array($object->getStyleValues())); }
/** * Test initiation for style type and paragraph style */ public function testInitiation() { $object = new Font('text', array('align' => 'both')); $this->assertEquals('text', $object->getStyleType()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle()); $this->assertTrue(is_array($object->getStyleValues())); }
/** * Write font style * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $styleName * @param \PhpOffice\PhpWord\Style\Font $style */ private function writeFontStyle(XMLWriter $xmlWriter, $styleName, FontStyle $style) { $paragraphStyle = $style->getParagraph(); $styleType = $style->getStyleType(); $type = $styleType == 'title' ? 'paragraph' : 'character'; if (!is_null($paragraphStyle)) { $type = 'paragraph'; } $xmlWriter->startElement('w:style'); $xmlWriter->writeAttribute('w:type', $type); // Heading style if ($styleType == 'title') { $arrStyle = explode('_', $styleName); $styleId = 'Heading' . $arrStyle[1]; $styleName = 'heading ' . $arrStyle[1]; $styleLink = 'Heading' . $arrStyle[1] . 'Char'; $xmlWriter->writeAttribute('w:styleId', $styleId); $xmlWriter->startElement('w:link'); $xmlWriter->writeAttribute('w:val', $styleLink); $xmlWriter->endElement(); } // Style name $xmlWriter->startElement('w:name'); $xmlWriter->writeAttribute('w:val', $styleName); $xmlWriter->endElement(); // Parent style $xmlWriter->writeElementIf(!is_null($paragraphStyle), 'w:basedOn', 'w:val', 'Normal'); // w:pPr if (!is_null($paragraphStyle)) { $styleWriter = new ParagraphStyleWriter($xmlWriter, $paragraphStyle); $styleWriter->write(); } // w:rPr $styleWriter = new FontStyleWriter($xmlWriter, $style); $styleWriter->write(); $xmlWriter->endElement(); }