2014-05-09 14:57:06 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
|
|
|
|
*
|
2017-11-04 22:44:12 +01:00
|
|
|
* @see https://github.com/PHPOffice/PHPWord
|
2018-03-08 23:52:25 +01:00
|
|
|
* @copyright 2010-2018 PHPWord contributors
|
2014-05-09 14:57:06 +07:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\RTF\Style;
|
|
|
|
|
|
2014-05-12 22:55:06 +07:00
|
|
|
use PhpOffice\PhpWord\Style\Font as FontStyle;
|
2014-05-09 14:57:06 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* RTF font style writer
|
|
|
|
|
*
|
|
|
|
|
* @since 0.11.0
|
|
|
|
|
*/
|
|
|
|
|
class Font extends AbstractStyle
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var int Font name index
|
|
|
|
|
*/
|
|
|
|
|
private $nameIndex = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int Font color index
|
|
|
|
|
*/
|
|
|
|
|
private $colorIndex = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write style
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function write()
|
|
|
|
|
{
|
|
|
|
|
$style = $this->getStyle();
|
2014-05-15 14:41:08 +07:00
|
|
|
if (!$style instanceof FontStyle) {
|
2014-05-14 19:41:44 +07:00
|
|
|
return '';
|
2014-05-09 14:57:06 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$content = '';
|
|
|
|
|
$content .= '\cf' . $this->colorIndex;
|
|
|
|
|
$content .= '\f' . $this->nameIndex;
|
2014-05-12 14:24:13 +07:00
|
|
|
|
|
|
|
|
$size = $style->getSize();
|
|
|
|
|
$content .= $this->getValueIf(is_numeric($size), '\fs' . ($size * 2));
|
2014-05-09 14:57:06 +07:00
|
|
|
|
2014-05-12 22:55:06 +07:00
|
|
|
$content .= $this->getValueIf($style->isBold(), '\b');
|
|
|
|
|
$content .= $this->getValueIf($style->isItalic(), '\i');
|
|
|
|
|
$content .= $this->getValueIf($style->getUnderline() != FontStyle::UNDERLINE_NONE, '\ul');
|
|
|
|
|
$content .= $this->getValueIf($style->isStrikethrough(), '\strike');
|
|
|
|
|
$content .= $this->getValueIf($style->isSuperScript(), '\super');
|
|
|
|
|
$content .= $this->getValueIf($style->isSubScript(), '\sub');
|
|
|
|
|
|
2017-11-04 22:44:12 +01:00
|
|
|
return $content . ' ';
|
2014-05-09 14:57:06 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Set font name index.
|
|
|
|
|
*
|
2014-05-09 14:57:06 +07:00
|
|
|
*
|
|
|
|
|
* @param int $value
|
|
|
|
|
*/
|
|
|
|
|
public function setNameIndex($value = 0)
|
|
|
|
|
{
|
|
|
|
|
$this->nameIndex = $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Set font color index.
|
2014-05-09 14:57:06 +07:00
|
|
|
*
|
|
|
|
|
* @param int $value
|
|
|
|
|
*/
|
|
|
|
|
public function setColorIndex($value = 0)
|
|
|
|
|
{
|
|
|
|
|
$this->colorIndex = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|