IMPROVED : Writer/ODText for just generating a simple file with some formatting texts and paragraphs

This commit is contained in:
Progi1984 2012-05-29 20:59:22 +02:00
parent f5da76e90a
commit e9a6a2c4f9
6 changed files with 601 additions and 39 deletions

View File

@ -65,32 +65,10 @@ class PHPWord_Section_Text {
*/
public function __construct($text = null, $styleFont = null, $styleParagraph = null) {
// Set font style
if(is_array($styleFont)) {
$this->_styleFont = new PHPWord_Style_Font('text');
foreach($styleFont as $key => $value) {
if(substr($key, 0, 1) != '_') {
$key = '_'.$key;
}
$this->_styleFont->setStyleValue($key, $value);
}
} else {
$this->_styleFont = $styleFont;
}
$this->setFontStyle($styleFont);
// Set paragraph style
if(is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph();
foreach($styleParagraph as $key => $value) {
if(substr($key, 0, 1) != '_') {
$key = '_'.$key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
$this->setParagraphStyle($styleParagraph);
$this->_text = $text;
@ -106,6 +84,26 @@ class PHPWord_Section_Text {
return $this->_styleFont;
}
/**
* Set Text style
*
* @return PHPWord_Style_Font
*/
public function setFontStyle($styleFont) {
if(is_array($styleFont)) {
$this->_styleFont = new PHPWord_Style_Font('text');
foreach($styleFont as $key => $value) {
if(substr($key, 0, 1) != '_') {
$key = '_'.$key;
}
$this->_styleFont->setStyleValue($key, $value);
}
} else {
$this->_styleFont = $styleFont;
}
}
/**
* Get Paragraph style
*
@ -115,6 +113,26 @@ class PHPWord_Section_Text {
return $this->_styleParagraph;
}
/**
* Set Paragraph style
*
* @return PHPWord_Style_Paragraph
*/
public function setParagraphStyle($styleParagraph) {
if(is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph();
foreach($styleParagraph as $key => $value) {
if(substr($key, 0, 1) != '_') {
$key = '_'.$key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
}
/**
* Get Text content
*

View File

@ -99,4 +99,28 @@ class PHPWord_Shared_Drawing
return 0;
}
}
/**
* Convert pixels to centimeters
*
* @param int $pValue Value in pixels
* @return int Value in centimeters
*/
public static function pixelsToCentimeters($pValue = 0) {
return $pValue * 0.028;
}
/**
* Convert centimeters width to pixels
*
* @param int $pValue Value in centimeters
* @return int Value in pixels
*/
public static function centimetersToPixels($pValue = 0) {
if ($pValue != 0) {
return $pValue * 0.028;
} else {
return 0;
}
}
}

View File

@ -32,7 +32,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
*
* @var PHPWord
*/
private $_presentation;
private $_document;
/**
* Private writer parts
@ -80,6 +80,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
$this->_writerParts['manifest'] = new PHPWord_Writer_ODText_Manifest();
$this->_writerParts['meta'] = new PHPWord_Writer_ODText_Meta();
$this->_writerParts['mimetype'] = new PHPWord_Writer_ODText_Mimetype();
$this->_writerParts['styles'] = new PHPWord_Writer_ODText_Styles();
// Assign parent IWriter
@ -99,7 +100,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
*/
public function save($pFilename = null)
{
if (!is_null($this->_presentation)) {
if (!is_null($this->_document)) {
// If $pFilename is php://output or php://stdout, make it a temporary file...
$originalFilename = $pFilename;
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
@ -123,16 +124,19 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
// Add mimetype to ZIP file
//@todo Not in ZIPARCHIVE::CM_STORE mode
$objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->writeMimetype($this->_presentation));
$objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->writeMimetype($this->_document));
// Add content.xml to ZIP file
$objZip->addFromString('content.xml', $this->getWriterPart('content')->writeContent($this->_presentation));
$objZip->addFromString('content.xml', $this->getWriterPart('content')->writeContent($this->_document));
// Add meta.xml to ZIP file
$objZip->addFromString('meta.xml', $this->getWriterPart('meta')->writeMeta($this->_presentation));
$objZip->addFromString('meta.xml', $this->getWriterPart('meta')->writeMeta($this->_document));
// Add styles.xml to ZIP file
$objZip->addFromString('styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document));
// Add META-INF/manifest.xml
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->_presentation));
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->_document));
// Add media
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
@ -192,8 +196,8 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
* @throws Exception
*/
public function getPHPWord() {
if (!is_null($this->_presentation)) {
return $this->_presentation;
if (!is_null($this->_document)) {
return $this->_document;
} else {
throw new Exception("No PHPWord assigned.");
}
@ -207,7 +211,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
* @return PHPWord_Writer_PowerPoint2007
*/
public function setPHPWord(PHPWord $pPHPWord = null) {
$this->_presentation = $pPHPWord;
$this->_document = $pPHPWord;
return $this;
}

View File

@ -89,17 +89,206 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
$objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2');
// We firstly search all fonts used
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
if($countSections > 0) {
$pSection = 0;
$numPStyles = 0;
$numFStyles = 0;
foreach($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach($_elements as $element) {
if($element instanceof PHPWord_Section_Text) {
$fStyle = $element->getFontStyle();
$pStyle = $element->getParagraphStyle();
if($fStyle instanceof PHPWord_Style_Font){
$numFStyles++;
$arrStyle = array(
'color'=>$fStyle->getColor(),
'name' =>$fStyle->getName()
);
$pPHPWord->addFontStyle('T'.$numFStyles, $arrStyle);
$element->setFontStyle('T'.$numFStyles);
}
elseif($pStyle instanceof PHPWord_Style_Paragraph){
$numPStyles++;
$pPHPWord->addParagraphStyle('P'.$numPStyles, array());
$element->setParagraph('P'.$numPStyles);
}
}
}
}
}
// office:font-face-decls
$objWriter->startElement('office:font-face-decls');
$arrFonts = array();
// office:automatic-styles
$objWriter->startElement('office:automatic-styles');
$objWriter->endElement();
$styles = PHPWord_Style::getStyles();
$numFonts = 0;
if(count($styles) > 0) {
foreach($styles as $styleName => $style) {
// PHPWord_Style_Font
if($style instanceof PHPWord_Style_Font) {
$numFonts++;
$name = $style->getName();
if(!in_array($name, $arrFonts)){
$arrFonts[] = $name;
// style:font-face
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
}
}
}
if(!in_array('Arial', $arrFonts)){
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', 'Arial');
$objWriter->writeAttribute('svg:font-family', 'Arial');
$objWriter->endElement();
}
}
$objWriter->endElement();
$objWriter->startElement('office:automatic-styles');
$styles = PHPWord_Style::getStyles();
$numPStyles = 0;
if(count($styles) > 0) {
foreach($styles as $styleName => $style) {
if(preg_match('#^T[0-9]+$#', $styleName) != 0
|| preg_match('#^P[0-9]+$#', $styleName) != 0){
// PHPWord_Style_Font
if($style instanceof PHPWord_Style_Font) {
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:color', '#'.$style->getColor());
$objWriter->writeAttribute('style:font-name', $style->getName());
$objWriter->writeAttribute('style:font-name-complex', $style->getName());
$objWriter->endElement();
$objWriter->endElement();
}
if($style instanceof PHPWord_Style_Paragraph){
$numPStyles++;
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'paragraph');
$objWriter->writeAttribute('style:parent-style-name', 'Standard');
$objWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('style:page-number', 'auto');
$objWriter->endElement();
$objWriter->endElement();
}
}
}
if($numPStyles == 0){
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', 'P1');
$objWriter->writeAttribute('style:family', 'paragraph');
$objWriter->writeAttribute('style:parent-style-name', 'Standard');
$objWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('style:page-number', 'auto');
$objWriter->endElement();
$objWriter->endElement();
}
}
$objWriter->endElement();
// office:body
$objWriter->startElement('office:body');
// office:text
$objWriter->startElement('office:text');
// text:sequence-decls
$objWriter->startElement('text:sequence-decls');
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Illustration');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Table');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Text');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Drawing');
$objWriter->endElement();
$objWriter->endElement();
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if($countSections > 0) {
foreach($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach($_elements as $element) {
if($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
}/* elseif($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element);
}*/ elseif($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter);
}/* elseif($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter);
} elseif($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
} elseif($element instanceof PHPWord_Section_ListItem) {
$this->_writeListItem($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage) {
$this->_writeImage($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Object) {
$this->_writeObject($objWriter, $element);
} elseif($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter);
}*/
else {
print_r($element);
echo '<br />';
}
}
if($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section);
} else {
$this->_writeSection($objWriter, $section);
}
}
}
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
@ -107,4 +296,52 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
// Return
return $objWriter->getData();
}
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();
}
}
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) {
$objWriter->startElement('text:p');
$objWriter->writeAttribute('text:style-name', 'Standard');
$objWriter->endElement();
}
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) {
}
}

View File

@ -76,7 +76,12 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'meta.xml');
$objWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'styles.xml');
$objWriter->endElement();
for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());

View File

@ -0,0 +1,274 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2009 - 2010 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord_Writer_ODText
* @copyright Copyright (c) 2009 - 2010 PHPWord (http://www.codeplex.com/PHPWord)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPWord_Writer_ODText_Styles
*
* @category PHPWord
* @package PHPWord_Writer_ODText
* @copyright Copyright (c) 2009 - 2010 PHPWord (http://www.codeplex.com/PHPWord)
*/
class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
{
/**
* Write Styles file to XML format
*
* @param PHPWord $pPHPWord
* @return string XML Output
* @throws Exception
*/
public function writeStyles(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0','UTF-8');
// Styles:Styles
$objWriter->startElement('office:document-styles');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2');
// office:font-face-decls
$objWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = PHPWord_Style::getStyles();
$numFonts = 0;
if(count($styles) > 0) {
foreach($styles as $styleName => $style) {
// PHPWord_Style_Font
if($style instanceof PHPWord_Style_Font) {
$numFonts++;
$name = $style->getName();
if(!in_array($name, $arrFonts)){
$arrFonts[] = $name;
// style:font-face
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
}
}
}
}
if(!in_array('Arial', $arrFonts)){
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', 'Arial');
$objWriter->writeAttribute('svg:font-family', 'Arial');
$objWriter->endElement();
}
$objWriter->endElement();
// office:styles
$objWriter->startElement('office:styles');
// style:default-style
$objWriter->startElement('style:default-style');
$objWriter->writeAttribute('style:family', 'paragraph');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit');
$objWriter->writeAttribute('style:text-autospace', 'ideograph-alpha');
$objWriter->writeAttribute('style:punctuation-wrap', 'hanging');
$objWriter->writeAttribute('style:line-break', 'strict');
$objWriter->writeAttribute('style:tab-stop-distance', '1.249cm');
$objWriter->writeAttribute('style:writing-mode', 'page');
$objWriter->endElement();
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('style:use-window-font-color', 'true');
$objWriter->writeAttribute('style:font-name', 'Arial');
$objWriter->writeAttribute('fo:font-size', '10pt');
$objWriter->writeAttribute('fo:language', 'fr');
$objWriter->writeAttribute('fo:country', 'FR');
$objWriter->writeAttribute('style:letter-kerning', 'true');
$objWriter->writeAttribute('style:font-name-asian', 'Arial2');
$objWriter->writeAttribute('style:font-size-asian', '10pt');
$objWriter->writeAttribute('style:language-asian', 'zh');
$objWriter->writeAttribute('style:country-asian', 'CN');
$objWriter->writeAttribute('style:font-name-complex', 'Arial2');
$objWriter->writeAttribute('style:font-size-complex', '10pt');
$objWriter->writeAttribute('style:language-complex', 'hi');
$objWriter->writeAttribute('style:country-complex', 'IN');
$objWriter->writeAttribute('fo:hyphenate', 'false');
$objWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
$objWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
$objWriter->endElement();
$objWriter->endElement();
// Write Style Definitions
$styles = PHPWord_Style::getStyles();
if(count($styles) > 0) {
foreach($styles as $styleName => $style) {
if(preg_match('#^T[0-9]+$#', $styleName) == 0
&& preg_match('#^P[0-9]+$#', $styleName) == 0){
// PHPWord_Style_Font
if($style instanceof PHPWord_Style_Font) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:font-size', ($style->getSize() / 2).'pt');
$objWriter->writeAttribute('style:font-size-asian', ($style->getSize() / 2).'pt');
$objWriter->writeAttribute('style:font-size-complex', ($style->getSize() / 2).'pt');
if($style->getItalic()) {
$objWriter->writeAttribute('fo:font-style', 'italic');
$objWriter->writeAttribute('style:font-style-asian', 'italic');
$objWriter->writeAttribute('style:font-style-complex', 'italic');
}
if($style->getBold()) {
$objWriter->writeAttribute('fo:font-weight', 'bold');
$objWriter->writeAttribute('style:font-weight-asian', 'bold');
}
$objWriter->endElement();
$objWriter->endElement();
}
// PHPWord_Style_Paragraph
elseif($style instanceof PHPWord_Style_Paragraph) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'paragraph');
//style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)).'cm');
$objWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)).'cm');
$objWriter->writeAttribute('fo:text-align', $style->getAlign());
$objWriter->endElement();
$objWriter->endElement();
}
// PHPWord_Style_TableFull
elseif($style instanceof PHPWord_Style_TableFull) {
}
}
}
}
$objWriter->endElement();
// office:automatic-styles
$objWriter->startElement('office:automatic-styles');
// style:page-layout
$objWriter->startElement('style:page-layout');
$objWriter->writeAttribute('style:name', 'Mpm1');
// style:page-layout-properties
$objWriter->startElement('style:page-layout-properties');
$objWriter->writeAttribute('fo:page-width', "21.001cm");
$objWriter->writeAttribute('fo:page-height','29.7cm');
$objWriter->writeAttribute('style:num-format','1');
$objWriter->writeAttribute('style:print-orientation','portrait');
$objWriter->writeAttribute('fo:margin-top','2.501cm');
$objWriter->writeAttribute('fo:margin-bottom','2cm');
$objWriter->writeAttribute('fo:margin-left','2.501cm');
$objWriter->writeAttribute('fo:margin-right','2.501cm');
$objWriter->writeAttribute('style:writing-mode','lr-tb');
$objWriter->writeAttribute('style:layout-grid-color','#c0c0c0');
$objWriter->writeAttribute('style:layout-grid-lines','25199');
$objWriter->writeAttribute('style:layout-grid-base-height','0.423cm');
$objWriter->writeAttribute('style:layout-grid-ruby-height','0cm');
$objWriter->writeAttribute('style:layout-grid-mode','none');
$objWriter->writeAttribute('style:layout-grid-ruby-below','false');
$objWriter->writeAttribute('style:layout-grid-print','false');
$objWriter->writeAttribute('style:layout-grid-display','false');
$objWriter->writeAttribute('style:layout-grid-base-width','0.37cm');
$objWriter->writeAttribute('style:layout-grid-snap-to','true');
$objWriter->writeAttribute('style:footnote-max-height','0cm');
//style:footnote-sep
$objWriter->startElement('style:footnote-sep');
$objWriter->writeAttribute('style:width', '0.018cm');
$objWriter->writeAttribute('style:line-style','solid');
$objWriter->writeAttribute('style:adjustment','left');
$objWriter->writeAttribute('style:rel-width','25%');
$objWriter->writeAttribute('style:color','#000000');
$objWriter->endElement();
$objWriter->endElement();
// style:header-style
$objWriter->startElement('style:header-style');
$objWriter->endElement();
// style:footer-style
$objWriter->startElement('style:footer-style');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// office:master-styles
$objWriter->startElement('office:master-styles');
// style:master-page
$objWriter->startElement('style:master-page');
$objWriter->writeAttribute('style:name', 'Standard');
$objWriter->writeAttribute('style:page-layout-name', 'Mpm1');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}