2014-05-29 16:44:00 +02: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.
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
|
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
|
|
|
|
|
|
|
|
|
use PhpOffice\PhpWord\Style\Line as LineStyle;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Line style writer
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class Line extends Image
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Write style
|
|
|
|
|
*/
|
|
|
|
|
public function write()
|
|
|
|
|
{
|
|
|
|
|
$style = $this->getStyle();
|
|
|
|
|
if (!$style instanceof LineStyle) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-05-30 01:05:55 +07:00
|
|
|
$this->writeStyle($style);
|
2014-05-29 16:44:00 +02:00
|
|
|
}
|
2014-05-30 01:05:55 +07:00
|
|
|
|
2014-05-29 16:44:00 +02:00
|
|
|
/**
|
|
|
|
|
* Write style attribute
|
2014-05-30 01:05:55 +07:00
|
|
|
*
|
|
|
|
|
* @param \PhpOffice\PhpWord\Style\Line $style
|
2014-05-29 16:44:00 +02:00
|
|
|
*/
|
2014-05-30 01:05:55 +07:00
|
|
|
protected function writeStyle($style)
|
2014-05-29 16:44:00 +02:00
|
|
|
{
|
|
|
|
|
$xmlWriter = $this->getXmlWriter();
|
2014-05-30 01:05:55 +07:00
|
|
|
|
|
|
|
|
$styles = $this->getElementStyle($style);
|
|
|
|
|
if ($style->isFlip()) {
|
|
|
|
|
$styles['flip'] = 'y';
|
2014-05-29 16:44:00 +02:00
|
|
|
}
|
2014-05-30 01:05:55 +07:00
|
|
|
$imageStyle = $this->assembleStyle($styles);
|
2014-05-29 16:44:00 +02:00
|
|
|
$xmlWriter->writeAttribute('style', $imageStyle);
|
2014-05-30 01:05:55 +07:00
|
|
|
|
|
|
|
|
// Connector type
|
2014-05-29 16:44:00 +02:00
|
|
|
$xmlWriter->writeAttribute('o:connectortype', $style->getConnectorType());
|
2014-05-30 01:05:55 +07:00
|
|
|
|
2014-05-29 16:44:00 +02:00
|
|
|
// Weight
|
|
|
|
|
$weight = $style->getWeight();
|
2014-05-30 01:05:55 +07:00
|
|
|
$xmlWriter->writeAttributeIf($weight !== null, 'strokeweight', $weight . 'pt');
|
|
|
|
|
|
2014-05-29 16:44:00 +02:00
|
|
|
// Color
|
|
|
|
|
$color = $style->getColor();
|
2014-05-30 01:05:55 +07:00
|
|
|
$xmlWriter->writeAttributeIf($color !== null, 'strokecolor', $color);
|
2014-05-29 16:44:00 +02:00
|
|
|
}
|
2014-05-30 01:05:55 +07:00
|
|
|
|
2014-05-29 17:11:54 +02:00
|
|
|
/**
|
|
|
|
|
* Write Line stroke
|
|
|
|
|
*/
|
2014-05-29 16:44:00 +02:00
|
|
|
public function writeStroke()
|
|
|
|
|
{
|
|
|
|
|
$xmlWriter = $this->getXmlWriter();
|
2014-05-30 01:05:55 +07:00
|
|
|
$style = $this->getStyle();
|
|
|
|
|
if (!$style instanceof LineStyle) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-29 16:44:00 +02:00
|
|
|
$dash = $style->getDash();
|
|
|
|
|
$beginArrow = $style->getBeginArrow();
|
|
|
|
|
$endArrow = $style->getEndArrow();
|
2014-05-30 01:05:55 +07:00
|
|
|
$dashStyles = array(
|
|
|
|
|
LineStyle::DASH_STYLE_DASH => 'dash',
|
|
|
|
|
LineStyle::DASH_STYLE_ROUND_DOT => '1 1',
|
|
|
|
|
LineStyle::DASH_STYLE_SQUARE_DOT => '1 1',
|
|
|
|
|
LineStyle::DASH_STYLE_DASH_DOT => 'dashDot',
|
|
|
|
|
LineStyle::DASH_STYLE_LONG_DASH => 'longDash',
|
|
|
|
|
LineStyle::DASH_STYLE_LONG_DASH_DOT => 'longDashDot',
|
|
|
|
|
LineStyle::DASH_STYLE_LONG_DASH_DOT_DOT => 'longDashDotDot',
|
|
|
|
|
);
|
|
|
|
|
|
2014-05-29 16:44:00 +02:00
|
|
|
if (($dash !== null) || ($beginArrow !== null) || ($endArrow !== null)) {
|
|
|
|
|
$xmlWriter->startElement('v:stroke');
|
2014-05-30 01:05:55 +07:00
|
|
|
|
|
|
|
|
$xmlWriter->writeAttributeIf($beginArrow !== null, 'startarrow', $beginArrow);
|
|
|
|
|
$xmlWriter->writeAttributeIf($endArrow !== null, 'endarrow', $endArrow);
|
|
|
|
|
|
|
|
|
|
if ($dash !== null) {
|
|
|
|
|
if (array_key_exists($dash, $dashStyles)) {
|
|
|
|
|
$xmlWriter->writeAttribute('dashstyle', $dashStyles[$dash]);
|
|
|
|
|
}
|
|
|
|
|
if ($dash == LineStyle::DASH_STYLE_ROUND_DOT) {
|
|
|
|
|
$xmlWriter->writeAttribute('endcap', 'round');
|
2014-05-29 16:44:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-05-30 01:05:55 +07:00
|
|
|
|
2014-05-29 16:44:00 +02:00
|
|
|
$xmlWriter->endElement(); //v:stroke
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|