Merge branch 'develop' of https://github.com/jhfangying/PHPWord into develop
This commit is contained in:
commit
d180ac7fdf
|
|
@ -44,7 +44,11 @@ class PHPWord
|
||||||
* Default font name (Arial)
|
* Default font name (Arial)
|
||||||
*/
|
*/
|
||||||
const DEFAULT_FONT_NAME = 'Arial';
|
const DEFAULT_FONT_NAME = 'Arial';
|
||||||
|
/**
|
||||||
|
* Default Font Content Type(default)
|
||||||
|
* default|eastAsia|cs
|
||||||
|
*/
|
||||||
|
const DEFAULT_FONT_CONTENT_TYPE='default';
|
||||||
/**
|
/**
|
||||||
* Default font size in points (10pt)
|
* Default font size in points (10pt)
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHPWord
|
* PHPWord
|
||||||
*
|
*
|
||||||
|
|
@ -24,14 +25,13 @@
|
||||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
* @version 0.7.0
|
* @version 0.7.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
|
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PHPWord_Style_Font
|
* Class PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
class PHPWord_Style_Font
|
class PHPWord_Style_Font {
|
||||||
{
|
|
||||||
const UNDERLINE_NONE = 'none';
|
const UNDERLINE_NONE = 'none';
|
||||||
const UNDERLINE_DASH = 'dash';
|
const UNDERLINE_DASH = 'dash';
|
||||||
const UNDERLINE_DASHHEAVY = 'dashHeavy';
|
const UNDERLINE_DASHHEAVY = 'dashHeavy';
|
||||||
|
|
@ -50,7 +50,6 @@ class PHPWord_Style_Font
|
||||||
const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
|
const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
|
||||||
const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
|
const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
|
||||||
const UNDERLINE_WORDS = 'words';
|
const UNDERLINE_WORDS = 'words';
|
||||||
|
|
||||||
const FGCOLOR_YELLOW = 'yellow';
|
const FGCOLOR_YELLOW = 'yellow';
|
||||||
const FGCOLOR_LIGHTGREEN = 'green';
|
const FGCOLOR_LIGHTGREEN = 'green';
|
||||||
const FGCOLOR_CYAN = 'cyan';
|
const FGCOLOR_CYAN = 'cyan';
|
||||||
|
|
@ -158,14 +157,20 @@ class PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
private $lineHeight = 1.0;
|
private $lineHeight = 1.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font Content Type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_hint = PHPWord::DEFAULT_FONT_CONTENT_TYPE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New font style
|
* New font style
|
||||||
*
|
*
|
||||||
* @param string $type Type of font
|
* @param string $type Type of font
|
||||||
* @param array $paragraphStyle Paragraph styles definition
|
* @param array $paragraphStyle Paragraph styles definition
|
||||||
*/
|
*/
|
||||||
public function __construct($type = 'text', $paragraphStyle = null)
|
public function __construct($type = 'text', $paragraphStyle = null) {
|
||||||
{
|
|
||||||
$this->_type = $type;
|
$this->_type = $type;
|
||||||
|
|
||||||
if ($paragraphStyle instanceof PHPWord_Style_Paragraph) {
|
if ($paragraphStyle instanceof PHPWord_Style_Paragraph) {
|
||||||
|
|
@ -182,8 +187,7 @@ class PHPWord_Style_Font
|
||||||
* @param array $style
|
* @param array $style
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setArrayStyle(array $style = array())
|
public function setArrayStyle(array $style = array()) {
|
||||||
{
|
|
||||||
foreach ($style as $key => $value) {
|
foreach ($style as $key => $value) {
|
||||||
if ($key === 'line-height') {
|
if ($key === 'line-height') {
|
||||||
$this->setLineHeight($value);
|
$this->setLineHeight($value);
|
||||||
|
|
@ -203,8 +207,7 @@ class PHPWord_Style_Font
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
public function setStyleValue($key, $value)
|
public function setStyleValue($key, $value) {
|
||||||
{
|
|
||||||
$method = 'set' . substr($key, 1);
|
$method = 'set' . substr($key, 1);
|
||||||
if (method_exists($this, $method)) {
|
if (method_exists($this, $method)) {
|
||||||
$this->$method($value);
|
$this->$method($value);
|
||||||
|
|
@ -216,8 +219,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName() {
|
||||||
{
|
|
||||||
return $this->_name;
|
return $this->_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,22 +229,21 @@ class PHPWord_Style_Font
|
||||||
* @param string $pValue
|
* @param string $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setName($pValue = PHPWord::DEFAULT_FONT_NAME)
|
public function setName($pValue = PHPWord::DEFAULT_FONT_NAME) {
|
||||||
{
|
|
||||||
if (is_null($pValue) || $pValue == '') {
|
if (is_null($pValue) || $pValue == '') {
|
||||||
$pValue = PHPWord::DEFAULT_FONT_NAME;
|
$pValue = PHPWord::DEFAULT_FONT_NAME;
|
||||||
}
|
}
|
||||||
$this->_name = $pValue;
|
$this->_name = $pValue;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get font size
|
* Get font size
|
||||||
*
|
*
|
||||||
* @return int|float
|
* @return int|float
|
||||||
*/
|
*/
|
||||||
public function getSize()
|
public function getSize() {
|
||||||
{
|
|
||||||
return $this->_size;
|
return $this->_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,8 +253,7 @@ class PHPWord_Style_Font
|
||||||
* @param int|float $pValue
|
* @param int|float $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE)
|
public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE) {
|
||||||
{
|
|
||||||
if (!is_numeric($pValue)) {
|
if (!is_numeric($pValue)) {
|
||||||
$pValue = PHPWord::DEFAULT_FONT_SIZE;
|
$pValue = PHPWord::DEFAULT_FONT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
@ -266,8 +266,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getBold()
|
public function getBold() {
|
||||||
{
|
|
||||||
return $this->_bold;
|
return $this->_bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,8 +276,7 @@ class PHPWord_Style_Font
|
||||||
* @param bool $pValue
|
* @param bool $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setBold($pValue = false)
|
public function setBold($pValue = false) {
|
||||||
{
|
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = false;
|
||||||
}
|
}
|
||||||
|
|
@ -291,8 +289,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getItalic()
|
public function getItalic() {
|
||||||
{
|
|
||||||
return $this->_italic;
|
return $this->_italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -302,8 +299,7 @@ class PHPWord_Style_Font
|
||||||
* @param bool $pValue
|
* @param bool $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setItalic($pValue = false)
|
public function setItalic($pValue = false) {
|
||||||
{
|
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = false;
|
||||||
}
|
}
|
||||||
|
|
@ -316,8 +312,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getSuperScript()
|
public function getSuperScript() {
|
||||||
{
|
|
||||||
return $this->_superScript;
|
return $this->_superScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -327,8 +322,7 @@ class PHPWord_Style_Font
|
||||||
* @param bool $pValue
|
* @param bool $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setSuperScript($pValue = false)
|
public function setSuperScript($pValue = false) {
|
||||||
{
|
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = false;
|
||||||
}
|
}
|
||||||
|
|
@ -342,8 +336,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getSubScript()
|
public function getSubScript() {
|
||||||
{
|
|
||||||
return $this->_subScript;
|
return $this->_subScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,8 +346,7 @@ class PHPWord_Style_Font
|
||||||
* @param bool $pValue
|
* @param bool $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setSubScript($pValue = false)
|
public function setSubScript($pValue = false) {
|
||||||
{
|
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = false;
|
||||||
}
|
}
|
||||||
|
|
@ -368,8 +360,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getUnderline()
|
public function getUnderline() {
|
||||||
{
|
|
||||||
return $this->_underline;
|
return $this->_underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,8 +370,7 @@ class PHPWord_Style_Font
|
||||||
* @param string $pValue
|
* @param string $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE)
|
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE) {
|
||||||
{
|
|
||||||
if ($pValue == '') {
|
if ($pValue == '') {
|
||||||
$pValue = PHPWord_Style_Font::UNDERLINE_NONE;
|
$pValue = PHPWord_Style_Font::UNDERLINE_NONE;
|
||||||
}
|
}
|
||||||
|
|
@ -393,8 +383,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getStrikethrough()
|
public function getStrikethrough() {
|
||||||
{
|
|
||||||
return $this->_strikethrough;
|
return $this->_strikethrough;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -404,8 +393,7 @@ class PHPWord_Style_Font
|
||||||
* @param bool $pValue
|
* @param bool $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setStrikethrough($pValue = false)
|
public function setStrikethrough($pValue = false) {
|
||||||
{
|
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = false;
|
||||||
}
|
}
|
||||||
|
|
@ -418,8 +406,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getColor()
|
public function getColor() {
|
||||||
{
|
|
||||||
return $this->_color;
|
return $this->_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -429,8 +416,7 @@ class PHPWord_Style_Font
|
||||||
* @param string $pValue
|
* @param string $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR)
|
public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR) {
|
||||||
{
|
|
||||||
if (is_null($pValue) || $pValue == '') {
|
if (is_null($pValue) || $pValue == '') {
|
||||||
$pValue = PHPWord::DEFAULT_FONT_COLOR;
|
$pValue = PHPWord::DEFAULT_FONT_COLOR;
|
||||||
}
|
}
|
||||||
|
|
@ -443,8 +429,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getFgColor()
|
public function getFgColor() {
|
||||||
{
|
|
||||||
return $this->_fgColor;
|
return $this->_fgColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -454,8 +439,7 @@ class PHPWord_Style_Font
|
||||||
* @param string $pValue
|
* @param string $pValue
|
||||||
* @return PHPWord_Style_Font
|
* @return PHPWord_Style_Font
|
||||||
*/
|
*/
|
||||||
public function setFgColor($pValue = null)
|
public function setFgColor($pValue = null) {
|
||||||
{
|
|
||||||
$this->_fgColor = $pValue;
|
$this->_fgColor = $pValue;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -465,8 +449,7 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getStyleType()
|
public function getStyleType() {
|
||||||
{
|
|
||||||
return $this->_type;
|
return $this->_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -475,12 +458,10 @@ class PHPWord_Style_Font
|
||||||
*
|
*
|
||||||
* @return PHPWord_Style_Paragraph
|
* @return PHPWord_Style_Paragraph
|
||||||
*/
|
*/
|
||||||
public function getParagraphStyle()
|
public function getParagraphStyle() {
|
||||||
{
|
|
||||||
return $this->_paragraphStyle;
|
return $this->_paragraphStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the line height
|
* Set the line height
|
||||||
*
|
*
|
||||||
|
|
@ -488,8 +469,7 @@ class PHPWord_Style_Font
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws InvalidStyleException
|
* @throws InvalidStyleException
|
||||||
*/
|
*/
|
||||||
public function setLineHeight($lineHeight)
|
public function setLineHeight($lineHeight) {
|
||||||
{
|
|
||||||
if (is_string($lineHeight)) {
|
if (is_string($lineHeight)) {
|
||||||
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
|
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
|
||||||
}
|
}
|
||||||
|
|
@ -506,8 +486,28 @@ class PHPWord_Style_Font
|
||||||
/**
|
/**
|
||||||
* @return int|float
|
* @return int|float
|
||||||
*/
|
*/
|
||||||
public function getLineHeight()
|
public function getLineHeight() {
|
||||||
{
|
|
||||||
return $this->lineHeight;
|
return $this->lineHeight;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get Font Content Type
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getHint() {
|
||||||
|
return $this->_hint;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Set Font Content Type
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PHPWord_Style_Font
|
||||||
|
*/
|
||||||
|
public function setHint($pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE) {
|
||||||
|
if (is_null($pValue) || $pValue == '') {
|
||||||
|
$pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
$this->_hint = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHPWord
|
* PHPWord
|
||||||
*
|
*
|
||||||
|
|
@ -28,14 +29,9 @@
|
||||||
/**
|
/**
|
||||||
* Class PHPWord_Writer_Word2007_Base
|
* Class PHPWord_Writer_Word2007_Base
|
||||||
*/
|
*/
|
||||||
class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) {
|
||||||
* Write text
|
|
||||||
*/
|
|
||||||
protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false)
|
|
||||||
{
|
|
||||||
$styleFont = $text->getFontStyle();
|
$styleFont = $text->getFontStyle();
|
||||||
|
|
||||||
$SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
|
$SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
|
||||||
|
|
@ -84,11 +80,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun) {
|
||||||
* Write text run
|
|
||||||
*/
|
|
||||||
protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun)
|
|
||||||
{
|
|
||||||
$elements = $textrun->getElements();
|
$elements = $textrun->getElements();
|
||||||
$styleParagraph = $textrun->getParagraphStyle();
|
$styleParagraph = $textrun->getParagraphStyle();
|
||||||
|
|
||||||
|
|
@ -138,6 +130,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
PHPWord_Style_Paragraph $style,
|
PHPWord_Style_Paragraph $style,
|
||||||
$withoutPPR = false
|
$withoutPPR = false
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$align = $style->getAlign();
|
$align = $style->getAlign();
|
||||||
$spacing = $style->getSpacing();
|
$spacing = $style->getSpacing();
|
||||||
$spaceBefore = $style->getSpaceBefore();
|
$spaceBefore = $style->getSpaceBefore();
|
||||||
|
|
@ -151,9 +144,9 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$pageBreakBefore = $style->getPageBreakBefore();
|
$pageBreakBefore = $style->getPageBreakBefore();
|
||||||
|
|
||||||
if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) ||
|
if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) ||
|
||||||
!is_null($spaceAfter) || !is_null($indent) || !is_null($hanging) ||
|
!is_null($spaceAfter) || !is_null($indent) || !is_null($hanging) ||
|
||||||
!is_null($tabs) || !is_null($widowControl) || !is_null($keepNext) ||
|
!is_null($tabs) || !is_null($widowControl) || !is_null($keepNext) ||
|
||||||
!is_null($keepLines) || !is_null($pageBreakBefore)) {
|
!is_null($keepLines) || !is_null($pageBreakBefore)) {
|
||||||
if (!$withoutPPR) {
|
if (!$withoutPPR) {
|
||||||
$objWriter->startElement('w:pPr');
|
$objWriter->startElement('w:pPr');
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +173,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
|
|
||||||
// Spacing
|
// Spacing
|
||||||
if (!is_null($spaceBefore) || !is_null($spaceAfter) ||
|
if (!is_null($spaceBefore) || !is_null($spaceAfter) ||
|
||||||
!is_null($spacing)) {
|
!is_null($spacing)) {
|
||||||
$objWriter->startElement('w:spacing');
|
$objWriter->startElement('w:spacing');
|
||||||
if (!is_null($spaceBefore)) {
|
if (!is_null($spaceBefore)) {
|
||||||
$objWriter->writeAttribute('w:before', $spaceBefore);
|
$objWriter->writeAttribute('w:before', $spaceBefore);
|
||||||
|
|
@ -228,11 +221,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false) {
|
||||||
* Write table
|
|
||||||
*/
|
|
||||||
protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false)
|
|
||||||
{
|
|
||||||
$rID = $link->getRelationId();
|
$rID = $link->getRelationId();
|
||||||
$linkName = $link->getLinkName();
|
$linkName = $link->getLinkName();
|
||||||
if (is_null($linkName)) {
|
if (is_null($linkName)) {
|
||||||
|
|
@ -287,11 +276,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footer_PreserveText $textrun) {
|
||||||
* Write preserve text
|
|
||||||
*/
|
|
||||||
protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footer_PreserveText $textrun)
|
|
||||||
{
|
|
||||||
$styleFont = $textrun->getFontStyle();
|
$styleFont = $textrun->getFontStyle();
|
||||||
$styleParagraph = $textrun->getParagraphStyle();
|
$styleParagraph = $textrun->getParagraphStyle();
|
||||||
|
|
||||||
|
|
@ -382,11 +367,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$objWriter->endElement(); // p
|
$objWriter->endElement(); // p
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Font $style) {
|
||||||
* Write text style
|
|
||||||
*/
|
|
||||||
protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Font $style)
|
|
||||||
{
|
|
||||||
$font = $style->getName();
|
$font = $style->getName();
|
||||||
$bold = $style->getBold();
|
$bold = $style->getBold();
|
||||||
$italic = $style->getItalic();
|
$italic = $style->getItalic();
|
||||||
|
|
@ -397,6 +378,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$underline = $style->getUnderline();
|
$underline = $style->getUnderline();
|
||||||
$superscript = $style->getSuperScript();
|
$superscript = $style->getSuperScript();
|
||||||
$subscript = $style->getSubScript();
|
$subscript = $style->getSubScript();
|
||||||
|
$hint = $style->getHint();
|
||||||
|
|
||||||
$objWriter->startElement('w:rPr');
|
$objWriter->startElement('w:rPr');
|
||||||
|
|
||||||
|
|
@ -405,10 +387,16 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$objWriter->startElement('w:rFonts');
|
$objWriter->startElement('w:rFonts');
|
||||||
$objWriter->writeAttribute('w:ascii', $font);
|
$objWriter->writeAttribute('w:ascii', $font);
|
||||||
$objWriter->writeAttribute('w:hAnsi', $font);
|
$objWriter->writeAttribute('w:hAnsi', $font);
|
||||||
|
$objWriter->writeAttribute('w:eastAsia', $font);
|
||||||
$objWriter->writeAttribute('w:cs', $font);
|
$objWriter->writeAttribute('w:cs', $font);
|
||||||
|
//Font Content Type
|
||||||
|
if ($hint != PHPWord::DEFAULT_FONT_CONTENT_TYPE) {
|
||||||
|
$objWriter->writeAttribute('w:hint', $hint);
|
||||||
|
}
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
if ($color != PHPWord::DEFAULT_FONT_COLOR) {
|
if ($color != PHPWord::DEFAULT_FONT_COLOR) {
|
||||||
$objWriter->startElement('w:color');
|
$objWriter->startElement('w:color');
|
||||||
|
|
@ -466,19 +454,11 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) {
|
||||||
* Write text break
|
|
||||||
*/
|
|
||||||
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null)
|
|
||||||
{
|
|
||||||
$objWriter->writeElement('w:p', null);
|
$objWriter->writeElement('w:p', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table) {
|
||||||
* Write table
|
|
||||||
*/
|
|
||||||
protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table)
|
|
||||||
{
|
|
||||||
$_rows = $table->getRows();
|
$_rows = $table->getRows();
|
||||||
$_cRows = count($_rows);
|
$_cRows = count($_rows);
|
||||||
|
|
||||||
|
|
@ -520,14 +500,14 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$objWriter->writeAttribute('w:val', $height);
|
$objWriter->writeAttribute('w:val', $height);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
if ($tblHeader) {
|
if (!is_null($tblHeader)) {
|
||||||
$objWriter->startElement('w:tblHeader');
|
$objWriter->startElement('w:tblHeader');
|
||||||
$objWriter->writeAttribute('w:val', '1');
|
$objWriter->writeAttribute('w:val', $tblHeader);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
if ($cantSplit) {
|
if (!is_null($cantSplit)) {
|
||||||
$objWriter->startElement('w:cantSplit');
|
$objWriter->startElement('w:cantSplit');
|
||||||
$objWriter->writeAttribute('w:val', '1');
|
$objWriter->writeAttribute('w:val', $cantSplit);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
@ -565,7 +545,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
} elseif ($element instanceof PHPWord_Section_ListItem) {
|
} elseif ($element instanceof PHPWord_Section_ListItem) {
|
||||||
$this->_writeListItem($objWriter, $element);
|
$this->_writeListItem($objWriter, $element);
|
||||||
} elseif ($element instanceof PHPWord_Section_Image ||
|
} elseif ($element instanceof PHPWord_Section_Image ||
|
||||||
$element instanceof PHPWord_Section_MemoryImage
|
$element instanceof PHPWord_Section_MemoryImage
|
||||||
) {
|
) {
|
||||||
$this->_writeImage($objWriter, $element);
|
$this->_writeImage($objWriter, $element);
|
||||||
} elseif ($element instanceof PHPWord_Section_Object) {
|
} elseif ($element instanceof PHPWord_Section_Object) {
|
||||||
|
|
@ -586,11 +566,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Table $style = null) {
|
||||||
* Write table style
|
|
||||||
*/
|
|
||||||
protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Table $style = null)
|
|
||||||
{
|
|
||||||
$margins = $style->getCellMargin();
|
$margins = $style->getCellMargin();
|
||||||
$mTop = (!is_null($margins[0])) ? true : false;
|
$mTop = (!is_null($margins[0])) ? true : false;
|
||||||
$mLeft = (!is_null($margins[1])) ? true : false;
|
$mLeft = (!is_null($margins[1])) ? true : false;
|
||||||
|
|
@ -634,11 +610,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null) {
|
||||||
* Write cell style
|
|
||||||
*/
|
|
||||||
protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null)
|
|
||||||
{
|
|
||||||
$bgColor = $style->getBgColor();
|
$bgColor = $style->getBgColor();
|
||||||
$valign = $style->getVAlign();
|
$valign = $style->getVAlign();
|
||||||
$textDir = $style->getTextDirection();
|
$textDir = $style->getTextDirection();
|
||||||
|
|
@ -744,8 +716,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
* @param \PHPWord_Shared_XMLWriter $objWriter
|
* @param \PHPWord_Shared_XMLWriter $objWriter
|
||||||
* @param \PHPWord_Section_Image $image
|
* @param \PHPWord_Section_Image $image
|
||||||
*/
|
*/
|
||||||
protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image, $withoutP = false)
|
protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image, $withoutP = false) {
|
||||||
{
|
|
||||||
$rId = $image->getRelationId();
|
$rId = $image->getRelationId();
|
||||||
|
|
||||||
$style = $image->getStyle();
|
$style = $image->getStyle();
|
||||||
|
|
@ -821,11 +792,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image) {
|
||||||
* Write watermark
|
|
||||||
*/
|
|
||||||
protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image)
|
|
||||||
{
|
|
||||||
$rId = $image->getRelationId();
|
$rId = $image->getRelationId();
|
||||||
|
|
||||||
$style = $image->getStyle();
|
$style = $image->getStyle();
|
||||||
|
|
@ -868,11 +835,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Title $title) {
|
||||||
* Write title
|
|
||||||
*/
|
|
||||||
protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Title $title)
|
|
||||||
{
|
|
||||||
$text = htmlspecialchars($title->getText());
|
$text = htmlspecialchars($title->getText());
|
||||||
$text = PHPWord_Shared_String::ControlCharacterPHP2OOXML($text);
|
$text = PHPWord_Shared_String::ControlCharacterPHP2OOXML($text);
|
||||||
$anchor = $title->getAnchor();
|
$anchor = $title->getAnchor();
|
||||||
|
|
@ -913,9 +876,6 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Write footnote
|
|
||||||
*/
|
|
||||||
protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote)
|
protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote)
|
||||||
{
|
{
|
||||||
$objWriter->startElement('w:footnote');
|
$objWriter->startElement('w:footnote');
|
||||||
|
|
@ -951,9 +911,6 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
||||||
$objWriter->endElement(); // w:footnote
|
$objWriter->endElement(); // w:footnote
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Write footnote reference
|
|
||||||
*/
|
|
||||||
protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false)
|
protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false)
|
||||||
{
|
{
|
||||||
if (!$withoutP) {
|
if (!$withoutP) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||||
|
define('EOL', PHP_EOL);
|
||||||
|
} else {
|
||||||
|
define('EOL', '<br />');
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once '../Classes/PHPWord.php';
|
||||||
|
|
||||||
|
// New Word Document
|
||||||
|
echo date('H:i:s') , ' Create new PHPWord object' , EOL;
|
||||||
|
$PHPWord = new PHPWord();
|
||||||
|
$section = $PHPWord->createSection();
|
||||||
|
$header = array('size' => 16, 'bold' => true);
|
||||||
|
//1.Use EastAisa FontStyle
|
||||||
|
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
|
||||||
|
|
||||||
|
// Save File
|
||||||
|
echo date('H:i:s') , ' Write to Word2007 format' , EOL;
|
||||||
|
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
|
||||||
|
$objWriter->save(str_replace('.php', '.docx', __FILE__));
|
||||||
|
|
||||||
|
// Echo memory peak usage
|
||||||
|
echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL;
|
||||||
|
|
||||||
|
// Echo done
|
||||||
|
echo date('H:i:s') , ' Done writing file' , EOL;
|
||||||
Loading…
Reference in New Issue