Add support for changing the document language (#1108)
This commit is contained in:
parent
743dbff9d4
commit
0beeb275fe
|
|
@ -14,8 +14,8 @@ This is the last version to support PHP 5.3
|
||||||
- Introduced the `\PhpOffice\PhpWord\SimpleType\NumberFormat` simple type. - @troosan
|
- Introduced the `\PhpOffice\PhpWord\SimpleType\NumberFormat` simple type. - @troosan
|
||||||
- Support for ContextualSpacing - @postHawk #1088
|
- Support for ContextualSpacing - @postHawk #1088
|
||||||
- Possiblity to hide spelling and/or grammatical errors - @troosan #542
|
- Possiblity to hide spelling and/or grammatical errors - @troosan #542
|
||||||
|
- Possiblity to set default document language as well as changing the language for each text element - @troosan #1108
|
||||||
- Support for Comments - @troosan #1067
|
- Support for Comments - @troosan #1067
|
||||||
- Add support for changing the document language - @troosan #1108
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Loosen dependency to Zend
|
- Loosen dependency to Zend
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,25 @@ The default symbol to represent a decimal figure is the ``.`` in english. In fre
|
||||||
|
|
||||||
$phpWord->getSettings()->setDecimalSymbol(',');
|
$phpWord->getSettings()->setDecimalSymbol(',');
|
||||||
|
|
||||||
|
Document Language
|
||||||
|
~~~~~~~~~~~~~~~~~
|
||||||
|
The default language of the document can be change with the following.
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
$phpWord->getSettings()->setThemeFontLang(new Language(Language::FR_BE));
|
||||||
|
|
||||||
|
``Languge`` has 3 parameters, one for Latin languages, one for East Asian languages and one for Complex (Bi-Directional) languages.
|
||||||
|
A couple of language codes are provided in the ``PhpOffice\PhpWord\ComplexType\Language`` class but any valid code/ID can be used.
|
||||||
|
|
||||||
|
In case you are generating an RTF document the Language need to be set differently.
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
$lang = new Language();
|
||||||
|
$lang->setLangId(Language::EN_GB_ID);
|
||||||
|
$phpWord->getSettings()->setThemeFontLang($lang);
|
||||||
|
|
||||||
Document information
|
Document information
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@ Available Font style options:
|
||||||
- ``subScript``. Subscript, *true* or *false*.
|
- ``subScript``. Subscript, *true* or *false*.
|
||||||
- ``superScript``. Superscript, *true* or *false*.
|
- ``superScript``. Superscript, *true* or *false*.
|
||||||
- ``underline``. Underline, *dash*, *dotted*, etc.
|
- ``underline``. Underline, *dash*, *dotted*, etc.
|
||||||
|
- ``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.
|
||||||
|
|
||||||
.. _paragraph-style:
|
.. _paragraph-style:
|
||||||
|
|
||||||
|
|
@ -64,7 +66,7 @@ Paragraph
|
||||||
Available Paragraph style options:
|
Available Paragraph style options:
|
||||||
|
|
||||||
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
|
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
|
||||||
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
|
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
|
||||||
- ``basedOn``. Parent style.
|
- ``basedOn``. Parent style.
|
||||||
- ``hanging``. Hanging by how much.
|
- ``hanging``. Hanging by how much.
|
||||||
- ``indent``. Indent by how much.
|
- ``indent``. Indent by how much.
|
||||||
|
|
@ -87,7 +89,7 @@ Table
|
||||||
Available Table style options:
|
Available Table style options:
|
||||||
|
|
||||||
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
|
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
|
||||||
See ``\PhpOffice\PhpWord\SimpleType\JcTable`` and ``\PhpOffice\PhpWord\SimpleType\Jc`` classes for the details.
|
See ``\PhpOffice\PhpWord\SimpleType\JcTable`` and ``\PhpOffice\PhpWord\SimpleType\Jc`` classes for the details.
|
||||||
- ``bgColor``. Background color, e.g. '9966CC'.
|
- ``bgColor``. Background color, e.g. '9966CC'.
|
||||||
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
|
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
|
||||||
- ``border(Top|Right|Bottom|Left)Size``. Border size in twips.
|
- ``border(Top|Right|Bottom|Left)Size``. Border size in twips.
|
||||||
|
|
@ -106,7 +108,8 @@ Available Cell style options:
|
||||||
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
|
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
|
||||||
- ``border(Top|Right|Bottom|Left)Size``. Border size in twips.
|
- ``border(Top|Right|Bottom|Left)Size``. Border size in twips.
|
||||||
- ``gridSpan``. Number of columns spanned.
|
- ``gridSpan``. Number of columns spanned.
|
||||||
- ``textDirection(btLr|tbRl)``. Direction of text. You can use constants ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR`` and ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_TBRL``
|
- ``textDirection(btLr|tbRl)``. Direction of text.
|
||||||
|
You can use constants ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR`` and ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_TBRL``
|
||||||
- ``valign``. Vertical alignment, *top*, *center*, *both*, *bottom*.
|
- ``valign``. Vertical alignment, *top*, *center*, *both*, *bottom*.
|
||||||
- ``vMerge``. *restart* or *continue*.
|
- ``vMerge``. *restart* or *continue*.
|
||||||
- ``width``. Cell width in twips.
|
- ``width``. Cell width in twips.
|
||||||
|
|
@ -133,7 +136,7 @@ Numbering level
|
||||||
Available NumberingLevel style options:
|
Available NumberingLevel style options:
|
||||||
|
|
||||||
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
|
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
|
||||||
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
|
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
|
||||||
- ``font``. Font name.
|
- ``font``. Font name.
|
||||||
- ``format``. Numbering format bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter.
|
- ``format``. Numbering format bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter.
|
||||||
- ``hanging``. See paragraph style.
|
- ``hanging``. See paragraph style.
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
|
||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
|
|
||||||
|
$languageEnGb = new \PhpOffice\PhpWord\Style\Language(\PhpOffice\PhpWord\Style\Language::EN_GB);
|
||||||
|
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->getSettings()->setThemeFontLang($languageEnGb);
|
||||||
|
|
||||||
$fontStyleName = 'rStyle';
|
$fontStyleName = 'rStyle';
|
||||||
$phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
|
$phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
|
||||||
|
|
@ -20,6 +27,10 @@ $section = $phpWord->addSection();
|
||||||
$section->addTitle('Welcome to PhpWord', 1);
|
$section->addTitle('Welcome to PhpWord', 1);
|
||||||
$section->addText('Hello World!');
|
$section->addText('Hello World!');
|
||||||
|
|
||||||
|
// $pStyle = new Font();
|
||||||
|
// $pStyle->setLang()
|
||||||
|
$section->addText('Ce texte-ci est en français.', array('lang' => \PhpOffice\PhpWord\Style\Language::FR_BE));
|
||||||
|
|
||||||
// Two text break
|
// Two text break
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$header = array('size' => 16, 'bold' => true);
|
$header = array('size' => 16, 'bold' => true);
|
||||||
//1.Use EastAisa FontStyle
|
//1.Use EastAisa FontStyle
|
||||||
$section->addText('中文楷体样式测试', array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
|
$section->addText('中文楷体样式测试', array('name' => '楷体', 'size' => 16, 'color' => '1B2232', 'lang' => array('latin' => 'en-US', 'eastAsia' => 'zh-CN')));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -135,10 +135,10 @@ final class TrackChangesView
|
||||||
/**
|
/**
|
||||||
* Set Display Formatting Revisions
|
* Set Display Formatting Revisions
|
||||||
*
|
*
|
||||||
* @param boolean $insDel
|
* @param boolean|null $formatting
|
||||||
* Set to true to show formatting revisions
|
* Set to true to show formatting revisions
|
||||||
*/
|
*/
|
||||||
public function setFormatting($formatting)
|
public function setFormatting($formatting = null)
|
||||||
{
|
{
|
||||||
$this->formatting = $formatting === null ? true : $formatting;
|
$this->formatting = $formatting === null ? true : $formatting;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ abstract class AbstractElement
|
||||||
/**
|
/**
|
||||||
* Get element unique ID
|
* Get element unique ID
|
||||||
*
|
*
|
||||||
* @return string
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function getElementId()
|
public function getElementId()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,7 @@ class Bookmark extends AbstractElement
|
||||||
*/
|
*/
|
||||||
public function __construct($name)
|
public function __construct($name)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->name = CommonText::toUTF8($name);
|
$this->name = CommonText::toUTF8($name);
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ class CheckBox extends Text
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param mixed $fontStyle
|
* @param mixed $fontStyle
|
||||||
* @param mixed $paragraphStyle
|
* @param mixed $paragraphStyle
|
||||||
* @return self
|
|
||||||
*/
|
*/
|
||||||
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
|
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,6 @@ class Comment extends TrackChange
|
||||||
{
|
{
|
||||||
parent::__construct($author, $date);
|
parent::__construct($author, $date);
|
||||||
$this->initials = $initials;
|
$this->initials = $initials;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class FormField extends Text
|
||||||
/**
|
/**
|
||||||
* Form field name
|
* Form field name
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string|bool|int
|
||||||
*/
|
*/
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
|
|
@ -70,7 +70,6 @@ class FormField extends Text
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param mixed $fontStyle
|
* @param mixed $fontStyle
|
||||||
* @param mixed $paragraphStyle
|
* @param mixed $paragraphStyle
|
||||||
* @return self
|
|
||||||
*/
|
*/
|
||||||
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
|
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,6 @@ class Link extends AbstractElement
|
||||||
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
|
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
|
||||||
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
||||||
$this->internal = $internal;
|
$this->internal = $internal;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ class PreserveText extends AbstractElement
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param mixed $fontStyle
|
* @param mixed $fontStyle
|
||||||
* @param mixed $paragraphStyle
|
* @param mixed $paragraphStyle
|
||||||
* @return self
|
|
||||||
*/
|
*/
|
||||||
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ class SDT extends Text
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param mixed $fontStyle
|
* @param mixed $fontStyle
|
||||||
* @param mixed $paragraphStyle
|
* @param mixed $paragraphStyle
|
||||||
* @return self
|
|
||||||
*/
|
*/
|
||||||
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
|
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class TOC extends AbstractElement
|
||||||
/**
|
/**
|
||||||
* Font style
|
* Font style
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\Font|array|string
|
* @var \PhpOffice\PhpWord\Style\Font|string
|
||||||
*/
|
*/
|
||||||
private $fontStyle;
|
private $fontStyle;
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ class TOC extends AbstractElement
|
||||||
/**
|
/**
|
||||||
* Get Font Style
|
* Get Font Style
|
||||||
*
|
*
|
||||||
* @return \PhpOffice\PhpWord\Style\Font
|
* @return \PhpOffice\PhpWord\Style\Font|string
|
||||||
*/
|
*/
|
||||||
public function getStyleFont()
|
public function getStyleFont()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class TrackChange extends AbstractContainer
|
||||||
* Create a new TrackChange Element
|
* Create a new TrackChange Element
|
||||||
*
|
*
|
||||||
* @param string $author
|
* @param string $author
|
||||||
* @param DateTime $date
|
* @param \DateTime $date
|
||||||
*/
|
*/
|
||||||
public function __construct($author, \DateTime $date)
|
public function __construct($author, \DateTime $date)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Metadata;
|
||||||
use PhpOffice\PhpWord\ComplexType\ProofState;
|
use PhpOffice\PhpWord\ComplexType\ProofState;
|
||||||
use PhpOffice\PhpWord\SimpleType\Zoom;
|
use PhpOffice\PhpWord\SimpleType\Zoom;
|
||||||
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
||||||
|
use PhpOffice\PhpWord\Style\Language;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setting class
|
* Setting class
|
||||||
|
|
@ -100,6 +101,13 @@ class Settings
|
||||||
*/
|
*/
|
||||||
private $evenAndOddHeaders = false;
|
private $evenAndOddHeaders = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Theme Font Languages
|
||||||
|
*
|
||||||
|
* @var Language
|
||||||
|
*/
|
||||||
|
private $themeFontLang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Radix Point for Field Code Evaluation
|
* Radix Point for Field Code Evaluation
|
||||||
*
|
*
|
||||||
|
|
@ -291,6 +299,26 @@ class Settings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Language
|
||||||
|
*
|
||||||
|
* @return Language
|
||||||
|
*/
|
||||||
|
public function getThemeFontLang()
|
||||||
|
{
|
||||||
|
return $this->themeFontLang;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the Language for this document
|
||||||
|
*
|
||||||
|
* @param Language $themeFontLang
|
||||||
|
*/
|
||||||
|
public function setThemeFontLang($themeFontLang)
|
||||||
|
{
|
||||||
|
$this->themeFontLang = $themeFontLang;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Radix Point for Field Code Evaluation
|
* Returns the Radix Point for Field Code Evaluation
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -326,6 +326,8 @@ abstract class AbstractPart
|
||||||
'keepNext' => array(self::READ_TRUE, 'w:keepNext'),
|
'keepNext' => array(self::READ_TRUE, 'w:keepNext'),
|
||||||
'keepLines' => array(self::READ_TRUE, 'w:keepLines'),
|
'keepLines' => array(self::READ_TRUE, 'w:keepLines'),
|
||||||
'pageBreakBefore' => array(self::READ_TRUE, 'w:pageBreakBefore'),
|
'pageBreakBefore' => array(self::READ_TRUE, 'w:pageBreakBefore'),
|
||||||
|
'contextualSpacing' => array(self::READ_TRUE, 'w:contextualSpacing'),
|
||||||
|
'bidi' => array(self::READ_TRUE, 'w:bidi'),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
||||||
|
|
@ -369,6 +371,9 @@ abstract class AbstractPart
|
||||||
'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'),
|
'rtl' => array(self::READ_TRUE, 'w:rtl'),
|
||||||
|
'font-latin' => array(self::READ_VALUE, 'w:font', 'w:val'),
|
||||||
|
'font-eastAsia' => array(self::READ_VALUE, 'w:font', 'w:eastAsia'),
|
||||||
|
'font-bidi' => array(self::READ_VALUE, 'w:font', 'w:bidi'),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,9 @@
|
||||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||||
|
|
||||||
use PhpOffice\Common\XMLReader;
|
use PhpOffice\Common\XMLReader;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
|
||||||
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Style\Language;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings reader
|
* Settings reader
|
||||||
|
|
@ -66,6 +67,28 @@ class Settings extends AbstractPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the document Language
|
||||||
|
*
|
||||||
|
* @param XMLReader $xmlReader
|
||||||
|
* @param PhpWord $phpWord
|
||||||
|
* @param \DOMNode $node
|
||||||
|
*/
|
||||||
|
protected function setThemeFontLang(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
|
||||||
|
{
|
||||||
|
|
||||||
|
$val = $xmlReader->getAttribute('w:val', $node);
|
||||||
|
$eastAsia = $xmlReader->getAttribute('w:eastAsia', $node);
|
||||||
|
$bidi = $xmlReader->getAttribute('w:bidi', $node);
|
||||||
|
|
||||||
|
$themeFontLang = new Language();
|
||||||
|
$themeFontLang->setLatin($val);
|
||||||
|
$themeFontLang->setLatin($eastAsia);
|
||||||
|
$themeFontLang->setLatin($bidi);
|
||||||
|
|
||||||
|
$phpWord->getSettings()->setThemeFontLang($themeFontLang);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the document protection
|
* Sets the document protection
|
||||||
*
|
*
|
||||||
|
|
@ -73,7 +96,7 @@ class Settings extends AbstractPart
|
||||||
* @param PhpWord $phpWord
|
* @param PhpWord $phpWord
|
||||||
* @param \DOMNode $node
|
* @param \DOMNode $node
|
||||||
*/
|
*/
|
||||||
protected function setDocumentProtection(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node)
|
protected function setDocumentProtection(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
|
||||||
{
|
{
|
||||||
$documentProtection = $phpWord->getSettings()->getDocumentProtection();
|
$documentProtection = $phpWord->getSettings()->getDocumentProtection();
|
||||||
|
|
||||||
|
|
@ -88,17 +111,17 @@ class Settings extends AbstractPart
|
||||||
* @param PhpWord $phpWord
|
* @param PhpWord $phpWord
|
||||||
* @param \DOMNode $node
|
* @param \DOMNode $node
|
||||||
*/
|
*/
|
||||||
protected function setProofState(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node)
|
protected function setProofState(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
|
||||||
{
|
{
|
||||||
$proofState = $phpWord->getSettings()->getProofState();
|
$proofState = $phpWord->getSettings()->getProofState();
|
||||||
|
|
||||||
$spelling = $xmlReader->getAttribute('w:spelling', $node);
|
$spelling = $xmlReader->getAttribute('w:spelling', $node);
|
||||||
$grammar = $xmlReader->getAttribute('w:grammar', $node);
|
$grammar = $xmlReader->getAttribute('w:grammar', $node);
|
||||||
|
|
||||||
if ($spelling != null) {
|
if ($spelling !== null) {
|
||||||
$proofState->setSpelling($spelling);
|
$proofState->setSpelling($spelling);
|
||||||
}
|
}
|
||||||
if ($grammar != null) {
|
if ($grammar !== null) {
|
||||||
$proofState->setGrammar($grammar);
|
$proofState->setGrammar($grammar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,13 +133,13 @@ class Settings extends AbstractPart
|
||||||
* @param PhpWord $phpWord
|
* @param PhpWord $phpWord
|
||||||
* @param \DOMNode $node
|
* @param \DOMNode $node
|
||||||
*/
|
*/
|
||||||
protected function setZoom(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node)
|
protected function setZoom(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
|
||||||
{
|
{
|
||||||
$percent = $xmlReader->getAttribute('w:percent', $node);
|
$percent = $xmlReader->getAttribute('w:percent', $node);
|
||||||
$val = $xmlReader->getAttribute('w:val', $node);
|
$val = $xmlReader->getAttribute('w:val', $node);
|
||||||
|
|
||||||
if ($percent != null || $val != null) {
|
if ($percent !== null || $val !== null) {
|
||||||
$phpWord->getSettings()->setZoom($percent == null ? $val : $percent);
|
$phpWord->getSettings()->setZoom($percent === null ? $val : $percent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +150,7 @@ class Settings extends AbstractPart
|
||||||
* @param PhpWord $phpWord
|
* @param PhpWord $phpWord
|
||||||
* @param \DOMNode $node
|
* @param \DOMNode $node
|
||||||
*/
|
*/
|
||||||
protected function setRevisionView(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node)
|
protected function setRevisionView(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
|
||||||
{
|
{
|
||||||
$revisionView = new TrackChangesView();
|
$revisionView = new TrackChangesView();
|
||||||
$revisionView->setMarkup($xmlReader->getAttribute('w:markup', $node));
|
$revisionView->setMarkup($xmlReader->getAttribute('w:markup', $node));
|
||||||
|
|
|
||||||
|
|
@ -329,7 +329,7 @@ abstract class AbstractStyle
|
||||||
protected function setPairedVal(&$property, &$pairProperty, $value)
|
protected function setPairedVal(&$property, &$pairProperty, $value)
|
||||||
{
|
{
|
||||||
$property = $this->setBoolVal($value, $property);
|
$property = $this->setBoolVal($value, $property);
|
||||||
if ($value == true) {
|
if ($value === true) {
|
||||||
$pairProperty = false;
|
$pairProperty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,12 @@ class Font extends AbstractStyle
|
||||||
*/
|
*/
|
||||||
private $rtl = false;
|
private $rtl = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Languages
|
||||||
|
* @var \PhpOffice\PhpWord\Style\Language
|
||||||
|
*/
|
||||||
|
private $lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new font style
|
* Create new font style
|
||||||
*
|
*
|
||||||
|
|
@ -276,6 +282,7 @@ class Font extends AbstractStyle
|
||||||
'paragraph' => $this->getParagraph(),
|
'paragraph' => $this->getParagraph(),
|
||||||
'rtl' => $this->isRTL(),
|
'rtl' => $this->isRTL(),
|
||||||
'shading' => $this->getShading(),
|
'shading' => $this->getShading(),
|
||||||
|
'lang' => $this->getLang(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $styles;
|
return $styles;
|
||||||
|
|
@ -783,6 +790,32 @@ class Font extends AbstractStyle
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get language
|
||||||
|
*
|
||||||
|
* @return \PhpOffice\PhpWord\Style\Language
|
||||||
|
*/
|
||||||
|
public function getLang()
|
||||||
|
{
|
||||||
|
return $this->lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set language
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setLang($value = null)
|
||||||
|
{
|
||||||
|
if (is_string($value) && $value != '') {
|
||||||
|
$value = new Language($value);
|
||||||
|
}
|
||||||
|
$this->setObjectVal($value, 'Language', $this->lang);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get bold
|
* Get bold
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,218 @@
|
||||||
|
<?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-2016 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
* A couple of predefined values are defined here, see the websites below for more values
|
||||||
|
*
|
||||||
|
* @see http://www.datypic.com/sc/ooxml/t-w_CT_Language.html
|
||||||
|
* @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx
|
||||||
|
*/
|
||||||
|
final class Language extends AbstractStyle
|
||||||
|
{
|
||||||
|
|
||||||
|
const EN_US = 'en-US';
|
||||||
|
const EN_US_ID = 1033;
|
||||||
|
|
||||||
|
const EN_GB = 'en-GB';
|
||||||
|
const EN_GB_ID = 2057;
|
||||||
|
|
||||||
|
const FR_FR = 'fr-FR';
|
||||||
|
const FR_FR_ID = 1036;
|
||||||
|
|
||||||
|
const FR_BE = 'fr-BE';
|
||||||
|
const FR_BE_ID = 2060;
|
||||||
|
|
||||||
|
const ES_ES = 'es-ES';
|
||||||
|
const ES_ES_ID = 3082;
|
||||||
|
|
||||||
|
const DE_DE = 'de-DE';
|
||||||
|
const DE_DE_ID = 1031;
|
||||||
|
|
||||||
|
const HE_IL = 'he-IL';
|
||||||
|
const HE_IL_ID = 1037;
|
||||||
|
|
||||||
|
const JA_JP = 'ja-JP';
|
||||||
|
const JA_JP_ID = 1041;
|
||||||
|
|
||||||
|
const KO_KR = 'ko-KR';
|
||||||
|
const KO_KR_ID = 1042;
|
||||||
|
|
||||||
|
const ZH_CN = 'zh-CN';
|
||||||
|
const ZH_CN_ID = 2052;
|
||||||
|
|
||||||
|
const HI_IN = 'hi-IN';
|
||||||
|
const HI_IN_ID = 1081;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language ID, used for RTF document generation
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @see https://technet.microsoft.com/en-us/library/cc179219.aspx
|
||||||
|
*/
|
||||||
|
private $langId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Latin Language
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $latin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* East Asian Language
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $eastAsia;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Complex Script Language
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $bidirectional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string|null $latin
|
||||||
|
* @param string|null $eastAsia
|
||||||
|
* @param string|null $bidirectional
|
||||||
|
*/
|
||||||
|
public function __construct($latin = null, $eastAsia = null, $bidirectional = null)
|
||||||
|
{
|
||||||
|
if (!empty($latin)) {
|
||||||
|
$this->setLatin($latin);
|
||||||
|
}
|
||||||
|
if (!empty($eastAsia)) {
|
||||||
|
$this->setEastAsia($eastAsia);
|
||||||
|
}
|
||||||
|
if (!empty($bidirectional)) {
|
||||||
|
$this->setBidirectional($bidirectional);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Latin Language
|
||||||
|
*
|
||||||
|
* @param string $latin
|
||||||
|
* The value for the latin language
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setLatin($latin)
|
||||||
|
{
|
||||||
|
$this->validateLocale($latin);
|
||||||
|
$this->latin = $latin;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Latin Language
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getLatin()
|
||||||
|
{
|
||||||
|
return $this->latin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Language ID
|
||||||
|
*
|
||||||
|
* @param int $langId
|
||||||
|
* The value for the language ID
|
||||||
|
* @return self
|
||||||
|
* @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx
|
||||||
|
*/
|
||||||
|
public function setLangId($langId)
|
||||||
|
{
|
||||||
|
$this->langId = $langId;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Language ID
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getLangId()
|
||||||
|
{
|
||||||
|
return $this->langId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the East Asian Language
|
||||||
|
*
|
||||||
|
* @param string $eastAsia
|
||||||
|
* The value for the east asian language
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setEastAsia($eastAsia)
|
||||||
|
{
|
||||||
|
$this->validateLocale($eastAsia);
|
||||||
|
$this->eastAsia = $eastAsia;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the East Asian Language
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getEastAsia()
|
||||||
|
{
|
||||||
|
return $this->eastAsia;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Complex Script Language
|
||||||
|
*
|
||||||
|
* @param string $bidirectional
|
||||||
|
* The value for the complex script language
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setBidirectional($bidirectional)
|
||||||
|
{
|
||||||
|
$this->validateLocale($bidirectional);
|
||||||
|
$this->bidirectional = $bidirectional;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Complex Script Language
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getBidirectional()
|
||||||
|
{
|
||||||
|
return $this->bidirectional;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates that the language passed is in the format xx-xx
|
||||||
|
*
|
||||||
|
* @param string $locale
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private function validateLocale($locale)
|
||||||
|
{
|
||||||
|
if ($locale !== null && strstr($locale, '-') === false) {
|
||||||
|
throw new \InvalidArgumentException($locale . ' is not a valid language code');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -247,11 +247,12 @@ class ListItem extends AbstractStyle
|
||||||
|
|
||||||
// Populate style and register to global Style register
|
// Populate style and register to global Style register
|
||||||
$style = $listTypeStyles[$this->listType];
|
$style = $listTypeStyles[$this->listType];
|
||||||
|
$numProperties = count($properties);
|
||||||
foreach ($style['levels'] as $key => $value) {
|
foreach ($style['levels'] as $key => $value) {
|
||||||
$level = array();
|
$level = array();
|
||||||
$levelProperties = explode(', ', $value);
|
$levelProperties = explode(', ', $value);
|
||||||
$level['level'] = $key;
|
$level['level'] = $key;
|
||||||
for ($i = 0; $i < count($properties); $i++) {
|
for ($i = 0; $i < $numProperties; $i++) {
|
||||||
$property = $properties[$i];
|
$property = $properties[$i];
|
||||||
$level[$property] = $levelProperties[$i];
|
$level[$property] = $levelProperties[$i];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,13 @@ class Paragraph extends Border
|
||||||
*/
|
*/
|
||||||
private $contextualSpacing = false;
|
private $contextualSpacing = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Right to Left Paragraph Layout
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $bidi = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Style value
|
* Set Style value
|
||||||
*
|
*
|
||||||
|
|
@ -216,6 +223,7 @@ class Paragraph extends Border
|
||||||
'tabs' => $this->getTabs(),
|
'tabs' => $this->getTabs(),
|
||||||
'shading' => $this->getShading(),
|
'shading' => $this->getShading(),
|
||||||
'contextualSpacing' => $this->hasContextualSpacing(),
|
'contextualSpacing' => $this->hasContextualSpacing(),
|
||||||
|
'bidi' => $this->isBidi(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $styles;
|
return $styles;
|
||||||
|
|
@ -762,4 +770,28 @@ class Paragraph extends Border
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get bidirectional
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isBidi()
|
||||||
|
{
|
||||||
|
return $this->bidi;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set bidi
|
||||||
|
*
|
||||||
|
* @param bool $bidi
|
||||||
|
* Set to true to write from right to left
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setBidi($bidi)
|
||||||
|
{
|
||||||
|
$this->bidi = $bidi;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,8 @@ class TextBox extends Image
|
||||||
{
|
{
|
||||||
$hasInnerMargins = false;
|
$hasInnerMargins = false;
|
||||||
$margins = $this->getInnerMargin();
|
$margins = $this->getInnerMargin();
|
||||||
for ($i = 0; $i < count($margins); $i++) {
|
$numMargins = count($margins);
|
||||||
|
for ($i = 0; $i < $numMargins; $i++) {
|
||||||
if ($margins[$i] !== null) {
|
if ($margins[$i] !== null) {
|
||||||
$hasInnerMargins = true;
|
$hasInnerMargins = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,22 +81,27 @@ class Styles extends AbstractPart
|
||||||
$xmlWriter->writeAttribute('style:writing-mode', 'page');
|
$xmlWriter->writeAttribute('style:writing-mode', 'page');
|
||||||
$xmlWriter->endElement(); // style:paragraph-properties
|
$xmlWriter->endElement(); // style:paragraph-properties
|
||||||
|
|
||||||
|
$language = $this->getParentWriter()->getPhpWord()->getSettings()->getThemeFontLang();
|
||||||
|
$latinLang = $language != null && is_string($language->getLatin()) ? explode('-', $language->getLatin()) : array('fr', 'FR');
|
||||||
|
$asianLang = $language != null && is_string($language->getEastAsia()) ? explode('-', $language->getEastAsia()) : array('zh', 'CN');
|
||||||
|
$complexLang = $language != null && is_string($language->getBidirectional()) ? explode('-', $language->getBidirectional()) : array('hi', 'IN');
|
||||||
|
|
||||||
// Font
|
// Font
|
||||||
$xmlWriter->startElement('style:text-properties');
|
$xmlWriter->startElement('style:text-properties');
|
||||||
$xmlWriter->writeAttribute('style:use-window-font-color', 'true');
|
$xmlWriter->writeAttribute('style:use-window-font-color', 'true');
|
||||||
$xmlWriter->writeAttribute('style:font-name', Settings::getDefaultFontName());
|
$xmlWriter->writeAttribute('style:font-name', Settings::getDefaultFontName());
|
||||||
$xmlWriter->writeAttribute('fo:font-size', Settings::getDefaultFontSize() . 'pt');
|
$xmlWriter->writeAttribute('fo:font-size', Settings::getDefaultFontSize() . 'pt');
|
||||||
$xmlWriter->writeAttribute('fo:language', 'fr');
|
$xmlWriter->writeAttribute('fo:language', $latinLang[0]);
|
||||||
$xmlWriter->writeAttribute('fo:country', 'FR');
|
$xmlWriter->writeAttribute('fo:country', $latinLang[1]);
|
||||||
$xmlWriter->writeAttribute('style:letter-kerning', 'true');
|
$xmlWriter->writeAttribute('style:letter-kerning', 'true');
|
||||||
$xmlWriter->writeAttribute('style:font-name-asian', Settings::getDefaultFontName() . '2');
|
$xmlWriter->writeAttribute('style:font-name-asian', Settings::getDefaultFontName() . '2');
|
||||||
$xmlWriter->writeAttribute('style:font-size-asian', Settings::getDefaultFontSize() . 'pt');
|
$xmlWriter->writeAttribute('style:font-size-asian', Settings::getDefaultFontSize() . 'pt');
|
||||||
$xmlWriter->writeAttribute('style:language-asian', 'zh');
|
$xmlWriter->writeAttribute('style:language-asian', $asianLang[0]);
|
||||||
$xmlWriter->writeAttribute('style:country-asian', 'CN');
|
$xmlWriter->writeAttribute('style:country-asian', $asianLang[1]);
|
||||||
$xmlWriter->writeAttribute('style:font-name-complex', Settings::getDefaultFontName() . '2');
|
$xmlWriter->writeAttribute('style:font-name-complex', Settings::getDefaultFontName() . '2');
|
||||||
$xmlWriter->writeAttribute('style:font-size-complex', Settings::getDefaultFontSize() . 'pt');
|
$xmlWriter->writeAttribute('style:font-size-complex', Settings::getDefaultFontSize() . 'pt');
|
||||||
$xmlWriter->writeAttribute('style:language-complex', 'hi');
|
$xmlWriter->writeAttribute('style:language-complex', $complexLang[0]);
|
||||||
$xmlWriter->writeAttribute('style:country-complex', 'IN');
|
$xmlWriter->writeAttribute('style:country-complex', $complexLang[1]);
|
||||||
$xmlWriter->writeAttribute('fo:hyphenate', 'false');
|
$xmlWriter->writeAttribute('fo:hyphenate', 'false');
|
||||||
$xmlWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
|
$xmlWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
|
||||||
$xmlWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
|
$xmlWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,10 @@ class Document extends AbstractPart
|
||||||
*/
|
*/
|
||||||
private function writeFormatting()
|
private function writeFormatting()
|
||||||
{
|
{
|
||||||
|
$docSettings = $this->getParentWriter()->getPhpWord()->getSettings();
|
||||||
|
// Applies a language to a text run (defaults to 1036 : French (France))
|
||||||
|
$langId = $docSettings->getThemeFontLang() != null && $docSettings->getThemeFontLang()->getLangId() != null ? $docSettings->getThemeFontLang()->getLangId() : 1036;
|
||||||
|
|
||||||
$content = '';
|
$content = '';
|
||||||
|
|
||||||
$content .= '\deftab720'; // Set the default tab size (720 twips)
|
$content .= '\deftab720'; // Set the default tab size (720 twips)
|
||||||
|
|
@ -94,7 +98,7 @@ class Document extends AbstractPart
|
||||||
$content .= '\uc1'; // Set the numberof bytes that follows a unicode character
|
$content .= '\uc1'; // Set the numberof bytes that follows a unicode character
|
||||||
$content .= '\pard'; // Resets to default paragraph properties.
|
$content .= '\pard'; // Resets to default paragraph properties.
|
||||||
$content .= '\nowidctlpar'; // No widow/orphan control
|
$content .= '\nowidctlpar'; // No widow/orphan control
|
||||||
$content .= '\lang1036'; // Applies a language to a text run (1036 : French (France))
|
$content .= '\lang' . $langId;
|
||||||
$content .= '\kerning1'; // Point size (in half-points) above which to kern character pairs
|
$content .= '\kerning1'; // Point size (in half-points) above which to kern character pairs
|
||||||
$content .= '\fs' . (Settings::getDefaultFontSize() * 2); // Set the font size in half-points
|
$content .= '\fs' . (Settings::getDefaultFontSize() * 2); // Set the font size in half-points
|
||||||
$content .= PHP_EOL;
|
$content .= PHP_EOL;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Settings as DocumentSettings;
|
|
||||||
use PhpOffice\PhpWord\ComplexType\ProofState;
|
use PhpOffice\PhpWord\ComplexType\ProofState;
|
||||||
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
||||||
|
use PhpOffice\PhpWord\Style\Language;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Word2007 settings part writer: word/settings.xml
|
* Word2007 settings part writer: word/settings.xml
|
||||||
|
|
@ -110,7 +110,6 @@ class Settings extends AbstractPart
|
||||||
'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')),
|
'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')),
|
||||||
'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')),
|
'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')),
|
||||||
'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')),
|
'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')),
|
||||||
'w:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')),
|
|
||||||
'w:decimalSymbol' => array('@attributes' => array('w:val' => $documentSettings->getDecimalSymbol())),
|
'w:decimalSymbol' => array('@attributes' => array('w:val' => $documentSettings->getDecimalSymbol())),
|
||||||
'w:listSeparator' => array('@attributes' => array('w:val' => ';')),
|
'w:listSeparator' => array('@attributes' => array('w:val' => ';')),
|
||||||
'w:compat' => array(),
|
'w:compat' => array(),
|
||||||
|
|
@ -152,6 +151,7 @@ class Settings extends AbstractPart
|
||||||
$this->setOnOffValue('w:doNotTrackFormatting', $documentSettings->hasDoNotTrackFormatting());
|
$this->setOnOffValue('w:doNotTrackFormatting', $documentSettings->hasDoNotTrackFormatting());
|
||||||
$this->setOnOffValue('w:evenAndOddHeaders', $documentSettings->hasEvenAndOddHeaders());
|
$this->setOnOffValue('w:evenAndOddHeaders', $documentSettings->hasEvenAndOddHeaders());
|
||||||
|
|
||||||
|
$this->setThemeFontLang($documentSettings->getThemeFontLang());
|
||||||
$this->setRevisionView($documentSettings->getRevisionView());
|
$this->setRevisionView($documentSettings->getRevisionView());
|
||||||
$this->setDocumentProtection($documentSettings->getDocumentProtection());
|
$this->setDocumentProtection($documentSettings->getDocumentProtection());
|
||||||
$this->setProofState($documentSettings->getProofState());
|
$this->setProofState($documentSettings->getProofState());
|
||||||
|
|
@ -179,7 +179,7 @@ class Settings extends AbstractPart
|
||||||
/**
|
/**
|
||||||
* Get protection settings.
|
* Get protection settings.
|
||||||
*
|
*
|
||||||
* @param \PhpOffice\PhpWord\Metadata\Settings $documentProtection
|
* @param \PhpOffice\PhpWord\Metadata\Protection $documentProtection
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function setDocumentProtection($documentProtection)
|
private function setDocumentProtection($documentProtection)
|
||||||
|
|
@ -212,9 +212,9 @@ class Settings extends AbstractPart
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Proof state
|
* Set the Revision View
|
||||||
*
|
*
|
||||||
* @param ProofState $proofState
|
* @param TrackChangesView $trackChangesView
|
||||||
*/
|
*/
|
||||||
private function setRevisionView(TrackChangesView $trackChangesView = null)
|
private function setRevisionView(TrackChangesView $trackChangesView = null)
|
||||||
{
|
{
|
||||||
|
|
@ -229,6 +229,23 @@ class Settings extends AbstractPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the language
|
||||||
|
*
|
||||||
|
* @param Language $language
|
||||||
|
*/
|
||||||
|
private function setThemeFontLang(Language $language = null)
|
||||||
|
{
|
||||||
|
$latinLanguage = ($language == null || $language->getLatin() === null) ? 'en-US' : $language->getLatin();
|
||||||
|
$lang = array();
|
||||||
|
$lang['w:val'] = $latinLanguage;
|
||||||
|
if ($language != null) {
|
||||||
|
$lang['w:eastAsia'] = $language->getEastAsia() === null ? 'x-none' : $language->getEastAsia();
|
||||||
|
$lang['w:bidi'] = $language->getBidirectional() === null ? 'x-none' : $language->getBidirectional();
|
||||||
|
}
|
||||||
|
$this->settings['w:themeFontLang'] = array('@attributes' => $lang);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the magnification
|
* Set the magnification
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,8 @@ class Styles extends AbstractPart
|
||||||
{
|
{
|
||||||
$fontName = PhpWordSettings::getDefaultFontName();
|
$fontName = PhpWordSettings::getDefaultFontName();
|
||||||
$fontSize = PhpWordSettings::getDefaultFontSize();
|
$fontSize = PhpWordSettings::getDefaultFontSize();
|
||||||
|
$language = $this->getParentWriter()->getPhpWord()->getSettings()->getThemeFontLang();
|
||||||
|
$latinLanguage = ($language == null || $language->getLatin() === null) ? 'en-US' : $language->getLatin();
|
||||||
|
|
||||||
// Default font
|
// Default font
|
||||||
$xmlWriter->startElement('w:docDefaults');
|
$xmlWriter->startElement('w:docDefaults');
|
||||||
|
|
@ -102,6 +104,13 @@ class Styles extends AbstractPart
|
||||||
$xmlWriter->startElement('w:szCs');
|
$xmlWriter->startElement('w:szCs');
|
||||||
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
|
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
|
||||||
$xmlWriter->endElement(); // w:szCs
|
$xmlWriter->endElement(); // w:szCs
|
||||||
|
$xmlWriter->startElement('w:lang');
|
||||||
|
$xmlWriter->writeAttribute('w:val', $latinLanguage);
|
||||||
|
if ($language != null) {
|
||||||
|
$xmlWriter->writeAttributeIf($language->getEastAsia() !== null, 'w:eastAsia', $language->getEastAsia());
|
||||||
|
$xmlWriter->writeAttributeIf($language->getBidirectional() !== null, 'w:bidi', $language->getBidirectional());
|
||||||
|
}
|
||||||
|
$xmlWriter->endElement(); // w:lang
|
||||||
$xmlWriter->endElement(); // w:rPr
|
$xmlWriter->endElement(); // w:rPr
|
||||||
$xmlWriter->endElement(); // w:rPrDefault
|
$xmlWriter->endElement(); // w:rPrDefault
|
||||||
$xmlWriter->endElement(); // w:docDefaults
|
$xmlWriter->endElement(); // w:docDefaults
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ abstract class AbstractStyle
|
||||||
/**
|
/**
|
||||||
* Get Style
|
* Get Style
|
||||||
*
|
*
|
||||||
* @return \PhpOffice\PhpWord\Style\AbstractStyle
|
* @return string|\PhpOffice\PhpWord\Style\AbstractStyle
|
||||||
*/
|
*/
|
||||||
protected function getStyle()
|
protected function getStyle()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,16 @@ class Font extends AbstractStyle
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Language
|
||||||
|
$language = $style->getLang();
|
||||||
|
if ($language != null && ($language->getLatin() !== null || $language->getEastAsia() !== null || $language->getBidirectional() !== null)) {
|
||||||
|
$xmlWriter->startElement('w:lang');
|
||||||
|
$xmlWriter->writeAttributeIf($language->getLatin() !== null, 'w:val', $language->getLatin());
|
||||||
|
$xmlWriter->writeAttributeIf($language->getEastAsia() !== null, 'w:eastAsia', $language->getEastAsia());
|
||||||
|
$xmlWriter->writeAttributeIf($language->getBidirectional() !== null, 'w:bidi', $language->getBidirectional());
|
||||||
|
$xmlWriter->endElement();
|
||||||
|
}
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
$color = $style->getColor();
|
$color = $style->getColor();
|
||||||
$xmlWriter->writeElementIf($color !== null, 'w:color', 'w:val', $color);
|
$xmlWriter->writeElementIf($color !== null, 'w:color', 'w:val', $color);
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,9 @@ class Paragraph extends AbstractStyle
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Right to left
|
||||||
|
$xmlWriter->writeElementIf($styles['bidi'] === true, 'w:bidi');
|
||||||
|
|
||||||
//Paragraph contextualSpacing
|
//Paragraph contextualSpacing
|
||||||
$xmlWriter->writeElementIf($styles['contextualSpacing'] === true, 'w:contextualSpacing');
|
$xmlWriter->writeElementIf($styles['contextualSpacing'] === true, 'w:contextualSpacing');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
|
||||||
use PhpOffice\PhpWord\SimpleType\NumberFormat;
|
use PhpOffice\PhpWord\SimpleType\NumberFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\SimpleType\FootnoteProperties
|
* Test class for PhpOffice\PhpWord\ComplexType\FootnoteProperties
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\SimpleType\FootnoteProperties
|
* @coversDefaultClass \PhpOffice\PhpWord\ComplexType\FootnoteProperties
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase
|
class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?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-2016 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\ComplexType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\ComplexType\ProofState
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\ComplexType\ProofState
|
||||||
|
*/
|
||||||
|
class ProofStateTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the getters and setters
|
||||||
|
*/
|
||||||
|
public function testGetSet()
|
||||||
|
{
|
||||||
|
$pState= new ProofState();
|
||||||
|
$pState->setGrammar(ProofState::CLEAN);
|
||||||
|
$pState->setSpelling(ProofState::DIRTY);
|
||||||
|
|
||||||
|
$this->assertEquals(ProofState::CLEAN, $pState->getGrammar());
|
||||||
|
$this->assertEquals(ProofState::DIRTY, $pState->getSpelling());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test throws exception if wrong grammar proof state value given
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testWrongGrammar()
|
||||||
|
{
|
||||||
|
$pState = new ProofState();
|
||||||
|
$pState->setGrammar('Wrong');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test throws exception if wrong spelling proof state value given
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testWrongSpelling()
|
||||||
|
{
|
||||||
|
$pState= new ProofState();
|
||||||
|
$pState->setSpelling('Wrong');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -74,6 +74,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
||||||
'scale' => null,
|
'scale' => null,
|
||||||
'spacing' => null,
|
'spacing' => null,
|
||||||
'kerning' => null,
|
'kerning' => null,
|
||||||
|
'lang' => null,
|
||||||
);
|
);
|
||||||
foreach ($attributes as $key => $default) {
|
foreach ($attributes as $key => $default) {
|
||||||
$get = is_bool($default) ? "is{$key}" : "get{$key}";
|
$get = is_bool($default) ? "is{$key}" : "get{$key}";
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?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-2016 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Style\Language
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Style\Language
|
||||||
|
*/
|
||||||
|
class LanguageTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test get/set
|
||||||
|
*/
|
||||||
|
public function testGetSetProperties()
|
||||||
|
{
|
||||||
|
$object = new Language();
|
||||||
|
$properties = array(
|
||||||
|
'latin' => array(null, 'fr-BE'),
|
||||||
|
'eastAsia' => array(null, 'ja-JP'),
|
||||||
|
'bidirectional' => array(null, 'ar-SA'),
|
||||||
|
'langId' => array(null, 1036),
|
||||||
|
);
|
||||||
|
foreach ($properties as $property => $value) {
|
||||||
|
list($default, $expected) = $value;
|
||||||
|
$get = "get{$property}";
|
||||||
|
$set = "set{$property}";
|
||||||
|
|
||||||
|
$this->assertEquals($default, $object->$get()); // Default value
|
||||||
|
|
||||||
|
$object->$set($expected);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $object->$get()); // New value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test throws exception if wrong locale is given
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testWrongLanguage()
|
||||||
|
{
|
||||||
|
$language = new Language();
|
||||||
|
$language->setLatin('fr');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -80,6 +80,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
||||||
'keepLines' => true,
|
'keepLines' => true,
|
||||||
'pageBreakBefore' => true,
|
'pageBreakBefore' => true,
|
||||||
'contextualSpacing' => true,
|
'contextualSpacing' => true,
|
||||||
|
'bidi' => true,
|
||||||
);
|
);
|
||||||
foreach ($attributes as $key => $value) {
|
foreach ($attributes as $key => $value) {
|
||||||
$get = $this->findGetter($key, $value, $object);
|
$get = $this->findGetter($key, $value, $object);
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,12 @@
|
||||||
*/
|
*/
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
|
||||||
use PhpOffice\PhpWord\Settings;
|
use PhpOffice\PhpWord\Settings;
|
||||||
use PhpOffice\PhpWord\SimpleType\Zoom;
|
use PhpOffice\PhpWord\SimpleType\Zoom;
|
||||||
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
use PhpOffice\PhpWord\Style\Language;
|
||||||
|
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
|
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
|
||||||
|
|
@ -73,7 +74,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test language
|
* Test language
|
||||||
*/
|
*/
|
||||||
public function testLanguage()
|
public function testDefaultLanguage()
|
||||||
{
|
{
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
||||||
|
|
@ -88,6 +89,26 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals('en-US', $element->getAttribute('w:val'));
|
$this->assertEquals('en-US', $element->getAttribute('w:val'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test language
|
||||||
|
*/
|
||||||
|
public function testLanguage()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->getSettings()->setThemeFontLang(new Language(Language::DE_DE, Language::KO_KR, Language::HE_IL));
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
$file = 'word/settings.xml';
|
||||||
|
|
||||||
|
$path = '/w:settings/w:themeFontLang';
|
||||||
|
$this->assertTrue($doc->elementExists($path, $file));
|
||||||
|
$element = $doc->getElement($path, $file);
|
||||||
|
|
||||||
|
$this->assertEquals(Language::DE_DE, $element->getAttribute('w:val'));
|
||||||
|
$this->assertEquals(Language::KO_KR, $element->getAttribute('w:eastAsia'));
|
||||||
|
$this->assertEquals(Language::HE_IL, $element->getAttribute('w:bidi'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test spelling
|
* Test spelling
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue