Paragraph: Ability to define (1) normal paragraph style with PHPWord::setNormalStyle() and (2) parent style (basedOn) and style for following paragraph (next)
This commit is contained in:
parent
be4b01b652
commit
09ba95bd88
|
|
@ -198,6 +198,16 @@ class PHPWord
|
||||||
PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
|
PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set normal paragraph style definition to styles.xml
|
||||||
|
*
|
||||||
|
* @param array $styles Paragraph style definition
|
||||||
|
*/
|
||||||
|
public function setNormalStyle($styles)
|
||||||
|
{
|
||||||
|
PHPWord_Style::setNormalStyle($styles);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a hyperlink style to styles.xml
|
* Adds a hyperlink style to styles.xml
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,16 @@ class PHPWord_Style
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set normal (default) paragraph style
|
||||||
|
*
|
||||||
|
* @param array $styles Paragraph style definition
|
||||||
|
*/
|
||||||
|
public static function setNormalStyle($styles)
|
||||||
|
{
|
||||||
|
self::addParagraphStyle('Normal', $styles);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all styles
|
* Get all styles
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,20 @@ class PHPWord_Style_Paragraph
|
||||||
*/
|
*/
|
||||||
private $_hanging;
|
private $_hanging;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent style
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_basedOn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Style for next paragraph
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_next;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New Paragraph Style
|
* New Paragraph Style
|
||||||
*/
|
*/
|
||||||
|
|
@ -92,6 +106,8 @@ class PHPWord_Style_Paragraph
|
||||||
$this->_tabs = null;
|
$this->_tabs = null;
|
||||||
$this->_indent = null;
|
$this->_indent = null;
|
||||||
$this->_hanging = null;
|
$this->_hanging = null;
|
||||||
|
$this->_basedOn = 'Normal';
|
||||||
|
$this->_next = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -231,6 +247,16 @@ class PHPWord_Style_Paragraph
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get hanging
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getHanging()
|
||||||
|
{
|
||||||
|
return $this->_hanging;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set hanging
|
* Set hanging
|
||||||
*
|
*
|
||||||
|
|
@ -243,16 +269,6 @@ class PHPWord_Style_Paragraph
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get hanging
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getHanging()
|
|
||||||
{
|
|
||||||
return $this->_hanging;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tabs
|
* Get tabs
|
||||||
*
|
*
|
||||||
|
|
@ -262,4 +278,49 @@ class PHPWord_Style_Paragraph
|
||||||
{
|
{
|
||||||
return $this->_tabs;
|
return $this->_tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get parent style ID
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBasedOn()
|
||||||
|
{
|
||||||
|
return $this->_basedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set parent style ID
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PHPWord_Style_Paragraph
|
||||||
|
*/
|
||||||
|
public function setBasedOn($pValue = 'Normal')
|
||||||
|
{
|
||||||
|
$this->_basedOn = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get style for next paragraph
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNext()
|
||||||
|
{
|
||||||
|
return $this->_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style for next paragraph
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PHPWord_Style_Paragraph
|
||||||
|
*/
|
||||||
|
public function setNext($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_next = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -59,8 +59,30 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
|
||||||
|
|
||||||
// Write Style Definitions
|
// Write Style Definitions
|
||||||
$styles = PHPWord_Style::getStyles();
|
$styles = PHPWord_Style::getStyles();
|
||||||
|
|
||||||
|
// Write normal paragraph style
|
||||||
|
$normalStyle = null;
|
||||||
|
if (array_key_exists('Normal', $styles)) {
|
||||||
|
$normalStyle = $styles['Normal'];
|
||||||
|
}
|
||||||
|
$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();
|
||||||
|
if (!is_null($normalStyle)) {
|
||||||
|
$this->_writeParagraphStyle($objWriter, $normalStyle);
|
||||||
|
}
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
// Write other styles
|
||||||
if (count($styles) > 0) {
|
if (count($styles) > 0) {
|
||||||
foreach ($styles as $styleName => $style) {
|
foreach ($styles as $styleName => $style) {
|
||||||
|
if ($styleName == 'Normal') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($style instanceof PHPWord_Style_Font) {
|
if ($style instanceof PHPWord_Style_Font) {
|
||||||
|
|
||||||
$paragraphStyle = $style->getParagraphStyle();
|
$paragraphStyle = $style->getParagraphStyle();
|
||||||
|
|
@ -92,6 +114,10 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
if (!is_null($paragraphStyle)) {
|
if (!is_null($paragraphStyle)) {
|
||||||
|
// Point parent style to Normal
|
||||||
|
$objWriter->startElement('w:basedOn');
|
||||||
|
$objWriter->writeAttribute('w:val', 'Normal');
|
||||||
|
$objWriter->endElement();
|
||||||
$this->_writeParagraphStyle($objWriter, $paragraphStyle);
|
$this->_writeParagraphStyle($objWriter, $paragraphStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,6 +135,22 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
|
||||||
$objWriter->writeAttribute('w:val', $styleName);
|
$objWriter->writeAttribute('w:val', $styleName);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
// Parent style
|
||||||
|
$basedOn = $style->getBasedOn();
|
||||||
|
if (!is_null($basedOn)) {
|
||||||
|
$objWriter->startElement('w:basedOn');
|
||||||
|
$objWriter->writeAttribute('w:val', $basedOn);
|
||||||
|
$objWriter->endElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next paragraph style
|
||||||
|
$next = $style->getNext();
|
||||||
|
if (!is_null($next)) {
|
||||||
|
$objWriter->startElement('w:next');
|
||||||
|
$objWriter->writeAttribute('w:val', $next);
|
||||||
|
$objWriter->endElement();
|
||||||
|
}
|
||||||
|
|
||||||
$this->_writeParagraphStyle($objWriter, $style);
|
$this->_writeParagraphStyle($objWriter, $style);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,9 @@ Changes in branch for release 0.7.1 :
|
||||||
- Feature: (ivanlanin) GH-48 GH-86 - Paragraph: Hanging paragraph
|
- Feature: (ivanlanin) GH-48 GH-86 - Paragraph: Hanging paragraph
|
||||||
- Feature: (ivanlanin) GH-48 GH-86 - Section: Multicolumn and section break
|
- Feature: (ivanlanin) GH-48 GH-86 - Section: Multicolumn and section break
|
||||||
- QA: (Progi1984) - UnitTests
|
- QA: (Progi1984) - UnitTests
|
||||||
- Feature: (ivanlanin) - General: PHPWord_Shared_Font::pointSizeToTwips converter
|
- Feature: (ivanlanin) - General: PHPWord_Shared_Font::pointSizeToTwips() converter
|
||||||
|
- Feature: (ivanlanin) - Paragraph: Ability to define normal paragraph style with PHPWord::setNormalStyle()
|
||||||
|
- Feature: (ivanlanin) - Paragraph: Ability to define parent style (basedOn) and style for following paragraph (next)
|
||||||
|
|
||||||
Changes in branch for release 0.7.0 :
|
Changes in branch for release 0.7.0 :
|
||||||
- Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found
|
- Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue