protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) { $styleFont = $text->getFontStyle(); $SfIsObject = $styleFont instanceof PHPWord_Style_Font ? true : false; if (!$withoutP) { $objWriter->startElement('w:p'); $styleParagraph = $text->getParagraphStyle(); $SpIsObject = $styleParagraph instanceof PHPWord_Style_Paragraph ? true : false; if ($SpIsObject) { $this->_writeParagraphStyle($objWriter, $styleParagraph); } elseif (!$SpIsObject && !is_null($styleParagraph) || $styleFont->_align) { $objWriter->startElement('w:pPr'); if (!is_null($styleFont->_align)) { $objWriter->startElement('w:jc'); $objWriter->writeAttribute('w:val', $styleFont->_align); $objWriter->endElement(); } if (!is_null($styleParagraph)) { $objWriter->startElement('w:pStyle'); $objWriter->writeAttribute('w:val', $styleParagraph); $objWriter->endElement(); } $objWriter->endElement(); } } $strText = htmlspecialchars($text->getText()); $strText = PHPWord_Shared_String::ControlCharacterPHP2OOXML($strText); $objWriter->startElement('w:r'); if ($SfIsObject) { $this->_writeTextStyle($objWriter, $styleFont); } elseif (!$SfIsObject && !is_null($styleFont)) { $objWriter->startElement('w:rPr'); $objWriter->startElement('w:rStyle'); $objWriter->writeAttribute('w:val', $styleFont); $objWriter->endElement(); $objWriter->endElement(); } $objWriter->startElement('w:t'); $objWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text $objWriter->writeRaw($strText); $objWriter->endElement(); $objWriter->endElement(); // w:r if (!$withoutP) { $objWriter->endElement(); // w:p } }
protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) { $styleFont = $text->getFontStyle(); $SfIsObject = $styleFont instanceof PHPWord_Style_Font ? true : false; $strText = htmlspecialchars($text->getText()); // create array of newlines $str_tmp = explode("\n", $strText); // cycle through the array and create new paragraph per new line for ($iii = 0; $iii < count($str_tmp); $iii++) { if (!$withoutP) { $objWriter->startElement('w:p'); $styleParagraph = $text->getParagraphStyle(); $SpIsObject = $styleParagraph instanceof PHPWord_Style_Paragraph ? true : false; if ($SpIsObject) { $this->_writeParagraphStyle($objWriter, $styleParagraph); } elseif (!$SpIsObject && !is_null($styleParagraph)) { $objWriter->startElement('w:pPr'); $objWriter->startElement('w:pStyle'); $objWriter->writeAttribute('w:val', $styleParagraph); $objWriter->endElement(); $objWriter->endElement(); } } $strText = $str_tmp[$iii]; // htmlspecialchars($str_tmp[$iii]); $strText = PHPWord_Shared_String::ControlCharacterPHP2OOXML($strText); $objWriter->startElement('w:r'); if ($SfIsObject) { $this->_writeTextStyle($objWriter, $styleFont); } elseif (!$SfIsObject && !is_null($styleFont)) { $objWriter->startElement('w:rPr'); $objWriter->startElement('w:rStyle'); $objWriter->writeAttribute('w:val', $styleFont); $objWriter->endElement(); $objWriter->endElement(); } $objWriter->startElement('w:t'); $objWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text $objWriter->writeRaw($strText); $objWriter->endElement(); $objWriter->endElement(); // w:r if (!$withoutP) { $objWriter->endElement(); // w:p } } }
protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) { $styleFont = $text->getFontStyle(); $styleParagraph = $text->getParagraphStyle(); $SfIsObject = $styleFont instanceof PHPWord_Style_Font ? true : false; if ($SfIsObject) { // Don't never be the case, because I browse all sections for cleaning all styles not declared die('PHPWord : $SfIsObject wouldn\'t be an object'); } else { // text:p $objWriter->startElement('text:p'); if (empty($styleFont)) { if (empty($styleParagraph)) { $objWriter->writeAttribute('text:style-name', 'P1'); } else { $objWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); } $objWriter->writeRaw($text->getText()); } else { if (empty($styleParagraph)) { $objWriter->writeAttribute('text:style-name', 'Standard'); } else { $objWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); } // text:span $objWriter->startElement('text:span'); $objWriter->writeAttribute('text:style-name', $styleFont); $objWriter->writeRaw($text->getText()); $objWriter->endElement(); } $objWriter->endElement(); } }
private function _getDataContent_writeText(PHPWord_Section_Text $text) { $sRTFText = ''; $styleFont = $text->getFontStyle(); $SfIsObject = $styleFont instanceof PHPWord_Style_Font ? true : false; if (!$SfIsObject) { $styleFont = PHPWord_Style::getStyle($styleFont); } $styleParagraph = $text->getParagraphStyle(); $SpIsObject = $styleParagraph instanceof PHPWord_Style_Paragraph ? true : false; if (!$SpIsObject) { $styleParagraph = PHPWord_Style::getStyle($styleParagraph); } if ($styleParagraph) { if ($this->_lastParagraphStyle != $text->getParagraphStyle()) { $sRTFText .= '\\pard\\nowidctlpar'; if ($styleParagraph->getSpaceAfter() != null) { $sRTFText .= '\\sa' . $styleParagraph->getSpaceAfter(); } if ($styleParagraph->getAlign() != null) { if ($styleParagraph->getAlign() == 'center') { $sRTFText .= '\\qc'; } } $this->_lastParagraphStyle = $text->getParagraphStyle(); } else { $this->_lastParagraphStyle = ''; } } else { $this->_lastParagraphStyle = ''; } if ($styleFont) { if ($styleFont->getColor() != null) { $idxColor = array_search($styleFont->getColor(), $this->_colorTable); if ($idxColor !== FALSE) { $sRTFText .= '\\cf' . ($idxColor + 1); } } else { $sRTFText .= '\\cf0'; } if ($styleFont->getName() != null) { $idxFont = array_search($styleFont->getName(), $this->_fontTable); if ($idxFont !== FALSE) { $sRTFText .= '\\f' . $idxFont; } } else { $sRTFText .= '\\f0'; } if ($styleFont->getBold()) { $sRTFText .= '\\b'; } if ($styleFont->getBold()) { $sRTFText .= '\\i'; } if ($styleFont->getSize()) { $sRTFText .= '\\fs' . $styleFont->getSize(); } } if ($this->_lastParagraphStyle != '' || $styleFont) { $sRTFText .= ' '; } $sRTFText .= $text->getText(); if ($styleFont) { $sRTFText .= '\\cf0'; $sRTFText .= '\\f0'; if ($styleFont->getBold()) { $sRTFText .= '\\b0'; } if ($styleFont->getItalic()) { $sRTFText .= '\\i0'; } if ($styleFont->getSize()) { $sRTFText .= '\\fs20'; } } $sRTFText .= '\\par' . PHP_EOL; return $sRTFText; }