2014-04-26 11:14:27 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-04-26 11:14:27 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
|
|
|
|
|
|
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Font style writer
|
|
|
|
|
*
|
|
|
|
|
* @since 0.10.0
|
|
|
|
|
*/
|
|
|
|
|
class Font extends AbstractStyle
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Is inline in element
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
private $isInline = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write style
|
|
|
|
|
*/
|
|
|
|
|
public function write()
|
|
|
|
|
{
|
|
|
|
|
$isStyleName = $this->isInline && !is_null($this->style) && is_string($this->style);
|
|
|
|
|
if ($isStyleName) {
|
|
|
|
|
$this->xmlWriter->startElement('w:rPr');
|
|
|
|
|
$this->xmlWriter->startElement('w:rStyle');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:val', $this->style);
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
} else {
|
|
|
|
|
$this->writeStyle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write full style
|
|
|
|
|
*/
|
|
|
|
|
private function writeStyle()
|
|
|
|
|
{
|
|
|
|
|
if (!($this->style instanceof \PhpOffice\PhpWord\Style\Font)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$font = $this->style->getName();
|
|
|
|
|
$color = $this->style->getColor();
|
|
|
|
|
$size = $this->style->getSize();
|
|
|
|
|
|
|
|
|
|
$this->xmlWriter->startElement('w:rPr');
|
|
|
|
|
|
2014-05-01 23:56:55 +07:00
|
|
|
// Font name/family
|
2014-04-26 11:14:27 +07:00
|
|
|
if ($font != PhpWord::DEFAULT_FONT_NAME) {
|
|
|
|
|
$this->xmlWriter->startElement('w:rFonts');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:ascii', $font);
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:hAnsi', $font);
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:eastAsia', $font);
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:cs', $font);
|
|
|
|
|
//Font Content Type
|
2014-05-01 23:56:55 +07:00
|
|
|
if ($this->style->getHint() != PhpWord::DEFAULT_FONT_CONTENT_TYPE) {
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:hint', $this->style->getHint());
|
2014-04-26 11:14:27 +07:00
|
|
|
}
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Color
|
|
|
|
|
if ($color != PhpWord::DEFAULT_FONT_COLOR) {
|
|
|
|
|
$this->xmlWriter->startElement('w:color');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:val', $color);
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Size
|
|
|
|
|
if ($size != PhpWord::DEFAULT_FONT_SIZE) {
|
|
|
|
|
$this->xmlWriter->startElement('w:sz');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:val', $size * 2);
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
$this->xmlWriter->startElement('w:szCs');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:val', $size * 2);
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bold
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($this->style->isBold()) {
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->writeElement('w:b', null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Italic
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($this->style->isItalic()) {
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->writeElement('w:i', null);
|
|
|
|
|
$this->xmlWriter->writeElement('w:iCs', null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Underline
|
2014-05-01 23:56:55 +07:00
|
|
|
if ($this->style->getUnderline() != 'none') {
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->startElement('w:u');
|
2014-05-01 23:56:55 +07:00
|
|
|
$this->xmlWriter->writeAttribute('w:val', $this->style->getUnderline());
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Strikethrough
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($this->style->isStrikethrough()) {
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->writeElement('w:strike', null);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 23:56:55 +07:00
|
|
|
// Double strikethrough
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($this->style->isDoubleStrikethrough()) {
|
2014-05-01 23:56:55 +07:00
|
|
|
$this->xmlWriter->writeElement('w:dstrike', null);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-26 11:14:27 +07:00
|
|
|
// Foreground-Color
|
2014-05-01 23:56:55 +07:00
|
|
|
if (!is_null($this->style->getFgColor())) {
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->startElement('w:highlight');
|
2014-05-01 23:56:55 +07:00
|
|
|
$this->xmlWriter->writeAttribute('w:val', $this->style->getFgColor());
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Background-Color
|
2014-05-02 09:45:16 +07:00
|
|
|
if (!is_null($this->style->getShading())) {
|
|
|
|
|
$styleWriter = new Shading($this->xmlWriter, $this->style->getShading());
|
|
|
|
|
$styleWriter->write();
|
2014-04-26 11:14:27 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Superscript/subscript
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($this->style->isSuperScript() || $this->style->isSubScript()) {
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->startElement('w:vertAlign');
|
2014-05-04 15:13:31 +07:00
|
|
|
$this->xmlWriter->writeAttribute('w:val', $this->style->isSuperScript() ? 'superscript' : 'subscript');
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 23:56:55 +07:00
|
|
|
// Small caps
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($this->style->isSmallCaps()) {
|
2014-05-01 23:56:55 +07:00
|
|
|
$this->xmlWriter->writeElement('w:smallCaps', null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All caps
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($this->style->isAllCaps()) {
|
2014-05-01 23:56:55 +07:00
|
|
|
$this->xmlWriter->writeElement('w:caps', null);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set is inline
|
|
|
|
|
*
|
|
|
|
|
* @param bool $value
|
|
|
|
|
*/
|
|
|
|
|
public function setIsInline($value)
|
|
|
|
|
{
|
|
|
|
|
$this->isInline = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|