Added support for Vertically Raised or Lowered Text (w:position) (#1294)
* Added support for Vertically Raised or Lowered Text (w:position). Note that only docx writing is implemented for now. * Add tests + changelog * add reader + tests + doc
This commit is contained in:
parent
30b224b3d0
commit
250fbd49b1
|
|
@ -13,6 +13,7 @@ v0.15.0 (?? ??? 2018)
|
||||||
- Add support for fixed Table Layout @aoloe @ekopach @troosan #841 #1276
|
- Add support for fixed Table Layout @aoloe @ekopach @troosan #841 #1276
|
||||||
- Add support for Cell Spacing @dox07 @troosan #1040
|
- Add support for Cell Spacing @dox07 @troosan #1040
|
||||||
- Add parsing of formatting inside lists @atomicalnet @troosan #594
|
- Add parsing of formatting inside lists @atomicalnet @troosan #594
|
||||||
|
- Added support for Vertically Raised or Lowered Text (w:position) @anrikun @troosan #640
|
||||||
- Add support for MACROBUTTON field @phryneas @troosan #1021
|
- Add support for MACROBUTTON field @phryneas @troosan #1021
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ Available Font style options:
|
||||||
See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` constants for more values
|
See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` constants for more values
|
||||||
- ``lang``. Language, either a language code like *en-US*, *fr-BE*, etc. or an object (or as an array) if you need to set eastAsian or bidirectional languages
|
- ``lang``. Language, either a language code like *en-US*, *fr-BE*, etc. or an object (or as an array) if you need to set eastAsian or bidirectional languages
|
||||||
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
|
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
|
||||||
|
- ``position``. The text position, raised or lowered, in half points
|
||||||
|
|
||||||
.. _paragraph-style:
|
.. _paragraph-style:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -422,6 +422,7 @@ abstract class AbstractPart
|
||||||
'fgColor' => array(self::READ_VALUE, 'w:highlight'),
|
'fgColor' => array(self::READ_VALUE, 'w:highlight'),
|
||||||
'rtl' => array(self::READ_TRUE, 'w:rtl'),
|
'rtl' => array(self::READ_TRUE, 'w:rtl'),
|
||||||
'lang' => array(self::READ_VALUE, 'w:lang'),
|
'lang' => array(self::READ_VALUE, 'w:lang'),
|
||||||
|
'position' => array(self::READ_VALUE, 'w:position'),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
||||||
|
|
|
||||||
|
|
@ -232,6 +232,7 @@ class Font extends AbstractStyle
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Right to left languages
|
* Right to left languages
|
||||||
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $rtl = false;
|
private $rtl = false;
|
||||||
|
|
@ -246,10 +247,19 @@ class Font extends AbstractStyle
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Languages
|
* Languages
|
||||||
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\Language
|
* @var \PhpOffice\PhpWord\Style\Language
|
||||||
*/
|
*/
|
||||||
private $lang;
|
private $lang;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vertically Raised or Lowered Text
|
||||||
|
*
|
||||||
|
* @var int Signed Half-Point Measurement
|
||||||
|
* @see http://www.datypic.com/sc/ooxml/e-w_position-1.html
|
||||||
|
*/
|
||||||
|
private $position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new font style
|
* Create new font style
|
||||||
*
|
*
|
||||||
|
|
@ -294,6 +304,7 @@ class Font extends AbstractStyle
|
||||||
'scale' => $this->getScale(),
|
'scale' => $this->getScale(),
|
||||||
'spacing' => $this->getSpacing(),
|
'spacing' => $this->getSpacing(),
|
||||||
'kerning' => $this->getKerning(),
|
'kerning' => $this->getKerning(),
|
||||||
|
'position' => $this->getPosition(),
|
||||||
),
|
),
|
||||||
'paragraph' => $this->getParagraph(),
|
'paragraph' => $this->getParagraph(),
|
||||||
'rtl' => $this->isRTL(),
|
'rtl' => $this->isRTL(),
|
||||||
|
|
@ -926,4 +937,27 @@ class Font extends AbstractStyle
|
||||||
{
|
{
|
||||||
return $this->getParagraph();
|
return $this->getParagraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get position
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPosition()
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set position
|
||||||
|
*
|
||||||
|
* @param int $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setPosition($value = null)
|
||||||
|
{
|
||||||
|
$this->position = $this->setIntVal($value, null);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,14 @@ class Frame extends AbstractStyle
|
||||||
*/
|
*/
|
||||||
private $wrap;
|
private $wrap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vertically raised or lowered text
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @see http://www.datypic.com/sc/ooxml/e-w_position-1.html
|
||||||
|
*/
|
||||||
|
private $position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance
|
* Create a new instance
|
||||||
*
|
*
|
||||||
|
|
@ -538,4 +546,27 @@ class Frame extends AbstractStyle
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get position
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPosition()
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set position
|
||||||
|
*
|
||||||
|
* @param int $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setPosition($value = null)
|
||||||
|
{
|
||||||
|
$this->position = $this->setIntVal($value, null);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
|
||||||
use PhpOffice\Common\XMLWriter;
|
use PhpOffice\Common\XMLWriter;
|
||||||
use PhpOffice\PhpWord\Element\Image as ImageElement;
|
use PhpOffice\PhpWord\Element\Image as ImageElement;
|
||||||
|
use PhpOffice\PhpWord\Style\Font as FontStyle;
|
||||||
|
use PhpOffice\PhpWord\Style\Frame as FrameStyle;
|
||||||
|
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
|
||||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter;
|
use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -62,6 +65,16 @@ class Image extends AbstractElement
|
||||||
$this->writeCommentRangeStart();
|
$this->writeCommentRangeStart();
|
||||||
|
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
|
|
||||||
|
// Write position
|
||||||
|
$position = $style->getPosition();
|
||||||
|
if ($position && $style->getWrap() == FrameStyle::WRAP_INLINE) {
|
||||||
|
$fontStyle = new FontStyle('text');
|
||||||
|
$fontStyle->setPosition($position);
|
||||||
|
$fontStyleWriter = new FontStyleWriter($xmlWriter, $fontStyle);
|
||||||
|
$fontStyleWriter->write();
|
||||||
|
}
|
||||||
|
|
||||||
$xmlWriter->startElement('w:pict');
|
$xmlWriter->startElement('w:pict');
|
||||||
$xmlWriter->startElement('v:shape');
|
$xmlWriter->startElement('v:shape');
|
||||||
$xmlWriter->writeAttribute('type', '#_x0000_t75');
|
$xmlWriter->writeAttribute('type', '#_x0000_t75');
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,9 @@ class Font extends AbstractStyle
|
||||||
$xmlWriter->writeElementIf($styleName === null && $style->isRTL(), 'w:rtl');
|
$xmlWriter->writeElementIf($styleName === null && $style->isRTL(), 'w:rtl');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Position
|
||||||
|
$xmlWriter->writeElementIf($style->getPosition() !== null, 'w:position', 'w:val', $style->getPosition());
|
||||||
|
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,4 +66,28 @@ class StyleTest extends AbstractTestReader
|
||||||
$tableStyle = $elements[0]->getStyle();
|
$tableStyle = $elements[0]->getStyle();
|
||||||
$this->assertEquals(10.5, $tableStyle->getCellSpacing());
|
$this->assertEquals(10.5, $tableStyle->getCellSpacing());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test reading of position
|
||||||
|
*/
|
||||||
|
public function testReadPosition()
|
||||||
|
{
|
||||||
|
$documentXml = '<w:p>
|
||||||
|
<w:r>
|
||||||
|
<w:rPr>
|
||||||
|
<w:position w:val="15"/>
|
||||||
|
</w:rPr>
|
||||||
|
<w:t xml:space="preserve">This text is lowered</w:t>
|
||||||
|
</w:r>
|
||||||
|
</w:p>';
|
||||||
|
|
||||||
|
$phpWord = $this->getDocumentFromString($documentXml);
|
||||||
|
|
||||||
|
$elements = $this->get($phpWord->getSections(), 0)->getElements();
|
||||||
|
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $elements[0]);
|
||||||
|
$this->assertInstanceOf('PhpOffice\PhpWord\Style\Font', $elements[0]->getFontStyle());
|
||||||
|
/** @var \PhpOffice\PhpWord\Style\Font $fontStyle */
|
||||||
|
$fontStyle = $elements[0]->getFontStyle();
|
||||||
|
$this->assertEquals(15, $fontStyle->getPosition());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,4 +65,19 @@ class FontTest extends \PHPUnit\Framework\TestCase
|
||||||
$path = '/w:document/w:body/w:p/w:r/w:rPr/w:lang';
|
$path = '/w:document/w:body/w:p/w:r/w:rPr/w:lang';
|
||||||
$this->assertTrue($doc->elementExists($path, $file));
|
$this->assertTrue($doc->elementExists($path, $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test writing position
|
||||||
|
*/
|
||||||
|
public function testPosition()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$section->addText('This text is lowered', array('position' => -20));
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
|
|
||||||
|
$path = '/w:document/w:body/w:p/w:r/w:rPr/w:position';
|
||||||
|
$this->assertTrue($doc->elementExists($path));
|
||||||
|
$this->assertEquals(-20, $doc->getElementAttribute($path, 'w:val'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue