diff --git a/src/PHPWord/Section.php b/src/PHPWord/Section.php index 10d1ce6d..d1106d8a 100644 --- a/src/PHPWord/Section.php +++ b/src/PHPWord/Section.php @@ -109,8 +109,10 @@ class PHPWord_Section { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $givenText = utf8_encode($text); - $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } + $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text; } @@ -125,9 +127,13 @@ class PHPWord_Section { * @return PHPWord_Section_Link */ public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null) { - $linkSrc = utf8_encode($linkSrc); + if(!PHPWord_Shared_String::IsUTF8($linkSrc)){ + $linkSrc = utf8_encode($linkSrc); + } if(!is_null($linkName)) { - $linkName = utf8_encode($linkName); + if(!PHPWord_Shared_String::IsUTF8($linkName)){ + $linkName = utf8_encode($linkName); + } } $link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont, $styleParagraph); @@ -179,7 +185,9 @@ class PHPWord_Section { * @return PHPWord_Section_ListItem */ public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $listItem = new PHPWord_Section_ListItem($text, $depth, $styleFont, $styleList, $styleParagraph); $this->_elementCollection[] = $listItem; return $listItem; @@ -287,7 +295,9 @@ class PHPWord_Section { * @return PHPWord_Section_Title */ public function addTitle($text, $depth = 1) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $styles = PHPWord_Style::getStyles(); if(array_key_exists('Heading_'.$depth, $styles)) { $style = 'Heading'.$depth; diff --git a/src/PHPWord/Section/Footer.php b/src/PHPWord/Section/Footer.php index 90cc9a48..39115097 100644 --- a/src/PHPWord/Section/Footer.php +++ b/src/PHPWord/Section/Footer.php @@ -72,8 +72,10 @@ class PHPWord_Section_Footer { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $givenText = utf8_encode($text); - $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } + $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text; } @@ -162,7 +164,9 @@ class PHPWord_Section_Footer { * @return PHPWord_Section_Footer_PreserveText */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; diff --git a/src/PHPWord/Section/Header.php b/src/PHPWord/Section/Header.php index 5ea9919a..6734047e 100644 --- a/src/PHPWord/Section/Header.php +++ b/src/PHPWord/Section/Header.php @@ -72,8 +72,10 @@ class PHPWord_Section_Header { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $givenText = utf8_encode($text); - $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } + $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text; } @@ -162,7 +164,9 @@ class PHPWord_Section_Header { * @return PHPWord_Section_Footer_PreserveText */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; diff --git a/src/PHPWord/Section/Table/Cell.php b/src/PHPWord/Section/Table/Cell.php index 2cf03a62..989042fe 100644 --- a/src/PHPWord/Section/Table/Cell.php +++ b/src/PHPWord/Section/Table/Cell.php @@ -108,7 +108,9 @@ class PHPWord_Section_Table_Cell { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text; @@ -124,9 +126,13 @@ class PHPWord_Section_Table_Cell { */ public function addLink($linkSrc, $linkName = null, $style = null) { if($this->_insideOf == 'section') { - $linkSrc = utf8_encode($linkSrc); + if(!PHPWord_Shared_String::IsUTF8($linkSrc)){ + $linkSrc = utf8_encode($linkSrc); + } if(!is_null($linkName)) { - $linkName = utf8_encode($linkName); + if(!PHPWord_Shared_String::IsUTF8($linkName)){ + $linkName = utf8_encode($linkName); + } } $link = new PHPWord_Section_Link($linkSrc, $linkName, $style); @@ -160,7 +166,9 @@ class PHPWord_Section_Table_Cell { * @return PHPWord_Section_ListItem */ public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList); $this->_elementCollection[] = $listItem; return $listItem; @@ -269,7 +277,9 @@ class PHPWord_Section_Table_Cell { */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { if($this->_insideOf == 'footer' || $this->_insideOf == 'header') { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; diff --git a/src/PHPWord/Section/TextRun.php b/src/PHPWord/Section/TextRun.php index 4f5eece9..6a9bfaca 100644 --- a/src/PHPWord/Section/TextRun.php +++ b/src/PHPWord/Section/TextRun.php @@ -80,8 +80,10 @@ class PHPWord_Section_TextRun { * @return PHPWord_Section_Text */ public function addText($text = null, $styleFont = null) { - $givenText = utf8_encode($text); - $text = new PHPWord_Section_Text($givenText, $styleFont); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } + $text = new PHPWord_Section_Text($text, $styleFont); $this->_elementCollection[] = $text; return $text; } diff --git a/src/PHPWord/Template.php b/src/PHPWord/Template.php index 832776c3..72004253 100644 --- a/src/PHPWord/Template.php +++ b/src/PHPWord/Template.php @@ -86,7 +86,9 @@ class PHPWord_Template { } if(!is_array($replace)) { - $replace = utf8_encode($replace); + if(!PHPWord_Shared_String::IsUTF8($replace)){ + $replace = utf8_encode($replace); + } } $this->_documentXML = str_replace($search, $replace, $this->_documentXML);