2014-03-22 10:06:08 +04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
|
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Style;
|
|
|
|
|
|
|
|
|
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Tab style
|
|
|
|
|
*/
|
2014-04-08 03:03:14 +07:00
|
|
|
class Tab extends AbstractStyle
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Tab Stop Type
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-04-06 18:03:03 +07:00
|
|
|
private $val;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tab Leader Character
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-04-06 18:03:03 +07:00
|
|
|
private $leader;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tab Stop Position
|
|
|
|
|
*
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
2014-04-06 18:03:03 +07:00
|
|
|
private $position;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tab Stop Type
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
* @link http://www.schemacentral.com/sc/ooxml/a-w_val-26.html Tab Stop Type
|
|
|
|
|
*/
|
2014-04-06 18:03:03 +07:00
|
|
|
private static $possibleStopTypes = array(
|
2014-03-22 10:06:08 +04:00
|
|
|
'clear', // No Tab Stop
|
|
|
|
|
'left', // Left Tab Stop
|
|
|
|
|
'center', // Center Tab Stop
|
|
|
|
|
'right', // Right Tab Stop
|
|
|
|
|
'decimal', // Decimal Tab
|
|
|
|
|
'bar', // Bar Tab
|
|
|
|
|
'num' // List tab
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tab Leader Character
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
* @link http://www.schemacentral.com/sc/ooxml/a-w_leader-1.html Tab Leader Character
|
|
|
|
|
*/
|
2014-04-06 18:03:03 +07:00
|
|
|
private static $possibleLeaders = array(
|
2014-03-22 10:06:08 +04:00
|
|
|
'none', // No tab stop leader
|
|
|
|
|
'dot', // Dotted leader line
|
|
|
|
|
'hyphen', // Dashed tab stop leader line
|
|
|
|
|
'underscore', // Solid leader line
|
|
|
|
|
'heavy', // Heavy solid leader line
|
|
|
|
|
'middleDot' // Middle dot leader line
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new instance of Tab. Both $val and $leader
|
|
|
|
|
* must conform to the values put forth in the schema. If they do not
|
|
|
|
|
* they will be changed to default values.
|
|
|
|
|
*
|
|
|
|
|
* @param string $val Defaults to 'clear' if value is not possible.
|
|
|
|
|
* @param int $position Must be an integer; otherwise defaults to 0.
|
2014-04-08 22:00:36 +04:00
|
|
|
* @param string $leader Defaults to null if value is not possible.
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function __construct($val = null, $position = 0, $leader = null)
|
|
|
|
|
{
|
|
|
|
|
// Default to clear if the stop type is not matched
|
2014-04-06 18:03:03 +07:00
|
|
|
$this->val = (self::isStopType($val)) ? $val : 'clear';
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
// Default to 0 if the position is non-numeric
|
2014-04-06 18:03:03 +07:00
|
|
|
$this->position = (is_numeric($position)) ? intval($position) : 0;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-04-08 22:00:36 +04:00
|
|
|
// Default to null if no tab leader
|
2014-04-06 18:03:03 +07:00
|
|
|
$this->leader = (self::isLeaderType($leader)) ? $leader : null;
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-22 17:25:10 +07:00
|
|
|
* Get stop type
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-04-22 17:25:10 +07:00
|
|
|
* @return string
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-04-22 17:25:10 +07:00
|
|
|
public function getStopType()
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-04-22 17:25:10 +07:00
|
|
|
return $this->val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get leader
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getLeader()
|
|
|
|
|
{
|
|
|
|
|
return $this->leader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get position
|
|
|
|
|
*
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public function getPosition()
|
|
|
|
|
{
|
|
|
|
|
return $this->position;
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if attribute is a valid stop type.
|
|
|
|
|
*
|
|
|
|
|
* @param string $attribute
|
|
|
|
|
* @return bool True if it is; false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
private static function isStopType($attribute)
|
|
|
|
|
{
|
2014-04-06 18:03:03 +07:00
|
|
|
return in_array($attribute, self::$possibleStopTypes);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if attribute is a valid leader type.
|
|
|
|
|
*
|
|
|
|
|
* @param string $attribute
|
|
|
|
|
* @return bool True if it is; false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
private static function isLeaderType($attribute)
|
|
|
|
|
{
|
2014-04-06 18:03:03 +07:00
|
|
|
return in_array($attribute, self::$possibleLeaders);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
}
|