62 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Writer\HTML\Style;
use PhpOffice\PhpWord\PhpWord;
2014-04-26 11:14:27 +07:00
use PhpOffice\PhpWord\Style\Font as FontStyle;
/**
* Font style HTML writer
*
* @since 0.10.0
*/
2014-04-26 11:14:27 +07:00
class Font extends AbstractStyle
{
/**
* Write style
*
* @return string
*/
public function write()
{
$css = array();
if (PhpWord::DEFAULT_FONT_NAME != $this->style->getName()) {
$css['font-family'] = "'" . $this->style->getName() . "'";
}
if (PhpWord::DEFAULT_FONT_SIZE != $this->style->getSize()) {
$css['font-size'] = $this->style->getSize() . 'pt';
}
if (PhpWord::DEFAULT_FONT_COLOR != $this->style->getColor()) {
$css['color'] = '#' . $this->style->getColor();
}
$css['background'] = $this->style->getFgColor();
if ($this->style->getBold()) {
$css['font-weight'] = 'bold';
}
if ($this->style->getItalic()) {
$css['font-style'] = 'italic';
}
if ($this->style->getSuperScript()) {
$css['vertical-align'] = 'super';
} elseif ($this->style->getSubScript()) {
$css['vertical-align'] = 'sub';
}
$css['text-decoration'] = '';
2014-04-26 11:14:27 +07:00
if ($this->style->getUnderline() != FontStyle::UNDERLINE_NONE) {
$css['text-decoration'] .= 'underline ';
}
if ($this->style->getStrikethrough()) {
$css['text-decoration'] .= 'line-through ';
}
2014-04-26 11:14:27 +07:00
return $this->assembleCss($css);
}
}