Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature for columns in section, continuous section break, softbreak, hanging paragraph, and normal style #48

Closed
wants to merge 13 commits into from
7 changes: 5 additions & 2 deletions Classes/PHPWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
class PHPWord
{

const DEFAULT_FONT_NAME = 'Times New Roman';
const DEFAULT_FONT_SIZE = 24;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change default font ? Arial become Times New Roman & 20 become 24.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, my bad :) I forgot to set back my personal style to default setup. Will fix it.

/**
* Document properties
*
Expand Down Expand Up @@ -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;
}

/**
Expand Down
81 changes: 81 additions & 0 deletions Classes/PHPWord/Section/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ 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;

/**
* Create new Section Settings
*/
Expand All @@ -170,6 +191,9 @@ public function __construct()
$this->_borderRightColor = null;
$this->_borderBottomSize = null;
$this->_borderBottomColor = null;
$this->_colsNum = 1;
$this->_colsSpace = 720;
$this->_breakType = null;
}

/**
Expand Down Expand Up @@ -542,4 +566,61 @@ public function getBorderBottomColor()
{
return $this->_borderBottomColor;
}

/**
* Set Section Columns Count
*
* @param in $pValue
*/
public function setColsNum($pValue = '') {
$this->_colsNum = $pValue;
return $this;
}

/**
* 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;
}

/**
* 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;
}
}
53 changes: 32 additions & 21 deletions Classes/PHPWord/Section/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ class PHPWord_Section_Table
*/
private $_rows = array();

/**
* Row heights
*
* @var array
*/
private $_rowHeights = array();

/**
* Table holder
*
Expand All @@ -66,6 +59,13 @@ class PHPWord_Section_Table
*/
private $_pCount;

/**
* Table width
*
* @var int
*/
private $_width = null;


/**
* Create a new table
Expand Down Expand Up @@ -100,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;
}

/**
Expand All @@ -113,11 +114,10 @@ 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;
$this->_rows[$i][] = $cell;
$cell = $this->_rows[$i]->addCell($width, $style);
return $cell;
}

Expand All @@ -132,22 +132,33 @@ public function getRows()
}

/**
* Get all row heights
* Get table style
*
* @return array
* @return PHPWord_Style_Table
*/
public function getRowHeights()
public function getStyle()
{
return $this->_rowHeights;
return $this->_style;
}

/**
* Get table style
* Set table width
*
* @return PHPWord_Style_Table
* @var int $width
*/
public function getStyle()
public function setWidth($width)
{
return $this->_style;
$this->_width = $width;
}

/**
* Get table width
*
* @return int
*/
public function getWidth()
{
return $this->_width;
}

}
141 changes: 141 additions & 0 deletions Classes/PHPWord/Section/Table/Row.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2013 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
* @copyright Copyright (c) 2013 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.7.0
*/

/**
* PHPWord_Section_Table_Row
*/
class PHPWord_Section_Table_Row
{

/**
* Row height
*
* @var int
*/
private $_height = null;

/**
* Row style
*
* @var PHPWord_Style_Row
*/
private $_style;

/**
* Row cells
*
* @var array
*/
private $_cells = array();

/**
* Table holder
*
* @var string
*/
private $_insideOf;

/**
* Section/Header/Footer count
*
* @var int
*/
private $_pCount;


/**
* Create a new table row
*
* @param string $insideOf
* @param int $pCount
* @param int $height
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $height = null, $style = null)
{
$this->_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;
}
}
10 changes: 10 additions & 0 deletions Classes/PHPWord/Section/TextRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Loading