From 891798bc160948c6c08fcab3a0990b980a485447 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Tue, 31 Dec 2013 14:34:50 +0700 Subject: [PATCH 01/12] Unix format --- Classes/PHPWord/_staticDocParts/settings.xml | 2 +- README.md | 184 +++++++++---------- 2 files changed, 93 insertions(+), 93 deletions(-) diff --git a/Classes/PHPWord/_staticDocParts/settings.xml b/Classes/PHPWord/_staticDocParts/settings.xml index 5eb2289137..56ca986006 100644 --- a/Classes/PHPWord/_staticDocParts/settings.xml +++ b/Classes/PHPWord/_staticDocParts/settings.xml @@ -1,4 +1,4 @@ - + diff --git a/README.md b/README.md index 21c15959ac..d1d73199d6 100755 --- a/README.md +++ b/README.md @@ -1,92 +1,92 @@ -# PHPWord - OpenXML - Read, Write and Create Word documents in PHP - -PHPWord is a library written in PHP that create word documents. -No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be -opened by all major office software. - -## Want to contribute? -Fork us! - -## Requirements - -* PHP version 5.3.0 or higher - -## License -PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md) - -## Installation - -It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add -the following lines to your ``composer.json``. - -```json -{ - "require": { - "phpoffice/phpword": "dev-master" - } -} -``` - -## Usage - -The following is a basic example of the PHPWord library. - -```php -$PHPWord = new PHPWord(); - -// Every element you want to append to the word document is placed in a section. So you need a section: -$section = $PHPWord->createSection(); - -// After creating a section, you can append elements: -$section->addText('Hello world!'); - -// You can directly style your text by giving the addText function an array: -$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); - -// If you often need the same style again you can create a user defined style to the word document -// and give the addText function the name of the style: -$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); -$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); - -// You can also putthe appended element to local object an call functions like this: -$myTextElement = $section->addText('Hello World!'); -$myTextElement->setBold(); -$myTextElement->setName('Verdana'); -$myTextElement->setSize(22); - -// At least write the document to webspace: -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('helloWorld.docx'); -``` - -## Images - -You can add images easily using the following example. - -```php -$section = $PHPWord->createSection(); -$section->addImage('mars.jpg'); -``` - -Images settings include: - * ``width`` width in pixels - * ``height`` height in pixels - * ``align`` image alignment, __left__, __right__ or __center__ - * ``marginTop`` top margin in inches, can be negative - * ``marginLeft`` left margin in inches, can be negative - * ``wrappingStyle`` can be inline, __square__, __tight__, __behind__, __infront__ - - To add an image with settings, consider the following example. - - ```php -$section->addImage( - 'mars.jpg', - array( - 'width' => 100, - 'height' => 100, - 'marginTop' => -1, - 'marginLeft' => -1, - wrappingStyle => 'behind' - ) -); - ``` +# PHPWord - OpenXML - Read, Write and Create Word documents in PHP + +PHPWord is a library written in PHP that create word documents. +No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be +opened by all major office software. + +## Want to contribute? +Fork us! + +## Requirements + +* PHP version 5.3.0 or higher + +## License +PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md) + +## Installation + +It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add +the following lines to your ``composer.json``. + +```json +{ + "require": { + "phpoffice/phpword": "dev-master" + } +} +``` + +## Usage + +The following is a basic example of the PHPWord library. + +```php +$PHPWord = new PHPWord(); + +// Every element you want to append to the word document is placed in a section. So you need a section: +$section = $PHPWord->createSection(); + +// After creating a section, you can append elements: +$section->addText('Hello world!'); + +// You can directly style your text by giving the addText function an array: +$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); + +// If you often need the same style again you can create a user defined style to the word document +// and give the addText function the name of the style: +$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); +$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); + +// You can also putthe appended element to local object an call functions like this: +$myTextElement = $section->addText('Hello World!'); +$myTextElement->setBold(); +$myTextElement->setName('Verdana'); +$myTextElement->setSize(22); + +// At least write the document to webspace: +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('helloWorld.docx'); +``` + +## Images + +You can add images easily using the following example. + +```php +$section = $PHPWord->createSection(); +$section->addImage('mars.jpg'); +``` + +Images settings include: + * ``width`` width in pixels + * ``height`` height in pixels + * ``align`` image alignment, __left__, __right__ or __center__ + * ``marginTop`` top margin in inches, can be negative + * ``marginLeft`` left margin in inches, can be negative + * ``wrappingStyle`` can be inline, __square__, __tight__, __behind__, __infront__ + + To add an image with settings, consider the following example. + + ```php +$section->addImage( + 'mars.jpg', + array( + 'width' => 100, + 'height' => 100, + 'marginTop' => -1, + 'marginLeft' => -1, + wrappingStyle => 'behind' + ) +); + ``` From 3037fbf59e3b2a019dc3af4f81e2201aa4771219 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Wed, 1 Jan 2014 18:59:19 +0700 Subject: [PATCH 02/12] Read README.md --- Classes/PHPWord/Section/Settings.php | 20 ++++++++++++ Classes/PHPWord/Section/TextRun.php | 10 ++++++ Classes/PHPWord/Style/Paragraph.php | 34 +++++++++++++++++++- Classes/PHPWord/Writer/Word2007/Base.php | 21 ++++++++++-- Classes/PHPWord/Writer/Word2007/Document.php | 8 ++++- Classes/PHPWord/Writer/Word2007/Styles.php | 30 +++++++++++++++++ README.md | 10 +++++- 7 files changed, 128 insertions(+), 5 deletions(-) diff --git a/Classes/PHPWord/Section/Settings.php b/Classes/PHPWord/Section/Settings.php index e168821c87..87596a3e22 100755 --- a/Classes/PHPWord/Section/Settings.php +++ b/Classes/PHPWord/Section/Settings.php @@ -150,6 +150,9 @@ class PHPWord_Section_Settings */ private $_borderBottomColor; + private $_colsNum; + private $_colsSpace; + /** * Create new Section Settings */ @@ -170,6 +173,8 @@ public function __construct() $this->_borderRightColor = null; $this->_borderBottomSize = null; $this->_borderBottomColor = null; + $this->_colsNum = 1; + $this->_colsSpace = 360; } /** @@ -542,4 +547,19 @@ public function getBorderBottomColor() { return $this->_borderBottomColor; } + + public function getColsNum() { + return $this->_colsNum; + } + public function setColsNum($pValue = '') { + $this->_colsNum = $pValue; + return $this; + } + public function getColsSpace() { + return $this->_colsSpace; + } + public function setColsSpace($pValue = '') { + $this->_colsSpace = $pValue; + return $this; + } } diff --git a/Classes/PHPWord/Section/TextRun.php b/Classes/PHPWord/Section/TextRun.php index 2c7a216697..cfa5bc6c74 100755 --- a/Classes/PHPWord/Section/TextRun.php +++ b/Classes/PHPWord/Section/TextRun.php @@ -109,6 +109,16 @@ public function addLink($linkSrc, $linkName = null, $styleFont = null) return $link; } + /** + * Add a TextBreak Element + * + * @param int $count + */ + public function addTextBreak($count = 1) { + for($i=1; $i<=$count; $i++) { + $this->_elementCollection[] = new PHPWord_Section_TextBreak(); + } + } /** * Get TextRun content * diff --git a/Classes/PHPWord/Style/Paragraph.php b/Classes/PHPWord/Style/Paragraph.php index ccbbd616d9..3f367e5eb6 100755 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/Classes/PHPWord/Style/Paragraph.php @@ -73,6 +73,12 @@ class PHPWord_Style_Paragraph */ private $_indent; + /** + * Hanging by how much + * + * @var int + */ + private $_hanging; /** * New Paragraph Style @@ -85,6 +91,7 @@ public function __construct() $this->_spacing = null; $this->_tabs = null; $this->_indent = null; + $this->_hanging = null; } /** @@ -96,7 +103,10 @@ public function __construct() public function setStyleValue($key, $value) { if ($key == '_indent') { - $value = (int)$value * 720; // 720 twips per indent + $value = $value * 1440 / 2.54; // Measured by cm + } + if ($key == '_hanging') { + $value = $value * 1440 / 2.54; // Measured by cm } if ($key == '_spacing') { $value += 240; // because line height of 1 matches 240 twips @@ -221,6 +231,28 @@ public function setIndent($pValue = null) return $this; } + /** + * Get hanging + * + * @return int + */ + public function getHanging() + { + return $this->_hanging; + } + + /** + * Set hanging + * + * @param int $pValue + * @return PHPWord_Style_Paragraph + */ + public function setHanging($pValue = null) + { + $this->_hanging = $pValue; + return $this; + } + /** * Get tabs * diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 331625fccb..c9e81ab85a 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -106,6 +106,8 @@ protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHP $this->_writeText($objWriter, $element, true); } elseif ($element instanceof PHPWord_Section_Link) { $this->_writeLink($objWriter, $element, true); + } elseif($element instanceof PHPWord_Section_TextBreak) { + $objWriter->writeElement('w:br'); } } } @@ -120,6 +122,7 @@ protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = nu $spaceAfter = $style->getSpaceAfter(); $spacing = $style->getSpacing(); $indent = $style->getIndent(); + $hanging = $style->getHanging(); $tabs = $style->getTabs(); if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($indent) || !is_null($tabs)) { @@ -133,10 +136,15 @@ protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = nu $objWriter->endElement(); } - if (!is_null($indent)) { + if (!is_null($indent) || !is_null($hanging)) { $objWriter->startElement('w:ind'); $objWriter->writeAttribute('w:firstLine', 0); - $objWriter->writeAttribute('w:left', $indent); + if (!is_null($indent)) { + $objWriter->writeAttribute('w:left', $indent); + } + if (!is_null($hanging)) { + $objWriter->writeAttribute('w:hanging', $hanging); + } $objWriter->endElement(); } @@ -320,6 +328,8 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P $fgColor = $style->getFgColor(); $striketrough = $style->getStrikethrough(); $underline = $style->getUnderline(); + $superscript = $style->getSuperScript(); + $subscript = $style->getSubScript(); $objWriter->startElement('w:rPr'); @@ -379,6 +389,13 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P $objWriter->endElement(); } + // Superscript/subscript + if ($superscript || $subscript) { + $objWriter->startElement('w:vertAlign'); + $objWriter->writeAttribute('w:val', $superscript ? 'superscript' : 'subscript'); + $objWriter->endElement(); + } + $objWriter->endElement(); } diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php index 6539dd21e9..32c6954775 100755 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ b/Classes/PHPWord/Writer/Word2007/Document.php @@ -137,6 +137,9 @@ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PH $borders = $_settings->getBorderSize(); + $colsNum = $_settings->getColsNum(); + $colsSpace = $_settings->getColsSpace(); + $objWriter->startElement('w:sectPr'); foreach ($_headers as &$_header) { @@ -227,7 +230,10 @@ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PH $objWriter->startElement('w:cols'); - $objWriter->writeAttribute('w:space', '720'); + if($colsNum > 1){ + $objWriter->writeAttribute('w:num', $colsNum); + } + $objWriter->writeAttribute('w:space', $colsSpace); $objWriter->endElement(); diff --git a/Classes/PHPWord/Writer/Word2007/Styles.php b/Classes/PHPWord/Writer/Word2007/Styles.php index 71aca63711..fd4be1e1a8 100755 --- a/Classes/PHPWord/Writer/Word2007/Styles.php +++ b/Classes/PHPWord/Writer/Word2007/Styles.php @@ -56,6 +56,27 @@ public function writeStyles(PHPWord $pPHPWord = null) // Write DocDefaults $this->_writeDocDefaults($objWriter); + // Write Normal + // Start Hack + $objWriter->startElement('w:style'); + $objWriter->writeAttribute('w:type', 'paragraph'); + $objWriter->writeAttribute('w:default', '1'); + $objWriter->writeAttribute('w:styleId', 'Normal'); + + $objWriter->startElement('w:name'); + $objWriter->writeAttribute('w:val', 'Normal'); + $objWriter->endElement(); + + $objWriter->startElement('w:pPr'); + $objWriter->startElement('w:spacing'); + $objWriter->writeAttribute('w:before', 20 * 0); + $objWriter->writeAttribute('w:after', 20 * 0); + $objWriter->writeAttribute('w:line', 240 * 1); + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->endElement(); + // End Hack // Write Style Definitions $styles = PHPWord_Style::getStyles(); @@ -92,6 +113,10 @@ public function writeStyles(PHPWord $pPHPWord = null) $objWriter->endElement(); if (!is_null($paragraphStyle)) { + // 2013-12-31 11:34 IL + $objWriter->startElement('w:basedOn'); + $objWriter->writeAttribute('w:val', 'Normal'); + $objWriter->endElement(); $this->_writeParagraphStyle($objWriter, $paragraphStyle); } @@ -109,6 +134,11 @@ public function writeStyles(PHPWord $pPHPWord = null) $objWriter->writeAttribute('w:val', $styleName); $objWriter->endElement(); + // 2013-12-31 11:34 IL + $objWriter->startElement('w:basedOn'); + $objWriter->writeAttribute('w:val', 'Normal'); + $objWriter->endElement(); + $this->_writeParagraphStyle($objWriter, $style); $objWriter->endElement(); diff --git a/README.md b/README.md index d1d73199d6..8e57b9ddee 100755 --- a/README.md +++ b/README.md @@ -1,9 +1,17 @@ # PHPWord - OpenXML - Read, Write and Create Word documents in PHP -PHPWord is a library written in PHP that create word documents. +PHPWord is a library written in PHP that create word documents. No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be opened by all major office software. +## Forked features by Ivan Lanin + +* Superscript/subscript `w:vertAlign` +* Hanging +* Section with column +* Softbreak (SHIFT + ENTER) in Text Run +* Redefine normal paragraph style and base all other style from it + ## Want to contribute? Fork us! From 3fa49ee53b2e031391f8c83fb63e459a4c792380 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Wed, 1 Jan 2014 20:12:51 +0700 Subject: [PATCH 03/12] section breakType --- Classes/PHPWord/Section/Settings.php | 12 ++- Classes/PHPWord/Writer/Word2007/Document.php | 8 ++ README.md | 90 +------------------- 3 files changed, 22 insertions(+), 88 deletions(-) diff --git a/Classes/PHPWord/Section/Settings.php b/Classes/PHPWord/Section/Settings.php index 87596a3e22..c005ae40f8 100755 --- a/Classes/PHPWord/Section/Settings.php +++ b/Classes/PHPWord/Section/Settings.php @@ -152,6 +152,7 @@ class PHPWord_Section_Settings private $_colsNum; private $_colsSpace; + private $_breakType; /** * Create new Section Settings @@ -174,7 +175,8 @@ public function __construct() $this->_borderBottomSize = null; $this->_borderBottomColor = null; $this->_colsNum = 1; - $this->_colsSpace = 360; + $this->_colsSpace = 0.5 * 1440 / 2.54; // in twips: 1 twip = 1/1440 in; 1 cm = 2.54 in + $this->_breakType = null; } /** @@ -562,4 +564,12 @@ public function setColsSpace($pValue = '') { $this->_colsSpace = $pValue; return $this; } + + public function getBreakType() { + return $this->_breakType; + } + public function setBreakType($pValue = null) { + $this->_breakType = $pValue; + return $this; + } } diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php index 32c6954775..bcb5b756d4 100755 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ b/Classes/PHPWord/Writer/Word2007/Document.php @@ -139,6 +139,7 @@ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PH $colsNum = $_settings->getColsNum(); $colsSpace = $_settings->getColsSpace(); + $breakType = $_settings->getBreakType(); $objWriter->startElement('w:sectPr'); @@ -155,6 +156,13 @@ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PH $objWriter->endElement(); } + // http://www.schemacentral.com/sc/ooxml/a-w_val-43.html + if (!is_null($breakType)) { + $objWriter->startElement('w:type'); + $objWriter->writeAttribute('w:val', $breakType); + $objWriter->endElement(); + } + if (!is_null($_footer)) { $rId = $_footer->getRelationId(); $objWriter->startElement('w:footerReference'); diff --git a/README.md b/README.md index 8e57b9ddee..ea995d2fb2 100755 --- a/README.md +++ b/README.md @@ -1,100 +1,16 @@ # PHPWord - OpenXML - Read, Write and Create Word documents in PHP PHPWord is a library written in PHP that create word documents. -No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be -opened by all major office software. -## Forked features by Ivan Lanin +## Add features in this fork * Superscript/subscript `w:vertAlign` * Hanging * Section with column * Softbreak (SHIFT + ENTER) in Text Run * Redefine normal paragraph style and base all other style from it - -## Want to contribute? -Fork us! - -## Requirements - -* PHP version 5.3.0 or higher +* Section `breakType`. Used especially for continuous column ## License -PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md) - -## Installation - -It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add -the following lines to your ``composer.json``. - -```json -{ - "require": { - "phpoffice/phpword": "dev-master" - } -} -``` - -## Usage - -The following is a basic example of the PHPWord library. - -```php -$PHPWord = new PHPWord(); - -// Every element you want to append to the word document is placed in a section. So you need a section: -$section = $PHPWord->createSection(); -// After creating a section, you can append elements: -$section->addText('Hello world!'); - -// You can directly style your text by giving the addText function an array: -$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); - -// If you often need the same style again you can create a user defined style to the word document -// and give the addText function the name of the style: -$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); -$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); - -// You can also putthe appended element to local object an call functions like this: -$myTextElement = $section->addText('Hello World!'); -$myTextElement->setBold(); -$myTextElement->setName('Verdana'); -$myTextElement->setSize(22); - -// At least write the document to webspace: -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('helloWorld.docx'); -``` - -## Images - -You can add images easily using the following example. - -```php -$section = $PHPWord->createSection(); -$section->addImage('mars.jpg'); -``` - -Images settings include: - * ``width`` width in pixels - * ``height`` height in pixels - * ``align`` image alignment, __left__, __right__ or __center__ - * ``marginTop`` top margin in inches, can be negative - * ``marginLeft`` left margin in inches, can be negative - * ``wrappingStyle`` can be inline, __square__, __tight__, __behind__, __infront__ - - To add an image with settings, consider the following example. - - ```php -$section->addImage( - 'mars.jpg', - array( - 'width' => 100, - 'height' => 100, - 'marginTop' => -1, - 'marginLeft' => -1, - wrappingStyle => 'behind' - ) -); - ``` +PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md) From 0edaaaab500fa9fb7278d8b8f791dfba6a980eb3 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 2 Jan 2014 00:59:38 +0700 Subject: [PATCH 04/12] Tidy up for pull request --- Classes/PHPWord/Section/Settings.php | 67 ++++++++++++-- Classes/PHPWord/Style/Paragraph.php | 26 +++--- Classes/PHPWord/Writer/Word2007/Document.php | 4 +- Classes/PHPWord/Writer/Word2007/Styles.php | 23 ++--- README.md | 94 ++++++++++++++++++-- 5 files changed, 168 insertions(+), 46 deletions(-) diff --git a/Classes/PHPWord/Section/Settings.php b/Classes/PHPWord/Section/Settings.php index c005ae40f8..487a9d1952 100755 --- a/Classes/PHPWord/Section/Settings.php +++ b/Classes/PHPWord/Section/Settings.php @@ -150,8 +150,25 @@ class PHPWord_Section_Settings */ private $_borderBottomColor; + /** + * Section Columns Count + * + * @var int + */ private $_colsNum; + + /** + * Section Spacing Between Columns + * + * @var int + */ private $_colsSpace; + + /** + * Section Break Type + * + * @var string + */ private $_breakType; /** @@ -175,7 +192,7 @@ public function __construct() $this->_borderBottomSize = null; $this->_borderBottomColor = null; $this->_colsNum = 1; - $this->_colsSpace = 0.5 * 1440 / 2.54; // in twips: 1 twip = 1/1440 in; 1 cm = 2.54 in + $this->_colsSpace = 720; $this->_breakType = null; } @@ -550,26 +567,60 @@ public function getBorderBottomColor() return $this->_borderBottomColor; } - public function getColsNum() { - return $this->_colsNum; - } + /** + * Set Section Columns Count + * + * @param in $pValue + */ public function setColsNum($pValue = '') { $this->_colsNum = $pValue; return $this; } - public function getColsSpace() { - return $this->_colsSpace; + + /** + * Get Section Columns Count + * + * @return int + */ + public function getColsNum() { + return $this->_colsNum; } + + /** + * Set Section Space Between Columns + * + * @param int $pValue + */ public function setColsSpace($pValue = '') { $this->_colsSpace = $pValue; return $this; } - public function getBreakType() { - return $this->_breakType; + /** + * Get Section Space Between Columns + * + * @return int + */ + public function getColsSpace() { + return $this->_colsSpace; } + + /** + * Set Break Type + * + * @param string $pValue + */ public function setBreakType($pValue = null) { $this->_breakType = $pValue; return $this; } + + /** + * Get Break Type + * + * @return string + */ + public function getBreakType() { + return $this->_breakType; + } } diff --git a/Classes/PHPWord/Style/Paragraph.php b/Classes/PHPWord/Style/Paragraph.php index 3f367e5eb6..c5c0070bae 100755 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/Classes/PHPWord/Style/Paragraph.php @@ -103,10 +103,10 @@ public function __construct() public function setStyleValue($key, $value) { if ($key == '_indent') { - $value = $value * 1440 / 2.54; // Measured by cm + $value = (int)$value * 720; // 720 twips per indent } if ($key == '_hanging') { - $value = $value * 1440 / 2.54; // Measured by cm + $value =(int)$value * 720; } if ($key == '_spacing') { $value += 240; // because line height of 1 matches 240 twips @@ -231,16 +231,6 @@ public function setIndent($pValue = null) return $this; } - /** - * Get hanging - * - * @return int - */ - public function getHanging() - { - return $this->_hanging; - } - /** * Set hanging * @@ -253,10 +243,20 @@ public function setHanging($pValue = null) return $this; } + /** + * Get hanging + * + * @return int + */ + public function getHanging() + { + return $this->_hanging; + } + /** * Get tabs * - * @return PHPWord_Style_Tabs + * @return PHPWord_Style_Paragraph */ public function getTabs() { diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php index bcb5b756d4..738476cd6c 100755 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ b/Classes/PHPWord/Writer/Word2007/Document.php @@ -240,8 +240,10 @@ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PH $objWriter->startElement('w:cols'); if($colsNum > 1){ $objWriter->writeAttribute('w:num', $colsNum); + $objWriter->writeAttribute('w:space', $colsSpace); + } else { + $objWriter->writeAttribute('w:space', '720'); } - $objWriter->writeAttribute('w:space', $colsSpace); $objWriter->endElement(); diff --git a/Classes/PHPWord/Writer/Word2007/Styles.php b/Classes/PHPWord/Writer/Word2007/Styles.php index fd4be1e1a8..fb39b57bb9 100755 --- a/Classes/PHPWord/Writer/Word2007/Styles.php +++ b/Classes/PHPWord/Writer/Word2007/Styles.php @@ -56,27 +56,22 @@ public function writeStyles(PHPWord $pPHPWord = null) // Write DocDefaults $this->_writeDocDefaults($objWriter); - // Write Normal - // Start Hack + // Reset Normal Paragraph Style $objWriter->startElement('w:style'); $objWriter->writeAttribute('w:type', 'paragraph'); $objWriter->writeAttribute('w:default', '1'); $objWriter->writeAttribute('w:styleId', 'Normal'); - $objWriter->startElement('w:name'); $objWriter->writeAttribute('w:val', 'Normal'); - $objWriter->endElement(); - + $objWriter->endElement(); // w:name $objWriter->startElement('w:pPr'); $objWriter->startElement('w:spacing'); - $objWriter->writeAttribute('w:before', 20 * 0); - $objWriter->writeAttribute('w:after', 20 * 0); - $objWriter->writeAttribute('w:line', 240 * 1); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->endElement(); - // End Hack + $objWriter->writeAttribute('w:before', 0); + $objWriter->writeAttribute('w:after', 0); + $objWriter->writeAttribute('w:line', 240); + $objWriter->endElement(); // w:spacing + $objWriter->endElement(); // w:pPr + $objWriter->endElement(); // w:style // Write Style Definitions $styles = PHPWord_Style::getStyles(); @@ -113,7 +108,6 @@ public function writeStyles(PHPWord $pPHPWord = null) $objWriter->endElement(); if (!is_null($paragraphStyle)) { - // 2013-12-31 11:34 IL $objWriter->startElement('w:basedOn'); $objWriter->writeAttribute('w:val', 'Normal'); $objWriter->endElement(); @@ -134,7 +128,6 @@ public function writeStyles(PHPWord $pPHPWord = null) $objWriter->writeAttribute('w:val', $styleName); $objWriter->endElement(); - // 2013-12-31 11:34 IL $objWriter->startElement('w:basedOn'); $objWriter->writeAttribute('w:val', 'Normal'); $objWriter->endElement(); diff --git a/README.md b/README.md index ea995d2fb2..d1d73199d6 100755 --- a/README.md +++ b/README.md @@ -1,16 +1,92 @@ # PHPWord - OpenXML - Read, Write and Create Word documents in PHP -PHPWord is a library written in PHP that create word documents. +PHPWord is a library written in PHP that create word documents. +No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be +opened by all major office software. -## Add features in this fork +## Want to contribute? +Fork us! -* Superscript/subscript `w:vertAlign` -* Hanging -* Section with column -* Softbreak (SHIFT + ENTER) in Text Run -* Redefine normal paragraph style and base all other style from it -* Section `breakType`. Used especially for continuous column +## Requirements -## License +* PHP version 5.3.0 or higher +## License PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md) + +## Installation + +It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add +the following lines to your ``composer.json``. + +```json +{ + "require": { + "phpoffice/phpword": "dev-master" + } +} +``` + +## Usage + +The following is a basic example of the PHPWord library. + +```php +$PHPWord = new PHPWord(); + +// Every element you want to append to the word document is placed in a section. So you need a section: +$section = $PHPWord->createSection(); + +// After creating a section, you can append elements: +$section->addText('Hello world!'); + +// You can directly style your text by giving the addText function an array: +$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); + +// If you often need the same style again you can create a user defined style to the word document +// and give the addText function the name of the style: +$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); +$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); + +// You can also putthe appended element to local object an call functions like this: +$myTextElement = $section->addText('Hello World!'); +$myTextElement->setBold(); +$myTextElement->setName('Verdana'); +$myTextElement->setSize(22); + +// At least write the document to webspace: +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('helloWorld.docx'); +``` + +## Images + +You can add images easily using the following example. + +```php +$section = $PHPWord->createSection(); +$section->addImage('mars.jpg'); +``` + +Images settings include: + * ``width`` width in pixels + * ``height`` height in pixels + * ``align`` image alignment, __left__, __right__ or __center__ + * ``marginTop`` top margin in inches, can be negative + * ``marginLeft`` left margin in inches, can be negative + * ``wrappingStyle`` can be inline, __square__, __tight__, __behind__, __infront__ + + To add an image with settings, consider the following example. + + ```php +$section->addImage( + 'mars.jpg', + array( + 'width' => 100, + 'height' => 100, + 'marginTop' => -1, + 'marginLeft' => -1, + wrappingStyle => 'behind' + ) +); + ``` From 72e8f3fccf40d702e050f8cb0aa261ba4c62f502 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 2 Jan 2014 01:02:01 +0700 Subject: [PATCH 05/12] Fix comment error --- Classes/PHPWord/Style/Paragraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/PHPWord/Style/Paragraph.php b/Classes/PHPWord/Style/Paragraph.php index c5c0070bae..628f9791a7 100755 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/Classes/PHPWord/Style/Paragraph.php @@ -256,7 +256,7 @@ public function getHanging() /** * Get tabs * - * @return PHPWord_Style_Paragraph + * @return PHPWord_Style_Tabs */ public function getTabs() { From d3e8b69cc47dd67f163f87a08fd4c4f9beabbd01 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 2 Jan 2014 01:30:57 +0700 Subject: [PATCH 06/12] Remove (int) since there's a possibility for fraction --- Classes/PHPWord/Style/Paragraph.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/PHPWord/Style/Paragraph.php b/Classes/PHPWord/Style/Paragraph.php index 628f9791a7..d7e7f508e8 100755 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/Classes/PHPWord/Style/Paragraph.php @@ -103,10 +103,10 @@ public function __construct() public function setStyleValue($key, $value) { if ($key == '_indent') { - $value = (int)$value * 720; // 720 twips per indent + $value = $value * 720; // 720 twips per indent } if ($key == '_hanging') { - $value =(int)$value * 720; + $value = $value * 720; } if ($key == '_spacing') { $value += 240; // because line height of 1 matches 240 twips From d55db9da83bdc13de17824093236b87bac3e46eb Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 9 Jan 2014 07:45:41 +0700 Subject: [PATCH 07/12] Patch branch --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d1d73199d6..6ef55f31ac 100755 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # PHPWord - OpenXML - Read, Write and Create Word documents in PHP -PHPWord is a library written in PHP that create word documents. +PHPWord is a library written in PHP that create word documents. No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be opened by all major office software. +Test patch branch + ## Want to contribute? Fork us! From 4d94d5763cdd2bf6fa2a4db1985c46cf58c984a1 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Mon, 13 Jan 2014 23:14:05 +0700 Subject: [PATCH 08/12] (1) new width property for table; (2) allow table cell width to be null --- Classes/PHPWord/Section/Table.php | 30 +++++++++++++++++++++++- Classes/PHPWord/Style/Table.php | 4 ++++ Classes/PHPWord/Writer/Word2007/Base.php | 7 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Classes/PHPWord/Section/Table.php b/Classes/PHPWord/Section/Table.php index 5f3e1ea595..02aeacb7da 100755 --- a/Classes/PHPWord/Section/Table.php +++ b/Classes/PHPWord/Section/Table.php @@ -66,6 +66,13 @@ class PHPWord_Section_Table */ private $_pCount; + /** + * Table width + * + * @var int + */ + private $_width = null; + /** * Create a new table @@ -113,7 +120,7 @@ public function addRow($height = null) * @param mixed $style * @return PHPWord_Section_Table_Cell */ - public function addCell($width, $style = null) + public function addCell($width = null, $style = null) { $cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style); $i = count($this->_rows) - 1; @@ -150,4 +157,25 @@ public function getStyle() { return $this->_style; } + + /** + * Set table width + * + * @var int $width + */ + public function setWidth($width) + { + $this->_width = $width; + } + + /** + * Get table width + * + * @return int + */ + public function getWidth() + { + return $this->_width; + } + } diff --git a/Classes/PHPWord/Style/Table.php b/Classes/PHPWord/Style/Table.php index c3b49ea3ec..02a794aa30 100755 --- a/Classes/PHPWord/Style/Table.php +++ b/Classes/PHPWord/Style/Table.php @@ -30,6 +30,10 @@ */ class PHPWord_Style_Table { + const WIDTH_TYPE_NIL = 'nil'; // No Width + const WIDTH_TYPE_PERCENT = 'pct'; // Width in Fiftieths of a Percent + const WIDTH_TYPE_POINT = 'dxa'; // Width in Twentieths of a Point + const WIDTH_TYPE_AUTO = 'auto'; // Automatically Determined Width private $_cellMarginTop; private $_cellMarginLeft; diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index c9e81ab85a..47efd73a9b 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -412,6 +412,7 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo if ($_cRows > 0) { $objWriter->startElement('w:tbl'); $tblStyle = $table->getStyle(); + $tblWidth = $table->getWidth(); if ($tblStyle instanceof PHPWord_Style_Table) { $this->_writeTableStyle($objWriter, $tblStyle); } else { @@ -420,6 +421,12 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->startElement('w:tblStyle'); $objWriter->writeAttribute('w:val', $tblStyle); $objWriter->endElement(); + if (!is_null($tblWidth)) { + $objWriter->startElement('w:tblW'); + $objWriter->writeAttribute('w:w', $tblWidth); + $objWriter->writeAttribute('w:type', 'pct'); + $objWriter->endElement(); + } $objWriter->endElement(); } } From 194940d47801afdd5e6acaf3ded32210e759d851 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 16 Jan 2014 14:33:38 +0700 Subject: [PATCH 09/12] Width: dxa > pct --- Classes/PHPWord/Writer/Word2007/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 47efd73a9b..cfaedc78e4 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -455,7 +455,7 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->startElement('w:tcPr'); $objWriter->startElement('w:tcW'); $objWriter->writeAttribute('w:w', $width); - $objWriter->writeAttribute('w:type', 'dxa'); + $objWriter->writeAttribute('w:type', 'pct'); $objWriter->endElement(); if ($cellStyle instanceof PHPWord_Style_Cell) { From b0a24703f307433c29d73718ecd48422ce682d60 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sat, 22 Feb 2014 11:01:15 +0700 Subject: [PATCH 10/12] `Table Row` allows `tblHeader` and `cantSplit` --- Classes/PHPWord/Section/Table.php | 27 +---- Classes/PHPWord/Section/Table/Row.php | 141 +++++++++++++++++++++++ Classes/PHPWord/Style/Row.php | 85 ++++++++++++++ Classes/PHPWord/Writer/Word2007/Base.php | 28 +++-- 4 files changed, 252 insertions(+), 29 deletions(-) create mode 100644 Classes/PHPWord/Section/Table/Row.php create mode 100644 Classes/PHPWord/Style/Row.php diff --git a/Classes/PHPWord/Section/Table.php b/Classes/PHPWord/Section/Table.php index 02aeacb7da..157bf070d4 100755 --- a/Classes/PHPWord/Section/Table.php +++ b/Classes/PHPWord/Section/Table.php @@ -45,13 +45,6 @@ class PHPWord_Section_Table */ private $_rows = array(); - /** - * Row heights - * - * @var array - */ - private $_rowHeights = array(); - /** * Table holder * @@ -107,10 +100,11 @@ public function __construct($insideOf, $pCount, $style = null) * * @param int $height */ - public function addRow($height = null) + public function addRow($height = null, $style = null) { - $this->_rows[] = array(); - $this->_rowHeights[] = $height; + $row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style); + $this->_rows[] = $row; + return $row; } /** @@ -122,9 +116,8 @@ public function addRow($height = null) */ public function addCell($width = null, $style = null) { - $cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style); $i = count($this->_rows) - 1; - $this->_rows[$i][] = $cell; + $cell = $this->_rows[$i]->addCell($width, $style); return $cell; } @@ -138,16 +131,6 @@ public function getRows() return $this->_rows; } - /** - * Get all row heights - * - * @return array - */ - public function getRowHeights() - { - return $this->_rowHeights; - } - /** * Get table style * diff --git a/Classes/PHPWord/Section/Table/Row.php b/Classes/PHPWord/Section/Table/Row.php new file mode 100644 index 0000000000..9f8085a23c --- /dev/null +++ b/Classes/PHPWord/Section/Table/Row.php @@ -0,0 +1,141 @@ +_insideOf = $insideOf; + $this->_pCount = $pCount; + $this->_height = $height; + $this->_style = new PHPWord_Style_Row(); + + if (!is_null($style)) { + if (is_array($style)) { + + foreach ($style as $key => $value) { + if (substr($key, 0, 1) != '_') { + $key = '_' . $key; + } + $this->_style->setStyleValue($key, $value); + } + } + } + } + + /** + * Add a cell + * + * @param int $width + * @param mixed $style + * @return PHPWord_Section_Table_Cell + */ + public function addCell($width = null, $style = null) + { + $cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style); + $this->_cells[] = $cell; + return $cell; + } + + /** + * Get all cells + * + * @return array + */ + public function getCells() + { + return $this->_cells; + } + + /** + * Get row style + * + * @return PHPWord_Style_Row + */ + public function getStyle() + { + return $this->_style; + } + + /** + * Get row height + * + * @return int + */ + public function getHeight() + { + return $this->_height; + } +} \ No newline at end of file diff --git a/Classes/PHPWord/Style/Row.php b/Classes/PHPWord/Style/Row.php new file mode 100644 index 0000000000..0bd9914472 --- /dev/null +++ b/Classes/PHPWord/Style/Row.php @@ -0,0 +1,85 @@ +_tblHeader = null; + $this->_cantSplit = null; + } + + /** + * Set style value + */ + public function setStyleValue($key, $value) + { + $this->$key = $value; + } + + public function setTblHeader($pValue = null) + { + $this->_tblHeader = $pValue; + } + + public function getTblHeader() + { + return $this->_tblHeader ? 1 : 0; + } + + public function setCantSplit($pValue = null) + { + $this->_cantSplit = $pValue; + } + + public function getCantSplit() + { + return $this->_cantSplit ? 1 : 0; + } + +} \ No newline at end of file diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index cfaedc78e4..9ffbe59caa 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -431,22 +431,36 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo } } - $_heights = $table->getRowHeights(); for ($i = 0; $i < $_cRows; $i++) { $row = $_rows[$i]; - $height = $_heights[$i]; + $height = $row->getHeight(); + $rowStyle = $row->getStyle(); + $tblHeader = $rowStyle->getTblHeader(); + $cantSplit = $rowStyle->getCantSplit(); $objWriter->startElement('w:tr'); - if (!is_null($height)) { + if (!is_null($height) || !is_null($tblHeader) || !is_null($cantSplit)) { $objWriter->startElement('w:trPr'); - $objWriter->startElement('w:trHeight'); - $objWriter->writeAttribute('w:val', $height); - $objWriter->endElement(); + if (!is_null($height)) { + $objWriter->startElement('w:trHeight'); + $objWriter->writeAttribute('w:val', $height); + $objWriter->endElement(); + } + if (!is_null($tblHeader)) { + $objWriter->startElement('w:tblHeader'); + $objWriter->writeAttribute('w:val', $tblHeader); + $objWriter->endElement(); + } + if (!is_null($cantSplit)) { + $objWriter->startElement('w:cantSplit'); + $objWriter->writeAttribute('w:val', $cantSplit); + $objWriter->endElement(); + } $objWriter->endElement(); } - foreach ($row as $cell) { + foreach ($row->getCells() as $cell) { $objWriter->startElement('w:tc'); $cellStyle = $cell->getStyle(); From eb6b44ef85b87253ed629117814f6f2549a92236 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sat, 22 Feb 2014 22:52:19 +0700 Subject: [PATCH 11/12] Use constant instead of hardcoded 'Arial' name. --- Classes/PHPWord.php | 7 +++++-- Classes/PHPWord/Style/Font.php | 12 ++++++------ Classes/PHPWord/Writer/ODText/Content.php | 6 +++--- Classes/PHPWord/Writer/ODText/Styles.php | 8 ++++---- Classes/PHPWord/Writer/RTF.php | 4 ++-- Classes/PHPWord/Writer/Word2007/Base.php | 4 ++-- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Classes/PHPWord.php b/Classes/PHPWord.php index 3879d7cdd8..51b3736621 100755 --- a/Classes/PHPWord.php +++ b/Classes/PHPWord.php @@ -39,6 +39,9 @@ class PHPWord { + const DEFAULT_FONT_NAME = 'Arial'; + const DEFAULT_FONT_SIZE = 20; + /** * Document properties * @@ -74,8 +77,8 @@ class PHPWord public function __construct() { $this->_properties = new PHPWord_DocumentProperties(); - $this->_defaultFontName = 'Arial'; - $this->_defaultFontSize = 20; + $this->_defaultFontName = PHPWord::DEFAULT_FONT_NAME; + $this->_defaultFontSize = PHPWord::DEFAULT_FONT_SIZE; } /** diff --git a/Classes/PHPWord/Style/Font.php b/Classes/PHPWord/Style/Font.php index eafc10b7ec..293d7e3502 100755 --- a/Classes/PHPWord/Style/Font.php +++ b/Classes/PHPWord/Style/Font.php @@ -94,8 +94,8 @@ class PHPWord_Style_Font public function __construct($type = 'text', $styleParagraph = null) { $this->_type = $type; - $this->_name = 'Arial'; - $this->_size = 20; + $this->_name = PHPWord::DEFAULT_FONT_NAME; + $this->_size = PHPWord::DEFAULT_FONT_SIZE; $this->_bold = false; $this->_italic = false; $this->_superScript = false; @@ -132,10 +132,10 @@ public function setStyleValue($key, $value) $this->$key = $value; } - public function setName($pValue = 'Arial') + public function setName($pValue = PHPWord::DEFAULT_FONT_NAME) { if ($pValue == '') { - $pValue = 'Arial'; + $pValue = PHPWord::DEFAULT_FONT_NAME; } $this->_name = $pValue; return $this; @@ -146,10 +146,10 @@ public function getSize() return $this->_size; } - public function setSize($pValue = 20) + public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE) { if ($pValue == '') { - $pValue = 20; + $pValue = PHPWord::DEFAULT_FONT_SIZE; } $this->_size = ($pValue * 2); return $this; diff --git a/Classes/PHPWord/Writer/ODText/Content.php b/Classes/PHPWord/Writer/ODText/Content.php index 69ba3befb7..f8784e10ff 100755 --- a/Classes/PHPWord/Writer/ODText/Content.php +++ b/Classes/PHPWord/Writer/ODText/Content.php @@ -145,10 +145,10 @@ public function writeContent(PHPWord $pPHPWord = null) } } } - if (!in_array('Arial', $arrFonts)) { + if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) { $objWriter->startElement('style:font-face'); - $objWriter->writeAttribute('style:name', 'Arial'); - $objWriter->writeAttribute('svg:font-family', 'Arial'); + $objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME); + $objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME); $objWriter->endElement(); } } diff --git a/Classes/PHPWord/Writer/ODText/Styles.php b/Classes/PHPWord/Writer/ODText/Styles.php index 2ec591aec1..7830db78b8 100755 --- a/Classes/PHPWord/Writer/ODText/Styles.php +++ b/Classes/PHPWord/Writer/ODText/Styles.php @@ -104,10 +104,10 @@ public function writeStyles(PHPWord $pPHPWord = null) } } } - if (!in_array('Arial', $arrFonts)) { + if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) { $objWriter->startElement('style:font-face'); - $objWriter->writeAttribute('style:name', 'Arial'); - $objWriter->writeAttribute('svg:font-family', 'Arial'); + $objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME); + $objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME); $objWriter->endElement(); } $objWriter->endElement(); @@ -132,7 +132,7 @@ public function writeStyles(PHPWord $pPHPWord = null) // style:text-properties $objWriter->startElement('style:text-properties'); $objWriter->writeAttribute('style:use-window-font-color', 'true'); - $objWriter->writeAttribute('style:font-name', 'Arial'); + $objWriter->writeAttribute('style:font-name', PHPWord::DEFAULT_FONT_NAME); $objWriter->writeAttribute('fo:font-size', '10pt'); $objWriter->writeAttribute('fo:language', 'fr'); $objWriter->writeAttribute('fo:country', 'FR'); diff --git a/Classes/PHPWord/Writer/RTF.php b/Classes/PHPWord/Writer/RTF.php index 24f0157eab..3f5b73ee2d 100755 --- a/Classes/PHPWord/Writer/RTF.php +++ b/Classes/PHPWord/Writer/RTF.php @@ -191,8 +191,8 @@ private function _getDataFont() $pPHPWord = $this->_document; $arrFonts = array(); - // Default font : Arial - $arrFonts[] = 'Arial'; + // Default font : PHPWord::DEFAULT_FONT_NAME + $arrFonts[] = PHPWord::DEFAULT_FONT_NAME; // PHPWord object : $this->_document // Browse styles diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 9ffbe59caa..aedd4f50e9 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -334,7 +334,7 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P $objWriter->startElement('w:rPr'); // Font - if ($font != 'Arial') { + if ($font != PHPWord::DEFAULT_FONT_NAME) { $objWriter->startElement('w:rFonts'); $objWriter->writeAttribute('w:ascii', $font); $objWriter->writeAttribute('w:hAnsi', $font); @@ -350,7 +350,7 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P } // Size - if ($size != 20) { + if ($size != PHPWord::DEFAULT_FONT_SIZE) { $objWriter->startElement('w:sz'); $objWriter->writeAttribute('w:val', $size); $objWriter->endElement(); From ab2b2deac371643fc473c3765d5fc9bac6d6756b Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sun, 23 Feb 2014 11:40:32 +0700 Subject: [PATCH 12/12] Change default font to Times New Roman 12pt --- Classes/PHPWord.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/PHPWord.php b/Classes/PHPWord.php index 51b3736621..b930bfb582 100755 --- a/Classes/PHPWord.php +++ b/Classes/PHPWord.php @@ -39,8 +39,8 @@ class PHPWord { - const DEFAULT_FONT_NAME = 'Arial'; - const DEFAULT_FONT_SIZE = 20; + const DEFAULT_FONT_NAME = 'Times New Roman'; + const DEFAULT_FONT_SIZE = 24; /** * Document properties