Skip to content

This is 2012, assume already have UTF8 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/PHPWord/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getSettings() {
* @return PHPWord_Section_Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null) {
$givenText = utf8_encode($text);
$givenText = $text;
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
Expand All @@ -125,11 +125,7 @@ public function addText($text, $styleFont = null, $styleParagraph = null) {
* @return PHPWord_Section_Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null) {
$linkSrc = utf8_encode($linkSrc);
if(!is_null($linkName)) {
$linkName = utf8_encode($linkName);
}


$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont, $styleParagraph);
$rID = PHPWord_Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
Expand Down Expand Up @@ -179,7 +175,6 @@ public function addTable($style = null) {
* @return PHPWord_Section_ListItem
*/
public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null) {
$text = utf8_encode($text);
$listItem = new PHPWord_Section_ListItem($text, $depth, $styleFont, $styleList, $styleParagraph);
$this->_elementCollection[] = $listItem;
return $listItem;
Expand Down Expand Up @@ -287,7 +282,6 @@ public function addTOC($styleFont = null, $styleTOC = null) {
* @return PHPWord_Section_Title
*/
public function addTitle($text, $depth = 1) {
$text = utf8_encode($text);
$styles = PHPWord_Style::getStyles();
if(array_key_exists('Heading_'.$depth, $styles)) {
$style = 'Heading'.$depth;
Expand Down
3 changes: 1 addition & 2 deletions src/PHPWord/Section/Footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct($sectionCount) {
* @return PHPWord_Section_Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null) {
$givenText = utf8_encode($text);
$givenText = $text;
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
Expand Down Expand Up @@ -162,7 +162,6 @@ public function addMemoryImage($link, $style = null) {
* @return PHPWord_Section_Footer_PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) {
$text = utf8_encode($text);
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
Expand Down
3 changes: 1 addition & 2 deletions src/PHPWord/Section/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct($sectionCount) {
* @return PHPWord_Section_Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null) {
$givenText = utf8_encode($text);
$givenText = $text;
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
Expand Down Expand Up @@ -162,7 +162,6 @@ public function addMemoryImage($link, $style = null) {
* @return PHPWord_Section_Footer_PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) {
$text = utf8_encode($text);
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
Expand Down
9 changes: 1 addition & 8 deletions src/PHPWord/Section/Table/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public function __construct($insideOf, $pCount, $width = null, $style = null) {
* @return PHPWord_Section_Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null) {
$text = utf8_encode($text);
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
Expand All @@ -124,11 +123,7 @@ public function addText($text, $styleFont = null, $styleParagraph = null) {
*/
public function addLink($linkSrc, $linkName = null, $style = null) {
if($this->_insideOf == 'section') {
$linkSrc = utf8_encode($linkSrc);
if(!is_null($linkName)) {
$linkName = utf8_encode($linkName);
}


$link = new PHPWord_Section_Link($linkSrc, $linkName, $style);
$rID = PHPWord_Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
Expand Down Expand Up @@ -160,7 +155,6 @@ public function addTextBreak() {
* @return PHPWord_Section_ListItem
*/
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) {
$text = utf8_encode($text);
$listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList);
$this->_elementCollection[] = $listItem;
return $listItem;
Expand Down Expand Up @@ -269,7 +263,6 @@ public function addObject($src, $style = null) {
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) {
if($this->_insideOf == 'footer' || $this->_insideOf == 'header') {
$text = utf8_encode($text);
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
Expand Down
8 changes: 2 additions & 6 deletions src/PHPWord/Section/TextRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct($styleParagraph = null) {
* @return PHPWord_Section_Text
*/
public function addText($text = null, $styleFont = null) {
$givenText = utf8_encode($text);
$givenText = $text;
$text = new PHPWord_Section_Text($givenText, $styleFont);
$this->_elementCollection[] = $text;
return $text;
Expand All @@ -95,11 +95,7 @@ public function addText($text = null, $styleFont = null) {
* @return PHPWord_Section_Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null) {
$linkSrc = utf8_encode($linkSrc);
if(!is_null($linkName)) {
$linkName = utf8_encode($linkName);
}


$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont);
$rID = PHPWord_Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
Expand Down
4 changes: 1 addition & 3 deletions src/PHPWord/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ public function setValue($search, $replace) {
$search = '${'.$search.'}';
}

if(!is_array($replace)) {
$replace = utf8_encode($replace);
}

$this->_documentXML = str_replace($search, $replace, $this->_documentXML);
}

/**
* Returns array of all variables in template
*/
Expand Down
2 changes: 1 addition & 1 deletion src/PHPWord/Writer/Word2007/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWor

$objWriter->startElement('w:t');
$objWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text
$objWriter->writeRaw($linkName);
$objWriter->writeRaw(htmlspecialchars($linkName));
$objWriter->endElement();
$objWriter->endElement();

Expand Down