#331 : Word2007 Writer : Support for RTL
This commit is contained in:
parent
6f2d444ba9
commit
8d9e85b2ba
|
|
@ -13,3 +13,4 @@ phpword.ini
|
||||||
/.settings
|
/.settings
|
||||||
/build
|
/build
|
||||||
/vendor
|
/vendor
|
||||||
|
/phpunit.bat
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
|
||||||
- Setting: Ability to remove [Compatibility Mode] text in the MS Word title bar - @ivanlanin
|
- Setting: Ability to remove [Compatibility Mode] text in the MS Word title bar - @ivanlanin
|
||||||
- SDT: Ability to add structured document tag elements (comboBox, dropDownList, date) - @ivanlanin
|
- SDT: Ability to add structured document tag elements (comboBox, dropDownList, date) - @ivanlanin
|
||||||
- Paragraph: Support for paragraph with borders - @ivanlanin GH-294
|
- Paragraph: Support for paragraph with borders - @ivanlanin GH-294
|
||||||
|
- Word2007 Writer : Support for RTL - @Progi1984 GH-331
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ Features
|
||||||
run) that contains other elements
|
run) that contains other elements
|
||||||
- Insert titles (headers) and table of contents
|
- Insert titles (headers) and table of contents
|
||||||
- Insert text breaks and page breaks
|
- Insert text breaks and page breaks
|
||||||
|
- Insert right-to-left text
|
||||||
- Insert and format images, either local, remote, or as page watermarks
|
- Insert and format images, either local, remote, or as page watermarks
|
||||||
- Insert binary OLE Objects such as Excel or Visio
|
- Insert binary OLE Objects such as Excel or Visio
|
||||||
- Insert and format table with customized properties for each rows
|
- Insert and format table with customized properties for each rows
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ Available font styles:
|
||||||
- ``bgColor`` Font background color, e.g. *FF0000*
|
- ``bgColor`` Font background color, e.g. *FF0000*
|
||||||
- ``smallCaps`` Small caps, *true* or *false*
|
- ``smallCaps`` Small caps, *true* or *false*
|
||||||
- ``allCaps`` All caps, *true* or *false*
|
- ``allCaps`` All caps, *true* or *false*
|
||||||
|
- ``rtl`` Right to Left language, *true* or *false*
|
||||||
|
|
||||||
Paragraph
|
Paragraph
|
||||||
---------
|
---------
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
// New Word document
|
||||||
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$textrun->addText('This is a Left to Right paragraph.');
|
||||||
|
|
||||||
|
$textrun = $section->addTextRun(array('align' => 'right'));
|
||||||
|
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true));
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
if (!CLI) {
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
$requirements = array(
|
$requirements = array(
|
||||||
'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')),
|
'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')),
|
||||||
'xml' => array('PHP extension XML', extension_loaded('xml')),
|
'xml' => array('PHP extension XML', extension_loaded('xml')),
|
||||||
|
|
|
||||||
|
|
@ -373,6 +373,7 @@ abstract class AbstractPart
|
||||||
'superScript' => array(self::READ_EQUAL, 'w:vertAlign', 'w:val', 'superscript'),
|
'superScript' => array(self::READ_EQUAL, 'w:vertAlign', 'w:val', 'superscript'),
|
||||||
'subScript' => array(self::READ_EQUAL, 'w:vertAlign', 'w:val', 'subscript'),
|
'subScript' => array(self::READ_EQUAL, 'w:vertAlign', 'w:val', 'subscript'),
|
||||||
'fgColor' => array(self::READ_VALUE, 'w:highlight'),
|
'fgColor' => array(self::READ_VALUE, 'w:highlight'),
|
||||||
|
'rtl' => array(self::READ_TRUE, 'w:rtl'),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,12 @@ class Font extends AbstractStyle
|
||||||
*/
|
*/
|
||||||
private $shading;
|
private $shading;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Right to left languages
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $rtl = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new font style
|
* Create new font style
|
||||||
*
|
*
|
||||||
|
|
@ -268,6 +274,7 @@ class Font extends AbstractStyle
|
||||||
'kerning' => $this->getKerning(),
|
'kerning' => $this->getKerning(),
|
||||||
),
|
),
|
||||||
'paragraph' => $this->getParagraph(),
|
'paragraph' => $this->getParagraph(),
|
||||||
|
'rtl' => $this->isRTL(),
|
||||||
'shading' => $this->getShading(),
|
'shading' => $this->getShading(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -730,6 +737,29 @@ class Font extends AbstractStyle
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get rtl
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isRTL()
|
||||||
|
{
|
||||||
|
return $this->rtl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set rtl
|
||||||
|
*
|
||||||
|
* @param bool $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setRTL($value = true)
|
||||||
|
{
|
||||||
|
$this->rtl = $this->setBoolVal($value, $this->rtl);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shading
|
* Get shading
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,12 @@ class Font extends AbstractStyle
|
||||||
$styleWriter = new Shading($xmlWriter, $shading);
|
$styleWriter = new Shading($xmlWriter, $shading);
|
||||||
$styleWriter->write();
|
$styleWriter->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RTL
|
||||||
|
if ($this->isInline === true) {
|
||||||
|
$styleName = $style->getStyleName();
|
||||||
|
$xmlWriter->writeElementIf($styleName === null && $style->isRTL(), 'w:rtl');
|
||||||
|
}
|
||||||
|
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?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\Tests\Writer\Word2007\Part;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
||||||
|
use PhpOffice\PhpWord\Writer\Word2007;
|
||||||
|
use PhpOffice\PhpWord\Writer\Word2007\Style\Font;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Font
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Style\Font
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class FontTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Executed before each method of the class
|
||||||
|
*/
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
TestHelperDOCX::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test write styles
|
||||||
|
*/
|
||||||
|
public function testFontRTL()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true));
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
|
|
||||||
|
$file = 'word/document.xml';
|
||||||
|
$path = '/w:document/w:body/w:p/w:r/w:rPr/w:rtl';
|
||||||
|
$this->assertTrue($doc->elementExists($path, $file));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue