2014-05-07 21:27:51 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
2014-05-08 12:58:44 +07:00
|
|
|
* 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
|
|
|
|
|
*/
|
2014-05-07 21:27:51 +02:00
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
|
|
|
|
|
|
|
|
|
use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TextBox style writer
|
|
|
|
|
*
|
2014-05-08 12:58:44 +07:00
|
|
|
* @since 0.11.0
|
2014-05-07 21:27:51 +02:00
|
|
|
*/
|
2014-05-08 12:58:44 +07:00
|
|
|
class TextBox extends Image
|
2014-05-07 21:27:51 +02:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Write style
|
|
|
|
|
*/
|
|
|
|
|
public function write()
|
|
|
|
|
{
|
2014-05-08 12:58:44 +07:00
|
|
|
if (is_null($style = $this->getStyle())) {
|
2014-05-07 21:27:51 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter = $this->getXmlWriter();
|
|
|
|
|
$wrapping = $style->getWrappingStyle();
|
|
|
|
|
$positioning = $style->getPositioning();
|
2014-05-07 21:27:51 +02:00
|
|
|
|
|
|
|
|
// Default style array
|
|
|
|
|
$styleArray = array(
|
|
|
|
|
'mso-width-percent' => '0',
|
|
|
|
|
'mso-height-percent' => '0',
|
|
|
|
|
'mso-width-relative' => 'margin',
|
|
|
|
|
'mso-height-relative' => 'margin',
|
|
|
|
|
);
|
2014-05-08 12:58:44 +07:00
|
|
|
$styleArray = array_merge($styleArray, $this->getElementStyle($style));
|
2014-05-07 21:27:51 +02:00
|
|
|
|
|
|
|
|
// Absolute/relative positioning
|
|
|
|
|
$styleArray['position'] = $positioning;
|
|
|
|
|
if ($positioning == TextBoxStyle::POSITION_ABSOLUTE) {
|
|
|
|
|
$styleArray['mso-position-horizontal-relative'] = 'page';
|
|
|
|
|
$styleArray['mso-position-vertical-relative'] = 'page';
|
|
|
|
|
} elseif ($positioning == TextBoxStyle::POSITION_RELATIVE) {
|
2014-05-08 12:58:44 +07:00
|
|
|
$styleArray['mso-position-horizontal'] = $style->getPosHorizontal();
|
|
|
|
|
$styleArray['mso-position-vertical'] = $style->getPosVertical();
|
|
|
|
|
$styleArray['mso-position-horizontal-relative'] = $style->getPosHorizontalRel();
|
|
|
|
|
$styleArray['mso-position-vertical-relative'] = $style->getPosVerticalRel();
|
2014-05-07 21:27:51 +02:00
|
|
|
$styleArray['margin-left'] = 0;
|
|
|
|
|
$styleArray['margin-top'] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wrapping style
|
|
|
|
|
if ($wrapping == TextBoxStyle::WRAPPING_STYLE_INLINE) {
|
|
|
|
|
// Nothing to do when inline
|
|
|
|
|
} elseif ($wrapping == TextBoxStyle::WRAPPING_STYLE_BEHIND) {
|
|
|
|
|
$styleArray['z-index'] = -251658752;
|
|
|
|
|
} else {
|
|
|
|
|
$styleArray['z-index'] = 251659264;
|
|
|
|
|
$styleArray['mso-position-horizontal'] = 'absolute';
|
|
|
|
|
$styleArray['mso-position-vertical'] = 'absolute';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// w10 wrapping
|
|
|
|
|
if ($wrapping == TextBoxStyle::WRAPPING_STYLE_SQUARE) {
|
|
|
|
|
$this->w10wrap = 'square';
|
|
|
|
|
} elseif ($wrapping == TextBoxStyle::WRAPPING_STYLE_TIGHT) {
|
|
|
|
|
$this->w10wrap = 'tight';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$textboxStyle = $this->assembleStyle($styleArray);
|
|
|
|
|
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('style', $textboxStyle);
|
2014-05-07 21:27:51 +02:00
|
|
|
|
2014-05-08 12:58:44 +07:00
|
|
|
$borderSize = $style->getBorderSize();
|
2014-05-07 21:27:51 +02:00
|
|
|
if ($borderSize !== null) {
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('strokeweight', $style->getBorderSize().'pt');
|
2014-05-07 21:27:51 +02:00
|
|
|
}
|
2014-05-08 09:52:11 +07:00
|
|
|
|
2014-05-08 12:58:44 +07:00
|
|
|
$borderColor = $style->getBorderColor();
|
2014-05-07 21:27:51 +02:00
|
|
|
if (empty($borderColor)) {
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('stroked', 'f');
|
2014-05-07 21:27:51 +02:00
|
|
|
} else {
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('strokecolor', $borderColor);
|
2014-05-07 21:27:51 +02:00
|
|
|
}
|
|
|
|
|
//@todo <v:stroke dashstyle="dashDot" linestyle="thickBetweenThin"/>
|
2014-05-08 09:52:11 +07:00
|
|
|
|
2014-05-07 21:27:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write w10 wrapping
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function writeW10Wrap()
|
|
|
|
|
{
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter = $this->getXmlWriter();
|
|
|
|
|
|
2014-05-07 21:27:51 +02:00
|
|
|
if (!is_null($this->w10wrap)) {
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->startElement('w10:wrap');
|
|
|
|
|
$xmlWriter->writeAttribute('type', $this->w10wrap);
|
2014-05-08 09:52:11 +07:00
|
|
|
|
2014-05-08 12:58:44 +07:00
|
|
|
switch ($style->getPositioning()) {
|
2014-05-07 21:27:51 +02:00
|
|
|
case TextBoxStyle::POSITION_ABSOLUTE:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchorx', "page");
|
|
|
|
|
$xmlWriter->writeAttribute('anchory', "page");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
case TextBoxStyle::POSITION_RELATIVE:
|
2014-05-08 12:58:44 +07:00
|
|
|
switch ($style->getPosVerticalRel()) {
|
2014-05-07 21:27:51 +02:00
|
|
|
case TextBoxStyle::POSITION_RELATIVE_TO_MARGIN:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchory', "margin");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
case TextBoxStyle::POSITION_RELATIVE_TO_PAGE:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchory', "page");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
case TextBoxStyle::POSITION_RELATIVE_TO_TMARGIN:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchory', "margin");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
case TextBoxStyle::POSITION_RELATIVE_TO_BMARGIN:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchory', "page");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2014-05-08 12:58:44 +07:00
|
|
|
switch ($style->getPosHorizontalRel()) {
|
2014-05-07 21:27:51 +02:00
|
|
|
case TextBoxStyle::POSITION_RELATIVE_TO_MARGIN:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchorx', "margin");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
case TextBoxStyle::POSITION_RELATIVE_TO_PAGE:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchorx', "page");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
case TextBoxStyle::POSITION_RELATIVE_TO_LMARGIN:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchorx', "margin");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
case TextBoxStyle::POSITION_RELATIVE_TO_RMARGIN:
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->writeAttribute('anchorx', "page");
|
2014-05-07 21:27:51 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-08 09:52:11 +07:00
|
|
|
|
2014-05-08 12:58:44 +07:00
|
|
|
$xmlWriter->endElement(); // w10:wrap
|
2014-05-07 21:27:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|